mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 21:09:43 +00:00
* Add `typescript.implementationsCodeLens.showOnInterfaceMethods` setting (#136282) * Update codelenses when `typescript.referencesCodeLens.showOnAllFunctions` changes * Improve handling of disposables
This commit is contained in:
parent
678f6a544c
commit
77dc8793db
|
@ -259,6 +259,12 @@
|
||||||
"description": "%typescript.implementationsCodeLens.enabled%",
|
"description": "%typescript.implementationsCodeLens.enabled%",
|
||||||
"scope": "window"
|
"scope": "window"
|
||||||
},
|
},
|
||||||
|
"typescript.implementationsCodeLens.showOnInterfaceMethods": {
|
||||||
|
"type": "boolean",
|
||||||
|
"default": false,
|
||||||
|
"description": "%typescript.implementationsCodeLens.showOnInterfaceMethods%",
|
||||||
|
"scope": "window"
|
||||||
|
},
|
||||||
"typescript.tsserver.enableTracing": {
|
"typescript.tsserver.enableTracing": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"default": false,
|
"default": false,
|
||||||
|
|
|
@ -58,6 +58,7 @@
|
||||||
"typescript.referencesCodeLens.enabled": "Enable/disable references CodeLens in TypeScript files.",
|
"typescript.referencesCodeLens.enabled": "Enable/disable references CodeLens in TypeScript files.",
|
||||||
"typescript.referencesCodeLens.showOnAllFunctions": "Enable/disable references CodeLens on all functions 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.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.openTsServerLog.title": "Open TS Server log",
|
||||||
"typescript.restartTsServer": "Restart TS Server",
|
"typescript.restartTsServer": "Restart TS Server",
|
||||||
"typescript.selectTypeScriptVersion.title": "Select TypeScript Version...",
|
"typescript.selectTypeScriptVersion.title": "Select TypeScript Version...",
|
||||||
|
|
|
@ -9,6 +9,7 @@ import type * as Proto from '../../tsServer/protocol/protocol';
|
||||||
import * as typeConverters from '../../typeConverters';
|
import * as typeConverters from '../../typeConverters';
|
||||||
import { ITypeScriptServiceClient } from '../../typescriptService';
|
import { ITypeScriptServiceClient } from '../../typescriptService';
|
||||||
import { escapeRegExp } from '../../utils/regexp';
|
import { escapeRegExp } from '../../utils/regexp';
|
||||||
|
import { Disposable } from '../../utils/dispose';
|
||||||
|
|
||||||
|
|
||||||
export class ReferencesCodeLens extends vscode.CodeLens {
|
export class ReferencesCodeLens extends vscode.CodeLens {
|
||||||
|
@ -21,7 +22,9 @@ export class ReferencesCodeLens extends vscode.CodeLens {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export abstract class TypeScriptBaseCodeLensProvider implements vscode.CodeLensProvider<ReferencesCodeLens> {
|
export abstract class TypeScriptBaseCodeLensProvider extends Disposable implements vscode.CodeLensProvider<ReferencesCodeLens>{
|
||||||
|
protected changeEmitter = this._register(new vscode.EventEmitter<void>());
|
||||||
|
public onDidChangeCodeLenses = this.changeEmitter.event;
|
||||||
|
|
||||||
public static readonly cancelledCommand: vscode.Command = {
|
public static readonly cancelledCommand: vscode.Command = {
|
||||||
// Cancellation is not an error. Just show nothing until we can properly re-compute the code lens
|
// Cancellation is not an error. Just show nothing until we can properly re-compute the code lens
|
||||||
|
@ -37,8 +40,9 @@ export abstract class TypeScriptBaseCodeLensProvider implements vscode.CodeLensP
|
||||||
public constructor(
|
public constructor(
|
||||||
protected client: ITypeScriptServiceClient,
|
protected client: ITypeScriptServiceClient,
|
||||||
private readonly cachedResponse: CachedResponse<Proto.NavTreeResponse>
|
private readonly cachedResponse: CachedResponse<Proto.NavTreeResponse>
|
||||||
) { }
|
) {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
async provideCodeLenses(document: vscode.TextDocument, token: vscode.CancellationToken): Promise<ReferencesCodeLens[]> {
|
async provideCodeLenses(document: vscode.TextDocument, token: vscode.CancellationToken): Promise<ReferencesCodeLens[]> {
|
||||||
const filepath = this.client.toOpenTsFilePath(document);
|
const filepath = this.client.toOpenTsFilePath(document);
|
||||||
|
|
|
@ -17,6 +17,20 @@ import { ExecutionTarget } from '../../tsServer/server';
|
||||||
|
|
||||||
|
|
||||||
export default class TypeScriptImplementationsCodeLensProvider extends TypeScriptBaseCodeLensProvider {
|
export default class TypeScriptImplementationsCodeLensProvider extends TypeScriptBaseCodeLensProvider {
|
||||||
|
public constructor(
|
||||||
|
client: ITypeScriptServiceClient,
|
||||||
|
protected _cachedResponse: CachedResponse<Proto.NavTreeResponse>,
|
||||||
|
private readonly language: LanguageDescription
|
||||||
|
) {
|
||||||
|
super(client, _cachedResponse);
|
||||||
|
this._register(
|
||||||
|
vscode.workspace.onDidChangeConfiguration(evt => {
|
||||||
|
if (evt.affectsConfiguration(`${language.id}.implementationsCodeLens.showOnInterfaceMethods`)) {
|
||||||
|
this.changeEmitter.fire();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public async resolveCodeLens(
|
public async resolveCodeLens(
|
||||||
codeLens: ReferencesCodeLens,
|
codeLens: ReferencesCodeLens,
|
||||||
|
@ -71,8 +85,11 @@ export default class TypeScriptImplementationsCodeLensProvider extends TypeScrip
|
||||||
protected extractSymbol(
|
protected extractSymbol(
|
||||||
document: vscode.TextDocument,
|
document: vscode.TextDocument,
|
||||||
item: Proto.NavigationTree,
|
item: Proto.NavigationTree,
|
||||||
_parent: Proto.NavigationTree | undefined
|
parent: Proto.NavigationTree | undefined
|
||||||
): vscode.Range | 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) {
|
switch (item.kind) {
|
||||||
case PConst.Kind.interface:
|
case PConst.Kind.interface:
|
||||||
return getSymbolRange(document, item);
|
return getSymbolRange(document, item);
|
||||||
|
@ -102,6 +119,6 @@ export function register(
|
||||||
requireSomeCapability(client, ClientCapability.Semantic),
|
requireSomeCapability(client, ClientCapability.Semantic),
|
||||||
], () => {
|
], () => {
|
||||||
return vscode.languages.registerCodeLensProvider(selector.semantic,
|
return vscode.languages.registerCodeLensProvider(selector.semantic,
|
||||||
new TypeScriptImplementationsCodeLensProvider(client, cachedResponse));
|
new TypeScriptImplementationsCodeLensProvider(client, cachedResponse, language));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,13 @@ export class TypeScriptReferencesCodeLensProvider extends TypeScriptBaseCodeLens
|
||||||
private readonly language: LanguageDescription
|
private readonly language: LanguageDescription
|
||||||
) {
|
) {
|
||||||
super(client, _cachedResponse);
|
super(client, _cachedResponse);
|
||||||
|
this._register(
|
||||||
|
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> {
|
public async resolveCodeLens(codeLens: ReferencesCodeLens, token: vscode.CancellationToken): Promise<vscode.CodeLens> {
|
||||||
|
|
Loading…
Reference in a new issue