simrat39 / rust-tools.nvim

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

Incomplete Diagnostics, possibly when using Proc Macros #355

Open MinaMatta98 opened 1 year ago

MinaMatta98 commented 1 year ago

Hello,

Firstly, thank you for the outstanding plugin.

I have been running into an issue where there is a lack of diagnostic support. For example, refer to line 61 of the example below, where a is initialized as a boolean value, but passed into std::fs::File::open(), which expects a File struct. Of course, this is unacceptable, but rust-analyzer does not show any errors.

Note that this is with the rocket crate, which expects nightly.

image

This is not standard. For example, where there is no macro's, I get the following:

image

The following is my configuration:

local rust_opts = {
    tools = {
        -- rust-tools options
        -- Automatically set inlay hints (type hints)
        autoSetHints = true,
        executor = require("rust-tools.executors").termopen,
        -- Whether to show hover actions inside the hover window
        -- This overrides the default hover handler
        -- hover_with_actions = true,
        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 = {
            auto = true,
            -- 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,
        },
    },
    -- all the opts to send to nvim-lspconfig
    -- these override the defaults set by rust-tools.nvim
    -- see https://github.com/neovim/nvim-lspconfig/blob/master/CONFIG.md#rust_analyzer
    server = {
        on_attach = on_attach,
        capabilities = require("cmp_nvim_lsp").default_capabilities(),
        -- standalone = true,
        settings = {
            ["rust-analyzer"] = {
                -- enable clippy on save
                checkOnSave = {
                    command = "clippy",
                    extraArgs = { "--all", "--", "-W", "clippy::all" },
                },
                rustfmt = {
                    extraArgs = { "+nightly" },
                },
                procMacro = {
                    enable = true,
                },
            },
        },
        -- vim.keymap.set("n", "<C-g>", rt.hover_actions.hover_actions, bufopts)
        -- -- Code action groups
        -- vim.keymap.set("n", "<Leader>a", rt.code_action_group.code_action_group, bufopts)
        -- -- Hover actions
    -- end,
    },
    dap = {
        adapter = {
            type = "executable",
            command = "lldb-vscode",
            name = "rt_lldb",
        },
    },
}
require("rust-tools").setup(rust_opts)

If you have time, I would appreciate some support. If I do come across a solution or implement one myself, I will share it in this support thread.

Again, thank you for the plugin!!

MinaMatta98 commented 1 year ago

Ok,

I seem to have gotten a solution.

It is possible that the previous tooling that I was using prior to using your version of rust-analyzer was incompatible with the new configuration.

Running cargo-clean along with adding the following lines within my init.lua, seems to have fixed the issue:

    server = {
        on_attach = on_attach,
        capabilities = require("cmp_nvim_lsp").default_capabilities(),
        -- standalone = true,
        settings = {
            ["rust-analyzer"] = {
                -- enable clippy on save
                checkOnSave = {
                    command = "clippy",
                    extraArgs = { "--all", "--", "-W", "clippy::all" },
                },
                rustfmt = {
                    extraArgs = { "+nightly" },
                },
                cargo = {
                    loadOutDirsFromCheck = true,
                },
                procMacro = {
                    enable = true,
                },
            },
        },