Johannes Rieken 2022-01-03 11:34:27 +01:00
parent 84ef964f73
commit b5d3ec5b49
No known key found for this signature in database
GPG key ID: 96634B5AF12F8798
3 changed files with 31 additions and 14 deletions

View file

@ -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.
*/

View file

@ -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) {

View file

@ -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) {