@@ -2,6 +2,7 @@ import * as fs from "fs-extra"
22import * as path from "path"
33import { extend , paths } from "./util"
44import { logger } from "@coder/logger"
5+ import { Route } from "./http"
56
67export type Settings = { [ key : string ] : Settings | string | boolean | number }
78
@@ -29,11 +30,13 @@ export class SettingsProvider<T> {
2930
3031 /**
3132 * Write settings combined with current settings. On failure log a warning.
32- * Objects will be merged and everything else will be replaced .
33+ * Settings can be shallow or deep merged .
3334 */
34- public async write ( settings : Partial < T > ) : Promise < void > {
35+ public async write ( settings : Partial < T > , shallow = true ) : Promise < void > {
3536 try {
36- await fs . writeFile ( this . settingsPath , JSON . stringify ( extend ( await this . read ( ) , settings ) , null , 2 ) )
37+ const oldSettings = await this . read ( )
38+ const nextSettings = shallow ? Object . assign ( { } , oldSettings , settings ) : extend ( oldSettings , settings )
39+ await fs . writeFile ( this . settingsPath , JSON . stringify ( nextSettings , null , 2 ) )
3740 } catch ( error ) {
3841 logger . warn ( error . message )
3942 }
@@ -55,6 +58,7 @@ export interface CoderSettings extends UpdateSettings {
5558 url : string
5659 workspace : boolean
5760 }
61+ query : Route [ "query" ]
5862}
5963
6064/**
0 commit comments