Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re #183449. Roaming kernel history. #191138

Merged
merged 3 commits into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { Disposable } from 'vs/base/common/lifecycle';
import { Disposable, DisposableStore } from 'vs/base/common/lifecycle';
import { LinkedMap, Touch } from 'vs/base/common/map';
import { localize } from 'vs/nls';
import { Categories } from 'vs/platform/action/common/actionCommonCategories';
Expand Down Expand Up @@ -36,6 +36,9 @@ export class NotebookKernelHistoryService extends Disposable implements INoteboo

this._loadState();
this._register(this._storageService.onWillSaveState(() => this._saveState()));
this._register(this._storageService.onDidChangeValue(StorageScope.WORKSPACE, NotebookKernelHistoryService.STORAGE_KEY, this._register(new DisposableStore()))(() => {
this._restoreState();
}));
}

getKernels(notebook: INotebookTextModelLike): { selected: INotebookKernel | undefined; all: INotebookKernel[] } {
Expand Down Expand Up @@ -79,12 +82,30 @@ export class NotebookKernelHistoryService extends Disposable implements INoteboo

if (notEmpty) {
const serialized = this._serialize();
this._storageService.store(NotebookKernelHistoryService.STORAGE_KEY, JSON.stringify(serialized), StorageScope.WORKSPACE, StorageTarget.MACHINE);
this._storageService.store(NotebookKernelHistoryService.STORAGE_KEY, JSON.stringify(serialized), StorageScope.WORKSPACE, StorageTarget.USER);
} else {
this._storageService.remove(NotebookKernelHistoryService.STORAGE_KEY, StorageScope.WORKSPACE);
}
}

private _restoreState(): void {
const serialized = this._storageService.get(NotebookKernelHistoryService.STORAGE_KEY, StorageScope.WORKSPACE);
if (serialized) {
try {
for (const [viewType, kernels] of JSON.parse(serialized)) {
const linkedMap = this._mostRecentKernelsMap[viewType] ?? new LinkedMap<string, string>();
for (const entry of kernels.entries) {
linkedMap.set(entry, entry, Touch.AsOld);
}
rebornix marked this conversation as resolved.
Show resolved Hide resolved

this._mostRecentKernelsMap[viewType] = linkedMap;
}
} catch (e) {
console.error('Deserialize notebook kernel history failed', e);
}
}
}

private _loadState(): void {
const serialized = this._storageService.get(NotebookKernelHistoryService.STORAGE_KEY, StorageScope.WORKSPACE);
if (serialized) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { NotebookTextModel } from 'vs/workbench/contrib/notebook/common/model/no
import { PLAINTEXT_LANGUAGE_ID } from 'vs/editor/common/languages/modesRegistry';
import { IMenu, IMenuService } from 'vs/platform/actions/common/actions';
import { NotebookKernelHistoryService } from 'vs/workbench/contrib/notebook/browser/services/notebookKernelHistoryServiceImpl';
import { IStorageService, IWillSaveStateEvent, StorageScope } from 'vs/platform/storage/common/storage';
import { IApplicationStorageValueChangeEvent, IProfileStorageValueChangeEvent, IStorageService, IStorageValueChangeEvent, IWillSaveStateEvent, IWorkspaceStorageValueChangeEvent, StorageScope } from 'vs/platform/storage/common/storage';
import { INotebookLoggingService } from 'vs/workbench/contrib/notebook/common/notebookLoggingService';

suite('NotebookKernelHistoryService', () => {
Expand Down Expand Up @@ -70,6 +70,12 @@ suite('NotebookKernelHistoryService', () => {

instantiationService.stub(IStorageService, new class extends mock<IStorageService>() {
override onWillSaveState: Event<IWillSaveStateEvent> = Event.None;
override onDidChangeValue(scope: StorageScope.WORKSPACE, key: string | undefined, disposable: DisposableStore): Event<IWorkspaceStorageValueChangeEvent>;
override onDidChangeValue(scope: StorageScope.PROFILE, key: string | undefined, disposable: DisposableStore): Event<IProfileStorageValueChangeEvent>;
override onDidChangeValue(scope: StorageScope.APPLICATION, key: string | undefined, disposable: DisposableStore): Event<IApplicationStorageValueChangeEvent>;
override onDidChangeValue(scope: StorageScope, key: string | undefined, disposable: DisposableStore): Event<IStorageValueChangeEvent> {
return Event.None;
}
override get(key: string, scope: StorageScope, fallbackValue: string): string;
override get(key: string, scope: StorageScope, fallbackValue?: string | undefined): string | undefined;
override get(key: unknown, scope: unknown, fallbackValue?: unknown): string | undefined {
Expand Down Expand Up @@ -119,6 +125,12 @@ suite('NotebookKernelHistoryService', () => {

instantiationService.stub(IStorageService, new class extends mock<IStorageService>() {
override onWillSaveState: Event<IWillSaveStateEvent> = Event.None;
override onDidChangeValue(scope: StorageScope.WORKSPACE, key: string | undefined, disposable: DisposableStore): Event<IWorkspaceStorageValueChangeEvent>;
override onDidChangeValue(scope: StorageScope.PROFILE, key: string | undefined, disposable: DisposableStore): Event<IProfileStorageValueChangeEvent>;
override onDidChangeValue(scope: StorageScope.APPLICATION, key: string | undefined, disposable: DisposableStore): Event<IApplicationStorageValueChangeEvent>;
override onDidChangeValue(scope: StorageScope, key: string | undefined, disposable: DisposableStore): Event<IStorageValueChangeEvent> {
return Event.None;
}
override get(key: string, scope: StorageScope, fallbackValue: string): string;
override get(key: string, scope: StorageScope, fallbackValue?: string | undefined): string | undefined;
override get(key: unknown, scope: unknown, fallbackValue?: unknown): string | undefined {
Expand Down
Loading