stevearc / oil.nvim

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

bug: lua-language-server not working with LSP file operations #279

Closed mehalter closed 8 months ago

mehalter commented 8 months ago

Did you check the docs and existing issues?

Neovim version (nvim -v)

v0.10.0-dev-2051+gee3d4f6b9

Operating system/version

Arch Linux

Describe the bug

Lua language server LSP module renaming doesn't work in Oil. It doesn't prompt for modifications so something is going on with the LSP integration. I did testing on the latest stable neovim release and nightly. It seems related to nightly, on 0.9.5 it is working. It seems to work with both vtsls and tssserver. vtsls working and the lua language server not working is definitely a strange once since they both rely on didRenameFiles. So I'm not sure what is going on.

In depth demonstration with the repro.lua below comparing the operation from my own fork that I had opened a PR with and the current master branch: https://asciinema.org/a/kfPxsdk1wEtwhJKp8JCo3plt2

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 integration should work.

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 = {
  {
    "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,
  },
}
require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

Did you check the bug with a clean config?

stevearc commented 8 months ago

One thing I immediately ran into was that LuaLS was running in single-file mode. This was because lua_sample/ didn't have any of the lspconfig-defined root files: https://github.com/neovim/nvim-lspconfig/blob/7eed8b2150192e5ad05e1886fdf133493ddf2928/lua/lspconfig/server_configurations/lua_ls.lua#L3-L11

After adding one, nvim 0.9.5 started working. The issue with nightly was because of the filter glob matching. I thought that the paths were always relative to the workspace, and only matched against the absolute path on nvim <0.10 because it was covering a case that glob2reg couldn't handle. I thought that would be unnecessary on nvim 0.10 since we have real glob support, but turns out some LSP servers use absolute paths for their filter definitions, so we have to keep it.