Add file content as a parameter for the tsserver open command

This commit is contained in:
zhengbli
2015-11-10 13:36:19 -08:00
parent ad61788113
commit f92d241888
3 changed files with 14 additions and 7 deletions

View File

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

View File

@@ -513,6 +513,7 @@ declare namespace ts.server.protocol {
* Information found in an "open" request.
*/
export interface OpenRequestArgs extends FileRequestArgs {
fileContent?: string;
}
/**

View File

@@ -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 = <protocol.OpenRequestArgs>request.arguments;
this.openClientFile(openArgs.file);
this.openClientFile(openArgs.file, openArgs.fileContent);
return {responseRequired: false};
},
[CommandNames.Quickinfo]: (request: protocol.Request) => {