Add filesToSearch to documentHighlights request.

This commit is contained in:
Tien Nguyen
2015-08-06 14:01:36 -07:00
parent 71e6f3a947
commit bf7d923e09
4 changed files with 44 additions and 15 deletions

View File

@@ -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<protocol.DocumentHighlightsRequest>(CommandNames.DocumentHighlights, args);
let response = this.processResponse<protocol.DocumentHighlightsResponse>(request);

View File

@@ -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

View File

@@ -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 } = <protocol.FileLocationRequestArgs>request.arguments;
return {response: this.getDocumentHighlights(line, offset, fileName), responseRequired: true};
var { line, offset, file: fileName, filesToSearch } = <protocol.DocumentHighlightsRequestArgs>request.arguments;
return {response: this.getDocumentHighlights(line, offset, fileName, filesToSearch), responseRequired: true};
},
[CommandNames.ProjectInfo]: (request: protocol.Request) => {
var { file, needFileNameList } = <protocol.ProjectInfoRequestArgs>request.arguments;

View File

@@ -1,23 +1,35 @@
/// <reference path="../fourslash.ts"/>
// @Filename: a.ts
////function foo() {
////function [|foo|] () {
//// return 1;
////}
////[|foo|]();
// @Filename: b.ts
/////// <reference path="a.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"]);
}
}