Skip to content
This repository has been archived by the owner on Jan 3, 2024. It is now read-only.

lsp.commands not showing up anymore (e.g RustSetInlayHints) #114

Closed
Leandros opened this issue Dec 21, 2021 · 14 comments
Closed

lsp.commands not showing up anymore (e.g RustSetInlayHints) #114

Leandros opened this issue Dec 21, 2021 · 14 comments

Comments

@Leandros
Copy link

Using rust-tools.nvim together with nvim-lsp-installer.
Recently, it stopped working that the inlay hints show up when loading a buffer. Similarly the commands (like RustSetInlayHints) have disappeared.

I'm using the config which is in the nvim-lsp-installer wiki (and I'm aware of #89).

Current relevant .vimrc is here: https://github.com/Leandros/dotfiles/blob/e3cc5f7660df9f44056cecbcbdf0ccda64159a4f/.vimrc#L166-L231

The relevant parts:

lsp_installer.on_server_ready(function(server)
    local opts = {}

    -- Configure LSP through rust-tools.nvim plugin.
    -- rust-tools will configure and enable certain LSP features for us.
    -- See https://github.com/simrat39/rust-tools.nvim#configuration
    if server.name == "rust_analyzer" then
        local rust_opts = {
            tools = { -- rust-tools options
                autoSetHints = true,
                hover_with_actions = false,
                inlay_hints = {
                    -- Only show inlay hints for the current line
                    only_current_line = false,
                    -- wheter to show parameter hints with the inlay hints or not
                    show_parameter_hints = true,
                    -- prefix for parameter hints
                    parameter_hints_prefix = "<- ",
                    -- prefix for all the other hints (type, chaining)
                    other_hints_prefix = "=> ",
                    -- whether to align to the length of the longest line in the file
                    max_len_align = false,
                    -- padding from the left if max_len_align is true
                    max_len_align_padding = 1,
                    -- whether to align to the extreme right or not
                    right_align = false,
                    -- The color of the hints
                    highlight = "Comment",
                },
                runnables = {
                    use_telescope = true,
                },
                debuggables = {
                    use_telescope = true,
                },
            },
            server = vim.tbl_deep_extend("force", server:get_default_options(), opts, {
                settings = {
                    ["rust_analyzer"] = {
                        checkOnSave = {
                            command = "clippy"
                        }
                    }
                }
            }),
        }
        require("rust-tools").setup(rust_opts)
        server:attach_buffers()
    else
        -- This setup() function is exactly the same as lspconfig's setup function.
        -- Refer to https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md
        server:setup(opts)
    end
end)

Added on_attach, on_init or on_exit handlers on the server property are not called.

Opening the files, e.g src/main.rs directly via CLI (using nvim src/main.rs) works perfectly fine. While using a plugin like NERDTree or LeaderF to open the file doesn't seem to work.

VIM Version

NVIM v0.6.0
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3
Compiled by runneradmin@fv-az152-703

Features: -acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM\sysinit.vim"
  fall-back for $VIM: "C:/Program Files/nvim/share/nvim"

Run :checkhealth for more info

OS Version

image

@Leandros
Copy link
Author

This seems to be related to ray-x/navigator.lua, once the plugin is activated, the functionality ceases to work.

@sondr3
Copy link

sondr3 commented Dec 31, 2021

I just got this issue as well, did you manage to figure it out?

@Leandros
Copy link
Author

I disabled navigator.lua and went back to use lspsaga.

@sondr3
Copy link

sondr3 commented Dec 31, 2021

Hm, I don't use any of them directly or indirectly as far as I know, so for me at least neither of those are the root causes.

@Leandros
Copy link
Author

Do you use lsp installer of some sorts?

@sondr3
Copy link

sondr3 commented Jan 1, 2022

Seems the upgrade to neovim 0.6.1 fixed the issue for me, I can't reproduce it anymore.

@simrat39
Copy link
Owner

simrat39 commented Jan 1, 2022

I'm not really sure why this happens with nvim lsp installer, but @Leandros is it fixed with 6.1? else i'll look into it again

@LoydAndrew
Copy link

