mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-16 07:13:45 -05:00
Address feedback.
This commit is contained in:
@@ -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[] {
|
||||
|
||||
4
src/server/protocol.d.ts
vendored
4
src/server/protocol.d.ts
vendored
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user