Skip to content

Commit

Permalink
fix(typescript): avoid crash when converting relatedInformation from …
Browse files Browse the repository at this point in the history
…overly large files
  • Loading branch information
johnsoncodehk committed Nov 6, 2024
1 parent 48e49ea commit e242709
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,20 @@ export function createAsyncLanguageServicePlugin(
],
new FileMap(ts.sys.useCaseSensitiveFileNames),
fileName => {
let 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);
}
try { // getSnapshot could be crashed if the file is too large
let 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 { }
}
);

Expand Down
26 changes: 14 additions & 12 deletions packages/typescript/lib/quickstart/createLanguageServicePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,20 @@ export function createLanguageServicePlugin(
],
new FileMap(ts.sys.useCaseSensitiveFileNames),
fileName => {
let 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);
}
try { // getSnapshot could be crashed if the file is too large
let 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 { }
}
);

Expand Down

0 comments on commit e242709

Please sign in to comment.