-
-
Notifications
You must be signed in to change notification settings - Fork 157
Usage with nvim-lsp-installer
#89
Comments
local lsp_installer = require("nvim-lsp-installer")
lsp_installer.on_server_ready(function(server)
local opts = {}
-- (optional) Customize the options passed to the server
-- if server.name == "tsserver" then
-- opts.root_dir = function() ... end
-- end
if server.name == "rust_analyzer" then
require("rust-tools").setup({
dap = {
adapter = require("rust-tools.dap").get_codelldb_adapter(
"/home/simrat39/.vscode/extensions/vadimcn.vscode-lldb-1.6.7/adapter/codelldb",
"/home/simrat39/.vscode/extensions/vadimcn.vscode-lldb-1.6.7/lldb/lib/liblldb.so"
),
},
server = { cmd = server._default_options.cmd },
})
return
end
-- This setup() function is exactly the same as lspconfig's setup function.
-- Refer to https://github.com/neovim/nvim-lspconfig/blob/master/ADVANCED_README.md
server:setup(opts)
end)
This works, please ignore the dap stuff |
Hello, Same problem here and fortunately I was able to have rust-tools running thanks to the setup above with the exception of the better debugging features. I have properly setup the path and everything but variables like string wouldn't show the values at all. Here are my configuration for the rust_analyzer server elseif server.name == "rust_analyzer" then
local extension_path = os.getenv("HOME") .. '/.vscode-oss/extensions/vadimcn.vscode-lldb-1.6.9/'
local codelldb_path = extension_path .. 'adapter/codelldb'
local liblldb_path = extension_path .. 'lldb/lib/liblldb.so'
require("rust-tools").setup({
server = {
dap = {
adapter = require('rust-tools.dap').get_codelldb_adapter(
codelldb_path, liblldb_path)
},
server= {cmd = server._default_options.cmd}
}
})
return
end
|
@mkadit the dap key isn't inside the server key. It should be like this -> { |
Ah my mistake, thank you for that! |
Hey @simrat39, thanks for your reply. I could verify that this is working. I don't think that it is a problem in this case, but it is also not that perfect. But at least I have a working version for now. |
@nagua can't you just...call them before and after calling rust-tools' setup lol |
I'm having a problem using this with nvim-lsp-installer where I get an error when opening a I'm doing the similar as recommended by lsp_installer upstream: local lsp_installer = require("nvim-lsp-installer")
lsp_installer.on_server_ready(function(server)
if server.name == "rust_analyzer" then
local opts = {
server = vim.tbl_deep_extend("force", server:get_default_options(), {
on_attach = on_attach,
flags = {
debounce_text_changes = 150,
},
}),
}
require("rust-tools").setup(coq.lsp_ensure_capabilities(opts))
server:attach_buffers()
else
local opts = {
on_attach = on_attach,
flags = {
debounce_text_changes = 150,
},
}
server:setup(coq.lsp_ensure_capabilities(opts))
end
-- vim.cmd [[ do User LspAttachBuffers ]]
end) |
@GBeauregard could you try without the Coq ensure capabilities stuff? And you shouldnt need to call server:attach_buffers as well |
Ah yeah that was it since I had it in the wrong spot...oops 🤦 ; now without it, it just throws an error that it can't find the workplace (correctly). I don't mind the error but it'd be nice to silence it if possible i guess. I think this is on the LSP side and not your side though.
This is required and removing it breaks the server (auto)starting. This is only required with |
I have no idea how I had it working earlier, but now I'm getting the error again (with or w/o the coq line). My computer was at full load compiling something when it was working earlier so it may be indicative of some sort of lazy loading issue. But anyway this problem is back. |
local lsp_installer = require("nvim-lsp-installer")
local lsp_installer_servers = require("nvim-lsp-installer/servers")
local server_available, requested_server = lsp_installer_servers.get_server("rust_analyzer")
if server_available then
require("rust-tools").setup({
dap = {
adapter = require("rust-tools.dap").get_codelldb_adapter(
"/home/simrat39/.vscode/extensions/vadimcn.vscode-lldb-1.6.7/adapter/codelldb",
"/home/simrat39/.vscode/extensions/vadimcn.vscode-lldb-1.6.7/lldb/lib/liblldb.so"
),
},
server = { cmd = requested_server._default_options.cmd },
})
end
lsp_installer.on_server_ready(function(server)
local opts = {}
if server.name == "rust_analyzer" then
return
end
server:setup(opts)
end)
@GBeauregard it works with this setup. @nagua @mkadit consider updating to this |
nvim-lsp-installer
nvim-lsp-installer
I'd recommend the following change, to avoid reaching into private fields (also to make sure any other server options other than just diff --git a/a b/b
index ce46eb9..35a5872 100644
--- a/a
+++ b/b
@@ -11,7 +11,7 @@ if server_available then
"/home/simrat39/.vscode/extensions/vadimcn.vscode-lldb-1.6.7/lldb/lib/liblldb.so"
),
},
- server = { cmd = requested_server._default_options.cmd },
+ server = server:get_default_options()
})
end
I would also put this inside the |
@williamboman Can you please post a full config of how you suggest initializing both plugins? I'm trying to follow your suggestion of moving the opts into the on_server_ready block, but depending on what I pass as the top level key, I either get nothing (lsp doesn't seem to be active), or I get an error from LspInstall about rust-analyzer not being on the path BUT it still works. Things do work fine with the code provided by simrat39, but I'd like to future proof it. |
Have you tried something like the following? Just from reading the docs, I believe this should work lsp_installer.on_server_ready(function(server)
local opts = {}
if server.name == "rust_analyzer" then
-- Initialize the LSP via rust-tools instead
require("rust-tools").setup({
-- The "server" property provided in rust-tools setup function are the settings rust-tools will provide to
-- lspconfig during init.
-- We merge the necessary settings from nvim-lsp-installer (server:get_default_options()) with
-- the user's own settings (opts).
server = vim.tbl_deep_extend("force", server:get_default_options(), opts),
})
else
server:setup(opts)
end
end) |
Also a heads up to those who currently read the |
I can't seem to get it working. This code snippet works: local lsp_installer = require("nvim-lsp-installer")
local lsp_installer_servers = require("nvim-lsp-installer/servers")
local server_available, requested_server = lsp_installer_servers.get_server("rust_analyzer")
if server_available then
local opts = {
tools = {
autoSetHints = true,
hover_with_actions = false,
inlay_hints = {
show_parameter_hints = true,
parameter_hints_prefix = "",
other_hints_prefix = "",
},
},
server = {
cmd = requested_server._default_options.cmd,
settings = {
["rust-analyzer"] = {
completion = {
postfix = {
enable = false
}
},
checkOnSave = {
command = "clippy"
},
}
}
},
}
require("rust-tools").setup(opts)
end
lsp_installer.on_server_ready(function(server)
local opts = {}
if server.name == "rust_analyzer" then
return
end
server:setup(opts)
end) While this one doesn't, no error messages shown: lsp_installer.on_server_ready(function(server)
local opts = {}
if server.name == "rust_analyzer" then
local rustopts = {
tools = {
autoSetHints = true,
hover_with_actions = false,
inlay_hints = {
show_parameter_hints = true,
parameter_hints_prefix = "",
other_hints_prefix = "",
},
},
server = vim.tbl_deep_extend("force", server:get_default_options(), opts, {
settings = {
["rust-analyzer"] = {
completion = {
postfix = {
enable = false
}
},
checkOnSave = {
command = "clippy"
},
}
}
}),
}
require("rust-tools").setup(rustops)
else
server:setup(opts)
end
end) |
Minor and unrelated but convention re: - local lsp_installer_servers = require("nvim-lsp-installer/servers")
+ local lsp_installer_servers = require("nvim-lsp-installer.servers") Hmm, the snippet I suggested assumes you manage the installation of rust-analyzer via nvim-lsp-installer. Is it currently listed as installed ( |
Yes it is listed as installed (and I have removed it from my system altogether), the first snippet I posted actually uses that through |
Hmm weird, will have to tinker with it locally to understand more. |
So this seems to work just fine for me. The only problem is that it doesn't attach the very first buffer(s) that happen to be open when rust-tools is initialized. The reason for this is that nvim-lsp-installer schedules the "server ready" dispatches, so if you open a buffer like There's a convenience lsp_installer.on_server_ready(function(server)
local opts = {}
if server.name == "rust_analyzer" then
-- Initialize the LSP via rust-tools instead
require("rust-tools").setup({
-- The "server" property provided in rust-tools setup function are the settings rust-tools will provide to
-- lspconfig during init.
-- We merge the necessary settings from nvim-lsp-installer (server:get_default_options()) with
-- the user's own settings (opts).
server = vim.tbl_deep_extend("force", server:get_default_options(), opts),
})
+ server:attach_buffers()
else
server:setup(opts)
end
end) |
This doesn't appear to be working correctly; we should be getting inlayed type hints by default. You do appear to have coincidentally made a testfile that wouldn't have them despite them being fairly ubiquitous. Try the config here to see them: #89 (comment) |
That's probably because I've not set up either the Rust project or rust-tools properly. It does end up using nvim-lsp-installer's installation of rust_analyzer for starting the LSP server - anything further than that I feel like have nothing to do with rust-tools <-> nvim-lsp-installer interop, or am I missing something? |
@williamboman It seems the For everyone else looking for an example on how to specify some other options to pass along to rust analyzer, this is what I'm using: local lsp_installer = require("nvim-lsp-installer")
lsp_installer.on_server_ready(function(server)
local opts = {}
if server.name == "rust_analyzer" then
local rustopts = {
tools = {
autoSetHints = true,
hover_with_actions = false,
inlay_hints = {
show_parameter_hints = true,
parameter_hints_prefix = "",
other_hints_prefix = "",
},
},
server = vim.tbl_deep_extend("force", server:get_default_options(), opts, {
settings = {
["rust-analyzer"] = {
completion = {
postfix = {
enable = false
}
},
checkOnSave = {
command = "clippy"
},
}
}
}),
}
require("rust-tools").setup(rustopts)
server:attach_buffers()
else
server:setup(opts)
end
end) In the above example, I'm disabling postfix completions, and enabling clippy. |
edit: This Wiki page has since been removed. With the new setup mechanism in nvim-lsp-installer there is no special interaction needed - just setup rust-tools as you would normally! |
resolve conflicts with nvim-lsp-installer simrat39/rust-tools.nvim#89
Hello everyone,
I'm currently trying to integrate this plugin together with https://github.com/williamboman/nvim-lsp-installer.
I want to use
nvim-lsp-installer
to manage the installation ofrust-analyzer
and use this plugin for extended capabilities. But both api's are pretty incompatible.
nvim-lsp-installer
wants me to call its setup function in a callback provided by it andrust-tools.nvim
alsowants me to run their setup function to set everything up.
It seems like that it would be much more natural if
rust-tools.nvim
would provide a public function to inject(extend) the lsp server settings configuration instead of internalizing everything. (At least it should provide
the option for extended use cases.)
What do you think? Is this a good idea? Do you have other ideas on how to integrate these two plugins?
The text was updated successfully, but these errors were encountered: