Skip to content

Commit

Permalink
fix: cannot track latest ts file snapshot if file do not include to t…
Browse files Browse the repository at this point in the history
…sconfig

close #1946
  • Loading branch information
johnsoncodehk committed Oct 8, 2022
1 parent 17c50ca commit 51de991
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
6 changes: 6 additions & 0 deletions packages/language-core/src/languageContext.ts
Expand Up @@ -151,13 +151,19 @@ 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);
if (snapshot) {
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;
Expand Down
9 changes: 2 additions & 7 deletions packages/language-server/src/utils/snapshots.ts
Expand Up @@ -174,7 +174,6 @@ function _combineContinuousChangeRanges(a: ts.TextChangeRange, b: ts.TextChangeR
export function createSnapshots(connection: vscode.Connection) {

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

Expand All @@ -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 => {
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 1 addition & 4 deletions packages/language-server/src/utils/workspaces.ts
Expand Up @@ -30,10 +30,7 @@ export function createWorkspaces(

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

documents.onDidOpen(params => {
updateDiagnostics(params.textDocument.uri);
});
documents.onDidChangeContent(async params => {
documents.onDidChangeContent(params => {
updateDiagnostics(params.textDocument.uri);
});
documents.onDidClose(params => {
Expand Down

0 comments on commit 51de991

Please sign in to comment.