From 89c001b5ccf5fe5c69d229ee4872234e84203603 Mon Sep 17 00:00:00 2001 From: "Lyu, Wei-Da" <36730922+jasonlyu123@users.noreply.github.com> Date: Tue, 10 Dec 2024 04:51:36 +0800 Subject: [PATCH 1/2] fix: don't patch solution project in ts plugin (#2617) part of #2612 --- packages/typescript-plugin/src/utils.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/typescript-plugin/src/utils.ts b/packages/typescript-plugin/src/utils.ts index 1b14a6dbe..71425bc31 100644 --- a/packages/typescript-plugin/src/utils.ts +++ b/packages/typescript-plugin/src/utils.ts @@ -255,6 +255,14 @@ export function hasNodeModule(startPath: string, module: string) { } export function isSvelteProject(project: ts.server.Project) { + // internal api, the way to check requires checking the files config in tsconfig.json + // so we can't reimplement it without reading the tsconfig.json again + // The solution project is mostly just a container we don't need to patch it + // and having any files in this project cause TSServer to send config error while it originally won't + if ((project as any).isSolution?.()) { + return false; + } + const projectDirectory = getProjectDirectory(project); if (projectDirectory) { return hasNodeModule(projectDirectory, 'svelte'); From 29497af7a8e8633f3532f68237aad13950c6534a Mon Sep 17 00:00:00 2001 From: Simon H <5968653+dummdidumm@users.noreply.github.com> Date: Wed, 11 Dec 2024 00:04:59 +0100 Subject: [PATCH 2/2] chore: fix tests for Svelte 5 (#2626) --- .../test/plugins/svelte/SveltePlugin.test.ts | 10 ++++++---- .../plugins/svelte/features/getDiagnostics.test.ts | 11 +++++++---- .../fixtures/parser-error/expected_svelte_5.json | 2 +- .../svelte-element-error/expected_svelte_5.json | 2 +- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/packages/language-server/test/plugins/svelte/SveltePlugin.test.ts b/packages/language-server/test/plugins/svelte/SveltePlugin.test.ts index 1e57caea1..911e195e8 100644 --- a/packages/language-server/test/plugins/svelte/SveltePlugin.test.ts +++ b/packages/language-server/test/plugins/svelte/SveltePlugin.test.ts @@ -39,7 +39,7 @@ describe('Svelte Plugin', () => { const diagnostic = Diagnostic.create( Range.create(1, 0, 1, 21), isSvelte5Plus - ? '`` element should have an alt attribute' + ? '`` element should have an alt attribute\nhttps://svelte.dev/e/a11y_missing_attribute' : 'A11y: element should have an alt attribute', DiagnosticSeverity.Warning, isSvelte5Plus ? 'a11y_missing_attribute' : 'a11y-missing-attribute', @@ -54,10 +54,12 @@ describe('Svelte Plugin', () => { const diagnostics = await plugin.getDiagnostics(document); const diagnostic = Diagnostic.create( - Range.create(0, 10, 0, 18), - isSvelte5Plus ? 'Can only bind to state or props' : 'whatever is not declared', + Range.create(0, isSvelte5Plus ? 5 : 10, 0, 18), + isSvelte5Plus + ? '`bind:whatever` is not a valid binding\nhttps://svelte.dev/e/bind_invalid_name' + : 'whatever is not declared', DiagnosticSeverity.Error, - isSvelte5Plus ? 'bind_invalid_value' : 'binding-undeclared', + isSvelte5Plus ? 'bind_invalid_name' : 'binding-undeclared', 'svelte' ); diff --git a/packages/language-server/test/plugins/svelte/features/getDiagnostics.test.ts b/packages/language-server/test/plugins/svelte/features/getDiagnostics.test.ts index e4e72b497..b41958228 100644 --- a/packages/language-server/test/plugins/svelte/features/getDiagnostics.test.ts +++ b/packages/language-server/test/plugins/svelte/features/getDiagnostics.test.ts @@ -471,7 +471,8 @@ describe('SveltePlugin#getDiagnostics', () => { { range: { start: { line: 1, character: 15 }, end: { line: 1, character: 27 } }, message: - "Component has unused export property 'name'. If it is for external reference only, please consider using `export const name`", + "Component has unused export property 'name'. If it is for external reference only, please consider using `export const name`" + + (isSvelte5Plus ? '\nhttps://svelte.dev/e/export_let_unused' : ''), severity: 2, source: 'svelte', code: isSvelte5Plus ? 'export_let_unused' : 'unused-export-let' @@ -489,7 +490,7 @@ describe('SveltePlugin#getDiagnostics', () => { { range: { start: { line: 1, character: 4 }, end: { line: 1, character: 26 } }, message: isSvelte5Plus - ? 'Reactive declarations only exist at the top level of the instance script' + ? 'Reactive declarations only exist at the top level of the instance script\nhttps://svelte.dev/e/reactive_declaration_invalid_placement' : '$: has no effect in a module script', severity: 2, source: 'svelte', @@ -511,7 +512,8 @@ describe('SveltePlugin#getDiagnostics', () => { { code: isSvelte5Plus ? 'export_let_unused' : 'unused-export-let', message: - "Component has unused export property 'unused1'. If it is for external reference only, please consider using `export const unused1`", + "Component has unused export property 'unused1'. If it is for external reference only, please consider using `export const unused1`" + + (isSvelte5Plus ? '\nhttps://svelte.dev/e/export_let_unused' : ''), range: { start: { line: 5, @@ -528,7 +530,8 @@ describe('SveltePlugin#getDiagnostics', () => { { code: isSvelte5Plus ? 'export_let_unused' : 'unused-export-let', message: - "Component has unused export property 'unused2'. If it is for external reference only, please consider using `export const unused2`", + "Component has unused export property 'unused2'. If it is for external reference only, please consider using `export const unused2`" + + (isSvelte5Plus ? '\nhttps://svelte.dev/e/export_let_unused' : ''), range: { start: { line: 6, diff --git a/packages/language-server/test/plugins/typescript/features/diagnostics/fixtures/parser-error/expected_svelte_5.json b/packages/language-server/test/plugins/typescript/features/diagnostics/fixtures/parser-error/expected_svelte_5.json index c0fcc5b6d..65bcc0afb 100644 --- a/packages/language-server/test/plugins/typescript/features/diagnostics/fixtures/parser-error/expected_svelte_5.json +++ b/packages/language-server/test/plugins/typescript/features/diagnostics/fixtures/parser-error/expected_svelte_5.json @@ -3,7 +3,7 @@ "range": { "start": { "line": 1, "character": 0 }, "end": { "line": 1, "character": 0 } }, "severity": 1, "source": "js", - "message": "A component can have a single top-level `