diff --git a/src/node/app/vscode.ts b/src/node/app/vscode.ts index 37cf1046..8965fb6f 100644 --- a/src/node/app/vscode.ts +++ b/src/node/app/vscode.ts @@ -183,11 +183,10 @@ export class VscodeHttpProvider extends HttpProvider { }), ]) - if (startPath) { - settings.write({ - lastVisited: startPath, - }) - } + settings.write({ + lastVisited: startPath || lastVisited, // If startpath is undefined, then fallback to lastVisited + query: route.query, + }) if (!this.isDev) { response.content = response.content.replace(//g, "") diff --git a/src/node/settings.ts b/src/node/settings.ts index 32166ddb..7564b531 100644 --- a/src/node/settings.ts +++ b/src/node/settings.ts @@ -2,6 +2,7 @@ import * as fs from "fs-extra" import * as path from "path" import { extend, paths } from "./util" import { logger } from "@coder/logger" +import { Route } from "./http" export type Settings = { [key: string]: Settings | string | boolean | number } @@ -29,11 +30,13 @@ export class SettingsProvider { /** * Write settings combined with current settings. On failure log a warning. - * Objects will be merged and everything else will be replaced. + * Settings can be shallow or deep merged. */ - public async write(settings: Partial): Promise { + public async write(settings: Partial, shallow = true): Promise { try { - await fs.writeFile(this.settingsPath, JSON.stringify(extend(await this.read(), settings), null, 2)) + const oldSettings = await this.read() + const nextSettings = shallow ? Object.assign({}, oldSettings, settings) : extend(oldSettings, settings) + await fs.writeFile(this.settingsPath, JSON.stringify(nextSettings, null, 2)) } catch (error) { logger.warn(error.message) } @@ -55,6 +58,7 @@ export interface CoderSettings extends UpdateSettings { url: string workspace: boolean } + query: Route["query"] } /**