From f92d24188826e4e132f935a5c8571f0ebab53153 Mon Sep 17 00:00:00 2001 From: zhengbli Date: Tue, 10 Nov 2015 13:36:19 -0800 Subject: [PATCH] Add file content as a parameter for the tsserver open command --- src/server/editorServices.ts | 10 ++++++---- src/server/protocol.d.ts | 1 + src/server/session.ts | 10 +++++++--- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index 333cea2745d..45d987ea534 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -1006,14 +1006,15 @@ namespace ts.server { /** * @param filename is absolute pathname + * @param fileContent is a known version of the file content that is more up to date */ - openFile(fileName: string, openedByClient: boolean) { + openFile(fileName: string, openedByClient: boolean, fileContent?: string) { fileName = ts.normalizePath(fileName); let info = ts.lookUp(this.filenameToScriptInfo, fileName); if (!info) { let content: string; if (this.host.fileExists(fileName)) { - content = this.host.readFile(fileName); + content = fileContent ? fileContent : this.host.readFile(fileName); } if (!content) { if (openedByClient) { @@ -1060,10 +1061,11 @@ namespace ts.server { /** * Open file whose contents is managed by the client * @param filename is absolute pathname + * @param fileContent is a known version of the file content that is more up to date */ - openClientFile(fileName: string) { + openClientFile(fileName: string, fileContent?: string) { this.openOrUpdateConfiguredProjectForFile(fileName); - const info = this.openFile(fileName, true); + const info = this.openFile(fileName, true, fileContent); this.addOpenFile(info); this.printProjects(); return info; diff --git a/src/server/protocol.d.ts b/src/server/protocol.d.ts index ad1fc5e92de..6354a3a37ae 100644 --- a/src/server/protocol.d.ts +++ b/src/server/protocol.d.ts @@ -513,6 +513,7 @@ declare namespace ts.server.protocol { * Information found in an "open" request. */ export interface OpenRequestArgs extends FileRequestArgs { + fileContent?: string; } /** diff --git a/src/server/session.ts b/src/server/session.ts index 770256cc9f7..c589c528ec2 100644 --- a/src/server/session.ts +++ b/src/server/session.ts @@ -532,9 +532,13 @@ namespace ts.server { }; } - private openClientFile(fileName: string) { + /** + * @param fileName is the name of the file to be opened + * @param fileContent is a version of the file content that is known to be more up to date + */ + private openClientFile(fileName: string, fileContent?: string) { const file = ts.normalizePath(fileName); - this.projectService.openClientFile(file); + this.projectService.openClientFile(file, fileContent); } private getQuickInfo(line: number, offset: number, fileName: string): protocol.QuickInfoResponseBody { @@ -968,7 +972,7 @@ namespace ts.server { }, [CommandNames.Open]: (request: protocol.Request) => { const openArgs = request.arguments; - this.openClientFile(openArgs.file); + this.openClientFile(openArgs.file, openArgs.fileContent); return {responseRequired: false}; }, [CommandNames.Quickinfo]: (request: protocol.Request) => {