Skip to content
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

Fix #411 Allow to specify kind of code action to execute #598

Merged
merged 1 commit into from
Jan 28, 2021

Conversation

muffinmad
Copy link
Collaborator

@muffinmad muffinmad commented Jan 23, 2021

Make eglot-code-actions accept action-kind argument. If there are
only one action of that kind, apply it.
This will allow to create shortcuts for actions of the specific kind.

  • eglot.el (aglot--region-bounds): New function.
    (eglot-code-actions): Use it; Accept new argument action-kind.
    Execute the only action of that kind.
    (eglot-code-action-inline, eglot-code-action-extract,
    eglot-code-action-rewrite, eglot-code-action-quickfix,
    eglot-code-action-organize-imports): New commands.
  • NEWS.md: New entry.
  • README.md (Commands and keybindings): Mention changes to the
    eglot-code-actions function; Mention new commands.

@joaotavora
Copy link
Owner

This will allow to create actions shortcuts like

These shortcuts may be simple enough that they can be in eglot.el itself. But I don't see why they shouldn't also take beg and end, for completeness.

@muffinmad
Copy link
Collaborator Author

This will allow to create actions shortcuts like

These shortcuts may be simple enough that they can be in eglot.el itself. But I don't see why they shouldn't also take beg and end, for completeness.

Agree. If you think those shortcuts are not worth a separate PR, I can add it here.

Copy link
Owner

@joaotavora joaotavora left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please try to do the Lisp refactorings I suggest, otherwise go ahead and I'll do this cleanup later. Conceptually, I think the code is clean.

eglot.el Outdated Show resolved Hide resolved
eglot.el Outdated Show resolved Hide resolved
eglot.el Outdated Show resolved Hide resolved
eglot.el Outdated Show resolved Hide resolved
eglot.el Outdated Show resolved Hide resolved
eglot.el Outdated Show resolved Hide resolved
@joaotavora
Copy link
Owner

Agree. If you think those shortcuts are not worth a separate PR, I can add it here.

Agree. Add them here. Maybe in a separate commit, but not strictly necessary.

@joaotavora
Copy link
Owner

If you add the shortcuts, edit the README.md file too to mention them. Also, edit the NEWS.md file if you can find a terse way to describe this feature.

@muffinmad
Copy link
Collaborator Author

Ok, will do in a few days. Thanks!

@mdbergmann
Copy link

Just to confirm that the code as it is seems to work with either code-actions provided by menu and clicking them, and executing a code-action as the example for organize imports at the top post here.

eglot.el Outdated Show resolved Hide resolved
eglot.el Outdated Show resolved Hide resolved
eglot.el Outdated Show resolved Hide resolved
eglot.el Show resolved Hide resolved
@muffinmad
Copy link
Collaborator Author

Anyway, please change back to default

Can we keep default-action? IMO it looks better combined with preferred-action.

@joaotavora
Copy link
Owner

Can we keep default-action? IMO it looks better combined with preferred-action.

Sure, of course. Though I personally would do default + preferred. But the level of nitpickery is getting extreme here.

eglot.el Outdated Show resolved Hide resolved
@joaotavora
Copy link
Owner

I've tweaked this PR. It's ready for squashing and pushing IMO (after commit msg where I should appear as Co-authored-by). But have a look at the tweaks I made and let me know.

BTW your macro was fine, but some people including me, prefer macros to not secretly intern symbols, since it helps when finding definitions. A function defining macro should theoretically be called define-foo, but I let that go here in favour of some terse and readable one-liners.

@muffinmad
Copy link
Collaborator Author

I've tweaked this PR. It's ready for squashing and pushing IMO (after commit msg where I should appear as Co-authored-by). But have a look at the tweaks I made and let me know.

Looks absolutely good to me.

BTW your macro was fine, but some people including me, prefer macros to not secretly intern symbols, since it helps when finding definitions. A function defining macro should theoretically be called define-foo, but I let that go here in favour of some terse and readable one-liners.

Got it. Thanks!

…e actions

Make eglot-code-actions accept a new action-kind argument.  If there
is only one action of that kind, apply it.  This allows us to create
actions shortcuts like eglot-code-action-organize-imports, etc.

* eglot.el (eglot-code-actions): Accept new argument action-kind.
(eglot--code-action): New function-defining helper macro.
(eglot-code-action-organize-imports)
(eglot-code-action-extract)
(eglot-code-action-inline)
(eglot-code-action-rewrite)
(eglot-code-action-quickfix): New commands.

* README.md: Mention new feature.

* NEWS.md: Mention new feature.

Co-authored-by: João Távora <[email protected]>
@joaotavora joaotavora merged commit 147f3b0 into joaotavora:master Jan 28, 2021
@muffinmad muffinmad deleted the actions-shortcut branch January 28, 2021 18:49
bhankas pushed a commit to bhankas/emacs that referenced this pull request Sep 18, 2022
…ed code actions

See also joaotavora/eglot#598.

Make eglot-code-actions accept a new action-kind argument.  If there
is only one action of that kind, apply it.  This allows us to create
actions shortcuts like eglot-code-action-organize-imports, etc.

* eglot.el (eglot-code-actions): Accept new argument action-kind.
(eglot--code-action): New function-defining helper macro.
(eglot-code-action-organize-imports)
(eglot-code-action-extract)
(eglot-code-action-inline)
(eglot-code-action-rewrite)
(eglot-code-action-quickfix): New commands.

* README.md: Mention new feature.

* NEWS.md: Mention new feature.

Co-authored-by: João Távora <[email protected]>
bhankas pushed a commit to bhankas/emacs that referenced this pull request Sep 19, 2022
…ed code actions

See also joaotavora/eglot#598.

Make eglot-code-actions accept a new action-kind argument.  If there
is only one action of that kind, apply it.  This allows us to create
actions shortcuts like eglot-code-action-organize-imports, etc.

* eglot.el (eglot-code-actions): Accept new argument action-kind.
(eglot--code-action): New function-defining helper macro.
(eglot-code-action-organize-imports)
(eglot-code-action-extract)
(eglot-code-action-inline)
(eglot-code-action-rewrite)
(eglot-code-action-quickfix): New commands.

* README.md: Mention new feature.

* NEWS.md: Mention new feature.

Co-authored-by: João Távora <[email protected]>
bhankas pushed a commit to bhankas/emacs that referenced this pull request Sep 19, 2022
See also #598.

Make eglot-code-actions accept a new action-kind argument.  If there
is only one action of that kind, apply it.  This allows us to create
actions shortcuts like eglot-code-action-organize-imports, etc.

* eglot.el (eglot-code-actions): Accept new argument action-kind.
(eglot--code-action): New function-defining helper macro.
(eglot-code-action-organize-imports)
(eglot-code-action-extract)
(eglot-code-action-inline)
(eglot-code-action-rewrite)
(eglot-code-action-quickfix): New commands.

* README.md: Mention new feature.

* NEWS.md: Mention new feature.

Co-authored-by: João Távora <[email protected]>
#411: joaotavora/eglot#411
#598: joaotavora/eglot#598
jollaitbot pushed a commit to sailfishos-mirror/emacs that referenced this pull request Oct 12, 2022
See also joaotavora/eglot#598.

Make eglot-code-actions accept a new action-kind argument.  If there
is only one action of that kind, apply it.  This allows us to create
actions shortcuts like eglot-code-action-organize-imports, etc.

* eglot.el (eglot-code-actions): Accept new argument action-kind.
(eglot--code-action): New function-defining helper macro.
(eglot-code-action-organize-imports)
(eglot-code-action-extract)
(eglot-code-action-inline)
(eglot-code-action-rewrite)
(eglot-code-action-quickfix): New commands.

* README.md: Mention new feature.

* NEWS.md: Mention new feature.

Co-authored-by: João Távora <[email protected]>
GitHub-reference: close joaotavora/eglot#411
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants