Skip to content

Commit 084fb5c

Browse files
author
Benjamin Pasero
committed
sqlite - more adoption of next storage service
1 parent fbdb6f5 commit 084fb5c

10 files changed

Lines changed: 106 additions & 97 deletions

File tree

src/vs/platform/storage2/common/storage2.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
77
import { Event } from 'vs/base/common/event';
8+
import { ShutdownReason } from 'vs/platform/lifecycle/common/lifecycle';
89

910
export const INextStorage2Service = createDecorator<INextStorage2Service>('nextStorage2Service');
1011

@@ -21,7 +22,7 @@ export interface INextStorage2Service {
2122
* to persist data to ensure it is stored before the application shuts
2223
* down.
2324
*/
24-
readonly onWillClose: Event<void>;
25+
readonly onWillClose: Event<ShutdownReason>;
2526

2627
/**
2728
* Retrieve an element stored with the given key from storage. Use

src/vs/platform/storage2/electron-browser/nextStorage2Service.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,16 @@ import { Storage, IStorageLoggingOptions } from 'vs/base/node/storage';
1212
import { IStorageService, StorageScope as LocalStorageScope } from 'vs/platform/storage/common/storage';
1313
import { addDisposableListener } from 'vs/base/browser/dom';
1414
import { startsWith } from 'vs/base/common/strings';
15+
import { ShutdownReason } from 'vs/platform/lifecycle/common/lifecycle';
1516

1617
export class NextStorage2Service extends Disposable implements INextStorage2Service {
1718
_serviceBrand: any;
1819

1920
private _onDidChangeStorage: Emitter<IWorkspaceStorageChangeEvent> = this._register(new Emitter<IWorkspaceStorageChangeEvent>());
2021
get onDidChangeStorage(): Event<IWorkspaceStorageChangeEvent> { return this._onDidChangeStorage.event; }
2122

22-
private _onWillClose: Emitter<void> = this._register(new Emitter<void>());
23-
get onWillClose(): Event<void> { return this._onWillClose.event; }
23+
private _onWillClose: Emitter<ShutdownReason> = this._register(new Emitter<ShutdownReason>());
24+
get onWillClose(): Event<ShutdownReason> { return this._onWillClose.event; }
2425

2526
private globalStorage: Storage;
2627
private workspaceStorage: Storage;
@@ -77,10 +78,10 @@ export class NextStorage2Service extends Disposable implements INextStorage2Serv
7778
return this.getStorage(scope).delete(key);
7879
}
7980

80-
close(): Promise<void> {
81+
close(reason: ShutdownReason): Promise<void> {
8182

8283
// Signal as event so that clients can still store data
83-
this._onWillClose.fire();
84+
this._onWillClose.fire(reason);
8485

8586
// Do it
8687
return Promise.all([
@@ -100,8 +101,8 @@ export class NextDelegatingStorage2Service extends Disposable implements INextSt
100101
private _onDidChangeStorage: Emitter<IWorkspaceStorageChangeEvent> = this._register(new Emitter<IWorkspaceStorageChangeEvent>());
101102
get onDidChangeStorage(): Event<IWorkspaceStorageChangeEvent> { return this._onDidChangeStorage.event; }
102103

103-
private _onWillClose: Emitter<void> = this._register(new Emitter<void>());
104-
get onWillClose(): Event<void> { return this._onWillClose.event; }
104+
private _onWillClose: Emitter<ShutdownReason> = this._register(new Emitter<ShutdownReason>());
105+
get onWillClose(): Event<ShutdownReason> { return this._onWillClose.event; }
105106

106107
constructor(
107108
@INextStorage2Service private nextStorage2Service: NextStorage2Service,
@@ -116,7 +117,7 @@ export class NextDelegatingStorage2Service extends Disposable implements INextSt
116117

117118
private registerListeners(): void {
118119
this._register(this.nextStorage2Service.onDidChangeStorage(e => this._onDidChangeStorage.fire(e)));
119-
this._register(this.nextStorage2Service.onWillClose(e => this._onWillClose.fire()));
120+
this._register(this.nextStorage2Service.onWillClose(reason => this._onWillClose.fire(reason)));
120121

121122
const globalKeyMarker = 'storage://global/';
122123
this._register(addDisposableListener(window, 'storage', (e: StorageEvent) => {
@@ -173,8 +174,8 @@ export class NextDelegatingStorage2Service extends Disposable implements INextSt
173174
return this.nextStorage2Service.delete(key, scope);
174175
}
175176

176-
close(): Promise<void> {
177-
return this.nextStorage2Service.close();
177+
close(reason: ShutdownReason): Promise<void> {
178+
return this.nextStorage2Service.close(reason);
178179
}
179180

180181
private convertScope(scope: StorageScope): LocalStorageScope {

src/vs/workbench/electron-browser/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ function openWorkbench(configuration: IWindowConfiguration): Promise<void> {
121121

122122
// Gracefully Shutdown Storage
123123
shell.onShutdown(event => {
124-
event.join(nextStorage2Service.close());
124+
event.join(nextStorage2Service.close(event.reason));
125125
});
126126

127127
// Open Shell

src/vs/workbench/electron-browser/workbench.ts

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import { QuickInputService } from 'vs/workbench/browser/parts/quickinput/quickIn
3737
import { getServices } from 'vs/platform/instantiation/common/extensions';
3838
import { Position, Parts, IPartService, ILayoutOptions, IDimension, PositionToString } from 'vs/workbench/services/part/common/partService';
3939
import { IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/common/workspace';
40-
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
40+
import { INextStorage2Service, StorageScope } from 'vs/platform/storage2/common/storage2';
4141
import { ContextMenuService as NativeContextMenuService } from 'vs/workbench/services/contextview/electron-browser/contextmenuService';
4242
import { ContextMenuService as HTMLContextMenuService } from 'vs/platform/contextview/browser/contextMenuService';
4343
import { WorkbenchKeybindingService } from 'vs/workbench/services/keybinding/electron-browser/keybindingService';
@@ -239,7 +239,7 @@ export class Workbench extends Disposable implements IPartService {
239239
private mainProcessClient: IPCClient,
240240
@IInstantiationService private instantiationService: IInstantiationService,
241241
@IWorkspaceContextService private contextService: IWorkspaceContextService,
242-
@IStorageService private storageService: IStorageService,
242+
@INextStorage2Service private nextStorage2Service: INextStorage2Service,
243243
@IConfigurationService private configurationService: WorkspaceService,
244244
@IWorkbenchThemeService private themeService: WorkbenchThemeService,
245245
@IEnvironmentService private environmentService: IEnvironmentService,
@@ -483,6 +483,9 @@ export class Workbench extends Disposable implements IPartService {
483483

484484
private registerListeners(): void {
485485

486+
// Storage lifecycle
487+
this._register(this.nextStorage2Service.onWillClose(reason => this.saveState(reason)));
488+
486489
// Listen to visible editor changes
487490
this._register(this.editorService.onDidVisibleEditorsChange(() => this.onDidVisibleEditorsChange()));
488491

@@ -738,7 +741,7 @@ export class Workbench extends Disposable implements IPartService {
738741
this.sideBarVisibleContext.set(true);
739742

740743
if (this.shouldRestoreLastOpenedViewlet()) {
741-
viewletIdToRestore = this.storageService.get(SidebarPart.activeViewletSettingsKey, StorageScope.WORKSPACE);
744+
viewletIdToRestore = this.nextStorage2Service.get(SidebarPart.activeViewletSettingsKey, StorageScope.WORKSPACE);
742745
}
743746

744747
if (!viewletIdToRestore) {
@@ -755,7 +758,7 @@ export class Workbench extends Disposable implements IPartService {
755758

756759
// Restore Panel
757760
const panelRegistry = Registry.as<PanelRegistry>(PanelExtensions.Panels);
758-
const panelId = this.storageService.get(PanelPart.activePanelSettingsKey, StorageScope.WORKSPACE, panelRegistry.getDefaultPanelId());
761+
const panelId = this.nextStorage2Service.get(PanelPart.activePanelSettingsKey, StorageScope.WORKSPACE, panelRegistry.getDefaultPanelId());
759762
if (!this.panelHidden && !!panelId) {
760763
perf.mark('willRestorePanel');
761764
const isPanelToRestoreEnabled = !!this.panelPart.getPanels().filter(p => p.id === panelId).length;
@@ -764,12 +767,12 @@ export class Workbench extends Disposable implements IPartService {
764767
}
765768

766769
// Restore Zen Mode if active
767-
if (this.storageService.getBoolean(Workbench.zenModeActiveStorageKey, StorageScope.WORKSPACE, false)) {
770+
if (this.nextStorage2Service.getBoolean(Workbench.zenModeActiveStorageKey, StorageScope.WORKSPACE, false)) {
768771
this.toggleZenMode(true, true);
769772
}
770773

771774
// Restore Forced Editor Center Mode
772-
if (this.storageService.getBoolean(Workbench.centeredEditorLayoutActiveStorageKey, StorageScope.WORKSPACE, false)) {
775+
if (this.nextStorage2Service.getBoolean(Workbench.centeredEditorLayoutActiveStorageKey, StorageScope.WORKSPACE, false)) {
773776
this.centerEditorLayout(true);
774777
}
775778

@@ -796,9 +799,9 @@ export class Workbench extends Disposable implements IPartService {
796799
return true; // always restore sidebar when we are in development mode
797800
}
798801

799-
const restore = this.storageService.getBoolean(Workbench.sidebarRestoreStorageKey, StorageScope.WORKSPACE);
802+
const restore = this.nextStorage2Service.getBoolean(Workbench.sidebarRestoreStorageKey, StorageScope.WORKSPACE);
800803
if (restore) {
801-
this.storageService.remove(Workbench.sidebarRestoreStorageKey, StorageScope.WORKSPACE); // only support once
804+
this.nextStorage2Service.delete(Workbench.sidebarRestoreStorageKey, StorageScope.WORKSPACE); // only support once
802805
}
803806

804807
return restore;
@@ -889,11 +892,11 @@ export class Workbench extends Disposable implements IPartService {
889892
private initSettings(): void {
890893

891894
// Sidebar visibility
892-
this.sideBarHidden = this.storageService.getBoolean(Workbench.sidebarHiddenStorageKey, StorageScope.WORKSPACE, this.contextService.getWorkbenchState() === WorkbenchState.EMPTY);
895+
this.sideBarHidden = this.nextStorage2Service.getBoolean(Workbench.sidebarHiddenStorageKey, StorageScope.WORKSPACE, this.contextService.getWorkbenchState() === WorkbenchState.EMPTY);
893896

894897
// Panel part visibility
895898
const panelRegistry = Registry.as<PanelRegistry>(PanelExtensions.Panels);
896-
this.panelHidden = this.storageService.getBoolean(Workbench.panelHiddenStorageKey, StorageScope.WORKSPACE, true);
899+
this.panelHidden = this.nextStorage2Service.getBoolean(Workbench.panelHiddenStorageKey, StorageScope.WORKSPACE, true);
897900
if (!panelRegistry.getDefaultPanelId()) {
898901
this.panelHidden = true; // we hide panel part if there is no default panel
899902
}
@@ -933,7 +936,8 @@ export class Workbench extends Disposable implements IPartService {
933936

934937
private setPanelPositionFromStorageOrConfig() {
935938
const defaultPanelPosition = this.configurationService.getValue<string>(Workbench.defaultPanelPositionStorageKey);
936-
const panelPosition = this.storageService.get(Workbench.panelPositionStorageKey, StorageScope.WORKSPACE, defaultPanelPosition);
939+
const panelPosition = this.nextStorage2Service.get(Workbench.panelPositionStorageKey, StorageScope.WORKSPACE, defaultPanelPosition);
940+
937941
this.panelPosition = (panelPosition === 'right') ? Position.RIGHT : Position.BOTTOM;
938942
}
939943

@@ -1132,25 +1136,29 @@ export class Workbench extends Disposable implements IPartService {
11321136
return this.instantiationService;
11331137
}
11341138

1135-
dispose(reason = ShutdownReason.QUIT): void {
1136-
super.dispose();
1139+
private saveState(reason: ShutdownReason): void {
11371140

11381141
// Restore sidebar if we are being shutdown as a matter of a reload
11391142
if (reason === ShutdownReason.RELOAD) {
1140-
this.storageService.store(Workbench.sidebarRestoreStorageKey, 'true', StorageScope.WORKSPACE);
1143+
this.nextStorage2Service.set(Workbench.sidebarRestoreStorageKey, 'true', StorageScope.WORKSPACE);
11411144
}
11421145

11431146
// Preserve zen mode only on reload. Real quit gets out of zen mode so novice users do not get stuck in zen mode.
11441147
const zenConfig = this.configurationService.getValue<IZenModeSettings>('zenMode');
11451148
const restoreZenMode = this.zenMode.active && (zenConfig.restore || reason === ShutdownReason.RELOAD);
11461149
if (restoreZenMode) {
1147-
this.storageService.store(Workbench.zenModeActiveStorageKey, true, StorageScope.WORKSPACE);
1150+
this.nextStorage2Service.set(Workbench.zenModeActiveStorageKey, true, StorageScope.WORKSPACE);
11481151
} else {
11491152
if (this.zenMode.active) {
11501153
this.toggleZenMode(true);
11511154
}
1152-
this.storageService.remove(Workbench.zenModeActiveStorageKey, StorageScope.WORKSPACE);
1155+
1156+
this.nextStorage2Service.delete(Workbench.zenModeActiveStorageKey, StorageScope.WORKSPACE);
11531157
}
1158+
}
1159+
1160+
dispose(reason = ShutdownReason.QUIT): void {
1161+
super.dispose();
11541162

11551163
this.workbenchShutdown = true;
11561164
}
@@ -1331,7 +1339,7 @@ export class Workbench extends Disposable implements IPartService {
13311339
}
13321340

13331341
centerEditorLayout(active: boolean, skipLayout?: boolean): void {
1334-
this.storageService.store(Workbench.centeredEditorLayoutActiveStorageKey, active, StorageScope.WORKSPACE);
1342+
this.nextStorage2Service.set(Workbench.centeredEditorLayoutActiveStorageKey, active, StorageScope.WORKSPACE);
13351343
this.shouldCenterLayout = active;
13361344
let smartActive = active;
13371345
if (this.editorPart.groups.length > 1 && this.configurationService.getValue('workbench.editor.centeredLayoutAutoResize')) {
@@ -1410,9 +1418,9 @@ export class Workbench extends Disposable implements IPartService {
14101418
// Remember in settings
14111419
const defaultHidden = this.contextService.getWorkbenchState() === WorkbenchState.EMPTY;
14121420
if (hidden !== defaultHidden) {
1413-
this.storageService.store(Workbench.sidebarHiddenStorageKey, hidden ? 'true' : 'false', StorageScope.WORKSPACE);
1421+
this.nextStorage2Service.set(Workbench.sidebarHiddenStorageKey, hidden ? 'true' : 'false', StorageScope.WORKSPACE);
14141422
} else {
1415-
this.storageService.remove(Workbench.sidebarHiddenStorageKey, StorageScope.WORKSPACE);
1423+
this.nextStorage2Service.delete(Workbench.sidebarHiddenStorageKey, StorageScope.WORKSPACE);
14161424
}
14171425

14181426
// Layout
@@ -1452,9 +1460,9 @@ export class Workbench extends Disposable implements IPartService {
14521460

14531461
// Remember in settings
14541462
if (!hidden) {
1455-
this.storageService.store(Workbench.panelHiddenStorageKey, 'false', StorageScope.WORKSPACE);
1463+
this.nextStorage2Service.set(Workbench.panelHiddenStorageKey, 'false', StorageScope.WORKSPACE);
14561464
} else {
1457-
this.storageService.remove(Workbench.panelHiddenStorageKey, StorageScope.WORKSPACE);
1465+
this.nextStorage2Service.delete(Workbench.panelHiddenStorageKey, StorageScope.WORKSPACE);
14581466
}
14591467

14601468
// Layout
@@ -1522,7 +1530,7 @@ export class Workbench extends Disposable implements IPartService {
15221530
const newPositionValue = (position === Position.BOTTOM) ? 'bottom' : 'right';
15231531
const oldPositionValue = (this.panelPosition === Position.BOTTOM) ? 'bottom' : 'right';
15241532
this.panelPosition = position;
1525-
this.storageService.store(Workbench.panelPositionStorageKey, PositionToString(this.panelPosition).toLowerCase(), StorageScope.WORKSPACE);
1533+
this.nextStorage2Service.set(Workbench.panelPositionStorageKey, PositionToString(this.panelPosition).toLowerCase(), StorageScope.WORKSPACE);
15261534

15271535
// Adjust CSS
15281536
DOM.removeClass(this.panelPart.getContainer(), oldPositionValue);

src/vs/workbench/parts/debug/electron-browser/debugConfigurationManager.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { IJSONSchema } from 'vs/base/common/jsonSchema';
1515
import { ITextModel } from 'vs/editor/common/model';
1616
import { IEditor } from 'vs/workbench/common/editor';
1717
import { ILifecycleService } from 'vs/platform/lifecycle/common/lifecycle';
18-
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
18+
import { INextStorage2Service, StorageScope } from 'vs/platform/storage2/common/storage2';
1919
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
2020
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
2121
import { IFileService } from 'vs/platform/files/common/files';
@@ -61,7 +61,7 @@ export class ConfigurationManager implements IConfigurationManager {
6161
@IQuickInputService private quickInputService: IQuickInputService,
6262
@IInstantiationService private instantiationService: IInstantiationService,
6363
@ICommandService private commandService: ICommandService,
64-
@IStorageService private storageService: IStorageService,
64+
@INextStorage2Service private nextStorage2Service: INextStorage2Service,
6565
@ILifecycleService lifecycleService: ILifecycleService,
6666
@IExtensionService private extensionService: IExtensionService,
6767
@IContextKeyService contextKeyService: IContextKeyService
@@ -71,12 +71,12 @@ export class ConfigurationManager implements IConfigurationManager {
7171
this.toDispose = [];
7272
this.registerListeners(lifecycleService);
7373
this.initLaunches();
74-
const previousSelectedRoot = this.storageService.get(DEBUG_SELECTED_ROOT, StorageScope.WORKSPACE);
74+
const previousSelectedRoot = this.nextStorage2Service.get(DEBUG_SELECTED_ROOT, StorageScope.WORKSPACE);
7575
const previousSelectedLaunch = this.launches.filter(l => l.uri.toString() === previousSelectedRoot).pop();
7676
this.debugConfigurationTypeContext = CONTEXT_DEBUG_CONFIGURATION_TYPE.bindTo(contextKeyService);
7777
this.debugAdapterProviders = new Map<string, IDebugAdapterProvider>();
7878
if (previousSelectedLaunch) {
79-
this.selectConfiguration(previousSelectedLaunch, this.storageService.get(DEBUG_SELECTED_CONFIG_NAME_KEY, StorageScope.WORKSPACE));
79+
this.selectConfiguration(previousSelectedLaunch, this.nextStorage2Service.get(DEBUG_SELECTED_CONFIG_NAME_KEY, StorageScope.WORKSPACE));
8080
}
8181
}
8282

@@ -238,7 +238,7 @@ export class ConfigurationManager implements IConfigurationManager {
238238
}
239239
}));
240240

241-
this.toDispose.push(lifecycleService.onShutdown(this.store, this));
241+
this.toDispose.push(this.nextStorage2Service.onWillClose(this.store, this));
242242
}
243243

244244
private initLaunches(): void {
@@ -383,9 +383,9 @@ export class ConfigurationManager implements IConfigurationManager {
383383
}
384384

385385
private store(): void {
386-
this.storageService.store(DEBUG_SELECTED_CONFIG_NAME_KEY, this.selectedName, StorageScope.WORKSPACE);
386+
this.nextStorage2Service.set(DEBUG_SELECTED_CONFIG_NAME_KEY, this.selectedName, StorageScope.WORKSPACE);
387387
if (this.selectedLaunch) {
388-
this.storageService.store(DEBUG_SELECTED_ROOT, this.selectedLaunch.uri.toString(), StorageScope.WORKSPACE);
388+
this.nextStorage2Service.set(DEBUG_SELECTED_ROOT, this.selectedLaunch.uri.toString(), StorageScope.WORKSPACE);
389389
}
390390
}
391391

0 commit comments

Comments
 (0)