Skip to content

Commit

Permalink
feat: apply lsp commands (#1130)
Browse files Browse the repository at this point in the history
* Apply commands from the lsp

If the lsp returns commands to run on completion, we now execute them.
This is helpful for the Haskell language server which uses commands to
implement auto-importing.

* Update checkbox

* fix: run callback after executing LSP command

---------

Co-authored-by: Liam Dyer <[email protected]>
  • Loading branch information
jhgarner and Saghen authored Feb 4, 2025
1 parent 66ed234 commit 2de57ce
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/development/lsp-tracker.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,5 @@
- [x] `textEditText`
- [x] `additionalTextEdits` <- known issue where applying the main text edit will cause this to be wrong if the additional text edit comes after since the indices will be offset
- [ ] `commitCharacters`
- [ ] `command`
- [x] `command`
- [x] `data` <- Don't think there's anything special to do here
2 changes: 1 addition & 1 deletion lua/blink/cmp/sources/lib/provider/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ function source:execute(context, item)
if self.module.execute == nil then
return async.task.new(function(resolve) resolve() end)
end
return async.task.new(function(resolve) self.module:execute(context, item, resolve) end)
return async.task.new(function(resolve) return self.module:execute(context, item, resolve) end)
end

--- Signature help ---
Expand Down
11 changes: 11 additions & 0 deletions lua/blink/cmp/sources/lsp/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,15 @@ function lsp:get_signature_help(context, callback)
end)
end

--- Execute ---

function lsp:execute(_, item, callback)
local client = vim.lsp.get_client_by_id(item.client_id)
if client and item.command then
client.request('workspace/executeCommand', item.command, function() callback() end)
else
callback()
end
end

return lsp

0 comments on commit 2de57ce

Please sign in to comment.