diff --git a/src/server/client.ts b/src/server/client.ts index 2ec0dd4de62..cc89349b442 100644 --- a/src/server/client.ts +++ b/src/server/client.ts @@ -527,9 +527,9 @@ namespace ts.server { }); } - getDocumentHighlights(fileName: string, position: number): DocumentHighlights[] { + getDocumentHighlights(fileName: string, position: number, filesToSearch: string[]): DocumentHighlights[] { let { line, offset } = this.positionToOneBasedLineOffset(fileName, position); - let args: protocol.FileLocationRequestArgs = { file: fileName, line, offset }; + let args: protocol.DocumentHighlightsRequestArgs = { file: fileName, line, offset, filesToSearch }; let request = this.processRequest(CommandNames.DocumentHighlights, args); let response = this.processResponse(request); diff --git a/src/server/protocol.d.ts b/src/server/protocol.d.ts index bdabf89a982..837bce4f99d 100644 --- a/src/server/protocol.d.ts +++ b/src/server/protocol.d.ts @@ -156,6 +156,17 @@ declare namespace ts.server.protocol { arguments: FileLocationRequestArgs; } + /** + * Arguments in document highlight request; include: filesToSearch, file, + * line, offset. + */ + export interface DocumentHighlightsRequestArgs extends FileLocationRequestArgs { + /** + * List of files to search for document highlights. + */ + filesToSearch: string[]; + } + /** * Go to definition request; value of command field is * "definition". Return response giving the file locations that @@ -244,6 +255,7 @@ declare namespace ts.server.protocol { * in the file at a given line and column. */ export interface DocumentHighlightsRequest extends FileLocationRequest { + arguments: DocumentHighlightsRequestArgs } export interface HighlightSpan extends TextSpan { @@ -251,7 +263,14 @@ declare namespace ts.server.protocol { } export interface DocumentHighlightsItem { + /** + * File containing highlight spans. + */ file: string, + + /** + * Spans to highlight in file. + */ highlightSpans: HighlightSpan[]; } @@ -259,7 +278,6 @@ declare namespace ts.server.protocol { body?: DocumentHighlightsItem[]; } - /** * Find references request; value of command field is * "references". Return response giving the file locations that diff --git a/src/server/session.ts b/src/server/session.ts index 963c443f09b..54e4423d382 100644 --- a/src/server/session.ts +++ b/src/server/session.ts @@ -344,7 +344,7 @@ namespace ts.server { }); } - private getDocumentHighlights(line: number, offset: number, fileName: string): protocol.DocumentHighlightsItem[] { + private getDocumentHighlights(line: number, offset: number, fileName: string, filesToSearch: string[]): protocol.DocumentHighlightsItem[] { fileName = ts.normalizePath(fileName); let project = this.projectService.getProjectForFile(fileName); @@ -354,7 +354,6 @@ namespace ts.server { let { compilerService } = project; let position = compilerService.host.lineOffsetToPosition(fileName, line, offset); - let filesToSearch = [ fileName ]; // only search for highlights inside the current file let documentHighlights = compilerService.languageService.getDocumentHighlights(fileName, position, filesToSearch); @@ -976,8 +975,8 @@ namespace ts.server { return {response: this.getOccurrences(line, offset, fileName), responseRequired: true}; }, [CommandNames.DocumentHighlights]: (request: protocol.Request) => { - var { line, offset, file: fileName } = request.arguments; - return {response: this.getDocumentHighlights(line, offset, fileName), responseRequired: true}; + var { line, offset, file: fileName, filesToSearch } = request.arguments; + return {response: this.getDocumentHighlights(line, offset, fileName, filesToSearch), responseRequired: true}; }, [CommandNames.ProjectInfo]: (request: protocol.Request) => { var { file, needFileNameList } = request.arguments; diff --git a/tests/cases/fourslash/server/documentHighlights02.ts b/tests/cases/fourslash/server/documentHighlights02.ts index 8cf7038395a..357f82e9c2d 100644 --- a/tests/cases/fourslash/server/documentHighlights02.ts +++ b/tests/cases/fourslash/server/documentHighlights02.ts @@ -1,23 +1,35 @@ /// // @Filename: a.ts -////function foo() { +////function [|foo|] () { //// return 1; ////} +////[|foo|](); // @Filename: b.ts /////// -////[|foo|](); +////foo(); +// open two files +goTo.file("a.ts"); +goTo.file("b.ts"); let ranges = test.ranges(); -for (let r of ranges) { +for (let i = 0; i < ranges.length; ++i) { + let r = ranges[i]; + + if (i < 2) { + goTo.file("a.ts"); + } + else { + goTo.file("b.ts"); + } + goTo.position(r.start); - verify.documentHighlightsAtPositionCount(2, ["b.ts"]); + verify.documentHighlightsAtPositionCount(3, ["a.ts", "b.ts"]); - /*for (let range of ranges) { - verify.documentHighlightsAtPositionContains(range, ["a.ts"]); - }*/ + for (let range of ranges) { + verify.documentHighlightsAtPositionContains(range, ["a.ts", "b.ts"]); + } } -