simrat39 / rust-tools.nvim

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

Rust-tools does not start rust-analyzer anymore #369

Closed pcoves closed 1 year ago

pcoves commented 1 year ago

Hey there.

Rust-tools used to start rust-analyzer on my machine. It's not the case anymore.

The whole config can be found here: https://gitlab.com/pcoves/nvim/-/tree/main I use lazy and the points of interest are:

I removed the whole ~/.local/share/nvim and ~/.local/state/nvim and tried again so consider the latest versions of all plugins.

If I simply attach rust-analyzer, I get the LSP features. But I kind of love what you added on top :-)

❯ nvim --version
NVIM v0.9.0
Build type: Release
LuaJIT 2.1.0-beta3

Hope I provide enough information to help troubleshoot this 🙏

pcoves commented 1 year ago

Found-it: https://gitlab.com/pcoves/nvim/-/blob/fd4d0f14e7ebcf2da34cc9727541d45589f2c7d8/.config/nvim/lua/plugins/init.lua#L163

Commenting out the VeryLazy setting solves the issue. Not sure what to make of it, but hey, it works as planned.

pcoves commented 1 year ago

Hop, I was wrong.

Works for default setting, ad-hoc lua settings, but not for rust-tools.

pcoves commented 1 year ago

Here is a minimal example using lazy:

local lazypath = vim.fn.stdpath("data") .. "/lazy/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",
        "--branch=stable",
        lazypath,
    })
end

vim.opt.rtp:prepend(lazypath)

require("lazy").setup({
    {
        "neovim/nvim-lspconfig",
        name = "lspconfig",
        lazy = false,
        dependencies = {
            { "simrat39/rust-tools.nvim",          name = "rust-tools" },
            { "williamboman/mason-lspconfig.nvim", name = "mason-lspconfig" },
            { "williamboman/mason.nvim",           name = "mason" },
        },
        config = function()
            local lspconfig       = require("lspconfig")
            local mason           = require("mason")
            local mason_lspconfig = require("mason-lspconfig")

            mason.setup({})

            local servers = { "rust_analyzer" }
            mason_lspconfig.setup({ ensure_installed = servers })

            local function on_attach(_, _)
                print("Attached")
            end

            mason_lspconfig.setup_handlers({
                function(server_name) lspconfig[server_name].setup({ on_attach = on_attach, }) end,
                -- ["rust_analyzer"] = function() require("rust-tools").setup({ on_attach = on_attach }) end
            })
        end
    },
})

Opening a rust file will print Attached unless the rust-tools line is uncommented. Even with lazy = false.

pcoves commented 1 year ago

Pretty much the same behavior with packer, but I'm not sure that I'm using it the right way, as plugins and the config function are not automatically installed/called:

local ensure_packer = function()
    local fn = vim.fn
    local install_path = fn.stdpath("data") .. "/site/pack/packer/start/packer.nvim"
    if fn.empty(fn.glob(install_path)) > 0 then
        fn.system({ "git", "clone", "--depth", "1", "https://github.com/wbthomason/packer.nvim", install_path })
        vim.cmd [[packadd packer.nvim]]
        return true
    end
    return false
end

local packer_bootstrap = ensure_packer()

return require("packer").startup(function(use)
    use "wbthomason/packer.nvim"
    if packer_bootstrap then require("packer").sync() end

    use {
        "neovim/nvim-lspconfig",
        opt = false,
        requires = {
            "williamboman/mason-lspconfig.nvim",
            "williamboman/mason.nvim",
            "simrat39/rust-tools.nvim",
        },
        config = function()
            local lspconfig       = require("lspconfig")
            local mason           = require("mason")
            local mason_lspconfig = require("mason-lspconfig")

            mason.setup()

            local servers = { "rust_analyzer" }
            mason_lspconfig.setup({ ensure_installed = servers })

            local function on_attach(_, _) print("Attached") end

            mason_lspconfig.setup_handlers({
                function(server_name) lspconfig[server_name].setup({ on_attach = on_attach, }) end,
                -- ["rust_analyzer"] = function() require("rust-tools").setup({ on_attach = on_attach }) end
            })
        end
    }
end)
pcoves commented 1 year ago

Okay, this one is on me, as usual.

I wrote :

require("rust-tools").setup({ on_attach = on_attach })

Instead of :

require("rust-tools").setup({server = { on_attach = on_attach }})