Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 6 additions & 0 deletions extensions/typescript-language-features/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,12 @@
"description": "%typescript.implementationsCodeLens.enabled%",
"scope": "window"
},
"typescript.implementationsCodeLens.showOnInterfaceMethods": {
"type": "boolean",
"default": false,
"description": "%typescript.implementationsCodeLens.showOnInterfaceMethods%",
"scope": "window"
},
"typescript.tsserver.enableTracing": {
"type": "boolean",
"default": false,
Expand Down
1 change: 1 addition & 0 deletions extensions/typescript-language-features/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"typescript.referencesCodeLens.enabled": "Enable/disable references CodeLens in TypeScript files.",
"typescript.referencesCodeLens.showOnAllFunctions": "Enable/disable references CodeLens on all functions in TypeScript files.",
"typescript.implementationsCodeLens.enabled": "Enable/disable implementations CodeLens. This CodeLens shows the implementers of an interface.",
"typescript.implementationsCodeLens.showOnInterfaceMethods": "Enable/disable implementations CodeLens on interface methods.",
"typescript.openTsServerLog.title": "Open TS Server log",
"typescript.restartTsServer": "Restart TS Server",
"typescript.selectTypeScriptVersion.title": "Select TypeScript Version...",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ export class ReferencesCodeLens extends vscode.CodeLens {
}

export abstract class TypeScriptBaseCodeLensProvider implements vscode.CodeLensProvider<ReferencesCodeLens> {
protected readonly subscriptions: vscode.Disposable[] = [];
protected changeEmitter = new vscode.EventEmitter<void>();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This emitter should also get disposed of. You can inherit from Disposable too to make managing the disposables a little cleaner

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback.

This emitter should also get disposed of.

I derived the code from here:

export class NpmScriptLensProvider implements CodeLensProvider, Disposable {
private lensLocation = getFreshLensLocation();
private changeEmitter = new EventEmitter<void>();
private subscriptions: Disposable[] = [];

Does that code also fail to dispose its emitter, or did I overlook how/where it does the right thing?

You can inherit from Disposable too to make managing the disposables a little cleaner

By simply appending , Disposable to what TypeScriptBaseCodeLensProvider implements? Please help me understand what that will achieves.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it's likely missing there too

If you inherit from Disposable, then you don't have to implement dispose() yourself. Instead you can just call this._register with every disposable value

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have pushed what I think you meant.

public onDidChangeCodeLenses = this.changeEmitter.event;

public static readonly cancelledCommand: vscode.Command = {
// Cancellation is not an error. Just show nothing until we can properly re-compute the code lens
Expand All @@ -39,6 +42,9 @@ export abstract class TypeScriptBaseCodeLensProvider implements vscode.CodeLensP
private readonly cachedResponse: CachedResponse<Proto.NavTreeResponse>
) { }

public dispose() {
this.subscriptions.forEach(s => s.dispose());
}

async provideCodeLenses(document: vscode.TextDocument, token: vscode.CancellationToken): Promise<ReferencesCodeLens[]> {
const filepath = this.client.toOpenTsFilePath(document);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,20 @@ import { ExecutionTarget } from '../../tsServer/server';


export default class TypeScriptImplementationsCodeLensProvider extends TypeScriptBaseCodeLensProvider {
public constructor(
client: ITypeScriptServiceClient,
protected _cachedResponse: CachedResponse<Proto.NavTreeResponse>,
private readonly language: LanguageDescription
) {
super(client, _cachedResponse);
this.subscriptions.push(
vscode.workspace.onDidChangeConfiguration(evt => {
if (evt.affectsConfiguration(`${language.id}.implementationsCodeLens.showOnInterfaceMethods`)) {
this.changeEmitter.fire();
}
})
);
}

public async resolveCodeLens(
codeLens: ReferencesCodeLens,
Expand Down Expand Up @@ -71,8 +85,11 @@ export default class TypeScriptImplementationsCodeLensProvider extends TypeScrip
protected extractSymbol(
document: vscode.TextDocument,
item: Proto.NavigationTree,
_parent: Proto.NavigationTree | undefined
parent: Proto.NavigationTree | undefined
): vscode.Range | undefined {
if (item.kind === PConst.Kind.method && parent && parent.kind === PConst.Kind.interface && vscode.workspace.getConfiguration(this.language.id).get<boolean>('implementationsCodeLens.showOnInterfaceMethods')) {
return getSymbolRange(document, item);
}
switch (item.kind) {
case PConst.Kind.interface:
return getSymbolRange(document, item);
Expand Down Expand Up @@ -102,6 +119,6 @@ export function register(
requireSomeCapability(client, ClientCapability.Semantic),
], () => {
return vscode.languages.registerCodeLensProvider(selector.semantic,
new TypeScriptImplementationsCodeLensProvider(client, cachedResponse));
new TypeScriptImplementationsCodeLensProvider(client, cachedResponse, language));
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ export class TypeScriptReferencesCodeLensProvider extends TypeScriptBaseCodeLens
private readonly language: LanguageDescription
) {
super(client, _cachedResponse);
this.subscriptions.push(
vscode.workspace.onDidChangeConfiguration(evt => {
if (evt.affectsConfiguration(`${language.id}.referencesCodeLens.showOnAllFunctions`)) {
this.changeEmitter.fire();
}
})
);
}

public async resolveCodeLens(codeLens: ReferencesCodeLens, token: vscode.CancellationToken): Promise<vscode.CodeLens> {
Expand Down