I' m on the version 0.6.1 and it's not fixed
my setup function in lsp-instaler

    if server.name == "rust_analyzer" then
        local rustopts = {
            tools = { -- rust-tools options
                -- Automatically set inlay hints (type hints)
                autoSetHints = true,

                -- Whether to show hover actions inside the hover window
                -- This overrides the default hover handler
                hover_with_actions = true,

                -- how to execute terminal commands
                -- options right now: termopen / quickfix
                executor = require("rust-tools/executors").termopen,

                runnables = {
                    -- whether to use telescope for selection menu or not
                    use_telescope = true,

                    -- rest of the opts are forwarded to telescope
                },

                debuggables = {
                    -- whether to use telescope for selection menu or not
                    use_telescope = true,

                    -- rest of the opts are forwarded to telescope
                },

                -- These apply to the default RustSetInlayHints command
                inlay_hints = {

                    -- Only show inlay hints for the current line
                    only_current_line = false,

                    -- Event which triggers a refersh of the inlay hints.
                    -- You can make this "CursorMoved" or "CursorMoved,CursorMovedI" but
                    -- not that this may cause  higher CPU usage.
                    -- This option is only respected when only_current_line and
                    -- autoSetHints both are true.
                    only_current_line_autocmd = "CursorHold",

                    -- wheter to show parameter hints with the inlay hints or not
                    show_parameter_hints = true,

                    -- prefix for parameter hints
                    parameter_hints_prefix = "<- ",

                    -- prefix for all the other hints (type, chaining)
                    other_hints_prefix = "=> ",

                    -- whether to align to the length of the longest line in the file
                    max_len_align = false,

                    -- padding from the left if max_len_align is true
                    max_len_align_padding = 1,

                    -- whether to align to the extreme right or not
                    right_align = false,

                    -- padding from the right if right_align is true
                    right_align_padding = 7,

                    -- The color of the hints
                    highlight = "Comment",
                },

                hover_actions = {
                    -- the border that is used for the hover window
                    -- see vim.api.nvim_open_win()
                    border = {
                        { "", "FloatBorder" },
                        { "", "FloatBorder" },
                        { "", "FloatBorder" },
                        { "", "FloatBorder" },
                        { "", "FloatBorder" },
                        { "", "FloatBorder" },
                        { "", "FloatBorder" },
                        { "", "FloatBorder" },
                    },

                    -- whether the hover action window gets automatically focused
                    auto_focus = false,
                },

                -- settings for showing the crate graph based on graphviz and the dot
                -- command
                crate_graph = {
                    -- Backend used for displaying the graph
                    -- see: https://graphviz.org/docs/outputs/
                    -- default: x11
                    backend = "x11",
                    -- where to store the output, nil for no output stored (relative
                    -- path from pwd)
                    -- default: nil
                    output = nil,
                    -- true for all crates.io and external crates, false only the local
                    -- crates
                    -- default: true
                    full = true,
                },
            },
            opts = vim.tbl_deep_extend("force", server:get_default_options(), opts, {
                settings = {
                    ["rust-analyzer"] = {
                        completion = {
                            postfix = {
                                enable = true,
                            },
                        },
                        checkOnSave = {
                            command = "clippy",
                        },
                    },
                },
            }),
        }
        require("rust-tools").setup(rustopts)
        server:attach_buffers()

@nkhlmn
Copy link

nkhlmn commented Jan 5, 2022

I'm having issue as well. I'm on nvim 0.6.1 and using nvim-lsp-installer with the default rust-tools configuration.

Also noticed that inlay hints are enabled by default anymore when opening a rust file. Manually calling :lua require('rust-tools.inlay_hints').set_inlay_hints() does make them show up though.

@simrat39
Copy link
Owner

simrat39 commented Jan 9, 2022

Sorry i've been very busy so I couldn't get back to it faster.

Looks like this happens only with lsp-installer. I'll have to look at its internals a bit so please bear with me.

@nkhlmn
Copy link

nkhlmn commented Jan 9, 2022

It looks like this is happening (for me at least) when my config also calls nvim-lsp-installer's setup function (supposed to just be a wrapper for lspconfigs'). Ensuring that only the rust-tool setup gets called fixes the issues. Don't know enough about this to comment on whether that should be expected or not.

I was relying on the other setup function to pass in my on_attach callback where I have buffer specific mappings set. What would be the best way to do this with rust-tools?

@adamhjk
Copy link

adamhjk commented Jan 11, 2022

@nkhlmn I believe what you need to do is take the on_attach callback you desire, and instead call:

require('rust-tools').setup({ server = { on_attach = require('user.lsp.handlers').on_attach } })

(Assuming your on_attach callback is exported at user.lsp.handlers)

@refaelsh
Copy link

+1

@simrat39
Copy link
Owner

Yes, calling lspconfig's rust analyzer's setup overrides rust-tools setup, so please don't do it. This is why there is an if else in the rust-tools setup for nvim-lsp-installer, please see the wiki: https://github.com/williamboman/nvim-lsp-installer/wiki/Rust

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants