From b5d3ec5b49554bea1d7e1bc372ac8705595b98c4 Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Mon, 3 Jan 2022 11:34:27 +0100 Subject: [PATCH] fix https://github.com/microsoft/vscode/issues/139910 --- src/vs/base/common/lifecycle.ts | 7 ++++ src/vs/editor/contrib/codelens/codelens.ts | 4 +++ .../contrib/codelens/codelensController.ts | 34 +++++++++++-------- 3 files changed, 31 insertions(+), 14 deletions(-) diff --git a/src/vs/base/common/lifecycle.ts b/src/vs/base/common/lifecycle.ts index 0cc516977c8..0ffa00ff724 100644 --- a/src/vs/base/common/lifecycle.ts +++ b/src/vs/base/common/lifecycle.ts @@ -199,6 +199,13 @@ export class DisposableStore implements IDisposable { this.clear(); } + /** + * Returns `true` if this object has been disposed + */ + public get isDisposed(): boolean { + return this._isDisposed; + } + /** * Dispose of all registered disposables but do not mark this object as disposed. */ diff --git a/src/vs/editor/contrib/codelens/codelens.ts b/src/vs/editor/contrib/codelens/codelens.ts index 6463b1adf88..0bf2566db24 100644 --- a/src/vs/editor/contrib/codelens/codelens.ts +++ b/src/vs/editor/contrib/codelens/codelens.ts @@ -28,6 +28,10 @@ export class CodeLensModel { this._disposables.dispose(); } + get isDisposed(): boolean { + return this._disposables.isDisposed; + } + add(list: CodeLensList, provider: CodeLensProvider): void { this._disposables.add(list); for (const symbol of list.lenses) { diff --git a/src/vs/editor/contrib/codelens/codelensController.ts b/src/vs/editor/contrib/codelens/codelensController.ts index e25ee3c591a..21335bc7791 100644 --- a/src/vs/editor/contrib/codelens/codelensController.ts +++ b/src/vs/editor/contrib/codelens/codelensController.ts @@ -439,8 +439,8 @@ export class CodeLensContribution implements IEditorContribution { }); } - getLenses(): readonly CodeLensWidget[] { - return this._lenses; + getModel(): CodeLensModel | undefined { + return this._currentCodeLensModel; } } @@ -472,19 +472,20 @@ registerEditorAction(class ShowLensesInCurrentLine extends EditorAction { if (!codelensController) { return; } - const items: { label: string, command: Command }[] = []; - for (let lens of codelensController.getLenses()) { - if (lens.getLineNumber() === lineNumber) { - for (let item of lens.getItems()) { - const { command } = item.symbol; - if (command) { - items.push({ - label: command.title, - command: command - }); - } - } + const model = codelensController.getModel(); + if (!model) { + // nothing + return; + } + + const items: { label: string, command: Command }[] = []; + for (const lens of model.lenses) { + if (lens.symbol.command && lens.symbol.range.startLineNumber === lineNumber) { + items.push({ + label: lens.symbol.command.title, + command: lens.symbol.command + }); } } @@ -499,6 +500,11 @@ registerEditorAction(class ShowLensesInCurrentLine extends EditorAction { return; } + if (model.isDisposed) { + // retry whenever the model has been disposed + return await commandService.executeCommand(this.id); + } + try { await commandService.executeCommand(item.command.id, ...(item.command.arguments || [])); } catch (err) {