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:
parent
7687f1de95
commit
0db887a1a3
3 changed files with 31 additions and 3 deletions
|
@ -159,12 +159,24 @@
|
||||||
"description": "%javascript.referencesCodeLens.enabled%",
|
"description": "%javascript.referencesCodeLens.enabled%",
|
||||||
"scope": "window"
|
"scope": "window"
|
||||||
},
|
},
|
||||||
|
"javascript.referencesCodeLens.showOnAllFunctions": {
|
||||||
|
"type": "boolean",
|
||||||
|
"default": false,
|
||||||
|
"description": "%javascript.referencesCodeLens.showOnAllFunctions%",
|
||||||
|
"scope": "window"
|
||||||
|
},
|
||||||
"typescript.referencesCodeLens.enabled": {
|
"typescript.referencesCodeLens.enabled": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"default": false,
|
"default": false,
|
||||||
"description": "%typescript.referencesCodeLens.enabled%",
|
"description": "%typescript.referencesCodeLens.enabled%",
|
||||||
"scope": "window"
|
"scope": "window"
|
||||||
},
|
},
|
||||||
|
"typescript.referencesCodeLens.showOnAllFunctions": {
|
||||||
|
"type": "boolean",
|
||||||
|
"default": false,
|
||||||
|
"description": "%typescript.referencesCodeLens.showOnAllFunctions%",
|
||||||
|
"scope": "window"
|
||||||
|
},
|
||||||
"typescript.implementationsCodeLens.enabled": {
|
"typescript.implementationsCodeLens.enabled": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"default": false,
|
"default": false,
|
||||||
|
|
|
@ -36,7 +36,9 @@
|
||||||
"javascript.validate.enable": "Enable/disable JavaScript validation.",
|
"javascript.validate.enable": "Enable/disable JavaScript validation.",
|
||||||
"goToProjectConfig.title": "Go to Project Configuration",
|
"goToProjectConfig.title": "Go to Project Configuration",
|
||||||
"javascript.referencesCodeLens.enabled": "Enable/disable references CodeLens in JavaScript files.",
|
"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.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.enabled": "Enable/disable implementations CodeLens. This CodeLens shows the implementers of an interface.",
|
||||||
"typescript.openTsServerLog.title": "Open TS Server log",
|
"typescript.openTsServerLog.title": "Open TS Server log",
|
||||||
"typescript.restartTsServer": "Restart TS server",
|
"typescript.restartTsServer": "Restart TS server",
|
||||||
|
|
|
@ -15,7 +15,15 @@ import { getSymbolRange, ReferencesCodeLens, TypeScriptBaseCodeLensProvider } fr
|
||||||
|
|
||||||
const localize = nls.loadMessageBundle();
|
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> {
|
public async resolveCodeLens(inputCodeLens: vscode.CodeLens, token: vscode.CancellationToken): Promise<vscode.CodeLens> {
|
||||||
const codeLens = inputCodeLens as ReferencesCodeLens;
|
const codeLens = inputCodeLens as ReferencesCodeLens;
|
||||||
const args = typeConverters.Position.toFileLocationRequestArgs(codeLens.file, codeLens.range.start);
|
const args = typeConverters.Position.toFileLocationRequestArgs(codeLens.file, codeLens.range.start);
|
||||||
|
@ -59,10 +67,16 @@ class TypeScriptReferencesCodeLensProvider extends TypeScriptBaseCodeLensProvide
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (item.kind) {
|
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.const:
|
||||||
case PConst.Kind.let:
|
case PConst.Kind.let:
|
||||||
case PConst.Kind.variable:
|
case PConst.Kind.variable:
|
||||||
case PConst.Kind.function:
|
|
||||||
// Only show references for exported variables
|
// Only show references for exported variables
|
||||||
if (!item.kindModifiers.match(/\bexport\b/)) {
|
if (!item.kindModifiers.match(/\bexport\b/)) {
|
||||||
break;
|
break;
|
||||||
|
@ -98,6 +112,6 @@ export function register(
|
||||||
) {
|
) {
|
||||||
return new ConfigurationDependentRegistration(modeId, 'referencesCodeLens.enabled', () => {
|
return new ConfigurationDependentRegistration(modeId, 'referencesCodeLens.enabled', () => {
|
||||||
return vscode.languages.registerCodeLensProvider(selector,
|
return vscode.languages.registerCodeLensProvider(selector,
|
||||||
new TypeScriptReferencesCodeLensProvider(client, cachedResponse));
|
new TypeScriptReferencesCodeLensProvider(client, cachedResponse, modeId));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue