Skip to content

Commit c685ef0

Browse files
Keen Yee Liauayazhafiz
authored andcommitted
fix: do not include fileContent when opening file (#476)
When a file is first opened in the editor, we should not pass `fileContent` to the project service, because doing so assumes that the content in the editor is more up-to-date than the content on disk, which is not true. We only keep track of changes of files that are already on disk, so the content on disk is already the latest snapshot. This is a prerequisite to remove `getExternalFiles()`. See discussion at #473
1 parent c09e75e commit c685ef0

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

server/src/session.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,14 +161,18 @@ export class Session {
161161
}
162162

163163
private onDidOpenTextDocument(params: lsp.DidOpenTextDocumentParams) {
164-
const {uri, text, languageId} = params.textDocument;
164+
const {uri, languageId} = params.textDocument;
165165
const filePath = uriToFilePath(uri);
166166
if (!filePath) {
167167
return;
168168
}
169-
170169
const scriptKind = languageId === LanguageId.TS ? ts.ScriptKind.TS : ts.ScriptKind.External;
171-
const result = this.projectService.openClientFile(filePath, text, scriptKind);
170+
// Since we are only keeping track of changes of files that are already on
171+
// disk (see documentSelector.scheme in extension.ts), the content on disk
172+
// is up-to-date when a file is first opened in the editor.
173+
// In this case, we should not pass fileContent to projectService.
174+
const fileContent = undefined;
175+
const result = this.projectService.openClientFile(filePath, fileContent, scriptKind);
172176

173177
const {configFileName, configFileErrors} = result;
174178
if (configFileErrors && configFileErrors.length) {

0 commit comments

Comments
 (0)