diff --git a/docs/manual/languages.adoc b/docs/manual/languages.adoc index edc70e7..e6c9cbe 100644 --- a/docs/manual/languages.adoc +++ b/docs/manual/languages.adoc @@ -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..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"]; + }; +} +---- diff --git a/docs/release-notes/rl-0.5.adoc b/docs/release-notes/rl-0.5.adoc index ac6a199..31024f7 100644 --- a/docs/release-notes/rl-0.5.adoc +++ b/docs/release-notes/rl-0.5.adoc @@ -14,6 +14,8 @@ https://github.com/horriblename[horriblename]: * Streamlined and simplified extra plugin API with the addition of <> +* 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. diff --git a/modules/languages/clang.nix b/modules/languages/clang.nix index ba272c6..846fa89 100644 --- a/modules/languages/clang.nix +++ b/modules/languages/clang.nix @@ -9,6 +9,10 @@ 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; @@ -16,7 +20,7 @@ with builtins; let 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}"} } ''; @@ -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}"} } ''; @@ -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; }; diff --git a/modules/languages/dart/config.nix b/modules/languages/dart/config.nix index c4761cd..991a384 100644 --- a/modules/languages/dart/config.nix +++ b/modules/languages/dart/config.nix @@ -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}"} } ''; diff --git a/modules/languages/dart/dart.nix b/modules/languages/dart/dart.nix index b985224..07623cf 100644 --- a/modules/languages/dart/dart.nix +++ b/modules/languages/dart/dart.nix @@ -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}"} } ''; @@ -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 { diff --git a/modules/languages/go.nix b/modules/languages/go.nix index aae808b..0c69fe5 100644 --- a/modules/languages/go.nix +++ b/modules/languages/go.nix @@ -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"}'' + }, } ''; }; @@ -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; }; }; diff --git a/modules/languages/java.nix b/modules/languages/java.nix index 1792824..9bea591 100644 --- a/modules/languages/java.nix +++ b/modules/languages/java.nix @@ -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; }; }; @@ -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"}'' + }, } ''; }) diff --git a/modules/languages/nix.nix b/modules/languages/nix.nix index 5ee616c..29f0025 100644 --- a/modules/languages/nix.nix +++ b/modules/languages/nix.nix @@ -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; @@ -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"}, } ''; }; @@ -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"] = { @@ -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; }; }; diff --git a/modules/languages/python.nix b/modules/languages/python.nix index daea5b8..6739471 100644 --- a/modules/languages/python.nix +++ b/modules/languages/python.nix @@ -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"}'' + } } ''; }; @@ -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; }; }; diff --git a/modules/languages/rust.nix b/modules/languages/rust.nix index 21ab58d..95f03a5 100644 --- a/modules/languages/rust.nix +++ b/modules/languages/rust.nix @@ -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; }; @@ -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} } diff --git a/modules/languages/sql.nix b/modules/languages/sql.nix index 4093ec9..20b6896 100644 --- a/modules/languages/sql.nix +++ b/modules/languages/sql.nix @@ -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()) }'' + } } ''; }; @@ -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; }; }; diff --git a/modules/languages/svelte.nix b/modules/languages/svelte.nix index a300f05..dee4618 100644 --- a/modules/languages/svelte.nix +++ b/modules/languages/svelte.nix @@ -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"}'' + } } ''; }; @@ -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; }; }; diff --git a/modules/languages/ts.nix b/modules/languages/ts.nix index 2d651ed..0637873 100644 --- a/modules/languages/ts.nix +++ b/modules/languages/ts.nix @@ -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"}'' + } } ''; }; @@ -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"}'' + } } ''; }; @@ -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; }; }; diff --git a/modules/languages/zig.nix b/modules/languages/zig.nix index f6c42d3..0fe4c38 100644 --- a/modules/languages/zig.nix +++ b/modules/languages/zig.nix @@ -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; }; @@ -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",