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

warn/report invalid code lenses but don't surface them in the UI #199962

Merged
merged 1 commit into from
Dec 4, 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
21 changes: 15 additions & 6 deletions src/vs/workbench/api/common/extHostLanguageFeatures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import { StopWatch } from 'vs/base/common/stopwatch';
import { isCancellationError, NotImplementedError } from 'vs/base/common/errors';
import { raceCancellationError } from 'vs/base/common/async';
import { isProposedApiEnabled } from 'vs/workbench/services/extensions/common/extensions';
import { IExtHostTelemetry } from 'vs/workbench/api/common/extHostTelemetry';
import { ExtHostTelemetry, IExtHostTelemetry } from 'vs/workbench/api/common/extHostTelemetry';
import { localize } from 'vs/nls';
import { IAutoClosingPairConditional } from 'vs/editor/common/languages/languageConfiguration';

Expand Down Expand Up @@ -104,15 +104,16 @@ class DocumentSymbolAdapter {

class CodeLensAdapter {

private static _badCmd: vscode.Command = { command: 'missing', title: '!!MISSING: command!!' };

private readonly _cache = new Cache<vscode.CodeLens>('CodeLens');
private readonly _disposables = new Map<number, DisposableStore>();

constructor(
private readonly _documents: ExtHostDocuments,
private readonly _commands: CommandsConverter,
private readonly _provider: vscode.CodeLensProvider
private readonly _provider: vscode.CodeLensProvider,
private readonly _extension: IExtensionDescription,
private readonly _extTelemetry: ExtHostTelemetry,
private readonly _logService: ILogService,
) { }

async provideCodeLenses(resource: URI, token: CancellationToken): Promise<extHostProtocol.ICodeLensListDto | undefined> {
Expand Down Expand Up @@ -164,7 +165,15 @@ class CodeLensAdapter {
// disposed in the meantime
return undefined;
}
symbol.command = this._commands.toInternal(resolvedLens.command ?? CodeLensAdapter._badCmd, disposables);

if (!resolvedLens.command) {
const error = new Error('INVALID code lens resolved, lacks command: ' + this._extension.identifier.value);
this._extTelemetry.onExtensionError(this._extension.identifier, error);
this._logService.error(error);
return undefined;
}

symbol.command = this._commands.toInternal(resolvedLens.command, disposables);
return symbol;
}

Expand Down Expand Up @@ -2006,7 +2015,7 @@ export class ExtHostLanguageFeatures implements extHostProtocol.ExtHostLanguageF
const handle = this._nextHandle();
const eventHandle = typeof provider.onDidChangeCodeLenses === 'function' ? this._nextHandle() : undefined;

this._adapter.set(handle, new AdapterData(new CodeLensAdapter(this._documents, this._commands.converter, provider), extension));
this._adapter.set(handle, new AdapterData(new CodeLensAdapter(this._documents, this._commands.converter, provider, extension, this._extensionTelemetry, this._logService), extension));
this._proxy.$registerCodeLensSupport(handle, this._transformDocumentSelector(selector, extension), eventHandle);
let result = this._createDisposable(handle);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,7 @@ suite('ExtHostLanguageFeatures', function () {
assert.strictEqual(value.lenses.length, 1);
const [data] = value.lenses;
const symbol = await Promise.resolve(data.provider.resolveCodeLens!(model, data.symbol, CancellationToken.None));
assert.strictEqual(symbol!.command!.id, 'missing');
assert.strictEqual(symbol!.command!.title, '!!MISSING: command!!');
assert.strictEqual(symbol, undefined);
value.dispose();
});

Expand Down