diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index f7564ef52f..49ecc7d9a4 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -2128,8 +2128,7 @@ module FourSlash { this.raiseError('verifyOccurancesAtPositionListContains failed - found 0 references, expected at least one.'); } - for (let i = 0; i < occurrences.length; i++) { - let occurrence = occurrences[i]; + for (let occurrence of occurrences) { if (occurrence && occurrence.fileName === fileName && occurrence.textSpan.start === start && ts.textSpanEnd(occurrence.textSpan) === end) { if (typeof isWriteAccess !== "undefined" && occurrence.isWriteAccess !== isWriteAccess) { this.raiseError('verifyOccurrencesAtPositionListContains failed - item isWriteAccess value does not match, actual: ' + occurrence.isWriteAccess + ', expected: ' + isWriteAccess + '.'); @@ -2189,9 +2188,8 @@ module FourSlash { this.taoInvalidReason = 'verifyDocumentHighlightsAtPositionListCount NYI'; let documentHighlights = this.getDocumentHighlightsAtCurrentPosition(fileNamesToSearch); - let actualCount = documentHighlights - ? documentHighlights.reduce((currentCount, { fileName, highlightSpans }) => { - return currentCount + highlightSpans.length}, 0) + let actualCount = documentHighlights + ? documentHighlights.reduce((currentCount, { highlightSpans }) => currentCount + highlightSpans.length, 0) : 0; if (expectedCount !== actualCount) { diff --git a/src/server/client.ts b/src/server/client.ts index d11a3c7546..2ec0dd4de6 100644 --- a/src/server/client.ts +++ b/src/server/client.ts @@ -534,7 +534,7 @@ namespace ts.server { let request = this.processRequest(CommandNames.DocumentHighlights, args); let response = this.processResponse(request); - let _self = this; + let self = this; return response.body.map(convertToDocumentHighlights); function convertToDocumentHighlights(item: ts.server.protocol.DocumentHighlightsItem): ts.DocumentHighlights { @@ -542,12 +542,12 @@ namespace ts.server { return { fileName: file, - highlightSpans: highlightSpans.map(convertHighlightSpan2) + highlightSpans: highlightSpans.map(convertHighlightSpan) }; - function convertHighlightSpan2(span: ts.server.protocol.HighlightSpan): ts.HighlightSpan { - let start = _self.lineOffsetToPosition(file, span.start); - let end = _self.lineOffsetToPosition(file, span.end); + function convertHighlightSpan(span: ts.server.protocol.HighlightSpan): ts.HighlightSpan { + let start = self.lineOffsetToPosition(file, span.start); + let end = self.lineOffsetToPosition(file, span.end); return { textSpan: ts.createTextSpanFromBounds(start, end), kind: span.kind diff --git a/src/server/session.ts b/src/server/session.ts index 8a9c15b244..963c443f09 100644 --- a/src/server/session.ts +++ b/src/server/session.ts @@ -369,10 +369,10 @@ namespace ts.server { return { file: fileName, - highlightSpans: highlightSpans.map(convertHighlightSpan1) + highlightSpans: highlightSpans.map(convertHighlightSpan) }; - function convertHighlightSpan1(highlightSpan: ts.HighlightSpan): ts.server.protocol.HighlightSpan { + function convertHighlightSpan(highlightSpan: ts.HighlightSpan): ts.server.protocol.HighlightSpan { let { textSpan, kind } = highlightSpan; let start = compilerService.host.positionToLineOffset(fileName, textSpan.start); let end = compilerService.host.positionToLineOffset(fileName, ts.textSpanEnd(textSpan)); diff --git a/tests/cases/fourslash/server/documentHighlights02.ts b/tests/cases/fourslash/server/documentHighlights02.ts new file mode 100644 index 0000000000..8cf7038395 --- /dev/null +++ b/tests/cases/fourslash/server/documentHighlights02.ts @@ -0,0 +1,23 @@ +/// + +// @Filename: a.ts +////function foo() { +//// return 1; +////} + +// @Filename: b.ts +/////// +////[|foo|](); + + +let ranges = test.ranges(); + +for (let r of ranges) { + goTo.position(r.start); + verify.documentHighlightsAtPositionCount(2, ["b.ts"]); + + /*for (let range of ranges) { + verify.documentHighlightsAtPositionContains(range, ["a.ts"]); + }*/ +} +