Provide full TS symbol range when previewing definitions in VSCode

Fixes #72017

Has two fixes:

- Hooks up the JS/TS extension to consume the full symbol range provided by https://github.com/microsoft/TypeScript/pull/31587

- Makes the go the definition mouse implementation use the locationLink to compute the preview range. If a`targetSelectionRange` is provided, this means we use the normal `range` to get the preview range
This commit is contained in:
Matt Bierner
2019-06-17 15:39:56 -07:00
parent d859e67de9
commit 459939b905
3 changed files with 19 additions and 8 deletions

View File

@@ -37,10 +37,18 @@ export default class TypeScriptDefinitionProvider extends DefinitionProviderBase
return response.body.definitions
.map((location): vscode.DefinitionLink => {
const target = typeConverters.Location.fromTextSpan(this.client.toResource(location.file), location);
if ((location as any).contextStart) {
return {
originSelectionRange: span,
targetRange: typeConverters.Range.fromLocations((location as any).contextStart, (location as any).contextEnd),
targetUri: target.uri,
targetSelectionRange: target.range,
};
}
return {
originSelectionRange: span,
targetRange: target.range,
targetUri: target.uri,
targetUri: target.uri
};
});
}

View File

@@ -13,9 +13,12 @@ import { ITypeScriptServiceClient } from '../typescriptService';
export namespace Range {
export const fromTextSpan = (span: Proto.TextSpan): vscode.Range =>
fromLocations(span.start, span.end);
export const fromLocations = (start: Proto.Location, end: Proto.Location): vscode.Range =>
new vscode.Range(
Math.max(0, span.start.line - 1), Math.max(span.start.offset - 1, 0),
Math.max(0, span.end.line - 1), Math.max(0, span.end.offset - 1));
Math.max(0, start.line - 1), Math.max(start.offset - 1, 0),
Math.max(0, end.line - 1), Math.max(0, end.offset - 1));
export const toFileRangeRequestArgs = (file: string, range: vscode.Range): Proto.FileRangeRequestArgs => ({
file,