simrat39 / rust-tools.nvim

Tools for better development in rust using neovim's builtin lsp
MIT License
2.17k stars 158 forks source link

lua/rust-tools.lua:176: attempt to index local 'lsp_opts' (a nil value) #124

Closed kdheepak closed 2 years ago

kdheepak commented 2 years ago

With neovim v0.7.0 nightly release:

$ nvim --version | head -1                                                                                                                                                                                                                                 
NVIM v0.7.0-dev+861-g6ecaba510

I'm getting the following error as soon as I open a rust file in the project. I didn't get any error before upgrading to neovim v0.7.0.

Error detected while processing VimEnter Autocommands for "*.rs":
E5108: Error executing lua ...ite/pack/packer/start/rust-tools.nvim/lua/rust-tools.lua:176: attempt to index local 'lsp_opts' (a nil value)
stack traceback:
        ...ite/pack/packer/start/rust-tools.nvim/lua/rust-tools.lua:176: in function 'start_standalone_if_required'
        [string ":lua"]:1: in main chunk

I'm using nvim-lsp-installer and following the instructions from the wiki: https://github.com/williamboman/nvim-lsp-installer/wiki/Rust

Any idea what might be happening?

kdheepak commented 2 years ago

I believe this is the same issue described in this PR: https://github.com/simrat39/rust-tools.nvim/pull/118

LudoPinelli commented 2 years ago

Same error here.

I believe this is the same issue described in this PR: #118

It looks like it is, yes.

georglauterbach commented 2 years ago

Some problem here, using NeoVIM 0.7 too.

LudoPinelli commented 2 years ago

@georglauterbach The PR: #118 fixes the problem.

georglauterbach commented 2 years ago

@georglauterbach The PR: #118 fixes the problem.

Yes - I'm currently already working with this fix :)

dubcdr commented 2 years ago

bump this is happening for me too

ashishbinu commented 2 years ago

I am gettting the same error too.

ashishbinu commented 2 years ago

I tried PR #118 and when opening the single rust file I get this warning. After pressing enter the lsp server starts.

image

But my lualine shows no active lsp.

image

I use the below code get the currently active lsp server for showing in lualine.

    function()
        local msg = "No Active Lsp"
        local buf_ft = vim.api.nvim_buf_get_option(0, "filetype")
        local clients = vim.lsp.get_active_clients()
        if next(clients) == nil then
            return msg
        end
        for _, client in ipairs(clients) do
            local filetypes = client.config.filetypes
            if filetypes and vim.fn.index(filetypes, buf_ft) ~= -1 then
                return client.name
            end
        end
        return msg
    end,
JSchrtke commented 2 years ago

FYI, downgrading to 7b4d15 also fixes this. This then also works with the config described in the nvim-lsp-installer wiki.

I don't know if this will work for any neovim > 0.6.1, I have not tested that, but I assume it will. But for the stable release, it works just fine. Here are the relevant parts of my config.

I also tested a few other commits, it seems 97a6b6 introduced this bug.

simrat39 commented 2 years ago

Ok should be fixed now, please see the updated nvim-lsp-installer wiki https://github.com/williamboman/nvim-lsp-installer/wiki/Rust

The only change is that we run

require("rust-tools").start_standalone_if_required()

after

server:attach_buffers()

Since nvim-lsp-installer runs the setup a little later than the VimEnter autocmd, the standalone function short circuits and doesn't properly run, so we need to check again and start the standalone process