stevearc / oil.nvim

Neovim file explorer: edit your filesystem like a buffer
MIT License
3.84k stars 110 forks source link

bug: file renaming with LSP stopped working for certain files #386

Closed faergeek closed 4 months ago

faergeek commented 4 months ago

Did you check the docs and existing issues?

Neovim version (nvim -v)

0.10.0

Operating system/version

Arch Linux

Describe the bug

LSP renaming stopped working for me in neovim 0.10.0. I checked in v0.9.5, it works fine.

First I used git bisect in oil repo to figure out where it stopped working. Neovim is locally built from 0.10.0 git tag. At this commit it still works https://github.com/stevearc/oil.nvim/commit/1fce168881248e8310ebff2b4417db24ab7c175a, then it starts erroring out with oil.nvim/lua/oil/lsp_helpers.lua:24: attempt to call field '_match' on this commit https://github.com/stevearc/oil.nvim/commit/24027ed8d7f3ee5c38cfd713915e2e16d89e79b3. After https://github.com/stevearc/oil.nvim/commit/250e0af7a54d750792be8b1d6165b76b6603a867 (where ._match usage was removed) it doesn't error, but renaming also doesn't work.

I also used git bisect on neovim repo to figure out at which point it stopped working. oil.nvim is at https://github.com/stevearc/oil.nvim/commit/259b1fbc84734bfb74225b2c2f408dd7ed9cf474 locally. Turns out this is the first commit where it stopped working https://github.com/neovim/neovim/commit/92204b06e7365cf4c68e6ea8258dce801f0a5df9.

While preparing reproduction repo I noticed that it works fine when renaming .ts files, but not when renaming .tsx files. So it might be all related to glob handling I guess.

What is the severity of this bug?

breaking (some functionality is broken)

Steps To Reproduce

Not sure how else to easily reproduce it. Node and npm are required for this.

  1. Clone the repo https://github.com/faergeek/oil-issue-reproduction
  2. npm install
  3. nvim -u init.lua -o src/root.ts src/add.tsx src/subtract.ts
  4. Switch to add.tsx buffer, :Oil, rename file. Import in root.ts is not updated.
  5. Switch to subtract.ts buffer, :Oil, rename file. Import in root.ts is updated properly.

Expected Behavior

File renaming with LSP works in both cases.

Directory structure

No response

Repro

-- more files for reproduction are in the repo https://github.com/faergeek/oil-issue-reproduction
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,
    },
    {
        "neovim/nvim-lspconfig",
    },
    { "williamboman/mason.nvim", opts = {} },
    {
        "williamboman/mason-lspconfig.nvim",
        dependencies = { "mason.nvim", "neovim/nvim-lspconfig" },
        opts = {
            ensure_installed = { "tsserver" },
            handlers = {
                function(server_name)
                    require("lspconfig")[server_name].setup({})
                end,
            },
        },
    },
}
require("lazy").setup(plugins, {
    root = root .. "/plugins",
})

vim.cmd.colorscheme("tokyonight")

Did you check the bug with a clean config?

faergeek commented 4 months ago

So something is wrong with vim.glob.to_lpeg. All other extensions match except jsx and tsx:

vim.glob.to_lpeg('**/*.{ts,js,jsx,tsx,mjs,mts,cjs,cts}'):match('src/add.jsx')
vim.glob.to_lpeg('**/*.{ts,js,jsx,tsx,mjs,mts,cjs,cts}'):match('src/add.tsx')
faergeek commented 4 months ago

Reported here https://github.com/neovim/neovim/issues/28931

stevearc commented 4 months ago

Well I don't have a proper fix, but I put in a hack that works in this case. It probably won't cause more problems than it solves.

Thanks for the thorough repro! Made it very easy to test the fix.

faergeek commented 4 months ago

Awesome! Thank you for this great plugin which I use every day :+1: