From 39f5bf36d1f377dacb7c873e6ef54896f0a95f12 Mon Sep 17 00:00:00 2001 From: Simon Holthausen Date: Wed, 19 May 2021 20:22:40 +0200 Subject: [PATCH] (feat) load all Svelte files on startup 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. --- .../language-server/src/plugins/typescript/service.ts | 11 ++++++++++- .../typescript/features/CompletionProvider.test.ts | 8 ++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/packages/language-server/src/plugins/typescript/service.ts b/packages/language-server/src/plugins/typescript/service.ts index 9ae3a31d2..06a5c2a51 100644 --- a/packages/language-server/src/plugins/typescript/service.ts +++ b/packages/language-server/src/plugins/typescript/service.ts @@ -228,7 +228,16 @@ async function createLanguageService( forcedCompilerOptions, tsconfigPath, undefined, - [{ extension: 'svelte', isMixedContent: false, scriptKind: ts.ScriptKind.TSX }] + [ + { + extension: 'svelte', + isMixedContent: true, + // Deferred was added in a later TS version, fall back to tsx + // If Deferred exists, this means that all Svelte files are included + // in parsedConfig.fileNames + scriptKind: ts.ScriptKind.Deferred ?? ts.ScriptKind.TSX + } + ] ); const compilerOptions: ts.CompilerOptions = { diff --git a/packages/language-server/test/plugins/typescript/features/CompletionProvider.test.ts b/packages/language-server/test/plugins/typescript/features/CompletionProvider.test.ts index ebc3c4c46..a1a79e21a 100644 --- a/packages/language-server/test/plugins/typescript/features/CompletionProvider.test.ts +++ b/packages/language-server/test/plugins/typescript/features/CompletionProvider.test.ts @@ -606,12 +606,12 @@ describe.only('CompletionProviderImpl', () => { item! ); - assert.strictEqual(detail, 'Auto import from ./imported-file.svelte\nclass ImportedFile'); + assert.strictEqual(detail, 'Auto import from ../imported-file.svelte\nclass ImportedFile'); assert.strictEqual( harmonizeNewLines(additionalTextEdits![0]?.newText), // " instead of ' because VSCode uses " by default when there are no other imports indicating otherwise - `${newLine}import ImportedFile from "./imported-file.svelte";${newLine}` + `${newLine}import ImportedFile from "../imported-file.svelte";${newLine}` ); assert.deepEqual( @@ -641,12 +641,12 @@ describe.only('CompletionProviderImpl', () => { item! ); - assert.strictEqual(detail, 'Auto import from ./imported-file.svelte\nclass ImportedFile'); + assert.strictEqual(detail, 'Auto import from ../imported-file.svelte\nclass ImportedFile'); assert.strictEqual( harmonizeNewLines(additionalTextEdits![0]?.newText), // " instead of ' because VSCode uses " by default when there are no other imports indicating otherwise - `${newLine}` );