Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge additional config for a language-server? #100

Closed
rosenhouse opened this issue Jul 27, 2022 · 2 comments
Closed

Merge additional config for a language-server? #100

rosenhouse opened this issue Jul 27, 2022 · 2 comments

Comments

@rosenhouse
Copy link

Hi!

There's a config option for the rust_analyzer language-server that I'd like to add, but I know it's not an appropriate default for everyone.

So I'd like to make the change locally. Either for my machine, or just for this one rust workspace, if that's possible.

If I make the change directly to lua/lang.lua it looks like this:

--- a/lua/lang.lua
+++ b/lua/lang.lua
@@ -103,7 +103,8 @@ lspconfig.rust_analyzer.setup({
         importPrefix = "by_self",
       },
       cargo = {
-        loadOutDirsFromCheck = true
+        loadOutDirsFromCheck = true,
+        runBuildScripts = true
       },

But of course then I get the warning

[Config] Local changes detected
━━━━━━━━━━━━━━━━━━━━
Consider moving them to your user settings.

How can I "move" this 1-line change into my user settings?

Do I copy all of lang.lua into one of the lua/user files? Can I re-run the language-server's setup() function from one of those? Is there some clever way to just send my 1 extra config option to the language server at run-time or something?

Thanks!

@luan
Copy link
Owner

luan commented Jul 28, 2022

How can I "move" this 1-line change into my user settings?

You'd have to move the whole config.

Do I copy all of lang.lua into one of the lua/user files? Can I re-run the language-server's setup() function from one of those? Is there some clever way to just send my 1 extra config option to the language server at run-time or something?

Pretty much, you can re-run the setup() function after.lua, but beware, as we found in #90 it's a bit buggy, and you need to wrap it invim.schedule():

vim.schedule(function()
lspconfig.rust_analyzer.setup({
         importPrefix = "by_self",
       },
       cargo = {
         loadOutDirsFromCheck = true,
         runBuildScripts = true
       },
end)

This gave me an idea, we could probably export the built-in LSP configs so you can extend them. Basically we can pull out the table (aka object, thanks lua) out of the setup params into a file called lsp_configs.lua, which we then import in lang.lua. You could then import the same file in after.lua and override anything you wanted by merging a custom config in (cue in google how to merge tables in lua, lol).

I'm not sure I'll have time to work on that anytime soon, but would accept a PR.

@rosenhouse
Copy link
Author

Thanks Luan, I think that did it?!?

I had to copy over some dependencies from lang.lua, so now my full ~/.config/nvim/lua/user/after.lua looks like this, and it seems to be working...

local lspconfig = require('lspconfig')
local capabilities = vim.lsp.protocol.make_client_capabilities()
local lsp_status = require('lsp-status')
local on_attach = function(client, bufnr)
    lsp_status.on_attach(client, bufnr)

    require('lsp_signature').on_attach({
        debug = false,
        handler_opts = {
            border = "single",
        },
    })
end
vim.schedule(function()
    lspconfig.rust_analyzer.setup({
        capabilities = capabilities,
        on_attach = on_attach,
        settings = {
            ["rust-analyzer"] = {
                assist = {
                    importGranularity = "module",
                    importPrefix = "by_self",
                },
                cargo = {
                    loadOutDirsFromCheck = true,
                    runBuildScripts = true
                },
                procMacro = {
                    enable = true
                },
            },
        },
    })
end)

Thank you!

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

No branches or pull requests

2 participants