From 3a72859f0c374c9b94fecb2f85a9504708b11cba Mon Sep 17 00:00:00 2001 From: "Lyu, Wei Da" Date: Fri, 25 Oct 2024 09:13:07 +0800 Subject: [PATCH 1/9] feat: support typescript 5.6 --- package.json | 2 +- packages/language-server/package.json | 2 +- .../fixtures/bind-this/expected_svelte_4.json | 2 +- .../fixtures/bind-this/expected_svelte_5.json | 2 +- .../component-invalid/expected_svelte_5.json | 6 +-- .../component-invalid/expectedv2.json | 6 +-- .../component-handler/expectedv2.json | 4 +- .../fixtures/element-handler/expectedv2.json | 12 ++--- packages/svelte-check/package.json | 2 +- packages/svelte-vscode/package.json | 2 +- packages/svelte2tsx/package.json | 2 +- packages/typescript-plugin/package.json | 2 +- pnpm-lock.yaml | 54 +++++++++---------- 13 files changed, 49 insertions(+), 49 deletions(-) diff --git a/package.json b/package.json index 6e450086d..438c5c68b 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "lint": "prettier --check ." }, "dependencies": { - "typescript": "^5.5.2" + "typescript": "^5.6.3" }, "devDependencies": { "cross-env": "^7.0.2", diff --git a/packages/language-server/package.json b/packages/language-server/package.json index 2963ffe11..db4bc392a 100644 --- a/packages/language-server/package.json +++ b/packages/language-server/package.json @@ -61,7 +61,7 @@ "svelte": "^4.2.19", "svelte2tsx": "workspace:~", "typescript": "^5.5.2", - "typescript-auto-import-cache": "^0.3.3", + "typescript-auto-import-cache": "^0.3.4", "vscode-css-languageservice": "~6.3.0", "vscode-html-languageservice": "~5.3.0", "vscode-languageserver": "9.0.1", diff --git a/packages/language-server/test/plugins/typescript/features/diagnostics/fixtures/bind-this/expected_svelte_4.json b/packages/language-server/test/plugins/typescript/features/diagnostics/fixtures/bind-this/expected_svelte_4.json index 8a8f1c669..21042eeb7 100644 --- a/packages/language-server/test/plugins/typescript/features/diagnostics/fixtures/bind-this/expected_svelte_4.json +++ b/packages/language-server/test/plugins/typescript/features/diagnostics/fixtures/bind-this/expected_svelte_4.json @@ -69,7 +69,7 @@ }, "severity": 1, "source": "ts", - "message": "Type 'Component' is not assignable to type 'OtherComponent'.", + "message": "Type 'Component' is not assignable to type 'OtherComponent'.\n Type '{ prop: boolean; }' is not assignable to type '{ prop: string; }'.\n Types of property 'prop' are incompatible.\n Type 'boolean' is not assignable to type 'string'.", "code": 2322, "tags": [] }, diff --git a/packages/language-server/test/plugins/typescript/features/diagnostics/fixtures/bind-this/expected_svelte_5.json b/packages/language-server/test/plugins/typescript/features/diagnostics/fixtures/bind-this/expected_svelte_5.json index 06c967066..486c1058a 100644 --- a/packages/language-server/test/plugins/typescript/features/diagnostics/fixtures/bind-this/expected_svelte_5.json +++ b/packages/language-server/test/plugins/typescript/features/diagnostics/fixtures/bind-this/expected_svelte_5.json @@ -69,7 +69,7 @@ }, "severity": 1, "source": "ts", - "message": "Type 'Component' is not assignable to type 'OtherComponent'.", + "message": "Type 'Component' is not assignable to type 'OtherComponent'.\n Type '{ prop: boolean; }' is not assignable to type '{ prop: string; }'.\n Types of property 'prop' are incompatible.\n Type 'boolean' is not assignable to type 'string'.", "code": 2322, "tags": [] }, diff --git a/packages/language-server/test/plugins/typescript/features/diagnostics/fixtures/component-invalid/expected_svelte_5.json b/packages/language-server/test/plugins/typescript/features/diagnostics/fixtures/component-invalid/expected_svelte_5.json index ba1364156..aaa50c91c 100644 --- a/packages/language-server/test/plugins/typescript/features/diagnostics/fixtures/component-invalid/expected_svelte_5.json +++ b/packages/language-server/test/plugins/typescript/features/diagnostics/fixtures/component-invalid/expected_svelte_5.json @@ -28,7 +28,7 @@ }, "severity": 1, "source": "ts", - "message": "Argument of type 'typeof DoesntWork' is not assignable to parameter of type 'ConstructorOfATypedSvelteComponent | Component | null | undefined'.\n\nPossible causes:\n- You use the instance type of a component where you should use the constructor type\n- Type definitions are missing for this Svelte Component. ", + "message": "Argument of type 'typeof DoesntWork' is not assignable to parameter of type 'ConstructorOfATypedSvelteComponent | Component | null | undefined'.\n Type 'typeof DoesntWork' is not assignable to type 'ConstructorOfATypedSvelteComponent'.\n Type 'DoesntWork' is missing the following properties from type 'ATypedSvelteComponent': $$prop_def, $$events_def, $$slot_def, $on\n\nPossible causes:\n- You use the instance type of a component where you should use the constructor type\n- Type definitions are missing for this Svelte Component. ", "code": 2345, "tags": [] }, @@ -39,7 +39,7 @@ }, "severity": 1, "source": "ts", - "message": "Argument of type 'typeof DoesntWork' is not assignable to parameter of type 'ConstructorOfATypedSvelteComponent | Component | null | undefined'.\n\nPossible causes:\n- You use the instance type of a component where you should use the constructor type\n- Type definitions are missing for this Svelte Component. ", + "message": "Argument of type 'typeof DoesntWork' is not assignable to parameter of type 'ConstructorOfATypedSvelteComponent | Component | null | undefined'.\n Type 'typeof DoesntWork' is not assignable to type 'ConstructorOfATypedSvelteComponent'.\n Type 'DoesntWork' is missing the following properties from type 'ATypedSvelteComponent': $$prop_def, $$events_def, $$slot_def, $on\n\nPossible causes:\n- You use the instance type of a component where you should use the constructor type\n- Type definitions are missing for this Svelte Component. ", "code": 2345, "tags": [] }, @@ -50,7 +50,7 @@ }, "severity": 1, "source": "ts", - "message": "Argument of type 'typeof DoesntWork' is not assignable to parameter of type 'ConstructorOfATypedSvelteComponent | Component | null | undefined'.\n\nPossible causes:\n- You use the instance type of a component where you should use the constructor type\n- Type definitions are missing for this Svelte Component. ", + "message": "Argument of type 'typeof DoesntWork' is not assignable to parameter of type 'ConstructorOfATypedSvelteComponent | Component | null | undefined'.\n Type 'typeof DoesntWork' is not assignable to type 'ConstructorOfATypedSvelteComponent'.\n Type 'DoesntWork' is missing the following properties from type 'ATypedSvelteComponent': $$prop_def, $$events_def, $$slot_def, $on\n\nPossible causes:\n- You use the instance type of a component where you should use the constructor type\n- Type definitions are missing for this Svelte Component. ", "code": 2345, "tags": [] } diff --git a/packages/language-server/test/plugins/typescript/features/diagnostics/fixtures/component-invalid/expectedv2.json b/packages/language-server/test/plugins/typescript/features/diagnostics/fixtures/component-invalid/expectedv2.json index d4983991d..e07ee0dc1 100644 --- a/packages/language-server/test/plugins/typescript/features/diagnostics/fixtures/component-invalid/expectedv2.json +++ b/packages/language-server/test/plugins/typescript/features/diagnostics/fixtures/component-invalid/expectedv2.json @@ -28,7 +28,7 @@ }, "severity": 1, "source": "ts", - "message": "Argument of type 'typeof DoesntWork' is not assignable to parameter of type 'ConstructorOfATypedSvelteComponent'.\n\nPossible causes:\n- You use the instance type of a component where you should use the constructor type\n- Type definitions are missing for this Svelte Component. If you are using Svelte 3.31+, use SvelteComponentTyped to add a definition:\n import type { SvelteComponentTyped } from \"svelte\";\n class ComponentName extends SvelteComponentTyped<{propertyName: string;}> {}", + "message": "Argument of type 'typeof DoesntWork' is not assignable to parameter of type 'ConstructorOfATypedSvelteComponent'.\n Type 'DoesntWork' is missing the following properties from type 'ATypedSvelteComponent': $$prop_def, $$events_def, $$slot_def, $on\n\nPossible causes:\n- You use the instance type of a component where you should use the constructor type\n- Type definitions are missing for this Svelte Component. If you are using Svelte 3.31+, use SvelteComponentTyped to add a definition:\n import type { SvelteComponentTyped } from \"svelte\";\n class ComponentName extends SvelteComponentTyped<{propertyName: string;}> {}", "code": 2345, "tags": [] }, @@ -39,7 +39,7 @@ }, "severity": 1, "source": "ts", - "message": "Argument of type 'typeof DoesntWork' is not assignable to parameter of type 'ConstructorOfATypedSvelteComponent'.\n\nPossible causes:\n- You use the instance type of a component where you should use the constructor type\n- Type definitions are missing for this Svelte Component. If you are using Svelte 3.31+, use SvelteComponentTyped to add a definition:\n import type { SvelteComponentTyped } from \"svelte\";\n class ComponentName extends SvelteComponentTyped<{propertyName: string;}> {}", + "message": "Argument of type 'typeof DoesntWork' is not assignable to parameter of type 'ConstructorOfATypedSvelteComponent'.\n Type 'DoesntWork' is missing the following properties from type 'ATypedSvelteComponent': $$prop_def, $$events_def, $$slot_def, $on\n\nPossible causes:\n- You use the instance type of a component where you should use the constructor type\n- Type definitions are missing for this Svelte Component. If you are using Svelte 3.31+, use SvelteComponentTyped to add a definition:\n import type { SvelteComponentTyped } from \"svelte\";\n class ComponentName extends SvelteComponentTyped<{propertyName: string;}> {}", "code": 2345, "tags": [] }, @@ -50,7 +50,7 @@ }, "severity": 1, "source": "ts", - "message": "Argument of type 'typeof DoesntWork' is not assignable to parameter of type 'ConstructorOfATypedSvelteComponent'.\n\nPossible causes:\n- You use the instance type of a component where you should use the constructor type\n- Type definitions are missing for this Svelte Component. If you are using Svelte 3.31+, use SvelteComponentTyped to add a definition:\n import type { SvelteComponentTyped } from \"svelte\";\n class ComponentName extends SvelteComponentTyped<{propertyName: string;}> {}", + "message": "Argument of type 'typeof DoesntWork' is not assignable to parameter of type 'ConstructorOfATypedSvelteComponent'.\n Type 'DoesntWork' is missing the following properties from type 'ATypedSvelteComponent': $$prop_def, $$events_def, $$slot_def, $on\n\nPossible causes:\n- You use the instance type of a component where you should use the constructor type\n- Type definitions are missing for this Svelte Component. If you are using Svelte 3.31+, use SvelteComponentTyped to add a definition:\n import type { SvelteComponentTyped } from \"svelte\";\n class ComponentName extends SvelteComponentTyped<{propertyName: string;}> {}", "code": 2345, "tags": [] } diff --git a/packages/language-server/test/plugins/typescript/features/inlayHints/fixtures/component-handler/expectedv2.json b/packages/language-server/test/plugins/typescript/features/inlayHints/fixtures/component-handler/expectedv2.json index 750e37c29..bedfb19dd 100644 --- a/packages/language-server/test/plugins/typescript/features/inlayHints/fixtures/component-handler/expectedv2.json +++ b/packages/language-server/test/plugins/typescript/features/inlayHints/fixtures/component-handler/expectedv2.json @@ -12,8 +12,8 @@ "value": "MouseEvent", "location": { "range": { - "start": { "line": 15860, "character": 10 }, - "end": { "line": 15860, "character": 20 } + "start": { "line": 15340, "character": 10 }, + "end": { "line": 15340, "character": 20 } }, "uri": "/typescript/lib/lib.dom.d.ts" } diff --git a/packages/language-server/test/plugins/typescript/features/inlayHints/fixtures/element-handler/expectedv2.json b/packages/language-server/test/plugins/typescript/features/inlayHints/fixtures/element-handler/expectedv2.json index 07b3bf5b9..22ffb1aa7 100644 --- a/packages/language-server/test/plugins/typescript/features/inlayHints/fixtures/element-handler/expectedv2.json +++ b/packages/language-server/test/plugins/typescript/features/inlayHints/fixtures/element-handler/expectedv2.json @@ -6,8 +6,8 @@ "value": "MouseEvent", "location": { "range": { - "start": { "line": 15860, "character": 10 }, - "end": { "line": 15860, "character": 20 } + "start": { "line": 15340, "character": 10 }, + "end": { "line": 15340, "character": 20 } }, "uri": "/typescript/lib/lib.dom.d.ts" } @@ -21,8 +21,8 @@ "value": "EventTarget", "location": { "range": { - "start": { "line": 8318, "character": 10 }, - "end": { "line": 8318, "character": 21 } + "start": { "line": 8284, "character": 10 }, + "end": { "line": 8284, "character": 21 } }, "uri": "/typescript/lib/lib.dom.d.ts" } @@ -32,8 +32,8 @@ "value": "HTMLButtonElement", "location": { "range": { - "start": { "line": 9810, "character": 10 }, - "end": { "line": 9810, "character": 27 } + "start": { "line": 9721, "character": 10 }, + "end": { "line": 9721, "character": 27 } }, "uri": "/typescript/lib/lib.dom.d.ts" } diff --git a/packages/svelte-check/package.json b/packages/svelte-check/package.json index b49d294a2..8cf77806e 100644 --- a/packages/svelte-check/package.json +++ b/packages/svelte-check/package.json @@ -54,7 +54,7 @@ "rollup-plugin-copy": "^3.4.0", "svelte": "^4.2.19", "svelte-language-server": "workspace:*", - "typescript": "^5.5.2", + "typescript": "^5.6.3", "vscode-languageserver": "8.0.2", "vscode-languageserver-protocol": "3.17.2", "vscode-languageserver-types": "3.17.2", diff --git a/packages/svelte-vscode/package.json b/packages/svelte-vscode/package.json index 12260c440..6bfd184c1 100644 --- a/packages/svelte-vscode/package.json +++ b/packages/svelte-vscode/package.json @@ -726,7 +726,7 @@ "@types/vscode": "^1.67", "js-yaml": "^3.14.0", "tslib": "^2.4.0", - "typescript": "^5.5.2", + "typescript": "^5.6.3", "vscode-tmgrammar-test": "^0.0.11" }, "dependencies": { diff --git a/packages/svelte2tsx/package.json b/packages/svelte2tsx/package.json index 258f5397e..7cf2706ef 100644 --- a/packages/svelte2tsx/package.json +++ b/packages/svelte2tsx/package.json @@ -40,7 +40,7 @@ "svelte": "~4.2.19", "tiny-glob": "^0.2.6", "tslib": "^2.4.0", - "typescript": "^5.5.2" + "typescript": "^5.6.3" }, "peerDependencies": { "svelte": "^3.55 || ^4.0.0-next.0 || ^4.0 || ^5.0.0-next.0", diff --git a/packages/typescript-plugin/package.json b/packages/typescript-plugin/package.json index ebf00ea10..b3e934521 100644 --- a/packages/typescript-plugin/package.json +++ b/packages/typescript-plugin/package.json @@ -24,7 +24,7 @@ "license": "MIT", "devDependencies": { "@types/node": "^18.0.0", - "typescript": "^5.5.2", + "typescript": "^5.6.3", "svelte": "^4.2.19" }, "dependencies": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f7d19793f..cafa8a64a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -9,8 +9,8 @@ importers: .: dependencies: typescript: - specifier: ^5.5.2 - version: 5.5.2 + specifier: ^5.6.3 + version: 5.6.3 devDependencies: cross-env: specifier: ^7.0.2 @@ -20,7 +20,7 @@ importers: version: 3.3.3 ts-node: specifier: ^10.0.0 - version: 10.9.1(@types/node@18.19.46)(typescript@5.5.2) + version: 10.9.1(@types/node@18.19.46)(typescript@5.6.3) packages/language-server: dependencies: @@ -56,10 +56,10 @@ importers: version: link:../svelte2tsx typescript: specifier: ^5.5.2 - version: 5.5.2 + version: 5.6.3 typescript-auto-import-cache: - specifier: ^0.3.3 - version: 0.3.3 + specifier: ^0.3.4 + version: 0.3.4 vscode-css-languageservice: specifier: ~6.3.0 version: 6.3.0 @@ -105,7 +105,7 @@ importers: version: 11.1.2 ts-node: specifier: ^10.0.0 - version: 10.9.1(@types/node@18.19.46)(typescript@5.5.2) + version: 10.9.1(@types/node@18.19.46)(typescript@5.6.3) packages/svelte-check: dependencies: @@ -139,7 +139,7 @@ importers: version: 5.0.2(rollup@3.7.5) '@rollup/plugin-typescript': specifier: ^10.0.0 - version: 10.0.1(rollup@3.7.5)(tslib@2.5.2)(typescript@5.5.2) + version: 10.0.1(rollup@3.7.5)(tslib@2.5.2)(typescript@5.6.3) '@types/sade': specifier: ^1.7.2 version: 1.7.4 @@ -162,8 +162,8 @@ importers: specifier: workspace:* version: link:../language-server typescript: - specifier: ^5.5.2 - version: 5.5.2 + specifier: ^5.6.3 + version: 5.6.3 vscode-languageserver: specifier: 8.0.2 version: 8.0.2 @@ -211,8 +211,8 @@ importers: specifier: ^2.4.0 version: 2.5.2 typescript: - specifier: ^5.5.2 - version: 5.5.2 + specifier: ^5.6.3 + version: 5.6.3 vscode-tmgrammar-test: specifier: ^0.0.11 version: 0.0.11 @@ -243,7 +243,7 @@ importers: version: 15.0.2(rollup@3.7.5) '@rollup/plugin-typescript': specifier: ^10.0.0 - version: 10.0.1(rollup@3.7.5)(tslib@2.5.2)(typescript@5.5.2) + version: 10.0.1(rollup@3.7.5)(tslib@2.5.2)(typescript@5.6.3) '@types/estree': specifier: ^0.0.42 version: 0.0.42 @@ -293,8 +293,8 @@ importers: specifier: ^2.4.0 version: 2.5.2 typescript: - specifier: ^5.5.2 - version: 5.5.2 + specifier: ^5.6.3 + version: 5.6.3 packages/typescript-plugin: dependencies: @@ -312,8 +312,8 @@ importers: specifier: ^4.2.19 version: 4.2.19 typescript: - specifier: ^5.5.2 - version: 5.5.2 + specifier: ^5.6.3 + version: 5.6.3 packages: @@ -1269,11 +1269,11 @@ packages: resolution: {integrity: sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==} engines: {node: '>=4'} - typescript-auto-import-cache@0.3.3: - resolution: {integrity: sha512-ojEC7+Ci1ij9eE6hp8Jl9VUNnsEKzztktP5gtYNRMrTmfXVwA1PITYYAkpxCvvupdSYa/Re51B6KMcv1CTZEUA==} + typescript-auto-import-cache@0.3.4: + resolution: {integrity: sha512-ztlGq1CB0TX9wKv3DJPRBiT5GJf0Gio1bRzcXElEZMjW1VlyZifiZqk6No3OS1XwNBx+n74dSbH2Bjy+5fN5Xw==} - typescript@5.5.2: - resolution: {integrity: sha512-NcRtPEOsPFFWjobJEtfihkLCZCXZt/os3zf8nTxjVH3RvTSxjrCamJpbExGvYOF+tFHc3pA65qpdwPbzjohhew==} + typescript@5.6.3: + resolution: {integrity: sha512-hjcS1mhfuyi4WW8IWtjP7brDrG2cuDZukyrYrSauoXGNgx0S7zceP07adYkJycEr56BOUTNPzbInooiN3fn1qw==} engines: {node: '>=14.17'} hasBin: true @@ -1487,11 +1487,11 @@ snapshots: optionalDependencies: rollup: 3.7.5 - '@rollup/plugin-typescript@10.0.1(rollup@3.7.5)(tslib@2.5.2)(typescript@5.5.2)': + '@rollup/plugin-typescript@10.0.1(rollup@3.7.5)(tslib@2.5.2)(typescript@5.6.3)': dependencies: '@rollup/pluginutils': 5.0.2(rollup@3.7.5) resolve: 1.22.2 - typescript: 5.5.2 + typescript: 5.6.3 optionalDependencies: rollup: 3.7.5 tslib: 2.5.2 @@ -2318,7 +2318,7 @@ snapshots: dependencies: is-number: 7.0.0 - ts-node@10.9.1(@types/node@18.19.46)(typescript@5.5.2): + ts-node@10.9.1(@types/node@18.19.46)(typescript@5.6.3): dependencies: '@cspotcode/source-map-support': 0.8.1 '@tsconfig/node10': 1.0.9 @@ -2332,7 +2332,7 @@ snapshots: create-require: 1.1.1 diff: 4.0.2 make-error: 1.3.6 - typescript: 5.5.2 + typescript: 5.6.3 v8-compile-cache-lib: 3.0.1 yn: 3.1.1 @@ -2340,11 +2340,11 @@ snapshots: type-detect@4.0.8: {} - typescript-auto-import-cache@0.3.3: + typescript-auto-import-cache@0.3.4: dependencies: semver: 7.5.1 - typescript@5.5.2: {} + typescript@5.6.3: {} undici-types@5.26.5: {} From 5ec41e91a8096e8a27a19d6a628ac9f9ed0ec253 Mon Sep 17 00:00:00 2001 From: "Lyu, Wei Da" Date: Fri, 25 Oct 2024 09:25:57 +0800 Subject: [PATCH 2/9] fix build --- packages/svelte2tsx/src/svelte2tsx/nodes/ExportedNames.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/svelte2tsx/src/svelte2tsx/nodes/ExportedNames.ts b/packages/svelte2tsx/src/svelte2tsx/nodes/ExportedNames.ts index 8184da952..225dd9a60 100644 --- a/packages/svelte2tsx/src/svelte2tsx/nodes/ExportedNames.ts +++ b/packages/svelte2tsx/src/svelte2tsx/nodes/ExportedNames.ts @@ -550,9 +550,9 @@ export class ExportedNames { * Adds export to map */ private addExport( - name: ts.Identifier, + name: ts.ModuleExportName, isLet: boolean, - target: ts.Identifier = null, + target: ts.ModuleExportName = null, type: ts.TypeNode = null, required = false, isNamedExport = false @@ -601,7 +601,7 @@ export class ExportedNames { }); } - private getDoc(target: ts.BindingName) { + private getDoc(target: ts.BindingName | ts.ModuleExportName) { let doc = undefined; // Traverse `a` one up. If the declaration is part of a declaration list, // the comment is at this point already From ba4749a8c9024bd58502094678ef996cc082da1e Mon Sep 17 00:00:00 2001 From: Lyu Jason Date: Fri, 25 Oct 2024 20:57:48 +0800 Subject: [PATCH 3/9] autoImportSpecifierExcludeRegexes and organizeImports preference --- packages/language-server/src/ls-config.ts | 36 ++++++++++++++++++- .../typescript/features/preferences.test.ts | 3 +- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/packages/language-server/src/ls-config.ts b/packages/language-server/src/ls-config.ts index 63389e7bb..a4b4831ac 100644 --- a/packages/language-server/src/ls-config.ts +++ b/packages/language-server/src/ls-config.ts @@ -221,6 +221,19 @@ export interface TsUserPreferencesConfig { includePackageJsonAutoImports?: ts.UserPreferences['includePackageJsonAutoImports']; preferTypeOnlyAutoImports?: ts.UserPreferences['preferTypeOnlyAutoImports']; + + autoImportSpecifierExcludeRegexes?: string[]; + + organizeImports?: TsOrganizeImportPreferencesConfig; +} + +interface TsOrganizeImportPreferencesConfig { + accentCollation: ts.UserPreferences['organizeImportsAccentCollation']; + caseFirst: ts.UserPreferences['organizeImportsCaseFirst'] | 'default'; + caseSensitivity: ts.UserPreferences['organizeImportsIgnoreCase']; + locale: ts.UserPreferences['organizeImportsLocale']; + numericCollation: ts.UserPreferences['organizeImportsNumericCollation']; + typeOrder: ts.UserPreferences['organizeImportsTypeOrder'] | 'auto'; } /** @@ -474,10 +487,31 @@ export class LSConfigManager { includeInlayVariableTypeHintsWhenTypeMatchesName: inlayHints?.variableTypes?.suppressWhenTypeMatchesName === false, - interactiveInlayHints: true + autoImportSpecifierExcludeRegexes: + config.preferences?.autoImportSpecifierExcludeRegexes, + + organizeImportsAccentCollation: config.preferences?.organizeImports?.accentCollation, + organizeImportsCaseFirst: this.withDefaultAsUndefined( + config.preferences?.organizeImports?.caseFirst, + 'default' + ), + organizeImportsIgnoreCase: this.withDefaultAsUndefined( + config.preferences?.organizeImports?.caseSensitivity, + 'auto' + ), + organizeImportsLocale: config.preferences?.organizeImports?.locale, + organizeImportsNumericCollation: config.preferences?.organizeImports?.numericCollation, + organizeImportsTypeOrder: this.withDefaultAsUndefined( + config.preferences?.organizeImports?.typeOrder, + 'auto' + ) }; } + private withDefaultAsUndefined(value: T, def: O): Exclude | undefined { + return value === def ? undefined : (value as Exclude); + } + getTsUserPreferences( lang: TsUserConfigLang, normalizedWorkspacePath: string | null diff --git a/packages/language-server/test/plugins/typescript/features/preferences.test.ts b/packages/language-server/test/plugins/typescript/features/preferences.test.ts index b4c35f187..c6cac31d9 100644 --- a/packages/language-server/test/plugins/typescript/features/preferences.test.ts +++ b/packages/language-server/test/plugins/typescript/features/preferences.test.ts @@ -80,7 +80,8 @@ describe('ts user preferences', function () { importModuleSpecifier: 'non-relative', importModuleSpecifierEnding: undefined, quoteStyle: 'single', - includePackageJsonAutoImports: undefined + includePackageJsonAutoImports: undefined, + organizeImports: undefined }; } From f5ea1006975885ef39896b58705f2e1eaf2ac236 Mon Sep 17 00:00:00 2001 From: Lyu Jason Date: Fri, 25 Oct 2024 21:05:09 +0800 Subject: [PATCH 4/9] what --- packages/language-server/src/ls-config.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/language-server/src/ls-config.ts b/packages/language-server/src/ls-config.ts index a4b4831ac..cef978d81 100644 --- a/packages/language-server/src/ls-config.ts +++ b/packages/language-server/src/ls-config.ts @@ -486,6 +486,7 @@ export class LSConfigManager { includeInlayPropertyDeclarationTypeHints: inlayHints?.propertyDeclarationTypes?.enabled, includeInlayVariableTypeHintsWhenTypeMatchesName: inlayHints?.variableTypes?.suppressWhenTypeMatchesName === false, + interactiveInlayHints: true, autoImportSpecifierExcludeRegexes: config.preferences?.autoImportSpecifierExcludeRegexes, From 339333a98e6fb6ca635be750f4830a3caefc4993 Mon Sep 17 00:00:00 2001 From: Lyu Jason Date: Sat, 26 Oct 2024 07:54:32 +0800 Subject: [PATCH 5/9] bumps typescript-auto-import-cache --- packages/language-server/package.json | 2 +- pnpm-lock.yaml | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/language-server/package.json b/packages/language-server/package.json index db4bc392a..29f9b7e1d 100644 --- a/packages/language-server/package.json +++ b/packages/language-server/package.json @@ -61,7 +61,7 @@ "svelte": "^4.2.19", "svelte2tsx": "workspace:~", "typescript": "^5.5.2", - "typescript-auto-import-cache": "^0.3.4", + "typescript-auto-import-cache": "^0.3.5", "vscode-css-languageservice": "~6.3.0", "vscode-html-languageservice": "~5.3.0", "vscode-languageserver": "9.0.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index cafa8a64a..dbf60f431 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -58,8 +58,8 @@ importers: specifier: ^5.5.2 version: 5.6.3 typescript-auto-import-cache: - specifier: ^0.3.4 - version: 0.3.4 + specifier: ^0.3.5 + version: 0.3.5 vscode-css-languageservice: specifier: ~6.3.0 version: 6.3.0 @@ -1269,8 +1269,8 @@ packages: resolution: {integrity: sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==} engines: {node: '>=4'} - typescript-auto-import-cache@0.3.4: - resolution: {integrity: sha512-ztlGq1CB0TX9wKv3DJPRBiT5GJf0Gio1bRzcXElEZMjW1VlyZifiZqk6No3OS1XwNBx+n74dSbH2Bjy+5fN5Xw==} + typescript-auto-import-cache@0.3.5: + resolution: {integrity: sha512-fAIveQKsoYj55CozUiBoj4b/7WpN0i4o74wiGY5JVUEoD0XiqDk1tJqTEjgzL2/AizKQrXxyRosSebyDzBZKjw==} typescript@5.6.3: resolution: {integrity: sha512-hjcS1mhfuyi4WW8IWtjP7brDrG2cuDZukyrYrSauoXGNgx0S7zceP07adYkJycEr56BOUTNPzbInooiN3fn1qw==} @@ -2340,7 +2340,7 @@ snapshots: type-detect@4.0.8: {} - typescript-auto-import-cache@0.3.4: + typescript-auto-import-cache@0.3.5: dependencies: semver: 7.5.1 From fe1314fda51d16169f6ac718897278fe8db6e38f Mon Sep 17 00:00:00 2001 From: Lyu Jason Date: Sat, 26 Oct 2024 09:15:23 +0800 Subject: [PATCH 6/9] missed one --- packages/language-server/src/ls-config.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/language-server/src/ls-config.ts b/packages/language-server/src/ls-config.ts index cef978d81..3f5469940 100644 --- a/packages/language-server/src/ls-config.ts +++ b/packages/language-server/src/ls-config.ts @@ -231,6 +231,7 @@ interface TsOrganizeImportPreferencesConfig { accentCollation: ts.UserPreferences['organizeImportsAccentCollation']; caseFirst: ts.UserPreferences['organizeImportsCaseFirst'] | 'default'; caseSensitivity: ts.UserPreferences['organizeImportsIgnoreCase']; + collation: ts.UserPreferences['organizeImportsCollation']; locale: ts.UserPreferences['organizeImportsLocale']; numericCollation: ts.UserPreferences['organizeImportsNumericCollation']; typeOrder: ts.UserPreferences['organizeImportsTypeOrder'] | 'auto'; @@ -492,6 +493,7 @@ export class LSConfigManager { config.preferences?.autoImportSpecifierExcludeRegexes, organizeImportsAccentCollation: config.preferences?.organizeImports?.accentCollation, + organizeImportsCollation: config.preferences?.organizeImports?.collation, organizeImportsCaseFirst: this.withDefaultAsUndefined( config.preferences?.organizeImports?.caseFirst, 'default' From 8be633628f2e6bac2eebbd8ef1c94eca09cfe95b Mon Sep 17 00:00:00 2001 From: "Lyu, Wei Da" Date: Sat, 26 Oct 2024 20:21:05 +0800 Subject: [PATCH 7/9] use commit characters from typescript when possible --- .../language-server/src/plugins/PluginHost.ts | 21 ++++- .../typescript/features/CompletionProvider.ts | 94 +++++++++++++++++-- .../features/CompletionProvider.test.ts | 44 ++++++++- 3 files changed, 149 insertions(+), 10 deletions(-) diff --git a/packages/language-server/src/plugins/PluginHost.ts b/packages/language-server/src/plugins/PluginHost.ts index a4783a6a1..bbb3eac46 100644 --- a/packages/language-server/src/plugins/PluginHost.ts +++ b/packages/language-server/src/plugins/PluginHost.ts @@ -171,6 +171,22 @@ export class PluginHost implements LSProvider, OnWatchFileChanges { }); } + let itemDefaults: CompletionList['itemDefaults']; + if (completions.length === 1) { + itemDefaults = completions[0]?.result.itemDefaults; + } else { + // don't apply items default to the result of other plugins + for (const completion of completions) { + const itemDefaults = completion.result.itemDefaults; + if (!itemDefaults) { + continue; + } + completion.result.items.forEach((item) => { + item.commitCharacters ??= itemDefaults.commitCharacters; + }); + } + } + let flattenedCompletions = flatten( completions.map((completion) => completion.result.items) ); @@ -194,7 +210,10 @@ export class PluginHost implements LSProvider, OnWatchFileChanges { ); } - return CompletionList.create(flattenedCompletions, isIncomplete); + const result = CompletionList.create(flattenedCompletions, isIncomplete); + result.itemDefaults = itemDefaults; + + return result; } async resolveCompletion( diff --git a/packages/language-server/src/plugins/typescript/features/CompletionProvider.ts b/packages/language-server/src/plugins/typescript/features/CompletionProvider.ts index e7b5bec75..8e47b9b42 100644 --- a/packages/language-server/src/plugins/typescript/features/CompletionProvider.ts +++ b/packages/language-server/src/plugins/typescript/features/CompletionProvider.ts @@ -66,6 +66,12 @@ type LastCompletion = { completionList: AppCompletionList | null; }; +interface CommitCharactersOptions { + checkCommitCharacters: boolean; + defaultCommitCharacters?: string[]; + isNewIdentifierLocation?: boolean; +} + export class CompletionsProviderImpl implements CompletionsProvider { constructor( private readonly lsAndTsDocResolver: LSAndTSDocResolver, @@ -237,10 +243,8 @@ export class CompletionsProviderImpl implements CompletionsProvider { + item.commitCharacters ??= commitCharactersOptions.defaultCommitCharacters; + }); + } + } + this.lastCompletion = { key: document.getFilePath() || '', position, completionList }; return completionList; @@ -578,6 +603,7 @@ export class CompletionsProviderImpl implements CompletionsProvider ): AppCompletionItem | null { @@ -669,7 +695,7 @@ export class CompletionsProviderImpl implements CompletionsProvider { @@ -170,6 +170,34 @@ describe('CompletionProviderImpl', function () { }); } + it('provide completion with items default when supported', async () => { + const { completionProvider, document, lsConfigManager } = setup('completions.svelte'); + + lsConfigManager.updateClientCapabilities({ + textDocument: { + completion: { + completionList: { + itemDefaults: ['commitCharacters'] + } + } + } + }); + + const completions = await completionProvider.getCompletions( + document, + Position.create(0, 49), + { + triggerKind: CompletionTriggerKind.TriggerCharacter, + triggerCharacter: '.' + } + ); + + assert.deepStrictEqual(completions?.itemDefaults?.commitCharacters, ['.', ',', ';', '(']); + + const first = completions!.items[0]; + assert.strictEqual(first.commitCharacters, undefined); + }); + it('provides event completions', async () => { const { completionProvider, document } = setup('component-events-completion.svelte'); @@ -191,6 +219,7 @@ describe('CompletionProviderImpl', function () { assert.deepStrictEqual(eventCompletions, [ { + commitCharacters: [], detail: 'aa: CustomEvent', documentation: '', label: 'on:aa', @@ -199,6 +228,7 @@ describe('CompletionProviderImpl', function () { textEdit: undefined }, { + commitCharacters: [], detail: 'ab: MouseEvent', documentation: { kind: 'markdown', @@ -210,6 +240,7 @@ describe('CompletionProviderImpl', function () { textEdit: undefined }, { + commitCharacters: [], detail: 'ac: any', documentation: '', label: 'on:ac', @@ -309,6 +340,7 @@ describe('CompletionProviderImpl', function () { assert.deepStrictEqual(eventCompletions, [ { + commitCharacters: [], detail: 'aa: CustomEvent', documentation: '', label: 'on:aa', @@ -329,6 +361,7 @@ describe('CompletionProviderImpl', function () { } }, { + commitCharacters: [], detail: 'ab: MouseEvent', documentation: { kind: 'markdown', @@ -352,6 +385,7 @@ describe('CompletionProviderImpl', function () { } }, { + commitCharacters: [], detail: 'ac: any', documentation: '', label: 'on:ac', @@ -389,6 +423,7 @@ describe('CompletionProviderImpl', function () { assert.deepStrictEqual(eventCompletions, [ { + commitCharacters: [], detail: 'c: CustomEvent', documentation: { kind: 'markdown', @@ -417,6 +452,7 @@ describe('CompletionProviderImpl', function () { assert.deepStrictEqual(eventCompletions, [ { + commitCharacters: [], detail: 'event1: CustomEvent', documentation: '', label: 'on:event1', @@ -437,6 +473,7 @@ describe('CompletionProviderImpl', function () { } }, { + commitCharacters: [], detail: 'event2: CustomEvent', documentation: { kind: 'markdown', @@ -477,6 +514,7 @@ describe('CompletionProviderImpl', function () { assert.deepStrictEqual(eventCompletions, [ { + commitCharacters: [], detail: 'event1: CustomEvent | CustomEvent', label: 'on:event1', sortText: '-1', @@ -1101,6 +1139,7 @@ describe('CompletionProviderImpl', function () { assert.deepStrictEqual(slotLetCompletions, [ { + commitCharacters: [], detail: 'let1: boolean', documentation: '', label: 'let:let1', @@ -1121,6 +1160,7 @@ describe('CompletionProviderImpl', function () { } }, { + commitCharacters: [], detail: 'let2: string', documentation: { kind: 'markdown', @@ -1290,7 +1330,7 @@ describe('CompletionProviderImpl', function () { insertText: undefined, insertTextFormat: undefined, labelDetails: undefined, - commitCharacters: ['.', ',', ';', '('], + commitCharacters: [], textEdit: { newText: '@hi', range: { From 730b99b8d1e693090138be3066a93e675bc50420 Mon Sep 17 00:00:00 2001 From: "Lyu, Wei Da" Date: Sat, 26 Oct 2024 20:24:23 +0800 Subject: [PATCH 8/9] format --- .../src/plugins/typescript/features/CompletionProvider.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/language-server/src/plugins/typescript/features/CompletionProvider.ts b/packages/language-server/src/plugins/typescript/features/CompletionProvider.ts index 8e47b9b42..f620db97e 100644 --- a/packages/language-server/src/plugins/typescript/features/CompletionProvider.ts +++ b/packages/language-server/src/plugins/typescript/features/CompletionProvider.ts @@ -400,7 +400,7 @@ export class CompletionsProviderImpl implements CompletionsProvider Date: Tue, 5 Nov 2024 10:59:39 +0100 Subject: [PATCH 9/9] bump language server dep --- packages/language-server/package.json | 2 +- pnpm-lock.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/language-server/package.json b/packages/language-server/package.json index 29f9b7e1d..cbbc689e7 100644 --- a/packages/language-server/package.json +++ b/packages/language-server/package.json @@ -60,7 +60,7 @@ "prettier-plugin-svelte": "^3.2.6", "svelte": "^4.2.19", "svelte2tsx": "workspace:~", - "typescript": "^5.5.2", + "typescript": "^5.6.3", "typescript-auto-import-cache": "^0.3.5", "vscode-css-languageservice": "~6.3.0", "vscode-html-languageservice": "~5.3.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index dbf60f431..74ee595a3 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -55,7 +55,7 @@ importers: specifier: workspace:~ version: link:../svelte2tsx typescript: - specifier: ^5.5.2 + specifier: ^5.6.3 version: 5.6.3 typescript-auto-import-cache: specifier: ^0.3.5