Skip to content

Commit 6c4521f

Browse files
author
Keen Yee Liau
committed
fix: editor buffer out of sync with file on disk
In #476 it was incorrectly assumed that the content on disk is the most up-to-date version. An unsaved buffer in the editor could be newer than the file on disk and thus we should always load the script with the snapshot from editor. PR fix #632
1 parent 3c7f64b commit 6c4521f

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

server/src/session.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -166,19 +166,17 @@ export class Session {
166166
}
167167

168168
private onDidOpenTextDocument(params: lsp.DidOpenTextDocumentParams) {
169-
const {uri, languageId} = params.textDocument;
169+
const {uri, languageId, text} = params.textDocument;
170170
const filePath = uriToFilePath(uri);
171171
if (!filePath) {
172172
return;
173173
}
174174
const scriptKind = languageId === LanguageId.TS ? ts.ScriptKind.TS : ts.ScriptKind.External;
175-
// Since we are only keeping track of changes of files that are already on
176-
// disk (see documentSelector.scheme in extension.ts), the content on disk
177-
// is up-to-date when a file is first opened in the editor.
178-
// In this case, we should not pass fileContent to projectService.
179-
const fileContent = undefined;
180175
try {
181-
const result = this.projectService.openClientFile(filePath, fileContent, scriptKind);
176+
// The content could be newer than that on disk. This could be due to
177+
// buffer in the user's editor which has not been saved to disk.
178+
// See https://github.com/angular/vscode-ng-language-service/issues/632
179+
const result = this.projectService.openClientFile(filePath, text, scriptKind);
182180

183181
const {configFileName, configFileErrors} = result;
184182
if (configFileErrors && configFileErrors.length) {

0 commit comments

Comments
 (0)