diff --git a/extensions/typescript-language-features/package.json b/extensions/typescript-language-features/package.json index 3f7fdcf252f..ef5f9113fff 100644 --- a/extensions/typescript-language-features/package.json +++ b/extensions/typescript-language-features/package.json @@ -1074,6 +1074,168 @@ "description": "%typescript.preferences.renameMatchingJsxTags%", "scope": "language-overridable" }, + "typescript.preferences.organizeImports": { + "type": "object", + "markdownDescription": "%typescript.preferences.organizeImports%", + "properties": { + "presets": { + "type": "string", + "markdownDescription": "%typescript.preferences.organizeImports.presets%", + "enum": [ + "auto", + "eslint sort-imports", + "eslint plugin-simple-import-sort", + "dprint" + ], + "markdownEnumDescriptions": [ + "%typescript.preferences.organizeImports.presets.auto%", + "%typescript.preferences.organizeImports.presets.eslintSortImports%", + "%typescript.preferences.organizeImports.presets.eslintPluginSimpleImportSort%", + "%typescript.preferences.organizeImports.presets.dprint%" + ], + "default": "auto" + }, + "caseSensitivity": { + "type": "string", + "enum": [ + "auto", + "caseInsensitive", + "caseSensitive" + ], + "markdownEnumDescriptions": [ + "%typescript.preferences.organizeImports.caseSensitivity.auto%", + "%typescript.preferences.organizeImports.caseSensitivity.insensitive", + "%typescript.preferences.organizeImports.caseSensitivity.sensitive%" + ], + "default": "auto" + }, + "typeOrder": { + "type": "string", + "enum": [ + "auto", + "last", + "inline", + "first" + ], + "default": "auto" + }, + "unicodeCollation": { + "type": "string", + "enum": [ + "ordinal", + "unicode" + ], + "markdownEnumDescriptions": [ + "%typescript.preferences.organizeImports.unicodeCollation.ordinal%", + "%typescript.preferences.organizeImports.unicodeCollation.unicode%" + ], + "default": "ordinal" + }, + "locale": { + "type": "string", + "markdownDescription": "%typescript.preferences.organizeImports.locale%" + }, + "numericCollation": { + "type": "boolean", + "markdownDescription": "%typescript.preferences.organizeImports.numericCollation%" + }, + "accentCollation":{ + "type": "boolean", + "markdownDescription": "%typescript.preferences.organizeImports.accentCollation%" + }, + "caseFirst": { + "type": "string", + "markdownDescription": "%typescript.preferences.organizeImports.caseFirst%", + "enum": [ + "default", + "upper", + "lower" + ], + "default": "default" + } + } + }, + "javascript.preferences.organizeImports": { + "type": "object", + "markdownDescription": "%typescript.preferences.organizeImports%", + "properties": { + "presets": { + "type": "string", + "markdownDescription": "%typescript.preferences.organizeImports.presets%", + "enum": [ + "auto", + "eslint sort-imports", + "eslint plugin-simple-import-sort", + "dprint" + ], + "markdownEnumDescriptions": [ + "%typescript.preferences.organizeImports.presets.auto%", + "%typescript.preferences.organizeImports.presets.eslintSortImports%", + "%typescript.preferences.organizeImports.presets.eslintPluginSimpleImportSort%", + "%typescript.preferences.organizeImports.presets.dprint%" + ], + "default": "auto" + }, + "caseSensitivity": { + "type": "string", + "enum": [ + "auto", + "caseInsensitive", + "caseSensitive" + ], + "markdownEnumDescriptions": [ + "%typescript.preferences.organizeImports.caseSensitivity.auto%", + "%typescript.preferences.organizeImports.caseSensitivity.insensitive", + "%typescript.preferences.organizeImports.caseSensitivity.sensitive%" + ], + "default": "auto" + }, + "typeOrder": { + "type": "string", + "enum": [ + "auto", + "last", + "inline", + "first" + ], + "default": "auto" + }, + "unicodeCollation": { + "type": "string", + "enum": [ + "ordinal", + "unicode" + ], + "markdownEnumDescriptions": [ + "%typescript.preferences.organizeImports.unicodeCollation.ordinal%", + "%typescript.preferences.organizeImports.unicodeCollation.unicode%" + ], + "default": "ordinal" + }, + "locale": { + "type": "string", + "markdownDescription": "%typescript.preferences.organizeImports.locale%" + }, + "numericCollation": { + "type": "boolean", + "markdownDescription": "%typescript.preferences.organizeImports.numericCollation%" + }, + "accentCollation":{ + "type": "boolean", + "markdownDescription": "%typescript.preferences.organizeImports.accentCollation%" + }, + "caseFirst": { + "type": "string", + "markdownDescription": "%typescript.preferences.organizeImports.caseFirst%", + "enum": [ + "default", + "upper", + "lower" + ], + "default": "default" + } + } + }, "typescript.updateImportsOnFileMove.enabled": { "type": "string", "enum": [ diff --git a/extensions/typescript-language-features/package.nls.json b/extensions/typescript-language-features/package.nls.json index cba24007314..3067026fc75 100644 --- a/extensions/typescript-language-features/package.nls.json +++ b/extensions/typescript-language-features/package.nls.json @@ -187,6 +187,21 @@ "typescript.preferences.renameShorthandProperties.deprecationMessage": "The setting 'typescript.preferences.renameShorthandProperties' has been deprecated in favor of 'typescript.preferences.useAliasesForRenames'", "typescript.preferences.useAliasesForRenames": "Enable/disable introducing aliases for object shorthand properties during renames.", "typescript.preferences.renameMatchingJsxTags": "When on a JSX tag, try to rename the matching tag instead of renaming the symbol. Requires using TypeScript 5.1+ in the workspace.", + "typescript.preferences.organizeImports": "Advanced preferences that control how imports are ordered. Presets are available in `#typescript.preferences.organizeImports.presets#`", + "javascript.preferences.organizeImports": "Advanced preferences that control how imports are ordered. Presets are available in `#javascript.preferences.organizeImports.presets#`", + "typescript.preferences.organizeImports.caseSensitivity.auto": "Detect case-sensitivity for import sorting", + "typescript.preferences.organizeImports.caseSensitivity.insensitive": "Sort imports case-insensitively", + "typescript.preferences.organizeImports.caseSensitivity.sensitive": "Sort imports case-sensitively", + "typescript.preferences.organizeImports.typeOrder.auto": "Detect where type-only named imports should be sorted", + "typescript.preferences.organizeImports.typeOrder.last": "Type only named imports are sorted to the end of the import list", + "typescript.preferences.organizeImports.typeOrder.inline": "Named imports are sorted by name only", + "typescript.preferences.organizeImports.typeOrder.first": "Type only named imports are sorted to the end of the import list", + "typescript.preferences.organizeImports.unicodeCollation.ordinal": "Sort imports using the numeric value of each code point", + "typescript.preferences.organizeImports.unicodeCollation.unicode": "Sort imports using the Unicode code collation", + "typescript.preferences.organizeImports.locale": "Overrides the locale used for collation. Specify `auto` to use the UI locale. Only applies to `organizeImportsCollation: 'unicode'`", + "typescript.preferences.organizeImports.caseFirst": "Indicates whether upper-case comes before lower-case. Only applies to `organizeImportsCollation: 'unicode'`", + "typescript.preferences.organizeImports.numericCollation": "Sort numeric strings by integer value", + "typescript.preferences.organizeImports.accentCollation": "Compare characters with diacritical marks as unequal to base character", "typescript.workspaceSymbols.scope": "Controls which files are searched by [Go to Symbol in Workspace](https://code.visualstudio.com/docs/editor/editingevolved#_open-symbol-by-name).", "typescript.workspaceSymbols.scope.allOpenProjects": "Search all open JavaScript or TypeScript projects for symbols.", "typescript.workspaceSymbols.scope.currentProject": "Only search for symbols in the current JavaScript or TypeScript project.", diff --git a/extensions/typescript-language-features/src/languageFeatures/fileConfigurationManager.ts b/extensions/typescript-language-features/src/languageFeatures/fileConfigurationManager.ts index 1727b7e29b3..8101d92743a 100644 --- a/extensions/typescript-language-features/src/languageFeatures/fileConfigurationManager.ts +++ b/extensions/typescript-language-features/src/languageFeatures/fileConfigurationManager.ts @@ -199,6 +199,7 @@ export default class FileConfigurationManager extends Disposable { interactiveInlayHints: true, includeCompletionsForModuleExports: config.get('suggest.autoImports'), ...getInlayHintsPreferences(config), + ...this.getOrganizeImportsPreferences(config), }; return preferences; @@ -227,6 +228,23 @@ export default class FileConfigurationManager extends Disposable { wildcardPrefix + '**' + path.sep + p; }); } + + private getOrganizeImportsPreferences(config: vscode.WorkspaceConfiguration): Proto.UserPreferences { + return { + // More specific settings + organizeImportsAccentCollation: config.get('organizeImports.accentCollation'), + organizeImportsCaseFirst: withDefaultAsUndefined(config.get<'default' | 'upper' | 'lower'>('organizeImports.caseFirst', 'default'), 'default'), + organizeImportsCollation: config.get<'ordinal' | 'unicode'>('organizeImports.collation'), + organizeImportsIgnoreCase: withDefaultAsUndefined(config.get<'auto' | 'caseInsensitive' | 'caseSensitive'>('organizeImports.caseSensitivity'), 'auto'), + organizeImportsLocale: config.get('organizeImports.locale'), + organizeImportsNumericCollation: config.get('organizeImports.numericCollation'), + organizeImportsTypeOrder: withDefaultAsUndefined(config.get<'auto' | 'last' | 'inline' | 'first'>('organizeImports.typeOrder', 'auto'), 'auto'), + }; + } +} + +function withDefaultAsUndefined(value: T, def: O): Exclude | undefined { + return value === def ? undefined : value as Exclude; } export class InlayHintSettingNames {