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
Changes from 1 commit
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,28 @@ 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
}
} 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
Loading