mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-22 01:29:04 +01:00
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:
@@ -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));
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user