Skip to content

feat(completion): support lsp completion item.command#2372

Merged
echasnovski merged 1 commit intonvim-mini:backlogfrom
neo451:feat/support_item_command
Apr 16, 2026
Merged

feat(completion): support lsp completion item.command#2372
echasnovski merged 1 commit intonvim-mini:backlogfrom
neo451:feat/support_item_command

Conversation

@neo451
Copy link
Copy Markdown

@neo451 neo451 commented Apr 15, 2026

Use client:exec_cmd to run command field attached to completion items, useful for additional command running, found this is not supported while obsidian-nvim/obsidian.nvim#757 and which use command to create new notes on item accept, I think many LSP servers also use it to add auto imports

Did not find any discussions on it and not sure whether it is in scope, feels pretty natural to add.

@echasnovski
Copy link
Copy Markdown
Member

Thanks for the PR!

I am pretty sure I looked into this at least during the most recent 'mini.completion' set of improvements (LSP related and not). Don't quite remember the reason for this not being added, but vaguely remember there was one. Maybe the lack of an easy and not-that-new (client:exec_cmd is Neovim>=0.11) way to execute the command.

Although the code change looks reasonable. I'll take a closer look later.

@neo451
Copy link
Copy Markdown
Author

neo451 commented Apr 15, 2026

just for additional context

this is what blink.cmp use: https://github.com/saghen/blink.cmp/blob/37c96dc06032b3f128b230b5fb193706535b3811/lua/blink/cmp/sources/lsp/init.lua#L191

from this wrapper I would assume _exec_cmd is safe to call for pre-0.11, but need to verify

and I looked at what nvim-cmp does, it has this stalled issue on this hrsh7th/cmp-nvim-lsp#73

@echasnovski echasnovski changed the base branch from main to backlog April 16, 2026 11:02
@echasnovski echasnovski merged commit beb7cc3 into nvim-mini:backlog Apr 16, 2026
@echasnovski
Copy link
Copy Markdown
Member

Thanks again for the PR!

I've merged into a temporary branch to possibly finish this myself. If at all, It'll probably be merged into main at least tomorrow.

@echasnovski
Copy link
Copy Markdown
Member

@neo451, apart from 'obsidian.nvim', do you happen to know an example of a common LSP server that uses completionItem.command? I'd like to test it against the real world use case.

@neo451
Copy link
Copy Markdown
Author

neo451 commented Apr 16, 2026

@echasnovski I believe rust-analyzer expose auto import as a server command:

https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/auto_import.rs

But I have not used it myself for a long time, so not 100% sure.

@echasnovski
Copy link
Copy Markdown
Member

echasnovski commented Apr 16, 2026

@echasnovski I believe rust-analyzer expose auto import as a server command:

https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/auto_import.rs

But I have not used it myself for a long time, so not 100% sure.

Thanks! I've tried rust-analyzer with some auto-importing (like for MAX) and it uses additionalTextEdits. Don't know how to make it use the command field.

Is command support in 'obsidian.nvim' experimental (i.e. requires the unmerged PR)? If not, could you please list as detailed as possible steps for how I can test command support locally?

@echasnovski
Copy link
Copy Markdown
Member

I didn't manage to find a real world LSP server that I could easily set up and reproduce it returning completionItem.command. But let's hope that its support straightforward enough to not introduce any serious issues.

This should now be resolved on the main branch. @neo451, could you please test and see if it works as you'd expect?

@neo451
Copy link
Copy Markdown
Author

neo451 commented Apr 17, 2026

ok, I confirm it indeed works very well on the main now, I was on a small trip yesterday so did not get back to you as soon as possible, and just got back home to found you work so swiftly, thank you for your awesome work!


side note, now thinking about it, it does make sense that most common real world LSPs can just use additional text edits for these post actions, their editing footprint should be mostly contained in one file and be declarative, obsidian.nvim is just "abusing" it as a reliable way to run post completion accept hooks, but yeah I guess with more people writing in-process LSP plugins, this support is going to have more real world usecases in the neovim plugin ecosystem.

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.

2 participants