mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
fix(lsp): fix relative patterns for workspace/didChangeWatchedFiles
(#23548)
This commit is contained in:
parent
82bb7bbc48
commit
075a72d5ff
@ -198,16 +198,17 @@ function M.register(reg, ctx)
|
|||||||
end
|
end
|
||||||
local watch_regs = {}
|
local watch_regs = {}
|
||||||
for _, w in ipairs(reg.registerOptions.watchers) do
|
for _, w in ipairs(reg.registerOptions.watchers) do
|
||||||
|
local relative_pattern = false
|
||||||
local glob_patterns = {}
|
local glob_patterns = {}
|
||||||
if type(w.globPattern) == 'string' then
|
if type(w.globPattern) == 'string' then
|
||||||
for _, folder in ipairs(client.workspace_folders) do
|
for _, folder in ipairs(client.workspace_folders) do
|
||||||
table.insert(glob_patterns, { baseUri = folder.uri, pattern = w.globPattern })
|
table.insert(glob_patterns, { baseUri = folder.uri, pattern = w.globPattern })
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
relative_pattern = true
|
||||||
table.insert(glob_patterns, w.globPattern)
|
table.insert(glob_patterns, w.globPattern)
|
||||||
end
|
end
|
||||||
for _, glob_pattern in ipairs(glob_patterns) do
|
for _, glob_pattern in ipairs(glob_patterns) do
|
||||||
local pattern = parse(glob_pattern.pattern)
|
|
||||||
local base_dir = nil
|
local base_dir = nil
|
||||||
if type(glob_pattern.baseUri) == 'string' then
|
if type(glob_pattern.baseUri) == 'string' then
|
||||||
base_dir = glob_pattern.baseUri
|
base_dir = glob_pattern.baseUri
|
||||||
@ -216,9 +217,16 @@ function M.register(reg, ctx)
|
|||||||
end
|
end
|
||||||
assert(base_dir, "couldn't identify root of watch")
|
assert(base_dir, "couldn't identify root of watch")
|
||||||
base_dir = vim.uri_to_fname(base_dir)
|
base_dir = vim.uri_to_fname(base_dir)
|
||||||
|
|
||||||
local kind = w.kind
|
local kind = w.kind
|
||||||
or protocol.WatchKind.Create + protocol.WatchKind.Change + protocol.WatchKind.Delete
|
or protocol.WatchKind.Create + protocol.WatchKind.Change + protocol.WatchKind.Delete
|
||||||
|
|
||||||
|
local pattern = glob_pattern.pattern
|
||||||
|
if relative_pattern then
|
||||||
|
pattern = base_dir .. '/' .. pattern
|
||||||
|
end
|
||||||
|
pattern = parse(pattern)
|
||||||
|
|
||||||
table.insert(watch_regs, {
|
table.insert(watch_regs, {
|
||||||
base_dir = base_dir,
|
base_dir = base_dir,
|
||||||
pattern = pattern,
|
pattern = pattern,
|
||||||
|
@ -3855,7 +3855,7 @@ describe('LSP', function()
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
it('correctly registers and unregisters', function()
|
it('correctly registers and unregisters', function()
|
||||||
local root_dir = 'some_dir'
|
local root_dir = '/some_dir'
|
||||||
exec_lua(create_server_definition)
|
exec_lua(create_server_definition)
|
||||||
local result = exec_lua([[
|
local result = exec_lua([[
|
||||||
local root_dir = ...
|
local root_dir = ...
|
||||||
@ -4009,10 +4009,9 @@ describe('LSP', function()
|
|||||||
local watchers = {}
|
local watchers = {}
|
||||||
local max_kind = protocol.WatchKind.Create + protocol.WatchKind.Change + protocol.WatchKind.Delete
|
local max_kind = protocol.WatchKind.Create + protocol.WatchKind.Change + protocol.WatchKind.Delete
|
||||||
for i = 0, max_kind do
|
for i = 0, max_kind do
|
||||||
local j = i
|
|
||||||
table.insert(watchers, {
|
table.insert(watchers, {
|
||||||
globPattern = {
|
globPattern = {
|
||||||
baseUri = vim.uri_from_fname('/dir'..tostring(i)),
|
baseUri = vim.uri_from_fname('/dir'),
|
||||||
pattern = 'watch'..tostring(i),
|
pattern = 'watch'..tostring(i),
|
||||||
},
|
},
|
||||||
kind = i,
|
kind = i,
|
||||||
@ -4031,7 +4030,7 @@ describe('LSP', function()
|
|||||||
}, { client_id = client_id })
|
}, { client_id = client_id })
|
||||||
|
|
||||||
for i = 0, max_kind do
|
for i = 0, max_kind do
|
||||||
local filename = 'watch'..tostring(i)
|
local filename = '/dir/watch' .. tostring(i)
|
||||||
send_event(filename, vim._watch.FileChangeType.Created)
|
send_event(filename, vim._watch.FileChangeType.Created)
|
||||||
send_event(filename, vim._watch.FileChangeType.Changed)
|
send_event(filename, vim._watch.FileChangeType.Changed)
|
||||||
send_event(filename, vim._watch.FileChangeType.Deleted)
|
send_event(filename, vim._watch.FileChangeType.Deleted)
|
||||||
@ -4045,7 +4044,8 @@ describe('LSP', function()
|
|||||||
|
|
||||||
local function watched_uri(fname)
|
local function watched_uri(fname)
|
||||||
return exec_lua([[
|
return exec_lua([[
|
||||||
return vim.uri_from_fname(...)
|
local fname = ...
|
||||||
|
return vim.uri_from_fname('/dir/' .. fname)
|
||||||
]], fname)
|
]], fname)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user