-
Notifications
You must be signed in to change notification settings - Fork 27.9k
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
CodeActionScope #41782
CodeActionScope #41782
Conversation
src/vs/vscode.d.ts
Outdated
* | ||
* Specifies the type of a code action. A scope is a hierarchical list of identifiers separated by `.`, e.g. `"refactoring.extract.function"`. | ||
*/ | ||
export class CodeActionScope { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe CodeActionKind
is the better name because this is about the 'character' of a code action and because we have been using ...Kind already for similar purposes...
src/vs/vscode.d.ts
Outdated
/** | ||
* Base scope for refactoring extraction inline. | ||
*/ | ||
public static readonly RefactorInline: CodeActionScope; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if the Refactor
-prefix is needed? Isn't this implicit?
src/vs/vscode.d.ts
Outdated
* | ||
* Does not modify the current scope object. | ||
*/ | ||
public add(parts: string): CodeActionScope; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better append
src/vs/vscode.d.ts
Outdated
* | ||
* @param other Scope to check. | ||
*/ | ||
public contains(other: CodeActionScope): boolean; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have an use-case for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is used for the requestedScope
logic in the TS refactoring code action provider so that we can skip computing code actions that vscode will filter out later
src/vs/vscode.d.ts
Outdated
* | ||
* Actions not within this scope are filtered out before being shown by the lightbulb. | ||
*/ | ||
readonly requestedScope?: CodeActionScope; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe use a for with for select-semantics, like only
?
@@ -36,12 +37,12 @@ export class QuickFixOracle { | |||
this._disposables = dispose(this._disposables); | |||
} | |||
|
|||
trigger(type: 'manual' | 'auto'): void { | |||
trigger(type: 'manual' | 'auto', trigger?: CodeActionTrigger): void { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getting a little messy... can we fold both args into one request object and pass that along?
src/vs/vscode.d.ts
Outdated
* Base scope for refactoring extraction inline. | ||
*/ | ||
public static readonly RefactorInline: CodeActionScope; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should also have static readonly Rewrite
for things like 'Convert if-else into ternary statement' etc, etc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and also maybe CleanUp
category?
src/vs/vscode.d.ts
Outdated
/** | ||
* Empty scope. | ||
*/ | ||
public static readonly Empty: CodeActionScope; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no public
499b465
to
2a7d23d
Compare
Thanks for the feedback. Pushed change that updates the names as suggested. I'll also look into cleaning up the trigger implementation flow. The new change also allows for callers of
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think cAmEl is good for naming class's. Like codeActionKind
Take args as an object instead of as an array of values
dfba759
to
5f68a21
Compare
Most recent change makes the keybindings for this more like
|
59a30c7
to
0c30b3f
Compare
Will follow up with changes to expose a new "refactor" action with keybinding, as well as hooking up more of the TS quick fixes / refactorings to use |
Fixes #41048
Problem
We'd like to improve the UX for refactorings. Two specific ideas:
Proposal
Introduce a new
CodeActionScope
type. This identifies the class/type of a given refactoring. All refactoring code actions for example would have a scope ofrefactor.*
, with an extract method refactoring action having a scope ofrefactor.extract.method
For the refactoring context menu, we use
CodeActionScope
to filter out any code actions that are not refactorings. TheCodeActionContext
will also have a scope field on it that aCodeActionProvider
can use to determine which code actions to compute and returnFor keybindings, we can setup a keybinding such as:
where
"refactor"
is treated as the code action scope. Only code actions of the type"refactor.*"
should be shownTodo
Still a lot to do on this PR
CodeActionContext
editor.action.codeAction
command instead of overloading the existingeditor.action.quickFix
command