oil.nvim icon indicating copy to clipboard operation
oil.nvim copied to clipboard

bug: [Windows] LSP file operations not working

Open TheLeoP opened this issue 1 year ago • 0 comments

Did you check the docs and existing issues?

  • [X] I have read the docs
  • [X] I have searched the existing issues

Neovim version (nvim -v)

NVIM v0.10.0-dev-3100+gd3fa88b70

Operating system/version

Windows 11 Pro 23H2

Describe the bug

oil.nvim uses POSIX paths internally and transforms them to os specific paths when needed. When checking if a file matches a glob for LSP file operations, it uses the aforementioned internal POSIX representation:

https://github.com/stevearc/oil.nvim/blob/010b44a79d497c697686e2727049d3dd215bbbd6/lua/oil/lsp/workspace.lua#L109

This makes all checks fail in Windows (e.g. glob C:/Users/pcx/Desktop/test/** fails to match path /C/Users/pcx/Desktop/test/test2.lua)

Furthermore, simply using require("oil.fs").posix_to_os_path doesn't always work because servers like lua_ls send globs that use forward slashes as file separator in Windows (e.g. glob C:/Users/pcx/Desktop/test/** fails to match path C:\Users\pcx\Desktop\test\test2.lua)

What is the severity of this bug?

breaking (some functionality is broken)

Steps To Reproduce

  1. nvim -u repro.lua lua_sample/init.lua
  2. :LspInfo, make sure lua language server is attached
  3. :Oil, open the oil file manager and rename test.lua to hello.lua, save the buffer, and see that you don't get prompted to modify the requires

Expected Behavior

LSP file operations should work on Windows.

Directory structure

lua_sample/init.lua:


local test = require("test")

test.test()

lua_sample/test.lua:

local M = {}

function M.test()
  print("Hello")
end

return M

Repro

-- save as repro.lua
-- run with nvim -u repro.lua
-- DO NOT change the paths
local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "runtime", "cache" }) do
  vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({
    "git",
    "clone",
    "--filter=blob:none",
    "--single-branch",
    "https://github.com/folke/lazy.nvim.git",
    lazypath,
  })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
  "folke/tokyonight.nvim",
  {
        "stevearc/oil.nvim",
        config = function()
            require("oil").setup({
              -- add any needed settings here
            })
        end,
  },
 { -- basic configuration of lua language server
    "neovim/nvim-lspconfig",
    config = function()
      local lspconfig = require "lspconfig"
      lspconfig.lua_ls.setup {}
    end,
  },
  -- add any other plugins here
}
require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

vim.cmd.colorscheme("tokyonight")
-- add anything else here

Did you check the bug with a clean config?

  • [X] I have confirmed that the bug reproduces with nvim -u repro.lua using the repro.lua file above.

TheLeoP avatar May 11 '24 18:05 TheLeoP