99--- @class astrolsp
1010local M = {}
1111
12+ local utils = require " astrolsp.utils"
13+
1214local tbl_contains = vim .tbl_contains
1315local tbl_isempty = vim .tbl_isempty
1416
@@ -27,7 +29,7 @@ local function lsp_event(name) vim.api.nvim_exec_autocmds("User", { pattern = "A
2729local function check_cond (cond , client , bufnr )
2830 local cond_type = type (cond )
2931 if cond_type == " function" then return cond (client , bufnr ) end
30- if cond_type == " string" then return client .supports_method (cond ) end
32+ if cond_type == " string" then return utils .supports_method (client , cond , bufnr ) end
3133 if cond_type == " boolean" then return cond end
3234 return true
3335end
7981--- @param client vim.lsp.Client The LSP client details when attaching
8082--- @param bufnr integer The buffer that the LSP client is attaching to
8183function M .on_attach (client , bufnr )
82- if client .supports_method " textDocument/codeLens" and M .config .features .codelens then
84+ if utils .supports_method ( client , " textDocument/codeLens" , bufnr ) and M .config .features .codelens then
8385 vim .lsp .codelens .refresh { bufnr = bufnr }
8486 end
8587
8688 local formatting_disabled = vim .tbl_get (M .config , " formatting" , " disabled" )
8789 if
88- client .supports_method " textDocument/formatting"
90+ utils .supports_method ( client , " textDocument/formatting" , bufnr )
8991 and (formatting_disabled ~= true and not tbl_contains (formatting_disabled , client .name ))
9092 then
9193 local autoformat = assert (M .config .formatting .format_on_save )
@@ -97,7 +99,7 @@ function M.on_attach(client, bufnr)
9799 end
98100 end
99101
100- if client .supports_method " textDocument/semanticTokens/full" and vim .lsp .semantic_tokens then
102+ if utils .supports_method ( client , " textDocument/semanticTokens/full" , bufnr ) and vim .lsp .semantic_tokens then
101103 if M .config .features .semantic_tokens then
102104 if vim .b [bufnr ].semantic_tokens == nil then vim .b [bufnr ].semantic_tokens = true end
103105 else
@@ -278,7 +280,7 @@ function M.setup(opts)
278280 desc = " Add signature help triggers as language servers attach" ,
279281 callback = function (args )
280282 local client = vim .lsp .get_client_by_id (args .data .client_id )
281- if client and client .supports_method " textDocument/signatureHelp" then
283+ if client and utils .supports_method ( client , " textDocument/signatureHelp" , args . buf ) then
282284 for _ , set in ipairs { " triggerCharacters" , " retriggerCharacters" } do
283285 local set_var = " signature_help_" .. set
284286 local triggers = vim .b [args .buf ][set_var ] or {}
@@ -297,7 +299,9 @@ function M.setup(opts)
297299 if not vim .api .nvim_buf_is_valid (args .buf ) then return end
298300 local triggers , retriggers = {}, {}
299301 for _ , client in pairs (vim .lsp .get_clients { bufnr = args .buf }) do
300- if client .id ~= args .data .client_id and client .supports_method " textDocument/signatureHelp" then
302+ if
303+ client .id ~= args .data .client_id and utils .supports_method (client , " textDocument/signatureHelp" , args .buf )
304+ then
301305 for _ , trigger in ipairs (client .server_capabilities .signatureHelpProvider .triggerCharacters or {}) do
302306 triggers [trigger ] = true
303307 end
0 commit comments