mirror of
https://github.com/microsoft/vscode.git
synced 2026-07-08 02:24:51 -05:00
* Workaround for #16909 Fixes #16909 Worksaround TS2.1+ returning strings in the occurrences response we use for highlighting occurrences in documents The workaround is to look at the text surrounding the first occurrence to see if it is a string literal. * Small cleanup * Add gate for ts 2.1.x * Added check to make sure we don't compare the same character
This commit is contained in:
@@ -34,7 +34,18 @@ export default class TypeScriptDocumentHighlightProvider implements DocumentHigh
|
||||
}
|
||||
return this.client.execute('occurrences', args, token).then((response): DocumentHighlight[] => {
|
||||
let data = response.body;
|
||||
if (data) {
|
||||
if (data && data.length) {
|
||||
// Workaround for https://github.com/Microsoft/TypeScript/issues/12780
|
||||
// Don't highlight string occurrences
|
||||
const firstOccurrence = data[0];
|
||||
if (this.client.apiVersion.has213Features() && firstOccurrence.start.offset > 1) {
|
||||
// Check to see if contents around first occurrence are string delimiters
|
||||
const contents = resource.getText(new Range(firstOccurrence.start.line - 1, firstOccurrence.start.offset - 1 - 1, firstOccurrence.end.line - 1, firstOccurrence.end.offset - 1 + 1));
|
||||
const stringDelimiters = ['"', '\'', '`'];
|
||||
if (contents && contents.length > 2 && stringDelimiters.indexOf(contents[0]) >= 0 && contents[0] === contents[contents.length - 1]) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
return data.map((item) => {
|
||||
return new DocumentHighlight(new Range(item.start.line - 1, item.start.offset - 1, item.end.line - 1, item.end.offset - 1),
|
||||
item.isWriteAccess ? DocumentHighlightKind.Write : DocumentHighlightKind.Read);
|
||||
|
||||
Reference in New Issue
Block a user