Skip to content

Commit

Permalink
Merge pull request #134 from horriblename/optional-lsp-installation
Browse files Browse the repository at this point in the history
  • Loading branch information
NotAShelf authored Sep 23, 2023
2 parents 33daa8b + cd778b6 commit 0a1a12e
Show file tree
Hide file tree
Showing 14 changed files with 117 additions and 37 deletions.
15 changes: 15 additions & 0 deletions docs/manual/languages.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,18 @@ Language specific support means there is a combination of language specific plug

Adding support for more languages, and improving support for existing ones are great places where you can contribute with a PR.

=== LSP Custom Packages/Command

In any of the `opt.languages.<language>.lsp.package` options you can provide your own LSP package, or provide the command to launch the language server, as a list of strings.

You can use this to skip automatic installation of a language server, and instead use the one found in your `$PATH` during runtime, for example:

[source,nix]
----
vim.languages.java = {
lsp = {
enable = true;
package = ["jdt-language-server" "-data" "~/.cache/jdtls/workspace"];
};
}
----
2 changes: 2 additions & 0 deletions docs/release-notes/rl-0.5.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ https://github.com/horriblename[horriblename]:

* Streamlined and simplified extra plugin API with the addition of <<opt-vim.extraPlugins>>

* Allow using command names in place of LSP packages to avoid automatic installation.

https://github.com/amanse[amanse]:

* Added daily notes options for obsidian plugin.
Expand Down
13 changes: 9 additions & 4 deletions modules/languages/clang.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,18 @@ with builtins; let
cfg = config.vim.languages.clang;

defaultServer = "ccls";
packageToCmd = package: defaultCmd:
if isList cfg.lsp.package
then nvim.lua.expToLua cfg.lsp.package
else ''{ "${cfg.lsp.package}/bin/${defaultCmd}" }'';
servers = {
ccls = {
package = pkgs.ccls;
lspConfig = ''
lspconfig.ccls.setup{
capabilities = capabilities;
on_attach=default_on_attach;
cmd = {"${cfg.lsp.package}/bin/ccls"};
cmd = ${packageToCmd cfg.lsp.package "ccls"};
${optionalString (cfg.lsp.opts != null) "init_options = ${cfg.lsp.opts}"}
}
'';
Expand All @@ -30,7 +34,7 @@ with builtins; let
lspconfig.clangd.setup{
capabilities = clangd_cap;
on_attach=default_on_attach;
cmd = {"${cfg.lsp.package}/bin/clangd"};
cmd = ${packageToCmd cfg.lsp.package "clangd"};
${optionalString (cfg.lsp.opts != null) "init_options = ${cfg.lsp.opts}"}
}
'';
Expand Down Expand Up @@ -94,8 +98,9 @@ in {
};

package = mkOption {
description = "clang LSP server package";
type = types.package;
description = "clang LSP server package, or the command to run as a list of strings";
example = ''[lib.getExe pkgs.jdt-language-server " - data " " ~/.cache/jdtls/workspace "]'';
type = with types; either package (listOf str);
default = servers.${cfg.lsp.server}.package;
};

Expand Down
6 changes: 5 additions & 1 deletion modules/languages/dart/config.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ with builtins; let
lspconfig.dartls.setup{
capabilities = capabilities;
on_attach=default_on_attach;
cmd = {"${pkgs.dart}/bin/dart", "language-server", "--protocol=lsp"};
cmd = ${
if isList cfg.lsp.package
then nvim.lua.expToLua cfg.lsp.package
else ''{"${cfg.lsp.package}/bin/dart", "language-server", "--protocol=lsp"}''
};
${optionalString (cfg.lsp.opts != null) "init_options = ${cfg.lsp.dartOpts}"}
}
'';
Expand Down
11 changes: 8 additions & 3 deletions modules/languages/dart/dart.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ with builtins; let
lspconfig.dartls.setup{
capabilities = capabilities;
on_attach=default_on_attach;
cmd = {"${pkgs.dart}/bin/dart", "language-server", "--protocol=lsp"};
cmd = ${
if isList cfg.lsp.package
then nvim.lua.expToLua cfg.lsp.package
else ''{"${cfg.lsp.package}/bin/dart", "language-server", "--protocol=lsp"}''
};
${optionalString (cfg.lsp.opts != null) "init_options = ${cfg.lsp.dartOpts}"}
}
'';
Expand All @@ -38,8 +42,9 @@ in {
default = defaultServer;
};
package = mkOption {
description = "Dart LSP server package";
type = types.package;
description = "Dart LSP server package, or the command to run as a list of strings";
example = ''[lib.getExe pkgs.jdt-language-server "-data" "~/.cache/jdtls/workspace"]'';
type = with types; either package (listOf str);
default = servers.${cfg.lsp.server}.package;
};
opts = mkOption {
Expand Down
11 changes: 8 additions & 3 deletions modules/languages/go.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ with builtins; let
lspconfig.gopls.setup {
capabilities = capabilities;
on_attach = default_on_attach;
cmd = {"${cfg.lsp.package}/bin/gopls", "serve"},
cmd = ${
if isList cfg.lsp.package
then nvim.lua.expToLua cfg.lsp.package
else ''{"${cfg.lsp.package}/bin/gopls", "serve"}''
},
}
'';
};
Expand Down Expand Up @@ -81,8 +85,9 @@ in {
};

package = mkOption {
description = "Go LSP server package";
type = types.package;
description = "Go LSP server package, or the command to run as a list of strings";
example = ''[lib.getExe pkgs.jdt-language-server " - data " " ~/.cache/jdtls/workspace "]'';
type = with types; either package (listOf str);
default = servers.${cfg.lsp.server}.package;
};
};
Expand Down
11 changes: 8 additions & 3 deletions modules/languages/java.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ in {
enable = mkEnableOption "Java LSP support (java-language-server)" // {default = config.vim.languages.enableLSP;};

package = mkOption {
description = "java language server";
type = types.package;
description = "java language server package, or the command to run as a list of strings";
example = ''[lib.getExe pkgs.jdt-language-server "-data" "~/.cache/jdtls/workspace"]'';
type = with types; either package (listOf str);
default = pkgs.jdt-language-server;
};
};
Expand All @@ -32,7 +33,11 @@ in {
vim.lsp.lspconfig.enable = true;
vim.lsp.lspconfig.sources.jdtls = ''
lspconfig.jdtls.setup {
cmd = {"${cfg.lsp.package}/bin/jdt-language-server", "-data", vim.fn.stdpath("cache").."/jdtls/workspace"},
cmd = ${
if isList cfg.lsp.package
then nvim.lua.expToLua cfg.lsp.package
else ''{"${cfg.lsp.package}/bin/jdt-language-server", "-data", vim.fn.stdpath("cache").."/jdtls/workspace"}''
},
}
'';
})
Expand Down
13 changes: 9 additions & 4 deletions modules/languages/nix.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ with builtins; let
noFormat = "on_attach = attach_keymaps";

