Skip to content

Commit

Permalink
fix(windows): convert posix paths before matching LSP watch globs (#372)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevearc committed May 14, 2024
1 parent 3283dee commit b5a0f8b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lua/oil/lsp/helpers.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
local config = require("oil.config")
local fs = require("oil.fs")
local util = require("oil.util")
local workspace = require("oil.lsp.workspace")

Expand All @@ -17,23 +18,32 @@ M.will_perform_file_operations = function(actions)
local src_adapter = assert(config.get_adapter_by_scheme(src_scheme))
local dest_scheme, dest_path = util.parse_url(action.dest_url)
local dest_adapter = assert(config.get_adapter_by_scheme(dest_scheme))
src_path = fs.posix_to_os_path(src_path)
dest_path = fs.posix_to_os_path(dest_path)
if src_adapter.name == "files" and dest_adapter.name == "files" then
moves[src_path] = dest_path
elseif src_adapter.name == "files" then
table.insert(deletes, src_path)
elseif dest_adapter.name == "files" then
table.insert(creates, src_path)
end
elseif action.type == "create" then
local scheme, path = util.parse_url(action.url)
path = fs.posix_to_os_path(path)
local adapter = assert(config.get_adapter_by_scheme(scheme))
if adapter.name == "files" then
table.insert(creates, path)
end
elseif action.type == "delete" then
local scheme, path = util.parse_url(action.url)
path = fs.posix_to_os_path(path)
local adapter = assert(config.get_adapter_by_scheme(scheme))
if adapter.name == "files" then
table.insert(deletes, path)
end
elseif action.type == "copy" then
local scheme, path = util.parse_url(action.dest_url)
path = fs.posix_to_os_path(path)
local adapter = assert(config.get_adapter_by_scheme(scheme))
if adapter.name == "files" then
table.insert(creates, path)
Expand Down
6 changes: 6 additions & 0 deletions lua/oil/lsp/workspace.lua
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ local function get_matching_paths(client, filters, paths)
if ignore_case then
glob = glob:lower()
end

-- Some language servers use forward slashes as path separators on Windows (LuaLS)
if fs.is_windows then
glob = glob:gsub("/", "\\")
end

---@type nil|vim.lpeg.Pattern
local glob_pattern = vim.glob and vim.glob.to_lpeg and vim.glob.to_lpeg(glob)
local matches = pattern.matches
Expand Down

0 comments on commit b5a0f8b

Please sign in to comment.