diff --git a/src/services/services.ts b/src/services/services.ts index b8c086a67e7..5eb0f6a06ca 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1567,17 +1567,17 @@ namespace ts { /// References and Occurrences function getOccurrencesAtPosition(fileName: string, position: number): ReferenceEntry[] { - let results = getOccurrencesAtPositionCore(fileName, position); - - if (results) { - const sourceFile = getCanonicalFileName(normalizeSlashes(fileName)); - - // Get occurrences only supports reporting occurrences for the file queried. So - // filter down to that list. - results = filter(results, r => getCanonicalFileName(ts.normalizeSlashes(r.fileName)) === sourceFile); - } - - return results; + const canonicalFileName = getCanonicalFileName(normalizeSlashes(fileName)); + return flatMap(getDocumentHighlights(fileName, position, [fileName]), entry => entry.highlightSpans.map(highlightSpan => { + Debug.assert(getCanonicalFileName(normalizeSlashes(entry.fileName)) === canonicalFileName); // Get occurrences only supports reporting occurrences for the file queried. + return { + fileName: entry.fileName, + textSpan: highlightSpan.textSpan, + isWriteAccess: highlightSpan.kind === HighlightSpanKind.writtenReference, + isDefinition: false, + isInString: highlightSpan.isInString, + }; + })); } function getDocumentHighlights(fileName: string, position: number, filesToSearch: ReadonlyArray): DocumentHighlights[] { @@ -1587,31 +1587,6 @@ namespace ts { return DocumentHighlights.getDocumentHighlights(program, cancellationToken, sourceFile, position, sourceFilesToSearch); } - function getOccurrencesAtPositionCore(fileName: string, position: number): ReferenceEntry[] { - return convertDocumentHighlights(getDocumentHighlights(fileName, position, [fileName])); - - function convertDocumentHighlights(documentHighlights: DocumentHighlights[]): ReferenceEntry[] { - if (!documentHighlights) { - return undefined; - } - - const result: ReferenceEntry[] = []; - for (const entry of documentHighlights) { - for (const highlightSpan of entry.highlightSpans) { - result.push({ - fileName: entry.fileName, - textSpan: highlightSpan.textSpan, - isWriteAccess: highlightSpan.kind === HighlightSpanKind.writtenReference, - isDefinition: false, - isInString: highlightSpan.isInString, - }); - } - } - - return result; - } - } - function findRenameLocations(fileName: string, position: number, findInStrings: boolean, findInComments: boolean): RenameLocation[] { return getReferences(fileName, position, { findInStrings, findInComments, isForRename: true }); }