@@ -4,7 +4,9 @@ local group = vim.api.nvim_create_augroup("LSP", { clear = true })
44-- Format code and organize imports (if supported) (async).
55--
66--- @async
7- --- @type lsp.Apply
7+ --- @param client vim.lsp.Client
8+ --- @param bufnr number
9+ --- @type fun ( client : vim.lsp.Client , bufnr : number )
810local organize_imports = function (client , bufnr )
911 --- @type lsp.Handler
1012 --- @diagnostic disable-next-line : unused-local
@@ -18,7 +20,7 @@ local organize_imports = function(client, bufnr)
1820 local enc = client .offset_encoding or " utf-16"
1921 vim .lsp .util .apply_workspace_edit (r .edit , enc )
2022 elseif r .command and r .command .command then
21- vim . lsp . buf . execute_command (r .command )
23+ client : exec_cmd (r .command , { bufnr = bufnr } )
2224 end
2325 end
2426 vim .cmd ([[ noautocmd write]] )
@@ -27,7 +29,7 @@ local organize_imports = function(client, bufnr)
2729 local win = vim .api .nvim_get_current_win ()
2830 local params = vim .lsp .util .make_range_params (win , client .offset_encoding or " utf-16" )
2931 params .context = { only = { " source.organizeImports" } }
30- client . request (ms .textDocument_codeAction , params , handler , bufnr )
32+ client : request (ms .textDocument_codeAction , params , handler , bufnr )
3133end
3234
3335-- Checks if the given buffer has any lsp clients that support the given method.
4244
4345--- @param bufnr number
4446--- @param method string
45- --- @param apply lsp.Apply
46- --- @param filter ? lsp.Filter
47+ --- @param apply fun ( client : vim. lsp.Client , bufnr : number )
48+ --- @param filter ? fun ( client : vim. lsp.Client ): boolean ?
4749local on_clients = function (bufnr , method , apply , filter )
4850 local clients = vim .lsp .get_clients ({ bufnr = bufnr , method = method })
4951 if not filter then
@@ -67,7 +69,7 @@ M.setup = function()
6769 if client == nil then
6870 return
6971 end
70- if client . supports_method (ms .textDocument_codeLens ) then
72+ if client : supports_method (ms .textDocument_codeLens , vim . api . nvim_get_current_buf () ) then
7173 vim .lsp .inlay_hint .enable (true )
7274 end
7375 end ,
@@ -78,7 +80,7 @@ M.setup = function()
7880 if client == nil then
7981 return
8082 end
81- if client . supports_method (ms .textDocument_codeLens ) then
83+ if client : supports_method (ms .textDocument_codeLens , vim . api . nvim_get_current_buf () ) then
8284 vim .lsp .codelens .clear (client .id )
8385 end
8486 end ,
@@ -87,7 +89,7 @@ M.setup = function()
8789
8890 vim .api .nvim_create_autocmd ({ " BufWritePre" }, {
8991 callback = function ()
90- --- @type lsp.Apply
92+ --- @type fun ( client : vim. lsp.Client , bufnr : number )
9193 local format = function (client , bufnr )
9294 if client .server_capabilities .documentFormattingProvider then
9395 vim .lsp .buf .format ({
@@ -106,7 +108,7 @@ M.setup = function()
106108 vim .api .nvim_create_autocmd ({ " BufWritePost" }, {
107109 callback = function ()
108110 local bufnr = vim .api .nvim_get_current_buf ()
109- --- @type lsp.Filter
111+ --- @type fun ( client : vim. lsp.Client ): boolean ?
110112 local filter = function (client )
111113 -- lua_ls freaks out when you ask it to organize imports.
112114 return client .name ~= " lua_ls"
0 commit comments