Skip to content

Commit ecb9bb2

Browse files
committed
refactor: write lastVisited and query at the same time
In addition, the `settings.write` method now uses shallow merge by default
1 parent b6e791f commit ecb9bb2

File tree

2 files changed

+5
-10
lines changed

2 files changed

+5
-10
lines changed

src/node/app/vscode.ts

+3-8
Original file line numberDiff line numberDiff line change
@@ -183,14 +183,9 @@ export class VscodeHttpProvider extends HttpProvider {
183183
}),
184184
])
185185

186-
let promise = Promise.resolve()
187-
if (startPath) {
188-
promise = settings.write({ lastVisited: startPath })
189-
}
190-
// `settings.write` depends on `settings.read` internally. To avoid race conditions, a promise is added here to synchronize.
191-
promise.then(() => {
192-
// the query should not be extends, but should be replaced directly.
193-
settings.write({ query: route.query }, true)
186+
settings.write({
187+
lastVisited: startPath || lastVisited, // If startpath is undefined, then fallback to lastVisited
188+
query: route.query,
194189
})
195190

196191
if (!this.isDev) {

src/node/settings.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ export class SettingsProvider<T> {
3030

3131
/**
3232
* Write settings combined with current settings. On failure log a warning.
33-
* Objects will be merged and everything else will be replaced.
33+
* Settings can be shallow or deep merged.
3434
*/
35-
public async write(settings: Partial<T>, shallow?: boolean): Promise<void> {
35+
public async write(settings: Partial<T>, shallow = true): Promise<void> {
3636
try {
3737
const oldSettings = await this.read()
3838
const nextSettings = shallow ? Object.assign({}, oldSettings, settings) : extend(oldSettings, settings)

0 commit comments

Comments
 (0)