-
-
Notifications
You must be signed in to change notification settings - Fork 19
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
Make lsp server installation optional #44
Comments
I have a general idea of how I might add this change. Will take a look as soon as I find some extra time. |
If i remember correctly the cmd in lspconfig doesn't need absolute path to the binary, just giving "rust-analyzer" should make it search in PATH, the current thing can be the default string value |
cmd = mkOption {
description = "lsp command to run";
type = types.str;
default = "${lib.getExe pkgs.rust-analyzer}";
}; and then in config server = {
capabilities = capabilities,
on_attach = rust_on_attach,
cmd = {"${cfg.lsp.cmd}"},
settings = {
${cfg.lsp.opts}
} This is working for me with rust-analyzer(I installed rust-analyzer with rustup)
|
That is correct, but for maximum purity we prefer passing the full path to the executable instead of trying to read from PATH. I'll tweak the system slightly to accept a package or a string, and if it is a package the mainProgram will be executed. If it is a string, then the value will be parsed as is. |
A workaround - especially for the rust use case - is to use a custom derivation as the lsp package that just calls rust-analyzer on the path. rust = {
enable = true;
crates.enable = true;
lsp = {
enable = true;
package = writeShellApplication {
name = "rust-analyzer";
text = ''
rust-analyzer "$@"
'';
};
};
}; |
package = mkOption {
description = "rust-analyzer package";
type = with types; oneOf [string package];
default = pkgs.rust-analyzer;
}; and then
mainProgram doesn't seem to exist on multiple packages, rust-analyzer included, replacing lib.getExe with that should be close to what you were talking about. (idk why lib.types.isType always returns false lol, could use that with lib.types.package otherwise) |
Since we'll be checking if it's a package or a string we should probably add a function to the shared library, that goes something like pkgOrStr = v: if builtins.isString v then v else lib.getExe v; |
the hero we need, not the hero we deserve mainProgram does return not found on rust-analyzer, I'm using pkgs.rust-analyzer.mainProgram, is that the wrong way to write? pkgOrStr is nice, I'll try with that, lesgoo |
lib.getExe (unless they changed it as well) should return the meta.mainProgram attribute of a package. |
ohh it's under meta, that makes sense, that's why |
Should be done as of #134 |
🏷️ Feature Type
API Additions
🔖 Feature description
As previously discussed on discord:
vim.lsp.rust.enable = true;
.✔️ Solution
I believe one possible solution is:
vim.lsp.rust.lspServerPackage
cmd = {"rust-analyzer"},
Instead ofcmd = {"${pkgs.rust-analyzer}/bin/rust-analyzer"},
(link to what I'm talking about)The same can be done for formatters as well.
❓ Alternatives
No response
📝 Additional Context
The default value for this option can be left same to what is used now. So for rust it'll be
pkgs.rust-analyzer
. So nothing breaks for people who are using this alreadyThe text was updated successfully, but these errors were encountered: