Merge pull request #134 from horriblename/optional-lsp-installation

This commit is contained in:
NotAShelf 2023-09-23 13:19:14 +03:00 committed by GitHub
commit 0a1a12e778
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 117 additions and 37 deletions

View file

@ -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. 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"];
};
}
----

View file

@ -14,6 +14,8 @@ https://github.com/horriblename[horriblename]:
* Streamlined and simplified extra plugin API with the addition of <<opt-vim.extraPlugins>> * 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]: https://github.com/amanse[amanse]:
* Added daily notes options for obsidian plugin. * Added daily notes options for obsidian plugin.

View file

@ -9,6 +9,10 @@ with builtins; let
cfg = config.vim.languages.clang; cfg = config.vim.languages.clang;
defaultServer = "ccls"; defaultServer = "ccls";
packageToCmd = package: defaultCmd:
if isList cfg.lsp.package
then nvim.lua.expToLua cfg.lsp.package
else ''{ "${cfg.lsp.package}/bin/${defaultCmd}" }'';
servers = { servers = {
ccls = { ccls = {
package = pkgs.ccls; package = pkgs.ccls;
@ -16,7 +20,7 @@ with builtins; let
lspconfig.ccls.setup{ lspconfig.ccls.setup{
capabilities = capabilities; capabilities = capabilities;
on_attach=default_on_attach; 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}"} ${optionalString (cfg.lsp.opts != null) "init_options = ${cfg.lsp.opts}"}
} }
''; '';
@ -30,7 +34,7 @@ with builtins; let
lspconfig.clangd.setup{ lspconfig.clangd.setup{
capabilities = clangd_cap; capabilities = clangd_cap;
on_attach=default_on_attach; 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}"} ${optionalString (cfg.lsp.opts != null) "init_options = ${cfg.lsp.opts}"}
} }
''; '';
@ -94,8 +98,9 @@ in {
}; };
package = mkOption { package = mkOption {
description = "clang LSP server package"; description = "clang LSP server package, or the command to run as a list of strings";
type = types.package; example = ''[lib.getExe pkgs.jdt-language-server " - data " " ~/.cache/jdtls/workspace "]'';
type = with types; either package (listOf str);
default = servers.${cfg.lsp.server}.package; default = servers.${cfg.lsp.server}.package;
}; };

View file

@ -15,7 +15,11 @@ with builtins; let
lspconfig.dartls.setup{ lspconfig.dartls.setup{
capabilities = capabilities; capabilities = capabilities;
on_attach=default_on_attach; 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}"} ${optionalString (cfg.lsp.opts != null) "init_options = ${cfg.lsp.dartOpts}"}
} }
''; '';

View file

@ -15,7 +15,11 @@ with builtins; let
lspconfig.dartls.setup{ lspconfig.dartls.setup{
capabilities = capabilities; capabilities = capabilities;
on_attach=default_on_attach; 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}"} ${optionalString (cfg.lsp.opts != null) "init_options = ${cfg.lsp.dartOpts}"}
} }
''; '';
@ -38,8 +42,9 @@ in {
default = defaultServer; default = defaultServer;
}; };
package = mkOption { package = mkOption {
description = "Dart LSP server package"; description = "Dart LSP server package, or the command to run as a list of strings";
type = types.package; example = ''[lib.getExe pkgs.jdt-language-server "-data" "~/.cache/jdtls/workspace"]'';
type = with types; either package (listOf str);
default = servers.${cfg.lsp.server}.package; default = servers.${cfg.lsp.server}.package;
}; };
opts = mkOption { opts = mkOption {

View file

@ -16,7 +16,11 @@ with builtins; let
lspconfig.gopls.setup { lspconfig.gopls.setup {
capabilities = capabilities; capabilities = capabilities;
on_attach = default_on_attach; 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"}''
},
} }
''; '';
}; };
@ -81,8 +85,9 @@ in {
}; };
package = mkOption { package = mkOption {
description = "Go LSP server package"; description = "Go LSP server package, or the command to run as a list of strings";
type = types.package; example = ''[lib.getExe pkgs.jdt-language-server " - data " " ~/.cache/jdtls/workspace "]'';
type = with types; either package (listOf str);
default = servers.${cfg.lsp.server}.package; default = servers.${cfg.lsp.server}.package;
}; };
}; };

