From 51de9917963db44e80677f89e836976098102d13 Mon Sep 17 00:00:00 2001 From: johnsoncodehk Date: Sat, 8 Oct 2022 21:23:21 +0800 Subject: [PATCH] fix: cannot track latest ts file snapshot if file do not include to tsconfig close #1946 --- packages/language-core/src/languageContext.ts | 6 ++++++ packages/language-server/src/utils/snapshots.ts | 9 ++------- packages/language-server/src/utils/workspaces.ts | 5 +---- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/packages/language-core/src/languageContext.ts b/packages/language-core/src/languageContext.ts index dc69e7be0..c0854b5f4 100644 --- a/packages/language-core/src/languageContext.ts +++ b/packages/language-core/src/languageContext.ts @@ -151,6 +151,11 @@ export function createEmbeddedLanguageServiceHost( } } + // no any vue file version change, it mean project version was update by ts file change at this time + if (!sourceFilesToUpdate.length) { + tsFileUpdated = true; + } + // add for (const fileName of [...remainFileNames]) { const snapshot = host.getScriptSnapshot(fileName); @@ -158,6 +163,7 @@ export function createEmbeddedLanguageServiceHost( for (const languageModule of languageModules) { const sourceFile = languageModule.createSourceFile(fileName, snapshot); if (sourceFile) { + fileVersions.set(sourceFile.fileName, host.getScriptVersion(fileName)); documentRegistry.set(fileName, reactive(sourceFile), languageModule); remainFileNames.delete(fileName); break; diff --git a/packages/language-server/src/utils/snapshots.ts b/packages/language-server/src/utils/snapshots.ts index ed54ba623..98cbf0869 100644 --- a/packages/language-server/src/utils/snapshots.ts +++ b/packages/language-server/src/utils/snapshots.ts @@ -174,7 +174,6 @@ function _combineContinuousChangeRanges(a: ts.TextChangeRange, b: ts.TextChangeR export function createSnapshots(connection: vscode.Connection) { const snapshots = shared.createUriMap(); - const onDidOpens = new Set<(params: vscode.DidOpenTextDocumentParams) => void>(); const onDidChangeContents = new Set<(params: vscode.DidChangeTextDocumentParams) => void>(); const onDidCloses = new Set<(params: vscode.DidCloseTextDocumentParams) => void>(); @@ -185,8 +184,8 @@ export function createSnapshots(connection: vscode.Connection) { params.textDocument.version, params.textDocument.text, )); - for (const cb of onDidOpens) { - cb(params); + for (const cb of onDidChangeContents) { + cb({ textDocument: params.textDocument, contentChanges: [{ text: params.textDocument.text }] }); } }); connection.onDidChangeTextDocument(params => { @@ -220,10 +219,6 @@ export function createSnapshots(connection: vscode.Connection) { return { data: snapshots, - onDidOpen: (cb: (params: vscode.DidOpenTextDocumentParams) => void) => { - onDidOpens.add(cb); - return () => onDidOpens.delete(cb); - }, onDidChangeContent: (cb: (params: vscode.DidChangeTextDocumentParams) => void) => { onDidChangeContents.add(cb); return () => onDidChangeContents.delete(cb); diff --git a/packages/language-server/src/utils/workspaces.ts b/packages/language-server/src/utils/workspaces.ts index 60643471b..bda9ad8fe 100644 --- a/packages/language-server/src/utils/workspaces.ts +++ b/packages/language-server/src/utils/workspaces.ts @@ -30,10 +30,7 @@ export function createWorkspaces( const workspaces = new Map>(); - documents.onDidOpen(params => { - updateDiagnostics(params.textDocument.uri); - }); - documents.onDidChangeContent(async params => { + documents.onDidChangeContent(params => { updateDiagnostics(params.textDocument.uri); }); documents.onDidClose(params => {