defaultServer = "nil";
packageToCmd = package: defaultCmd:
if isList package
then lib.nvim.lua.expToLua package
else ''{"${package}/bin/${defaultCmd}"}'';
servers = {
rnix = {
package = pkgs.rnix-lsp;
Expand All @@ -24,7 +28,7 @@ with builtins; let
then useFormat
else noFormat
},
cmd = {"${cfg.lsp.package}/bin/rnix-lsp"},
cmd = ${packageToCmd cfg.lsp.package "rnix-lsp"},
}
'';
};
Expand All @@ -40,7 +44,7 @@ with builtins; let
then useFormat
else noFormat
},
cmd = {"${cfg.lsp.package}/bin/nil"},
cmd = ${packageToCmd cfg.lsp.package "nil"},
${optionalString cfg.format.enable ''
settings = {
["nil"] = {
Expand Down Expand Up @@ -130,8 +134,9 @@ in {
default = defaultServer;
};
package = mkOption {
description = "Nix LSP server package";
type = types.package;
description = "Nix LSP server package, or the command to run as a list of strings";
example = ''[lib.getExe pkgs.jdt-language-server "-data" "~/.cache/jdtls/workspace"]'';
type = with types; either package (listOf str);
default = servers.${cfg.lsp.server}.package;
};
};
Expand Down
11 changes: 8 additions & 3 deletions modules/languages/python.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ with builtins; let
lspconfig.pyright.setup{
capabilities = capabilities;
on_attach = default_on_attach;
cmd = {"${cfg.lsp.package}/bin/pyright-langserver", "--stdio"}
cmd = ${
if isList cfg.lsp.package
then nvim.lua.expToLua cfg.lsp.package
else ''{"${cfg.lsp.package}/bin/pyright-langserver", "--stdio"}''
}
}
'';
};
Expand Down Expand Up @@ -122,8 +126,9 @@ in {
};

package = mkOption {
description = "python LSP server package";
type = types.package;
description = "python LSP server package, or the command to run as a list of strings";
example = ''[lib.getExe pkgs.jdt-language-server "-data" "~/.cache/jdtls/workspace"]'';
type = with types; either package (listOf string);
default = servers.${cfg.lsp.server}.package;
};
};
Expand Down
11 changes: 8 additions & 3 deletions modules/languages/rust.nix
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ in {
enable = mkEnableOption "Rust LSP support (rust-analyzer with extra tools)" // {default = config.vim.languages.enableLSP;};

package = mkOption {
description = "rust-analyzer package";
type = types.package;
description = "rust-analyzer package, or the command to run as a list of strings";
example = ''[lib.getExe pkgs.jdt-language-server "-data" "~/.cache/jdtls/workspace"]'';
type = with types; either package (listOf str);
default = pkgs.rust-analyzer;
};

Expand Down Expand Up @@ -118,7 +119,11 @@ in {
server = {
capabilities = capabilities,
on_attach = rust_on_attach,
cmd = {"${cfg.lsp.package}/bin/rust-analyzer"},
cmd = ${
if isList cfg.lsp.package
then nvim.lua.expToLua cfg.lsp.package
else ''{"${cfg.lsp.package}/bin/rust-analyzer"}''
},
settings = {
${cfg.lsp.opts}
}
Expand Down
11 changes: 8 additions & 3 deletions modules/languages/sql.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ with builtins; let
on_attach_keymaps(client, bufnr)
require'sqls'.setup{}
end,
cmd = { "${cfg.lsp.package}/bin/sqls", "-config", string.format("%s/config.yml", vim.fn.getcwd()) }
cmd = ${
if isList cfg.lsp.package
then nvim.lua.expToLua cfg.lsp.package
else ''{ "${cfg.lsp.package}/bin/sqls", "-config", string.format("%s/config.yml", vim.fn.getcwd()) }''
}
}
'';
};
Expand Down Expand Up @@ -87,8 +91,9 @@ in {
};

package = mkOption {
description = "SQL LSP server package";
type = types.package;
description = "SQL LSP server package, or the command to run as a list of strings";
example = ''[lib.getExe pkgs.jdt-language-server "-data" "~/.cache/jdtls/workspace"]'';
type = with types; either package (listOf str);
default = servers.${cfg.lsp.server}.package;
};
};
Expand Down
11 changes: 8 additions & 3 deletions modules/languages/svelte.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ with builtins; let
lspconfig.svelte.setup {
capabilities = capabilities;
on_attach = attach_keymaps,
cmd = { "${cfg.lsp.package}/bin/svelteserver", "--stdio" }
cmd = ${
if isList cfg.lsp.package
then nvim.lua.expToLua cfg.lsp.package
else ''{"${cfg.lsp.package}/bin/svelteserver", "--stdio"}''
}
}
'';
};
Expand Down Expand Up @@ -73,8 +77,9 @@ in {
};