View file

@ -20,8 +20,9 @@ in {
enable = mkEnableOption "Java LSP support (java-language-server)" // {default = config.vim.languages.enableLSP;}; enable = mkEnableOption "Java LSP support (java-language-server)" // {default = config.vim.languages.enableLSP;};
package = mkOption { package = mkOption {
description = "java language server"; description = "java language server package, or the command to run as a list of strings";
type = types.package; example = ''[lib.getExe pkgs.jdt-language-server "-data" "~/.cache/jdtls/workspace"]'';
type = with types; either package (listOf str);
default = pkgs.jdt-language-server; default = pkgs.jdt-language-server;
}; };
}; };
@ -32,7 +33,11 @@ in {
vim.lsp.lspconfig.enable = true; vim.lsp.lspconfig.enable = true;
vim.lsp.lspconfig.sources.jdtls = '' vim.lsp.lspconfig.sources.jdtls = ''
lspconfig.jdtls.setup { 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"}''
},
} }
''; '';
}) })

View file

@ -12,6 +12,10 @@ with builtins; let
noFormat = "on_attach = attach_keymaps"; noFormat = "on_attach = attach_keymaps";
defaultServer = "nil"; defaultServer = "nil";
packageToCmd = package: defaultCmd:
if isList package
then lib.nvim.lua.expToLua package
else ''{"${package}/bin/${defaultCmd}"}'';
servers = { servers = {
rnix = { rnix = {
package = pkgs.rnix-lsp; package = pkgs.rnix-lsp;
@ -24,7 +28,7 @@ with builtins; let
then useFormat then useFormat
else noFormat else noFormat
}, },
cmd = {"${cfg.lsp.package}/bin/rnix-lsp"}, cmd = ${packageToCmd cfg.lsp.package "rnix-lsp"},
} }
''; '';
}; };
@ -40,7 +44,7 @@ with builtins; let
then useFormat then useFormat
else noFormat else noFormat
}, },
cmd = {"${cfg.lsp.package}/bin/nil"}, cmd = ${packageToCmd cfg.lsp.package "nil"},
${optionalString cfg.format.enable '' ${optionalString cfg.format.enable ''
settings = { settings = {
["nil"] = { ["nil"] = {
@ -130,8 +134,9 @@ in {
default = defaultServer; default = defaultServer;
}; };
package = mkOption { package = mkOption {
description = "Nix LSP server package"; description = "Nix LSP server package, or the command to run as a list of strings";
type = types.package; example = ''[lib.getExe pkgs.jdt-language-server "-data" "~/.cache/jdtls/workspace"]'';
type = with types; either package (listOf str);
default = servers.${cfg.lsp.server}.package; default = servers.${cfg.lsp.server}.package;
}; };
}; };

View file

@ -16,7 +16,11 @@ with builtins; let
lspconfig.pyright.setup{ lspconfig.pyright.setup{
capabilities = capabilities; capabilities = capabilities;
on_attach = default_on_attach; 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"}''
}
} }
''; '';
}; };
@ -122,8 +126,9 @@ in {
}; };
package = mkOption { package = mkOption {
description = "python LSP server package"; description = "python LSP server package, or the command to run as a list of strings";
type = types.package; example = ''[lib.getExe pkgs.jdt-language-server "-data" "~/.cache/jdtls/workspace"]'';
type = with types; either package (listOf string);
default = servers.${cfg.lsp.server}.package; default = servers.${cfg.lsp.server}.package;
}; };
}; };

View file

