-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Add option to OrganizeImports for removal only #50931
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -681,9 +681,17 @@ namespace ts.server.protocol { | |
|
||
export type OrganizeImportsScope = GetCombinedCodeFixScope; | ||
|
||
export const enum OrganizeImportsMode { | ||
All = "All", | ||
SortAndCombine = "SortAndCombine", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While the PR focuses on the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, to be clear, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ye, I got the fact that this one isn't a new option - but I had no idea that it was already a thing. So I'm glad that I've discovered that old option through this PR :P There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can't figure out how to actually use this old option in VS Code. I've found this in the source code: I've tried a lot of combinations with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "editor.codeActionsOnSave": {
"source.sortImports": true
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe Organize Imports is a VS Code standard command, and so automatically appears in the command palette when registered. These variations are registered so can be triggered by ID in configurations like |
||
RemoveUnused = "RemoveUnused", | ||
} | ||
|
||
export interface OrganizeImportsRequestArgs { | ||
scope: OrganizeImportsScope; | ||
/** @deprecated Use `mode` instead */ | ||
skipDestructiveCodeActions?: boolean; | ||
mode?: OrganizeImportsMode; | ||
andrewbranch marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
export interface OrganizeImportsResponse extends Response { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -575,8 +575,16 @@ namespace ts { | |
|
||
export interface CombinedCodeFixScope { type: "file"; fileName: string; } | ||
|
||
export const enum OrganizeImportsMode { | ||
All = "All", | ||
SortAndCombine = "SortAndCombine", | ||
RemoveUnused = "RemoveUnused", | ||
} | ||
andrewbranch marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
export interface OrganizeImportsArgs extends CombinedCodeFixScope { | ||
/** @deprecated Use `mode` instead */ | ||
skipDestructiveCodeActions?: boolean; | ||
mode?: OrganizeImportsMode; | ||
Comment on lines
+585
to
+587
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think |
||
} | ||
|
||
export type CompletionsTriggerCharacter = "." | '"' | "'" | "`" | "/" | "@" | "<" | "#" | " "; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/// <reference path="fourslash.ts" /> | ||
|
||
//// import { c, b, a } from "foo"; | ||
//// import d, { e } from "bar"; | ||
//// import * as f from "baz"; | ||
//// import { g } from "foo"; | ||
//// | ||
//// export { g, e, b, c }; | ||
|
||
verify.organizeImports( | ||
`import { c, b } from "foo"; | ||
import { e } from "bar"; | ||
import { g } from "foo"; | ||
|
||
export { g, e, b, c };`, | ||
ts.OrganizeImportsMode.RemoveUnused); |
Uh oh!
There was an error while loading. Please reload this page.