stevearc / oil.nvim

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

bug: expected table, got nil when LSP is active #269

Closed HakonHarnes closed 9 months ago

HakonHarnes commented 9 months ago

Did you check the docs and existing issues?

Neovim version (nvim -v)

NVIM v0.9.5

Operating system/version

Arch Linux (6.6.9)

Describe the bug

Oil throws the following error when attempting to create/delete files:

E5108: Error executing lua: vim/shared.lua:0: t: expected table, got nil
stack traceback:
        [C]: in function 'error'
        vim/shared.lua: in function 'validate'
        vim/shared.lua: in function 'tbl_map'
        .../repro/.repro/plugins/oil.nvim/lua/oil/lsp/workspace.lua:99: in function 'get_matching_paths'
        .../repro/.repro/plugins/oil.nvim/lua/oil/lsp/workspace.lua:255: in function 'will_rename_files'
        ...on/repro/.repro/plugins/oil.nvim/lua/oil/lsp/helpers.lua:73: in function 'will_perform_file_operations'
        ...n/repro/.repro/plugins/oil.nvim/lua/oil/mutator/init.lua:370: in function 'process_actions'
        ...n/repro/.repro/plugins/oil.nvim/lua/oil/mutator/init.lua:527: in function 'cb'
        ...epro/.repro/plugins/oil.nvim/lua/oil/mutator/preview.lua:129: in function 'confirm'
        ...epro/.repro/plugins/oil.nvim/lua/oil/mutator/preview.lua:177: in function <...epro/.repro/plugins/oil.nvim/l
ua/oil/mutator/preview.lua:176>

This only happens if an LSP is active, and it does not happen for all LSPs. The error is thrown when using tsserver and marksman, but not when using texlab. Disabling LSP with :LspStop resolves the issue.

What is the severity of this bug?

blocking (cannot use plugin)

Steps To Reproduce

  1. nvim -u repro.lua index.ts
  2. Let LSP server install and close.
  3. nvim -u repro.lua index.ts
  4. (Observe one client is attached with :LspInfo)
  5. :Oil and attempt to create a new folder

Expected Behavior

Oil should work when the LSP is active.

Directory structure

No response

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,
  },
  -- lsp
  "williamboman/mason.nvim",
  "williamboman/mason-lspconfig.nvim",
  {
    "neovim/nvim-lspconfig",
  },
  -- add any other plugins here
}
require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

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

require("mason").setup()
require("mason-lspconfig").setup {
  ensure_installed = { "tsserver" },
}

local lspconfig = require("lspconfig")
lspconfig.tsserver.setup {}

Did you check the bug with a clean config?

stevearc commented 9 months ago

Thanks for the report! Should be fixed now