Skip to content

lsp-code-actions: display actions of the current diagnostics #4848

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

Merged
merged 1 commit into from
Aug 3, 2025

Conversation

taquangtrung
Copy link
Contributor

Hi,

This PR enables lsp-code-actions to display more actions if there are diagnostics at the current point.

For example, in the screenshot below, there is a warning that format!("{}", e) can be refactored to format!("{e}"), but when putting the cursor at the beginning of this text (at the format statement), there is no code action to perform such refactoring.

lsp-code-action-before-1

I fixed this issue by finding the code range of the diagnostics and displaying all their code actions, so that the code action to refactor to format!("{e}") can be displayed like below:

lsp-code-action-after

Please consider merging it!

Thanks!

Copy link
Member

@jcs090218 jcs090218 left a comment

Choose a reason for hiding this comment

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

Sounds good to me! :)

@jcs090218 jcs090218 merged commit 226df20 into emacs-lsp:master Aug 3, 2025
18 checks passed
@corecode
Copy link

corecode commented Aug 4, 2025

this breaks for me, because lsp-cur-possition-diagnostics (spelling) returns a plist, not a hash.

jcs090218 added a commit that referenced this pull request Aug 4, 2025
@jcs090218
Copy link
Member

I have temporarily reverted it in b96102c. 🤔

cc @taquangtrung

@corecode
Copy link

corecode commented Aug 4, 2025

Note: I'm using LSP_USE_PLISTS (as suggested for performance)

@taquangtrung taquangtrung deleted the fix-lsp-code-actions branch August 4, 2025 13:46
@jcs090218
Copy link
Member

Note: I'm using LSP_USE_PLISTS (as suggested for performance)

Yeah, I completely forgot about this! I apologize! 😓

@taquangtrung
Copy link
Contributor Author

@corecode: Can you kindly test if this new PR works for you? https://github.com/emacs-lsp/lsp-mode/pull/4849/files

FYI, I tested and it works on my end.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants