Skip to content

Commit d4f2ffe

Browse files
authored
(perf) improve svelte-check performance (#872)
Because of the setTimeout in the debounceSameArg. The document update in LSAndTSDocResolver is actually done after all the diagnostic is done. Because of that, the typescript language service has to rebuild its type checker multiple times due to a new document being loaded in. Fix that by not debouncing the call on a new document. This makes svelte-check run a lot faster.
1 parent bb40cb8 commit d4f2ffe

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

packages/language-server/src/plugins/typescript/LSAndTSDocResolver.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,24 @@ export class LSAndTSDocResolver {
1919
private readonly configManager: LSConfigManager,
2020
private readonly transformOnTemplateError = true
2121
) {
22+
const handleDocumentChange = (document: Document) => {
23+
// This refreshes the document in the ts language service
24+
this.getLSAndTSDoc(document);
25+
};
2226
docManager.on(
2327
'documentChange',
2428
debounceSameArg(
25-
async (document: Document) => {
26-
// This refreshes the document in the ts language service
27-
this.getLSAndTSDoc(document);
28-
},
29+
handleDocumentChange,
2930
(newDoc, prevDoc) => newDoc.uri === prevDoc?.uri,
3031
1000
3132
)
3233
);
34+
35+
// New files would cause typescript to rebuild its type-checker.
36+
// Open it immediately to reduce rebuilds in the startup
37+
// where multiple files and their dependencies
38+
// being loaded in a short period of times
39+
docManager.on('documentOpen', handleDocumentChange);
3340
}
3441

3542
/**

0 commit comments

Comments
 (0)