folke / dot

☕️ My Dot Files
Apache License 2.0
866 stars 52 forks source link

Rust-tools doesn't appear used here, and if it is, buffer becomes all white text on launch #7

Closed amaanq closed 1 year ago

amaanq commented 1 year ago

Hi, so my config is heavily based off yours. I noticed rust-tools doesn't work, and that's because rust_analyzer is loaded in plugins/lsp/init.lua

I modified it to be like so at the bottom:

for server, opts in pairs(servers) do
  opts = vim.tbl_deep_extend("force", {}, options, opts or {})

  if server ~= "tsserver" and server ~= "rust_analyzer" then
    require("lspconfig")[server].setup(opts)
  elseif server == "rust_analyzer" then
    require("plugins.rust-tools").setup(opts)
  elseif server == "tsserver" then
    require("typescript").setup({ server = opts })
  end
end

however, this causes the first buffer opened in a session to be pure white, which is fixed by running :e

I'm here to ask for insight on how you think you could fix this, because rust-tools' inlay hints are just so nice I would rather not give them up, thanks :)

norbertkeri commented 1 year ago

The reason it doesn't work is because rust-tools is different from the other lsps, and it forwards the server table to nvim-lsp, instead of the whole table. You would need something like this, if you want to use a layout like Folke's:

local servers = {
        rust_analyzer = {
            tools = {
                autoSetHints = true,
                hover_with_actions = false,
                inlay_hints = {
                    show_parameter_hints = true,
                    parameter_hints_prefix = "",
                    other_hints_prefix = "",
                },
            },
            server = {
                settings = {
                    ["rust-analyzer"] = {
                        diagnostics = {
                            disabled = {"incorrect-ident-case"}
                        },
                        completion = {
                            postfix = {
                                enable = false
                            }
                        },
                        checkOnSave = {
                            command = "clippy"
                        },
                        procMacro = {
                            enable = true
                        },
                    }
                }
            }
        }
}

    local common_options = {
        on_attach = on_attach,
        capabilities = capabilities,
    }

    for server, opts in pairs(servers) do
        if server == "rust_analyzer" then
            -- rust-tools is special, and expects lsp server related configuration in the "server" key (everything else just uses the top level table)
            opts.server = vim.tbl_deep_extend("force", {}, common_options, opts.server or {})
            require("rust-tools").setup(opts)
        else
            opts = vim.tbl_deep_extend("force", {}, common_options, opts or {})
            lspconfig[server].setup(opts)
        end
    end
amaanq commented 1 year ago

wow! thank you so much for taking the time to answer this 2 months after I had asked it, I still had the issue and it appears solved now. thank you again!