From f630887cd845a7341bc16488fe8aaecffe3aaa8a Mon Sep 17 00:00:00 2001 From: Steven Arcangeli <506791+stevearc@users.noreply.github.com> Date: Tue, 14 May 2024 22:55:18 -0600 Subject: [PATCH] fix(windows): convert posix paths before matching LSP watch globs (#374) --- lua/oil/lsp/helpers.lua | 10 ++++++++++ lua/oil/lsp/workspace.lua | 6 ++++++ 2 files changed, 16 insertions(+) diff --git a/lua/oil/lsp/helpers.lua b/lua/oil/lsp/helpers.lua index 89c5469..45264dc 100644 --- a/lua/oil/lsp/helpers.lua +++ b/lua/oil/lsp/helpers.lua @@ -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") @@ -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) diff --git a/lua/oil/lsp/workspace.lua b/lua/oil/lsp/workspace.lua index 49065a0..9879e72 100644 --- a/lua/oil/lsp/workspace.lua +++ b/lua/oil/lsp/workspace.lua @@ -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