diff --git a/src/server/protocol.d.ts b/src/server/protocol.d.ts index ef66b0119d4..db093f09ef7 100644 --- a/src/server/protocol.d.ts +++ b/src/server/protocol.d.ts @@ -182,6 +182,15 @@ declare namespace ts.server.protocol { arguments: FileLocationRequestArgs; } + export interface FileSpanRequestArgs extends FileRequestArgs { + start: number; + length: number; + } + + export interface FileSpanRequest extends FileRequest { + arguments: FileSpanRequestArgs; + } + /** * Arguments in document highlight request; include: filesToSearch, file, * line, offset. diff --git a/src/server/session.ts b/src/server/session.ts index f797aa2b08d..f9820bc1f4b 100644 --- a/src/server/session.ts +++ b/src/server/session.ts @@ -138,6 +138,7 @@ namespace ts.server { export const CloseExternalProject = "closeExternalProject"; export const SynchronizeProjectList = "synchronizeProjectList"; export const ApplyChangedToOpenFiles = "applyChangedToOpenFiles"; + export const EncodedSemanticClassificationsFull = "encodedSemanticClassifications-full"; } namespace Errors { @@ -251,25 +252,6 @@ namespace ts.server { return { line, offset: offset + 1 }; } - private getSemanticDiagnostics(args: protocol.FileRequestArgs): protocol.DiagnosticWithLinePosition[] { - const file = normalizePath(args.file); - var project = (args.projectFileName && this.projectService.getProject(normalizePath(args.projectFileName))) || this.projectService.getProjectForFile(file); - if (!project) { - return []; - } - const scriptInfo = project.getScriptInfo(file); - const diagnostics = project.languageService.getSemanticDiagnostics(file); - return diagnostics.map(d => { - message: flattenDiagnosticMessageText(d.messageText, this.host.newLine), - start: d.start, - length: d.length, - category: DiagnosticCategory[d.category].toLowerCase(), - code: d.code, - startLocation: this.getLocation(d.start, scriptInfo), - endLocation: this.getLocation(d.start + d.length, scriptInfo) - }); - } - private semanticCheck(file: string, project: Project) { try { const diags = project.languageService.getSemanticDiagnostics(file); @@ -346,6 +328,34 @@ namespace ts.server { } } + private getEncodedSemanticClassifications(args: protocol.FileSpanRequestArgs) { + const file = normalizePath(args.file); + const project = this.projectService.getProjectForFile(file); + if (!project) { + throw Errors.NoProject; + } + return project.languageService.getEncodedSemanticClassifications(file, args); + } + + private getSemanticDiagnostics(args: protocol.FileRequestArgs): protocol.DiagnosticWithLinePosition[] { + const file = normalizePath(args.file); + var project = (args.projectFileName && this.projectService.getProject(normalizePath(args.projectFileName))) || this.projectService.getProjectForFile(file); + if (!project) { + throw Errors.NoProject; + } + const scriptInfo = project.getScriptInfo(file); + const diagnostics = project.languageService.getSemanticDiagnostics(file); + return diagnostics.map(d => { + message: flattenDiagnosticMessageText(d.messageText, this.host.newLine), + start: d.start, + length: d.length, + category: DiagnosticCategory[d.category].toLowerCase(), + code: d.code, + startLocation: this.getLocation(d.start, scriptInfo), + endLocation: this.getLocation(d.start + d.length, scriptInfo) + }); + } + private getDefinition(args: protocol.FileLocationRequestArgs, simplifiedResult: boolean): protocol.FileSpan[] | DefinitionInfo[] { const file = ts.normalizePath(args.file); const project = this.projectService.getProjectForFile(file); @@ -1198,6 +1208,9 @@ namespace ts.server { [CommandNames.SemanticDiagnosticsFull]: (request: protocol.FileRequest) => { return this.requiredResponse(this.getSemanticDiagnostics(request.arguments)); }, + [CommandNames.EncodedSemanticClassificationsFull]: (request: protocol.FileSpanRequest) => { + return this.requiredResponse(this.getEncodedSemanticClassifications(request.arguments)); + }, [CommandNames.Geterr]: (request: protocol.Request) => { const geterrArgs = request.arguments; return { response: this.getDiagnostics(geterrArgs.delay, geterrArgs.files), responseRequired: false };