mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-20 05:17:43 -05:00
Add file content as a parameter for the tsserver open command
This commit is contained in:
@@ -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;
|
||||
|
||||
1
src/server/protocol.d.ts
vendored
1
src/server/protocol.d.ts
vendored
@@ -513,6 +513,7 @@ declare namespace ts.server.protocol {
|
||||
* Information found in an "open" request.
|
||||
*/
|
||||
export interface OpenRequestArgs extends FileRequestArgs {
|
||||
fileContent?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
Reference in New Issue
Block a user