Skip to content

Commit 51de991

Browse files
committed
fix: cannot track latest ts file snapshot if file do not include to tsconfig
close #1946
1 parent 17c50ca commit 51de991

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed

packages/language-core/src/languageContext.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,19 @@ export function createEmbeddedLanguageServiceHost(
151151
}
152152
}
153153

154+
// no any vue file version change, it mean project version was update by ts file change at this time
155+
if (!sourceFilesToUpdate.length) {
156+
tsFileUpdated = true;
157+
}
158+
154159
// add
155160
for (const fileName of [...remainFileNames]) {
156161
const snapshot = host.getScriptSnapshot(fileName);
157162
if (snapshot) {
158163
for (const languageModule of languageModules) {
159164
const sourceFile = languageModule.createSourceFile(fileName, snapshot);
160165
if (sourceFile) {
166+
fileVersions.set(sourceFile.fileName, host.getScriptVersion(fileName));
161167
documentRegistry.set(fileName, reactive(sourceFile), languageModule);
162168
remainFileNames.delete(fileName);
163169
break;

packages/language-server/src/utils/snapshots.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@ function _combineContinuousChangeRanges(a: ts.TextChangeRange, b: ts.TextChangeR
174174
export function createSnapshots(connection: vscode.Connection) {
175175

176176
const snapshots = shared.createUriMap<IncrementalScriptSnapshot>();
177-
const onDidOpens = new Set<(params: vscode.DidOpenTextDocumentParams) => void>();
178177
const onDidChangeContents = new Set<(params: vscode.DidChangeTextDocumentParams) => void>();
179178
const onDidCloses = new Set<(params: vscode.DidCloseTextDocumentParams) => void>();
180179

@@ -185,8 +184,8 @@ export function createSnapshots(connection: vscode.Connection) {
185184
params.textDocument.version,
186185
params.textDocument.text,
187186
));
188-
for (const cb of onDidOpens) {
189-
cb(params);
187+
for (const cb of onDidChangeContents) {
188+
cb({ textDocument: params.textDocument, contentChanges: [{ text: params.textDocument.text }] });
190189
}
191190
});
192191
connection.onDidChangeTextDocument(params => {
@@ -220,10 +219,6 @@ export function createSnapshots(connection: vscode.Connection) {
220219

221220
return {
222221
data: snapshots,
223-
onDidOpen: (cb: (params: vscode.DidOpenTextDocumentParams) => void) => {
224-
onDidOpens.add(cb);
225-
return () => onDidOpens.delete(cb);
226-
},
227222
onDidChangeContent: (cb: (params: vscode.DidChangeTextDocumentParams) => void) => {
228223
onDidChangeContents.add(cb);
229224
return () => onDidChangeContents.delete(cb);

packages/language-server/src/utils/workspaces.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,7 @@ export function createWorkspaces(
3030

3131
const workspaces = new Map<string, ReturnType<typeof createWorkspaceProjects>>();
3232

33-
documents.onDidOpen(params => {
34-
updateDiagnostics(params.textDocument.uri);
35-
});
36-
documents.onDidChangeContent(async params => {
33+
documents.onDidChangeContent(params => {
3734
updateDiagnostics(params.textDocument.uri);
3835
});
3936
documents.onDidClose(params => {

0 commit comments

Comments
 (0)