mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-22 17:48:56 +01: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:
@@ -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