Skip to content

Commit 3761f7b

Browse files
authored
Patch VS Code to wait for storage write (#2049)
VS Code has a short delay before writing storage (probably to queue up rapid changes). In the web version of VS Code this happens on the client which means if the page is reloaded before the delay expires the write never happens. Storage updates are already promises so this simply returns the promise returned by the delayer so it won't resolve until the write actually happens. Fixes #2021.
1 parent ceceef1 commit 3761f7b

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

ci/dev/vscode.patch

+61
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,49 @@ index 2185bb5228c..35463ca6520 100644
696696
(err: any, socket: ISocket | undefined) => {
697697
if (err || !socket) {
698698
options.logService.error(`${logPrefix} socketFactory.connect() failed. Error:`);
699+
diff --git a/src/vs/platform/storage/browser/storageService.ts b/src/vs/platform/storage/browser/storageService.ts
700+
index 59b1baf912..cf9805554b 100644
701+
--- a/src/vs/platform/storage/browser/storageService.ts
702+
+++ b/src/vs/platform/storage/browser/storageService.ts
703+
@@ -116,8 +116,8 @@ export class BrowserStorageService extends Disposable implements IStorageService
704+
return this.getStorage(scope).getNumber(key, fallbackValue);
705+
}
706+
707+
- store(key: string, value: string | boolean | number | undefined | null, scope: StorageScope): void {
708+
- this.getStorage(scope).set(key, value);
709+
+ store(key: string, value: string | boolean | number | undefined | null, scope: StorageScope): Promise<void> {
710+
+ return this.getStorage(scope).set(key, value);
711+
}
712+
713+
remove(key: string, scope: StorageScope): void {
714+
diff --git a/src/vs/platform/storage/common/storage.ts b/src/vs/platform/storage/common/storage.ts
715+
index 1623957cb1..d366438d54 100644
716+
--- a/src/vs/platform/storage/common/storage.ts
717+
+++ b/src/vs/platform/storage/common/storage.ts
718+
@@ -83,7 +83,7 @@ export interface IStorageService {
719+
* The scope argument allows to define the scope of the storage
720+
* operation to either the current workspace only or all workspaces.
721+
*/
722+
- store(key: string, value: string | boolean | number | undefined | null, scope: StorageScope): void;
723+
+ store(key: string, value: string | boolean | number | undefined | null, scope: StorageScope): Promise<void> | void;
724+
725+
/**
726+
* Delete an element stored under the provided key from storage.
727+
diff --git a/src/vs/platform/storage/node/storageService.ts b/src/vs/platform/storage/node/storageService.ts
728+
index 75514fe5a4..62d97c6048 100644
729+
--- a/src/vs/platform/storage/node/storageService.ts
730+
+++ b/src/vs/platform/storage/node/storageService.ts
731+
@@ -204,8 +204,8 @@ export class NativeStorageService extends Disposable implements IStorageService
732+
return this.getStorage(scope).getNumber(key, fallbackValue);
733+
}
734+
735+
- store(key: string, value: string | boolean | number | undefined | null, scope: StorageScope): void {
736+
- this.getStorage(scope).set(key, value);
737+
+ store(key: string, value: string | boolean | number | undefined | null, scope: StorageScope): Promise<void> {
738+
+ return this.getStorage(scope).set(key, value);
739+
}
740+
741+
remove(key: string, scope: StorageScope): void {
699742
diff --git a/src/vs/server/browser/client.ts b/src/vs/server/browser/client.ts
700743
new file mode 100644
701744
index 00000000000..3c0703b7174
@@ -2811,6 +2854,24 @@ index 3d77009b908..11deb1b99ac 100644
28112854
import './mainThreadTunnelService';
28122855
import './mainThreadAuthentication';
28132856
import './mainThreadTimeline';
2857+
diff --git a/src/vs/workbench/api/browser/mainThreadStorage.ts b/src/vs/workbench/api/browser/mainThreadStorage.ts
2858+
index 7bc3904963..c6db2368ae 100644
2859+
--- a/src/vs/workbench/api/browser/mainThreadStorage.ts
2860+
+++ b/src/vs/workbench/api/browser/mainThreadStorage.ts
2861+
@@ -58,11 +58,11 @@ export class MainThreadStorage implements MainThreadStorageShape {
2862+
return JSON.parse(jsonValue);
2863+
}
2864+
2865+
- $setValue(shared: boolean, key: string, value: object): Promise<void> {
2866+
+ async $setValue(shared: boolean, key: string, value: object): Promise<void> {
2867+
let jsonValue: string;
2868+
try {
2869+
jsonValue = JSON.stringify(value);
2870+
- this._storageService.store(key, jsonValue, shared ? StorageScope.GLOBAL : StorageScope.WORKSPACE);
2871+
+ await this._storageService.store(key, jsonValue, shared ? StorageScope.GLOBAL : StorageScope.WORKSPACE);
2872+
} catch (err) {
2873+
return Promise.reject(err);
2874+
}
28142875
diff --git a/src/vs/workbench/api/common/extHost.api.impl.ts b/src/vs/workbench/api/common/extHost.api.impl.ts
28152876
index 97793666ad8..13cd137db1e 100644
28162877
--- a/src/vs/workbench/api/common/extHost.api.impl.ts

0 commit comments

Comments
 (0)