diff --git a/extensions/typescript-language-features/package.json b/extensions/typescript-language-features/package.json index 13e2f020be3..7ea2b6f5af6 100644 --- a/extensions/typescript-language-features/package.json +++ b/extensions/typescript-language-features/package.json @@ -159,12 +159,24 @@ "description": "%javascript.referencesCodeLens.enabled%", "scope": "window" }, + "javascript.referencesCodeLens.showOnAllFunctions": { + "type": "boolean", + "default": false, + "description": "%javascript.referencesCodeLens.showOnAllFunctions%", + "scope": "window" + }, "typescript.referencesCodeLens.enabled": { "type": "boolean", "default": false, "description": "%typescript.referencesCodeLens.enabled%", "scope": "window" }, + "typescript.referencesCodeLens.showOnAllFunctions": { + "type": "boolean", + "default": false, + "description": "%typescript.referencesCodeLens.showOnAllFunctions%", + "scope": "window" + }, "typescript.implementationsCodeLens.enabled": { "type": "boolean", "default": false, diff --git a/extensions/typescript-language-features/package.nls.json b/extensions/typescript-language-features/package.nls.json index bb4187716ba..1bd543cb55c 100644 --- a/extensions/typescript-language-features/package.nls.json +++ b/extensions/typescript-language-features/package.nls.json @@ -36,7 +36,9 @@ "javascript.validate.enable": "Enable/disable JavaScript validation.", "goToProjectConfig.title": "Go to Project Configuration", "javascript.referencesCodeLens.enabled": "Enable/disable references CodeLens in JavaScript files.", + "javascript.referencesCodeLens.showOnAllFunctions": "Enable/disable references CodeLens on all functions in JavaScript 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.implementationsCodeLens.enabled": "Enable/disable implementations CodeLens. This CodeLens shows the implementers of an interface.", "typescript.openTsServerLog.title": "Open TS Server log", "typescript.restartTsServer": "Restart TS server", diff --git a/extensions/typescript-language-features/src/features/referencesCodeLens.ts b/extensions/typescript-language-features/src/features/referencesCodeLens.ts index b926f6058ac..5504bb05d4a 100644 --- a/extensions/typescript-language-features/src/features/referencesCodeLens.ts +++ b/extensions/typescript-language-features/src/features/referencesCodeLens.ts @@ -15,7 +15,15 @@ import { getSymbolRange, ReferencesCodeLens, TypeScriptBaseCodeLensProvider } fr const localize = nls.loadMessageBundle(); -class TypeScriptReferencesCodeLensProvider extends TypeScriptBaseCodeLensProvider { +export class TypeScriptReferencesCodeLensProvider extends TypeScriptBaseCodeLensProvider { + public constructor( + protected client: ITypeScriptServiceClient, + protected _cachedResponse: CachedResponse, + private modeId: string + ) { + super(client, _cachedResponse); + } + public async resolveCodeLens(inputCodeLens: vscode.CodeLens, token: vscode.CancellationToken): Promise { const codeLens = inputCodeLens as ReferencesCodeLens; const args = typeConverters.Position.toFileLocationRequestArgs(codeLens.file, codeLens.range.start); @@ -59,10 +67,16 @@ class TypeScriptReferencesCodeLensProvider extends TypeScriptBaseCodeLensProvide } switch (item.kind) { + case PConst.Kind.function: + const showOnAllFunctions = vscode.workspace.getConfiguration(this.modeId).get('referencesCodeLens.showOnAllFunctions'); + if (showOnAllFunctions) { + return getSymbolRange(document, item); + } + // fallthrough + case PConst.Kind.const: case PConst.Kind.let: case PConst.Kind.variable: - case PConst.Kind.function: // Only show references for exported variables if (!item.kindModifiers.match(/\bexport\b/)) { break; @@ -98,6 +112,6 @@ export function register( ) { return new ConfigurationDependentRegistration(modeId, 'referencesCodeLens.enabled', () => { return vscode.languages.registerCodeLensProvider(selector, - new TypeScriptReferencesCodeLensProvider(client, cachedResponse)); + new TypeScriptReferencesCodeLensProvider(client, cachedResponse, modeId)); }); }