Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error showing LSP definitions #3183

Closed
mfelsche opened this issue Jun 25, 2024 · 2 comments · Fixed by #3184
Closed

Error showing LSP definitions #3183

mfelsche opened this issue Jun 25, 2024 · 2 comments · Fixed by #3184
Labels
bug Something isn't working

Comments

@mfelsche
Copy link

mfelsche commented Jun 25, 2024

Description

I get regular errors when opening lsp results upon using goto-definition.

My nvim is giving this error message with traceback:

Error executing vim.schedule lua callback: vim/shared.lua:275: Expected table, got nil
stack traceback:
	[C]: in function 'assert'
	vim/shared.lua:275: in function 'tbl_isempty'
	...nvim/lazy/telescope.nvim/lua/telescope/builtin/__lsp.lua:156: in function 'filter_file_ignore_patters'
	...nvim/lazy/telescope.nvim/lua/telescope/builtin/__lsp.lua:198: in function 'handler'
	/usr/local/share/nvim/runtime/lua/vim/lsp.lua:1393: in function 'cb'
	vim/_editor.lua:263: in function <vim/_editor.lua:262>

Neovim version

NVIM v0.9.5
Build type: Release
LuaJIT 2.1.1699801871

Operating system and version

FreeBSD 14.1

Telescope version / branch / rev

58ec6ec

checkhealth telescope

telescope: 

- ERROR No healthcheck found for "telescope" plugin.

Steps to reproduce

  1. install and configure rust-analyzer via nvim-lspconfig or mason or whatever means. Any other LSP should work as well.
  2. Move the cursor to some typename e.g. over Option here:
fn main() {
   let foo: Option<usize> = None;
}
  1. type :Telescope lsp_definitions
  2. experience the error described above.

Expected behavior

telescope should open and show the definition list of the given type.

Actual behavior

telescope errors with the traceback and error message pasted above.

Minimal config

this requires rust-analyzer to be on the PATH

local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs { "config", "data", "state", "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",
    "https://github.com/folke/lazy.nvim.git",
    lazypath,
  }
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
  {
    "nvim-telescope/telescope.nvim",
    dependencies = {
      "nvim-lua/plenary.nvim",
    },
    config = function()
      -- ADD INIT.LUA SETTINGS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE
      require("telescope").setup {}
    end,
  },
  {
    "neovim/nvim-lspconfig",
    opts = function()
        return {
          servers = {
            rust_analyzer = {},
        },
        setup = {},
      }
    end,
  ---@param opts PluginLspOpts
  config = function(_, opts)
    local servers = opts.servers
    local has_cmp, cmp_nvim_lsp = pcall(require, "cmp_nvim_lsp")
    local capabilities = vim.tbl_deep_extend(
      "force",
      {},
      vim.lsp.protocol.make_client_capabilities(),
      has_cmp and cmp_nvim_lsp.default_capabilities() or {},
      opts.capabilities or {}
    )

    local function setup(server)
      local server_opts = vim.tbl_deep_extend("force", {
        capabilities = vim.deepcopy(capabilities),
      }, servers[server] or {})

      if opts.setup[server] then
        if opts.setup[server](server, server_opts) then
          return
        end
      elseif opts.setup["*"] then
        if opts.setup["*"](server, server_opts) then
          return
        end
      end
      require("lspconfig")[server].setup(server_opts)
    end

    local all_mslp_servers = {}

    local ensure_installed = {} ---@type string[]
    for server, server_opts in pairs(servers) do
      if server_opts then
        server_opts = server_opts == true and {} or server_opts
        if server_opts.enabled ~= false then
          -- run manual setup if mason=false or if this is a server that cannot be installed with mason-lspconfig
          if server_opts.mason == false or not vim.tbl_contains(all_mslp_servers, server) then
            setup(server)
          else
            ensure_installed[#ensure_installed + 1] = server
          end
        end
      end
    end
  end,
  }
}

require("lazy").setup(plugins, {
  root = root .. "/plugins",
})
@mfelsche mfelsche added the bug Something isn't working label Jun 25, 2024
@oozzal
Copy link

oozzal commented Jun 25, 2024

Latest commit is broken. Reverting to commit: af78ba3 should work.

@jamestrew
Copy link
Contributor

Oh wow this bug confused me since it looked like shouldn't be possible and wasn't able to reproduce initially but turns out vim.F.if_nil behavior was changed in neovim 0.10.

I will put a fix for <0.10.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants