From 17d709f8e1b6afde971c858f03ac382f279aaa38 Mon Sep 17 00:00:00 2001 From: Jack Garner Date: Tue, 28 Jan 2025 18:39:24 -0800 Subject: [PATCH 1/3] 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. --- lua/blink/cmp/sources/lsp/init.lua | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lua/blink/cmp/sources/lsp/init.lua b/lua/blink/cmp/sources/lsp/init.lua index ad2772ef..f41e20e5 100644 --- a/lua/blink/cmp/sources/lsp/init.lua +++ b/lua/blink/cmp/sources/lsp/init.lua @@ -147,4 +147,12 @@ function lsp:get_signature_help(context, callback) end) end +--- Execute --- + +function lsp:execute(_, item) + local client = vim.lsp.get_client_by_id(item.client_id) + if client and item.command then client.request('workspace/executeCommand', item.command) end + return function() end +end + return lsp From 9f4093bf4a9a6bfbed7ec51a57dd735211b5ebbb Mon Sep 17 00:00:00 2001 From: Jack Garner Date: Fri, 31 Jan 2025 15:53:43 -0800 Subject: [PATCH 2/3] Update checkbox --- docs/development/lsp-tracker.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/development/lsp-tracker.md b/docs/development/lsp-tracker.md index 5f694170..f8ea2e85 100644 --- a/docs/development/lsp-tracker.md +++ b/docs/development/lsp-tracker.md @@ -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 From 6d4a2e9a114ac198b66236fb691820d85da8905e Mon Sep 17 00:00:00 2001 From: Liam Dyer Date: Tue, 4 Feb 2025 12:22:22 -0500 Subject: [PATCH 3/3] fix: run callback after executing LSP command --- lua/blink/cmp/sources/lib/provider/init.lua | 2 +- lua/blink/cmp/sources/lsp/init.lua | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lua/blink/cmp/sources/lib/provider/init.lua b/lua/blink/cmp/sources/lib/provider/init.lua index 02e13896..bcaf4eda 100644 --- a/lua/blink/cmp/sources/lib/provider/init.lua +++ b/lua/blink/cmp/sources/lib/provider/init.lua @@ -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 --- diff --git a/lua/blink/cmp/sources/lsp/init.lua b/lua/blink/cmp/sources/lsp/init.lua index f41e20e5..1d075ec1 100644 --- a/lua/blink/cmp/sources/lsp/init.lua +++ b/lua/blink/cmp/sources/lsp/init.lua @@ -149,10 +149,13 @@ end --- Execute --- -function lsp:execute(_, item) +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) end - return function() end + if client and item.command then + client.request('workspace/executeCommand', item.command, function() callback() end) + else + callback() + end end return lsp