Show JS/TS References Code Lens for Inner Functions (#84689)

* Show code lens for inner functions

* Create typescript.referencesCodeLens.showOnAllFunctions setting

* Create javascript.referencesCodeLens.showOnAllFunctions setting

* Add a new setting in a existing class

* Avoid unnecessary fallthrough
This commit is contained in:
okmttdhr
2019-11-23 11:06:24 +09:00
committed by Matt Bierner
parent 7687f1de95
commit 0db887a1a3
3 changed files with 31 additions and 3 deletions

View File

@@ -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<Proto.NavTreeResponse>,
private modeId: string
) {
super(client, _cachedResponse);
}
public async resolveCodeLens(inputCodeLens: vscode.CodeLens, token: vscode.CancellationToken): Promise<vscode.CodeLens> {
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<boolean>('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));
});
}