diff --git a/README.md b/README.md index ab12c490..35aa63ba 100644 --- a/README.md +++ b/README.md @@ -156,8 +156,16 @@ Request: { command: '_typescript.organizeImports' arguments: [ - // The "skipDestructiveCodeActions" argument is supported from Typescript 4.4+ - [string] | [string, { skipDestructiveCodeActions?: boolean }], + string, // file URI + // Optional options: + { + // @deprecated - use "mode". Supported from Typescript 4.4+. + skipDestructiveCodeActions?: boolean + // 'All' - organizes imports including destructive actions (removing unused imports) + // 'SortAndCombine' - Doesn't perform destructive actions. + // 'RemoveUnused' - Only removes unused imports. + mode?: 'All' | 'SortAndCombine' | 'RemoveUnused' + }, ] } ``` diff --git a/src/lsp-server.ts b/src/lsp-server.ts index 30dc102b..1eb94781 100644 --- a/src/lsp-server.ts +++ b/src/lsp-server.ts @@ -903,9 +903,10 @@ export class LspServer { return; } - const additionalArguments = (params.arguments[1] || {}) as { skipDestructiveCodeActions?: boolean; }; + const additionalArguments = (params.arguments[1] || {}) as { skipDestructiveCodeActions?: boolean; mode?: OrganizeImportsMode; }; const body = await this.tsClient.interruptGetErr(async () => { await this.fileConfigurationManager.ensureConfigurationForDocument(document); + const mode = additionalArguments.mode ?? (additionalArguments.skipDestructiveCodeActions ? OrganizeImportsMode.SortAndCombine : OrganizeImportsMode.All); const response = await this.tsClient.execute( CommandTypes.OrganizeImports, { @@ -915,7 +916,7 @@ export class LspServer { }, // Deprecated in 4.9; `mode` takes priority skipDestructiveCodeActions: additionalArguments.skipDestructiveCodeActions, - mode: additionalArguments.skipDestructiveCodeActions ? OrganizeImportsMode.SortAndCombine : OrganizeImportsMode.All, + mode, }, token, );