package = mkOption {
description = "Svelte LSP server package";
type = types.package;
description = "Svelte LSP server package, or the command to run as a list of strings";
example = ''[lib.getExe pkgs.jdt-language-server "-data" "~/.cache/jdtls/workspace"]'';
type = with types; either package (listOf str);
default = servers.${cfg.lsp.server}.package;
};
};
Expand Down
17 changes: 13 additions & 4 deletions modules/languages/ts.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ with builtins; let
lspconfig.tsserver.setup {
capabilities = capabilities;
on_attach = attach_keymaps,
cmd = { "${cfg.lsp.package}/bin/typescript-language-server", "--stdio" }
cmd = ${
if isList cfg.lsp.package
then nvim.lua.expToLua cfg.lsp.package
else ''{"${cfg.lsp.package}/bin/typescript-language-server", "--stdio"}''
}
}
'';
};
Expand All @@ -27,7 +31,11 @@ with builtins; let
lspconfig.denols.setup {
capabilities = capabilities;
on_attach = attach_keymaps,
cmd = { "${cfg.lsp.package}/bin/deno", "lsp" }
cmd = ${
if isList cfg.lsp.package
then nvim.lua.expToLua cfg.lsp.package
else ''{"${cfg.lsp.package}/bin/deno", "lsp"}''
}
}
'';
};
Expand Down Expand Up @@ -95,8 +103,9 @@ in {
};

package = mkOption {
description = "Typescript/Javascript LSP server package";
type = types.package;
description = "Typescript/Javascript LSP server package, or the command to run as a list of strings";
example = ''[lib.getExe pkgs.jdt-language-server "-data" "~/.cache/jdtls/workspace"]'';
type = with types; either package (listOf str);
default = servers.${cfg.lsp.server}.package;
};
};
Expand Down
11 changes: 8 additions & 3 deletions modules/languages/zig.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ in {
enable = mkEnableOption "Zig LSP support (zls)" // {default = config.vim.languages.enableLSP;};

package = mkOption {
description = "ZLS package";
type = types.package;
description = "ZLS package, or the command to run as a list of strings";
example = ''[lib.getExe pkgs.jdt-language-server "-data" "~/.cache/jdtls/workspace"]'';
type = with types; either package (listOf str);
default = pkgs.zls;
};

Expand All @@ -44,7 +45,11 @@ in {
lspconfig.zls.setup {
capabilities = capabilities,
on_attach=default_on_attach,
cmd = {"${cfg.lsp.package}/bin/zls"},
cmd = ${
if isList cfg.lsp.package
then nvim.lua.expToLua cfg.lsp.package
else ''{"${cfg.lsp.package}/bin/zls"}''
},
settings = {
["zls"] = {
zig_exe_path = "${cfg.lsp.zigPackage}/bin/zig",
Expand Down

0 comments on commit 0a1a12e

Please sign in to comment.