From ba4749a8c9024bd58502094678ef996cc082da1e Mon Sep 17 00:00:00 2001 From: Lyu Jason Date: Fri, 25 Oct 2024 20:57:48 +0800 Subject: [PATCH] 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 }; }