Skip to content

Commit

Permalink
Use TS's document highlight API instead of references api to get high…
Browse files Browse the repository at this point in the history
…lights

Fixes #65921
Fixes #65051
  • Loading branch information
mjbvz committed Jan 2, 2019
1 parent 7086fb7 commit 44b5a77
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import * as vscode from 'vscode';
import * as Proto from '../protocol';
import { ITypeScriptServiceClient } from '../typescriptService';
import { flatten } from '../utils/arrays';
import * as typeConverters from '../utils/typeConverters';

class TypeScriptDocumentHighlightProvider implements vscode.DocumentHighlightProvider {
Expand All @@ -23,22 +24,27 @@ class TypeScriptDocumentHighlightProvider implements vscode.DocumentHighlightPro
return [];
}

const args = typeConverters.Position.toFileLocationRequestArgs(file, position);
const response = await this.client.execute('references', args, token);
const args = {
...typeConverters.Position.toFileLocationRequestArgs(file, position),
filesToSearch: [file]
};
const response = await this.client.execute('documentHighlights', args, token);
if (response.type !== 'response' || !response.body) {
return [];
}

return response.body.refs
.filter(ref => ref.file === file)
.map(documentHighlightFromReference);
return flatten(
response.body
.filter(highlight => highlight.file === file)

This comment has been minimized.

Copy link
@DanielRosenwasser

DanielRosenwasser Jan 2, 2019

Member

This is sort of funny - we probably should just never have deprecated occurrences.

.map(convertDocumentHighlight));
}
}

function documentHighlightFromReference(reference: Proto.ReferencesResponseItem): vscode.DocumentHighlight {
return new vscode.DocumentHighlight(
typeConverters.Range.fromTextSpan(reference),
reference.isWriteAccess ? vscode.DocumentHighlightKind.Write : vscode.DocumentHighlightKind.Read);
function convertDocumentHighlight(highlight: Proto.DocumentHighlightsItem): ReadonlyArray<vscode.DocumentHighlight> {
return highlight.highlightSpans.map(span =>
new vscode.DocumentHighlight(
typeConverters.Range.fromTextSpan(span),
span.kind === 'writtenReference' ? vscode.DocumentHighlightKind.Write : vscode.DocumentHighlightKind.Read));
}

export function register(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ interface TypeScriptRequestTypes {
'definition': [Proto.FileLocationRequestArgs, Proto.DefinitionResponse];
'definitionAndBoundSpan': [Proto.FileLocationRequestArgs, Proto.DefinitionInfoAndBoundSpanReponse];
'docCommentTemplate': [Proto.FileLocationRequestArgs, Proto.DocCommandTemplateResponse];
'documentHighlights': [Proto.DocumentHighlightsRequestArgs, Proto.DocumentHighlightsResponse];
'format': [Proto.FormatRequestArgs, Proto.FormatResponse];
'formatonkey': [Proto.FormatOnKeyRequestArgs, Proto.FormatResponse];
'getApplicableRefactors': [Proto.GetApplicableRefactorsRequestArgs, Proto.GetApplicableRefactorsResponse];
Expand Down

0 comments on commit 44b5a77

Please sign in to comment.