🌐 AI搜索 & 代理 主页
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'
},
]
}
```
Expand Down
5 changes: 3 additions & 2 deletions src/lsp-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
{
Expand All @@ -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,
);
Expand Down