switch to use explicit list of open files

This commit is contained in:
Vladimir Matveev 2016-06-09 13:55:08 -07:00
parent e817faabfe
commit b9729a79fc
3 changed files with 20 additions and 15 deletions

View File

@ -1484,18 +1484,18 @@ namespace ts.server {
return files;
}
applyChangesInOpenFiles(openFiles: protocol.OpenFile[], closedFiles: string[]): void {
applyChangesInOpenFiles(openFiles: protocol.NewOpenFile[], changedFiles: protocol.ChangedOpenFile[], closedFiles: string[]): void {
for (const file of openFiles) {
const scriptInfo = this.getScriptInfo(file.fileName);
if (!scriptInfo || !scriptInfo.isOpen) {
Debug.assert(!!file.content);
this.openClientFile(file.fileName, file.content);
}
else {
Debug.assert(!!file.textChanges);
for (const change of file.textChanges) {
scriptInfo.editContent(change.span.start, change.span.start + change.span.length, change.newText);
}
Debug.assert(!scriptInfo || !scriptInfo.isOpen);
this.openClientFile(file.fileName, file.content);
}
for (const file of changedFiles) {
const scriptInfo = this.getScriptInfo(file.fileName);
Debug.assert(!!scriptInfo);
for (const change of file.changes) {
scriptInfo.editContent(change.span.start, change.span.start + change.span.length, change.newText);
}
}

View File

@ -451,10 +451,14 @@ declare namespace ts.server.protocol {
* Represents a set of changes for open document with a given file name.
* Either content of textChanges should be present.
*/
export interface OpenFile {
export interface NewOpenFile {
fileName: string;
content?: string;
textChanges?: ts.TextChange[];
content: string;
}
export interface ChangedOpenFile {
fileName: string;
changes: ts.TextChange[];
}
/**
@ -611,7 +615,8 @@ declare namespace ts.server.protocol {
}
export interface ApplyChangedToOpenFilesRequestArgs {
openFiles: OpenFile[];
openFiles: NewOpenFile[];
changedFiles: ChangedOpenFile[];
closedFiles: string[];
}

View File

@ -1063,7 +1063,7 @@ namespace ts.server {
return this.requiredResponse(result);
},
[CommandNames.ApplyChangedToOpenFiles]: (request: protocol.ApplyChangedToOpenFilesRequest) => {
this.projectService.applyChangesInOpenFiles(request.arguments.openFiles, request.arguments.closedFiles);
this.projectService.applyChangesInOpenFiles(request.arguments.openFiles, request.arguments.changedFiles, request.arguments.closedFiles);
// TODO: report errors
return this.requiredResponse(true);
},