From 6f8783305a608bbfa4ece4bca314aff96b18c31d Mon Sep 17 00:00:00 2001 From: "Lyu, Wei Da" Date: Fri, 16 Aug 2024 12:53:08 +0800 Subject: [PATCH] breaking: put non-project files to default service --- .../src/plugins/typescript/service.ts | 12 ++++-- .../test/plugins/typescript/service.test.ts | 39 +++++++++++-------- 2 files changed, 31 insertions(+), 20 deletions(-) diff --git a/packages/language-server/src/plugins/typescript/service.ts b/packages/language-server/src/plugins/typescript/service.ts index cdeed8b2b..5a378d246 100644 --- a/packages/language-server/src/plugins/typescript/service.ts +++ b/packages/language-server/src/plugins/typescript/service.ts @@ -156,7 +156,7 @@ export async function getService( ); }; - const tsconfigPath = + let tsconfigPath = configFileForOpenFiles.get(path) ?? findTsConfigPath(path, workspaceUris, fileExistsWithCache, getCanonicalFileName); @@ -171,9 +171,13 @@ export async function getService( return service; } - service = (await findDefaultServiceForFile(service, triedTsConfig)) ?? service; - configFileForOpenFiles.set(path, service.tsconfigPath); - return service; + const defaultService = await findDefaultServiceForFile(service, triedTsConfig); + if (defaultService) { + configFileForOpenFiles.set(path, defaultService.tsconfigPath); + return defaultService; + } + + tsconfigPath = ''; } // Find closer boundary: workspace uri or node_modules diff --git a/packages/language-server/test/plugins/typescript/service.test.ts b/packages/language-server/test/plugins/typescript/service.test.ts index ee195b079..a76c82773 100644 --- a/packages/language-server/test/plugins/typescript/service.test.ts +++ b/packages/language-server/test/plugins/typescript/service.test.ts @@ -54,6 +54,11 @@ describe('service', () => { }) ); + virtualSystem.writeFile( + path.join(dirPath, 'random.svelte'), + '' + ); + const ls = await getService( path.join(dirPath, 'random.svelte'), rootUris, @@ -89,6 +94,11 @@ describe('service', () => { }) ); + virtualSystem.writeFile( + path.join(dirPath, 'random.svelte'), + '' + ); + const ls = await getService( path.join(dirPath, 'random.svelte'), rootUris, @@ -160,6 +170,11 @@ describe('service', () => { }) ); + virtualSystem.writeFile( + path.join(dirPath, 'random.svelte'), + '' + ); + const { reloadPromise, docContextWithReload } = createReloadTester( { ...lsDocumentContext, watchTsConfig: true }, testAfterReload @@ -207,6 +222,11 @@ describe('service', () => { }) ); + virtualSystem.writeFile( + path.join(dirPath, 'random.svelte'), + '' + ); + const { reloadPromise, docContextWithReload } = createReloadTester( { ...lsDocumentContext, watchTsConfig: true }, testAfterReload @@ -304,18 +324,9 @@ describe('service', () => { it('can open client file that do not exist in fs', async () => { const dirPath = getRandomVirtualDirPath(testDir); - const { virtualSystem, lsDocumentContext, rootUris } = setup(); - - virtualSystem.writeFile( - path.join(dirPath, 'tsconfig.json'), - JSON.stringify({ - compilerOptions: { - checkJs: true, - strict: true - } - }) - ); + const { lsDocumentContext, rootUris } = setup(); + // don't need tsconfig because files doesn't exist in fs goes to a service with default config const ls = await getService( path.join(dirPath, 'random.svelte'), rootUris, @@ -380,11 +391,7 @@ describe('service', () => { return fileExists(realPath); }; - const ls = await getService( - path.join(package1, 'DoNotMatter.svelte'), - rootUris, - lsDocumentContext - ); + const ls = await getService(importing, rootUris, lsDocumentContext); assert.deepStrictEqual(getSemanticDiagnosticsMessages(ls, importing), []); });