@ -29,8 +29,9 @@ in {
enable = mkEnableOption "Rust LSP support (rust-analyzer with extra tools)" // {default = config.vim.languages.enableLSP;}; enable = mkEnableOption "Rust LSP support (rust-analyzer with extra tools)" // {default = config.vim.languages.enableLSP;};
package = mkOption { package = mkOption {
description = "rust-analyzer package"; description = "rust-analyzer package, or the command to run as a list of strings";
type = types.package; example = ''[lib.getExe pkgs.jdt-language-server "-data" "~/.cache/jdtls/workspace"]'';
type = with types; either package (listOf str);
default = pkgs.rust-analyzer; default = pkgs.rust-analyzer;
}; };
@ -118,7 +119,11 @@ in {
server = { server = {
capabilities = capabilities, capabilities = capabilities,
on_attach = rust_on_attach, 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 = { settings = {
${cfg.lsp.opts} ${cfg.lsp.opts}
} }

View file

@ -20,7 +20,11 @@ with builtins; let
on_attach_keymaps(client, bufnr) on_attach_keymaps(client, bufnr)
require'sqls'.setup{} require'sqls'.setup{}
end, 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()) }''
}
} }
''; '';
}; };
@ -87,8 +91,9 @@ in {
}; };
package = mkOption { package = mkOption {
description = "SQL LSP server package"; description = "SQL LSP server package, or the command to run as a list of strings";
type = types.package; example = ''[lib.getExe pkgs.jdt-language-server "-data" "~/.cache/jdtls/workspace"]'';
type = with types; either package (listOf str);
default = servers.${cfg.lsp.server}.package; default = servers.${cfg.lsp.server}.package;
}; };
}; };

View file

@ -16,7 +16,11 @@ with builtins; let
lspconfig.svelte.setup { lspconfig.svelte.setup {
capabilities = capabilities; capabilities = capabilities;
on_attach = attach_keymaps, 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"}''
}
} }
''; '';
}; };
@ -73,8 +77,9 @@ in {
}; };
package = mkOption { package = mkOption {
description = "Svelte LSP server package"; description = "Svelte LSP server package, or the command to run as a list of strings";
type = types.package; example = ''[lib.getExe pkgs.jdt-language-server "-data" "~/.cache/jdtls/workspace"]'';
type = with types; either package (listOf str);
default = servers.${cfg.lsp.server}.package; default = servers.${cfg.lsp.server}.package;
}; };
}; };

View file

@ -16,7 +16,11 @@ with builtins; let
lspconfig.tsserver.setup { lspconfig.tsserver.setup {
capabilities = capabilities; capabilities = capabilities;
on_attach = attach_keymaps, 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"}''
}
} }
''; '';
}; };
@ -27,7 +31,11 @@ with builtins; let
lspconfig.denols.setup { lspconfig.denols.setup {
capabilities = capabilities; capabilities = capabilities;
on_attach = attach_keymaps, 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"}''
}
} }
''; '';
}; };
@ -95,8 +103,9 @@ in {
}; };
package = mkOption { package = mkOption {
description = "Typescript/Javascript LSP server package"; description = "Typescript/Javascript LSP server package, or the command to run as a list of strings";
type = types.package; example = ''[lib.getExe pkgs.jdt-language-server "-data" "~/.cache/jdtls/workspace"]'';
type = with types; either package (listOf str);
default = servers.${cfg.lsp.server}.package; default = servers.${cfg.lsp.server}.package;
}; };
}; };

View file

@ -20,8 +20,9 @@ in {
enable = mkEnableOption "Zig LSP support (zls)" // {default = config.vim.languages.enableLSP;}; enable = mkEnableOption "Zig LSP support (zls)" // {default = config.vim.languages.enableLSP;};
package = mkOption { package = mkOption {
description = "ZLS package"; description = "ZLS package, or the command to run as a list of strings";
type = types.package; example = ''[lib.getExe pkgs.jdt-language-server "-data" "~/.cache/jdtls/workspace"]'';
type = with types; either package (listOf str);
default = pkgs.zls; default = pkgs.zls;
}; };
@ -44,7 +45,11 @@ in {
lspconfig.zls.setup { lspconfig.zls.setup {
capabilities = capabilities, capabilities = capabilities,
on_attach=default_on_attach, 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 = { settings = {
["zls"] = { ["zls"] = {
zig_exe_path = "${cfg.lsp.zigPackage}/bin/zig", zig_exe_path = "${cfg.lsp.zigPackage}/bin/zig",