Address feedback.

This commit is contained in:
Tien Nguyen 2015-08-04 15:46:38 -07:00
parent 67d986af43
commit 8550c7de4e
5 changed files with 53 additions and 47 deletions

View File

@ -2166,15 +2166,17 @@ module FourSlash {
this.raiseError('verifyDocumentHighlightsAtPositionListContains failed - found 0 highlights, expected at least one.');
}
for (let i = 0; i < documentHighlights.length; i++) if (documentHighlights[i].fileName === fileName) {
let { highlightSpans } = documentHighlights[i];
for (let documentHighlight of documentHighlights) {
if (documentHighlight.fileName === fileName) {
let { highlightSpans } = documentHighlight;
for (let highlight of highlightSpans) {
if (highlight && highlight.textSpan.start === start && ts.textSpanEnd(highlight.textSpan) === end) {
if (typeof kind !== "undefined" && highlight.kind !== kind) {
this.raiseError('verifyDocumentHighlightsAtPositionListContains failed - item "kind" value does not match, actual: ' + highlight.kind + ', expected: ' + kind + '.');
for (let highlight of highlightSpans) {
if (highlight && highlight.textSpan.start === start && ts.textSpanEnd(highlight.textSpan) === end) {
if (typeof kind !== "undefined" && highlight.kind !== kind) {
this.raiseError('verifyDocumentHighlightsAtPositionListContains failed - item "kind" value does not match, actual: ' + highlight.kind + ', expected: ' + kind + '.');
}
return;
}
return;
}
}
}
@ -2187,9 +2189,9 @@ module FourSlash {
this.taoInvalidReason = 'verifyDocumentHighlightsAtPositionListCount NYI';
let documentHighlights = this.getDocumentHighlightsAtCurrentPosition(fileNamesToSearch);
let actualCount = documentHighlights
? documentHighlights.reduce((currentCount, currentDocumentHighlights) => {
return currentCount + currentDocumentHighlights.highlightSpans.length}, 0)
let actualCount = documentHighlights
? documentHighlights.reduce((currentCount, { fileName, highlightSpans }) => {
return currentCount + highlightSpans.length}, 0)
: 0;
if (expectedCount !== actualCount) {

View File

@ -528,29 +528,32 @@ namespace ts.server {
}
getDocumentHighlights(fileName: string, position: number): DocumentHighlights[] {
var lineOffset = this.positionToOneBasedLineOffset(fileName, position);
var args: protocol.FileLocationRequestArgs = {
file: fileName,
line: lineOffset.line,
offset: lineOffset.offset,
};
let { line, offset } = this.positionToOneBasedLineOffset(fileName, position);
let args: protocol.FileLocationRequestArgs = { file: fileName, line, offset };
var request = this.processRequest<protocol.DocumentHighlightsRequest>(CommandNames.DocumentHighlights, args);
var response = this.processResponse<protocol.DocumentHighlightsResponse>(request);
let request = this.processRequest<protocol.DocumentHighlightsRequest>(CommandNames.DocumentHighlights, args);
let response = this.processResponse<protocol.DocumentHighlightsResponse>(request);
let _self = this;
return response.body.map(convertToDocumentHighlights);
function convertToDocumentHighlights(item: ts.server.protocol.DocumentHighlightsItem): ts.DocumentHighlights {
let { file, highlightSpans } = item;
return response.body.map(entry => { // convert ts.server.protocol.DocumentHighlightsItem to ts.DocumentHighlights
return {
fileName: entry.file,
highlightSpans: entry.highlightSpans.map(span => { // convert ts.server.protocol.HighlightSpan to ts.HighlighSpan
var start = this.lineOffsetToPosition(entry.file, span.start);
var end = this.lineOffsetToPosition(entry.file, span.end);
return {
textSpan: ts.createTextSpanFromBounds(start, end),
kind: span.kind
};
})
fileName: file,
highlightSpans: highlightSpans.map(convertHighlightSpan2)
};
});
function convertHighlightSpan2(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
};
}
}
}
getOutliningSpans(fileName: string): OutliningSpan[] {

View File

@ -246,13 +246,13 @@ declare namespace ts.server.protocol {
export interface DocumentHighlightsRequest extends FileLocationRequest {
}
export interface HighLightSpan extends TextSpan {
export interface HighlightSpan extends TextSpan {
kind: string
}
export interface DocumentHighlightsItem {
file: string,
highlightSpans: HighLightSpan[];
highlightSpans: HighlightSpan[];
}
export interface DocumentHighlightsResponse extends Response {

View File

@ -354,7 +354,7 @@ 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 filesToSearch = [ fileName ]; // only search for highlights inside the current file
let documentHighlights = compilerService.languageService.getDocumentHighlights(fileName, position, filesToSearch);
@ -362,22 +362,23 @@ namespace ts.server {
return undefined;
}
return documentHighlights.map(documentHighlight => { // convert ts.DocumentHighlights to ts.server.protocol.DocumentHighlightsItem
var file = documentHighlight.fileName;
return documentHighlights.map(convertToDocumentHighlightsItem);
function convertToDocumentHighlightsItem(documentHighlights: ts.DocumentHighlights): ts.server.protocol.DocumentHighlightsItem {
let { fileName, highlightSpans } = documentHighlights;
return {
file: file,
highlightSpans: documentHighlight.highlightSpans.map(highlightSpan => { // convert to ts.HighlightSpan to ts.server.protocol.HighlightSpan
let { textSpan, kind } = highlightSpan;
let start = compilerService.host.positionToLineOffset(file, textSpan.start);
let end = compilerService.host.positionToLineOffset(file, ts.textSpanEnd(textSpan));
return {
start: start,
end: end,
kind: kind
}
})
file: fileName,
highlightSpans: highlightSpans.map(convertHighlightSpan1)
};
function convertHighlightSpan1(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));
return { start, end, kind };
}
});
}
}
private getProjectInfo(fileName: string, needFileNameList: boolean): protocol.ProjectInfo {

View File

@ -425,7 +425,7 @@ module FourSlashInterface {
FourSlash.currentTestState.verifyDocumentHighlightsAtPositionListContains(range.fileName, range.start, range.end, fileNamesToSearch, kind);
}
public documentHighlightsAtPositionCount(expectedCount: number, fileNamesToSearch: string[], kind?: string) {
public documentHighlightsAtPositionCount(expectedCount: number, fileNamesToSearch: string[]) {
FourSlash.currentTestState.verifyDocumentHighlightsAtPositionListCount(expectedCount, fileNamesToSearch);
}