Skip to content

Commit 134e035

Browse files
authored
(feat) load all Svelte files on startup (#1013)
Change the ScriptKind to Deferred which means that the tsconfig loader is able to also determine all Svelte files that are part of the tsconfig. This should ensure slightly better startup times and also make it possible to import Svelte files which are referenced nowhere else yet.
1 parent 9d9fd7b commit 134e035

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,16 @@ async function createLanguageService(
228228
forcedCompilerOptions,
229229
tsconfigPath,
230230
undefined,
231-
[{ extension: 'svelte', isMixedContent: false, scriptKind: ts.ScriptKind.TSX }]
231+
[
232+
{
233+
extension: 'svelte',
234+
isMixedContent: true,
235+
// Deferred was added in a later TS version, fall back to tsx
236+
// If Deferred exists, this means that all Svelte files are included
237+
// in parsedConfig.fileNames
238+
scriptKind: ts.ScriptKind.Deferred ?? ts.ScriptKind.TSX
239+
}
240+
]
232241
);
233242

234243
const compilerOptions: ts.CompilerOptions = {

packages/language-server/test/plugins/typescript/features/CompletionProvider.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -606,12 +606,12 @@ describe.only('CompletionProviderImpl', () => {
606606
item!
607607
);
608608

609-
assert.strictEqual(detail, 'Auto import from ./imported-file.svelte\nclass ImportedFile');
609+
assert.strictEqual(detail, 'Auto import from ../imported-file.svelte\nclass ImportedFile');
610610

611611
assert.strictEqual(
612612
harmonizeNewLines(additionalTextEdits![0]?.newText),
613613
// " instead of ' because VSCode uses " by default when there are no other imports indicating otherwise
614-
`${newLine}import ImportedFile from "./imported-file.svelte";${newLine}`
614+
`${newLine}import ImportedFile from "../imported-file.svelte";${newLine}`
615615
);
616616

617617
assert.deepEqual(
@@ -641,12 +641,12 @@ describe.only('CompletionProviderImpl', () => {
641641
item!
642642
);
643643

644-
assert.strictEqual(detail, 'Auto import from ./imported-file.svelte\nclass ImportedFile');
644+
assert.strictEqual(detail, 'Auto import from ../imported-file.svelte\nclass ImportedFile');
645645

646646
assert.strictEqual(
647647
harmonizeNewLines(additionalTextEdits![0]?.newText),
648648
// " instead of ' because VSCode uses " by default when there are no other imports indicating otherwise
649-
`<script>${newLine}import ImportedFile from "./imported-file.svelte";` +
649+
`<script>${newLine}import ImportedFile from "../imported-file.svelte";` +
650650
`${newLine}${newLine}</script>${newLine}`
651651
);
652652

0 commit comments

Comments
 (0)