mirror of
https://github.com/microsoft/vscode.git
synced 2025-12-24 12:19:20 +00:00
[typescript-language-features] Support replacing Go to Definition with Go to Source Definition by preference (#178840)
* Add preference for replacing Go to Definition with Go to Source Definition * Support replacing Go to Definition with Go to Source Definition by preference * Predicate call on TS version
This commit is contained in:
@@ -1210,6 +1210,18 @@
|
||||
"tags": [
|
||||
"experimental"
|
||||
]
|
||||
},
|
||||
"typescript.preferGoToSourceDefinition": {
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"description": "%configuration.preferGoToSourceDefinition%",
|
||||
"scope": "window"
|
||||
},
|
||||
"javascript.preferGoToSourceDefinition": {
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"description": "%configuration.preferGoToSourceDefinition%",
|
||||
"scope": "window"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -80,6 +80,7 @@
|
||||
"configuration.implicitProjectConfig.strictFunctionTypes": "Enable/disable [strict function types](https://www.typescriptlang.org/tsconfig#strictFunctionTypes) in JavaScript and TypeScript files that are not part of a project. Existing `jsconfig.json` or `tsconfig.json` files override this setting.",
|
||||
"configuration.suggest.jsdoc.generateReturns": "Enable/disable generating `@returns` annotations for JSDoc templates.",
|
||||
"configuration.suggest.autoImports": "Enable/disable auto import suggestions.",
|
||||
"configuration.preferGoToSourceDefinition": "Makes Go to Definition avoid type declaration files when possible by triggering Go to Source Definition instead. This allows Go to Source Definition to be triggered with the mouse gesture. Requires using TypeScript 4.7+ in the workspace.",
|
||||
"inlayHints.parameterNames.none": "Disable parameter name hints.",
|
||||
"inlayHints.parameterNames.literals": "Enable parameter name hints only for literal arguments.",
|
||||
"inlayHints.parameterNames.all": "Enable parameter name hints for literal and non-literal arguments.",
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
import * as vscode from 'vscode';
|
||||
import { DocumentSelector } from '../configuration/documentSelector';
|
||||
import { API } from '../tsServer/api';
|
||||
import * as typeConverters from '../typeConverters';
|
||||
import { ClientCapability, ITypeScriptServiceClient } from '../typescriptService';
|
||||
import DefinitionProviderBase from './definitionProviderBase';
|
||||
@@ -29,7 +30,16 @@ export default class TypeScriptDefinitionProvider extends DefinitionProviderBase
|
||||
}
|
||||
|
||||
const span = response.body.textSpan ? typeConverters.Range.fromTextSpan(response.body.textSpan) : undefined;
|
||||
return response.body.definitions
|
||||
let definitions = response.body.definitions;
|
||||
|
||||
if (vscode.workspace.getConfiguration(document.languageId).get('preferGoToSourceDefinition', false) && this.client.apiVersion.gte(API.v470)) {
|
||||
const sourceDefinitionsResponse = await this.client.execute('findSourceDefinition', args, token);
|
||||
if (sourceDefinitionsResponse.type === 'response' && sourceDefinitionsResponse.body?.length) {
|
||||
definitions = sourceDefinitionsResponse.body;
|
||||
}
|
||||
}
|
||||
|
||||
return definitions
|
||||
.map((location): vscode.DefinitionLink => {
|
||||
const target = typeConverters.Location.fromTextSpan(this.client.toResource(location.file), location);
|
||||
if (location.contextStart && location.contextEnd) {
|
||||
|
||||
Reference in New Issue
Block a user