aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/lsp/_dynamic.lua
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/lua/vim/lsp/_dynamic.lua')
-rw-r--r--runtime/lua/vim/lsp/_dynamic.lua31
1 files changed, 18 insertions, 13 deletions
diff --git a/runtime/lua/vim/lsp/_dynamic.lua b/runtime/lua/vim/lsp/_dynamic.lua
index 04040e8e28..819b03a63a 100644
--- a/runtime/lua/vim/lsp/_dynamic.lua
+++ b/runtime/lua/vim/lsp/_dynamic.lua
@@ -1,4 +1,4 @@
-local wf = require('vim.lsp._watchfiles')
+local glob = vim.glob
--- @class lsp.DynamicCapabilities
--- @field capabilities table<string, lsp.Registration[]>
@@ -6,6 +6,7 @@ local wf = require('vim.lsp._watchfiles')
local M = {}
--- @param client_id number
+--- @return lsp.DynamicCapabilities
function M.new(client_id)
return setmetatable({
capabilities = {},
@@ -18,12 +19,12 @@ function M:supports_registration(method)
if not client then
return false
end
- local capability = vim.tbl_get(client.config.capabilities, unpack(vim.split(method, '/')))
+ local capability = vim.tbl_get(client.capabilities, unpack(vim.split(method, '/')))
return type(capability) == 'table' and capability.dynamicRegistration
end
--- @param registrations lsp.Registration[]
---- @private
+--- @package
function M:register(registrations)
-- remove duplicates
self:unregister(registrations)
@@ -37,7 +38,7 @@ function M:register(registrations)
end
--- @param unregisterations lsp.Unregistration[]
---- @private
+--- @package
function M:unregister(unregisterations)
for _, unreg in ipairs(unregisterations) do
local method = unreg.method
@@ -55,9 +56,9 @@ function M:unregister(unregisterations)
end
--- @param method string
---- @param opts? {bufnr?: number}
+--- @param opts? {bufnr: integer?}
--- @return lsp.Registration? (table|nil) the registration if found
---- @private
+--- @package
function M:get(method, opts)
opts = opts or {}
opts.bufnr = opts.bufnr or vim.api.nvim_get_current_buf()
@@ -69,15 +70,15 @@ function M:get(method, opts)
if not documentSelector then
return reg
end
- if M.match(opts.bufnr, documentSelector) then
+ if self:match(opts.bufnr, documentSelector) then
return reg
end
end
end
--- @param method string
---- @param opts? {bufnr?: number}
---- @private
+--- @param opts? {bufnr: integer?}
+--- @package
function M:supports(method, opts)
return self:get(method, opts) ~= nil
end
@@ -85,19 +86,23 @@ end
--- @param bufnr number
--- @param documentSelector lsp.DocumentSelector
--- @private
-function M.match(bufnr, documentSelector)
- local ft = vim.bo[bufnr].filetype
+function M:match(bufnr, documentSelector)
+ local client = vim.lsp.get_client_by_id(self.client_id)
+ if not client then
+ return false
+ end
+ local language = client.get_language_id(bufnr, vim.bo[bufnr].filetype)
local uri = vim.uri_from_bufnr(bufnr)
local fname = vim.uri_to_fname(uri)
for _, filter in ipairs(documentSelector) do
local matches = true
- if filter.language and ft ~= filter.language then
+ if filter.language and language ~= filter.language then
matches = false
end
if matches and filter.scheme and not vim.startswith(uri, filter.scheme .. ':') then
matches = false
end
- if matches and filter.pattern and not wf._match(filter.pattern, fname) then
+ if matches and filter.pattern and not glob.to_lpeg(filter.pattern):match(fname) then
matches = false
end
if matches then