Skip to content

Commit

Permalink
fix(typescript): should not suppressing getLanguageId crashes
Browse files Browse the repository at this point in the history
close #253
  • Loading branch information
johnsoncodehk committed Dec 8, 2024
1 parent 3e996b3 commit bdbd555
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,20 +82,23 @@ export function createAsyncLanguageServicePlugin(
],
new FileMap(ts.sys.useCaseSensitiveFileNames),
fileName => {
let snapshot: ts.IScriptSnapshot | undefined;

try { // getSnapshot could be crashed if the file is too large
let snapshot = info.project.getScriptInfo(fileName)?.getSnapshot();
snapshot = info.project.getScriptInfo(fileName)?.getSnapshot();
if (!snapshot) {
// trigger projectService.getOrCreateScriptInfoNotOpenedByClient
info.project.getScriptVersion(fileName);
snapshot = info.project.getScriptInfo(fileName)?.getSnapshot();
}
if (snapshot) {
language.scripts.set(fileName, snapshot);
}
else {
language.scripts.delete(fileName);
}
} catch { }

if (snapshot) {
language.scripts.set(fileName, snapshot);
}
else {
language.scripts.delete(fileName);
}
}
);

Expand Down
17 changes: 10 additions & 7 deletions packages/typescript/lib/quickstart/createLanguageServicePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,23 @@ export function createLanguageServicePlugin(
],
new FileMap(ts.sys.useCaseSensitiveFileNames),
fileName => {
let snapshot: ts.IScriptSnapshot | undefined;

try { // getSnapshot could be crashed if the file is too large
let snapshot = info.project.getScriptInfo(fileName)?.getSnapshot();
snapshot = info.project.getScriptInfo(fileName)?.getSnapshot();
if (!snapshot) {
// trigger projectService.getOrCreateScriptInfoNotOpenedByClient
info.project.getScriptVersion(fileName);
snapshot = info.project.getScriptInfo(fileName)?.getSnapshot();
}
if (snapshot) {
language.scripts.set(fileName, snapshot);
}
else {
language.scripts.delete(fileName);
}
} catch { }

if (snapshot) {
language.scripts.set(fileName, snapshot);
}
else {
language.scripts.delete(fileName);
}
}
);

Expand Down

0 comments on commit bdbd555

Please sign in to comment.