Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(windows): convert posix paths before matching LSP watch globs #374

Merged
merged 1 commit into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(assert(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(assert(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(assert(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(assert(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
Loading