diff --git a/configuration.nix b/configuration.nix index 2c687794..33b9f119 100644 --- a/configuration.nix +++ b/configuration.nix @@ -34,7 +34,7 @@ isMaximal: { lspSignature.enable = !isMaximal; # conflicts with blink in maximal otter-nvim.enable = isMaximal; nvim-docs-view.enable = isMaximal; - harper-ls.enable = isMaximal; + presets.harper.enable = isMaximal; }; debugger = { @@ -103,7 +103,6 @@ isMaximal: { make.enable = false; qml.enable = false; jinja.enable = false; - tailwind.enable = false; svelte.enable = false; liquid.enable = false; tera.enable = false; diff --git a/docs/manual/configuring/languages.md b/docs/manual/configuring/languages.md index f956a0e3..9a82fc1e 100644 --- a/docs/manual/configuring/languages.md +++ b/docs/manual/configuring/languages.md @@ -75,8 +75,6 @@ languages have sections under the `vim.languages` attribute. [vim.languages.scala.enable](./options.html#option-vim-languages-scala-enable) - Svelte: [vim.languages.svelte.enable](./options.html#option-vim-languages-svelte-enable) -- Tailwind: - [vim.languages.tailwind.enable](./options.html#option-vim-languages-tailwind-enable) - Terraform: [vim.languages.terraform.enable](./options.html#option-vim-languages-terraform-enable) - Typst: diff --git a/docs/manual/release-notes/rl-0.9.md b/docs/manual/release-notes/rl-0.9.md index a6e5dfd6..0271b4bc 100644 --- a/docs/manual/release-notes/rl-0.9.md +++ b/docs/manual/release-notes/rl-0.9.md @@ -63,6 +63,45 @@ - Added `json5` into `languages.json`. Some options where renamed. +- Moved `vim.lsp.harper-ls` to `vim.lsp.presets.haper`. + +- Removed `typst_lsp` from `languages.typst.lsp.servers`, because it is + deprecated and thus was pulled from nixpkgs. + + +- Renamed `ts_ls` to `typescript-language-server`. + +- Renamed `denols` to `deno`. + +- Renamed `tsgo` to `typescript-go`. + +- Renamed `vala_ls` to `vala-language-server`. + +- Renamed `terraformls-tf` and `terraformls-hcl` to `terraform-ls`. + +- Renamed `tofuls-tf` and `tofuls-hcl` to `tofu-ls`. + +- Renamed `ruby_lsp` to `ruby-lsp`. + +- Renamed `r_language_server` to `r-languageserver`. + +- Renamed `julials` to `julia-languageserver`. + +- Renamed `astro` to `astro-language-server`. + +- Renamed `bash-ls` to `bash-language-server`. + +- Renamed `jsonls` to `vscode-json-language-server`. + +- Renamed `cssls` to `vscode-css-language-server`. + +- Renamed `jdtls` to `jdt-language-server`. + +- Renamed `elixirls` to `elixir-ls`. + +- Removed `languages.tailwind` which only provided an LSP. Use + `lsp.presets.tailwindcss-language-server` instead. + ## Changelog {#sec-release-0-9-changelog} [SecBear](https://github.com/SecBear): @@ -195,6 +234,7 @@ {command}`:healthcheck` doesn't know that. - Remove [which-key.nvim] `o` `+Notes` description which did not actually correspond to any keybinds. + - Allow disabling nvf's vendored keymaps by toggling `vendoredKeymaps.enable`. [pyrox0](https://github.com/pyrox0): @@ -229,6 +269,13 @@ [Snoweuph](https://github.com/snoweuph) +- Added `vim.lsp.presets.` to contain LSP configurations. This allows for + more flexibility in nvf and reuse of LSPs across languages. Dropped + `deprecatedSingleOrListOf` in favor of `listOf` for the affected LSP options. + +- Fix `vim.lsp.presets.vala-language-server` to be wrapped correctly with + `uncrustify`. + - Fix `tressiter` to allow `null` in grammar options, so they can be filtered out. diff --git a/lib/types/custom.nix b/lib/types/custom.nix index f6905b02..9974070e 100644 --- a/lib/types/custom.nix +++ b/lib/types/custom.nix @@ -1,9 +1,9 @@ {lib}: let - inherit (builtins) toJSON; + inherit (builtins) toJSON attrNames; inherit (lib.options) mergeEqualOption; inherit (lib.lists) singleton; inherit (lib.strings) isString stringLength match; - inherit (lib.types) listOf mkOptionType coercedTo; + inherit (lib.types) listOf mkOptionType coercedTo enum; inherit (lib.trivial) warn; in { mergelessListOf = elemType: @@ -39,4 +39,28 @@ in { '' (singleton x)) (listOf t); + + # Create an enum type for `values`, which additionally accepts deprecated + # values listed in the `renames` attrset as `old = new` pairs. + # + # Example: + # + # vim.languages.typescript.lsp.servers = mkOption { + # type = renamedEnum + # "vim.languages.typescript.lsp.servers" + # ["typescript-language-server" "some-other-server"] + # { ts_ls = "typescript-language-server"; }; + # } + # + # With this option definition, when users enter `ts_ls`, they + # get a warning "`ts_ls` is deprecated, use `typescript-language-server` + # instead", and typescript-language-server is automatically used. + enumWithRename = option: values: renames: + coercedTo (enum (attrNames renames)) ( + old: + warn + "${option}: `${old}` is deprecated, use `${renames.${old}}` instead" + renames.${old} + ) + (enum values); } diff --git a/lib/types/default.nix b/lib/types/default.nix index 66adfbbc..9b5469db 100644 --- a/lib/types/default.nix +++ b/lib/types/default.nix @@ -5,10 +5,12 @@ typesDag = import ./dag.nix {inherit lib;}; typesPlugin = import ./plugins.nix {inherit lib self;}; typesLanguage = import ./languages.nix {inherit lib;}; + typesLsp = import ./lsp.nix {inherit lib;}; customTypes = import ./custom.nix {inherit lib;}; in { inherit (typesDag) dagOf; inherit (typesPlugin) pluginsOpt extraPluginType mkPluginSetupOption luaInline pluginType borderType; inherit (typesLanguage) diagnostics mkGrammarOption; - inherit (customTypes) char hexColor mergelessListOf deprecatedSingleOrListOf; + inherit (typesLsp) mkLspPresetEnableOption; + inherit (customTypes) char hexColor mergelessListOf deprecatedSingleOrListOf enumWithRename; } diff --git a/lib/types/lsp.nix b/lib/types/lsp.nix new file mode 100644 index 00000000..d05b8783 --- /dev/null +++ b/lib/types/lsp.nix @@ -0,0 +1,12 @@ +{lib}: let + inherit (lib.options) mkEnableOption; + + mkLspPresetEnableOption = option: display: fileTypes: + mkEnableOption '' + the ${display} Language Server. + Default `filetypes = ${lib.generators.toPretty {} fileTypes}`. + Use {option}`vim.lsp.servers.${option}` for customization + ''; +in { + inherit mkLspPresetEnableOption; +} diff --git a/modules/extra/deprecations.nix b/modules/extra/deprecations.nix index 1572f249..91e31404 100644 --- a/modules/extra/deprecations.nix +++ b/modules/extra/deprecations.nix @@ -242,9 +242,6 @@ in { (mkRenamedLspServer "svelte") (mkRemovedLspPackage "svelte") - (mkRenamedLspServer "tailwind") - (mkRemovedLspPackage "tailwind") - (mkRemovedLspPackage "terraform") (mkRenamedLspServer "ts") @@ -347,5 +344,11 @@ in { [ (mkRenamedOptionModule ["vim" "treesitter" "foldByDefault"] ["vim" "options" "foldenable"]) ] + + # 2026-13-04 + [ + (mkRenamedOptionModule ["vim" "lsp" "harper-ls" "enable"] ["vim" "lsp" "presets" "harper" "enable"]) + (mkRenamedOptionModule ["vim" "lsp" "harper-ls" "settings"] ["vim" "lsp" "servers" "harper" "settings"]) + ] ]; } diff --git a/modules/plugins/languages/arduino.nix b/modules/plugins/languages/arduino.nix index 89f9e051..f3c300f0 100644 --- a/modules/plugins/languages/arduino.nix +++ b/modules/plugins/languages/arduino.nix @@ -4,54 +4,16 @@ lib, ... }: let - inherit (builtins) attrNames; - inherit (lib.generators) mkLuaInline; - inherit (lib.meta) getExe getExe'; + inherit (lib) genAttrs; inherit (lib.modules) mkIf mkMerge; inherit (lib.options) mkEnableOption mkOption literalExpression; inherit (lib.types) enum listOf str; - inherit (lib.nvim.attrsets) mapListToAttrs; inherit (lib.nvim.types) mkGrammarOption; cfg = config.vim.languages.arduino; defaultServers = ["arduino-language-server"]; - servers = { - arduino-language-server = { - enable = true; - cmd = - [ - (getExe pkgs.arduino-language-server) - "-clangd" - (getExe' pkgs.clang-tools "clangd") - "-cli" - (getExe pkgs.arduino-cli) - "-cli-config" - "$HOME/.arduino15/arduino-cli.yaml" - ] - ++ cfg.lsp.extraArgs; - filetypes = ["arduino"]; - root_dir = - mkLuaInline - /* - lua - */ - '' - function(bufnr, on_dir) - local fname = vim.api.nvim_buf_get_name(bufnr) - on_dir(util.root_pattern("*.ino")(fname)) - end - ''; - capabilities = { - textDocument = { - semanticTokens = mkLuaInline "vim.NIL"; - }; - workspace = { - semanticTokens = mkLuaInline "vim.NIL"; - }; - }; - }; - }; + servers = ["arduino-language-server"]; in { options.vim.languages.arduino = { enable = mkEnableOption "Arduino support"; @@ -74,7 +36,7 @@ in { defaultText = literalExpression "config.vim.lsp.enable"; }; servers = mkOption { - type = listOf (enum (attrNames servers)); + type = listOf (enum servers); default = defaultServers; description = "Arduino LSP servers to use"; }; @@ -94,12 +56,12 @@ in { }) (mkIf cfg.lsp.enable { - vim.lsp.servers = - mapListToAttrs (n: { - name = n; - value = servers.${n}; - }) - cfg.lsp.servers; + vim.lsp = { + presets = genAttrs cfg.lsp.servers (_: {enable = true;}); + servers = genAttrs cfg.lsp.servers (_: { + filetypes = ["arduino"]; + }); + }; }) ]); } diff --git a/modules/plugins/languages/asm.nix b/modules/plugins/languages/asm.nix index f1831401..41b9f4bd 100644 --- a/modules/plugins/languages/asm.nix +++ b/modules/plugins/languages/asm.nix @@ -4,24 +4,15 @@ lib, ... }: let - inherit (builtins) attrNames; inherit (lib.options) mkEnableOption mkOption literalExpression; inherit (lib.modules) mkIf mkMerge; - inherit (lib.types) enum; - inherit (lib.nvim.types) mkGrammarOption deprecatedSingleOrListOf; - inherit (lib.meta) getExe; - inherit (lib.nvim.attrsets) mapListToAttrs; + inherit (lib.types) enum listOf; + inherit (lib) genAttrs; + inherit (lib.nvim.types) mkGrammarOption; cfg = config.vim.languages.assembly; defaultServers = ["asm-lsp"]; - servers = { - asm-lsp = { - enable = true; - cmd = [(getExe pkgs.asm-lsp)]; - filetypes = ["asm" "nasm" "masm" "vmasm" "fasm" "tasm" "tiasm" "asm68k" "asm8300"]; - root_markers = [".asm-lsp.toml" ".git"]; - }; - }; + servers = ["asm-lsp"]; in { options.vim.languages.assembly = { enable = mkEnableOption "Assembly support"; @@ -46,7 +37,7 @@ in { defaultText = literalExpression "config.vim.lsp.enable"; }; servers = mkOption { - type = deprecatedSingleOrListOf "vim.language.asm.lsp.servers" (enum (attrNames servers)); + type = listOf (enum servers); default = defaultServers; description = "Assembly LSP server to use"; }; @@ -63,12 +54,12 @@ in { }) (mkIf cfg.lsp.enable { - vim.lsp.servers = - mapListToAttrs (n: { - name = n; - value = servers.${n}; - }) - cfg.lsp.servers; + vim.lsp = { + presets = genAttrs cfg.lsp.servers (_: {enable = true;}); + servers = genAttrs cfg.lsp.servers (_: { + filetypes = ["asm" "nasm" "masm" "vmasm" "fasm" "tasm" "tiasm" "asm68k" "asm8300"]; + }); + }; }) ]); } diff --git a/modules/plugins/languages/astro.nix b/modules/plugins/languages/astro.nix index af647ad0..08dfe17b 100644 --- a/modules/plugins/languages/astro.nix +++ b/modules/plugins/languages/astro.nix @@ -9,37 +9,15 @@ inherit (lib.options) mkEnableOption mkOption literalExpression; inherit (lib.modules) mkIf mkMerge; inherit (lib.meta) getExe; - inherit (lib.types) enum coercedTo; + inherit (lib.types) enum coercedTo listOf; inherit (lib.nvim.attrsets) mapListToAttrs; - inherit (lib.nvim.types) mkGrammarOption diagnostics deprecatedSingleOrListOf; - inherit (lib.generators) mkLuaInline; + inherit (lib.nvim.types) mkGrammarOption diagnostics deprecatedSingleOrListOf enumWithRename; + inherit (lib) genAttrs; cfg = config.vim.languages.astro; - defaultServers = ["astro"]; - servers = { - astro = { - enable = true; - cmd = [(getExe pkgs.astro-language-server) "--stdio"]; - filetypes = ["astro"]; - root_markers = ["package.json" "tsconfig.json" "jsconfig.json" ".git"]; - init_options = { - typescript = {}; - }; - before_init = - mkLuaInline - /* - lua - */ - '' - function(_, config) - if config.init_options and config.init_options.typescript and not config.init_options.typescript.tsdk then - config.init_options.typescript.tsdk = util.get_typescript_server_path(config.root_dir) - end - end - ''; - }; - }; + defaultServers = ["astro-language-server"]; + servers = ["astro-language-server"]; defaultFormat = ["prettier"]; formats = let @@ -107,7 +85,12 @@ in { defaultText = literalExpression "config.vim.lsp.enable"; }; servers = mkOption { - type = deprecatedSingleOrListOf "vim.language.astro.lsp.servers" (enum (attrNames servers)); + type = listOf (enumWithRename + "vim.languages.astro.lsp.servers" + servers + { + astro = "astro-language-server"; + }); default = defaultServers; description = "Astro LSP server to use"; }; @@ -151,12 +134,12 @@ in { }) (mkIf cfg.lsp.enable { - vim.lsp.servers = - mapListToAttrs (n: { - name = n; - value = servers.${n}; - }) - cfg.lsp.servers; + vim.lsp = { + presets = genAttrs cfg.lsp.servers (_: {enable = true;}); + servers = genAttrs cfg.lsp.servers (_: { + filetypes = ["astro"]; + }); + }; }) (mkIf cfg.format.enable { diff --git a/modules/plugins/languages/bash.nix b/modules/plugins/languages/bash.nix index d9d78b2b..be1eaca9 100644 --- a/modules/plugins/languages/bash.nix +++ b/modules/plugins/languages/bash.nix @@ -8,27 +8,15 @@ inherit (lib.options) mkOption mkEnableOption literalExpression; inherit (lib.meta) getExe; inherit (lib.modules) mkIf mkMerge; - inherit (lib.types) enum bool; - inherit (lib.generators) mkLuaInline; - inherit (lib.nvim.types) diagnostics mkGrammarOption deprecatedSingleOrListOf; + inherit (lib.types) enum bool listOf; + inherit (lib) genAttrs; + inherit (lib.nvim.types) diagnostics mkGrammarOption deprecatedSingleOrListOf enumWithRename; inherit (lib.nvim.attrsets) mapListToAttrs; cfg = config.vim.languages.bash; - defaultServers = ["bash-ls"]; - servers = { - bash-ls = { - enable = true; - cmd = [(getExe pkgs.bash-language-server) "start"]; - filetypes = ["bash" "sh"]; - root_markers = [".git"]; - settings = { - basheIde = { - globPattern = mkLuaInline "vim.env.GLOB_PATTERN or '*@(.sh|.inc|.bash|.command)'"; - }; - }; - }; - }; + defaultServers = ["bash-language-server"]; + servers = ["bash-language-server"]; defaultFormat = ["shfmt"]; formats = { @@ -65,7 +53,12 @@ in { defaultText = literalExpression "config.vim.lsp.enable"; }; servers = mkOption { - type = deprecatedSingleOrListOf "vim.language.bash.lsp.servers" (enum (attrNames servers)); + type = listOf (enumWithRename + "vim.languages.bash.lsp.servers" + servers + { + bash-ls = "bash-language-server"; + }); default = defaultServers; description = "Bash LSP server to use"; }; @@ -107,12 +100,12 @@ in { }) (mkIf cfg.lsp.enable { - vim.lsp.servers = - mapListToAttrs (n: { - name = n; - value = servers.${n}; - }) - cfg.lsp.servers; + vim.lsp = { + presets = genAttrs cfg.lsp.servers (_: {enable = true;}); + servers = genAttrs cfg.lsp.servers (_: { + filetypes = ["bash" "sh" "zsh"]; + }); + }; }) (mkIf cfg.format.enable { diff --git a/modules/plugins/languages/clang.nix b/modules/plugins/languages/clang.nix index 5115ed2a..844074a5 100644 --- a/modules/plugins/languages/clang.nix +++ b/modules/plugins/languages/clang.nix @@ -6,141 +6,16 @@ }: let inherit (builtins) attrNames; inherit (lib.options) mkEnableOption mkOption literalExpression; - inherit (lib.types) bool enum package; - inherit (lib.meta) getExe; + inherit (lib.types) bool enum package listOf; + inherit (lib) genAttrs; inherit (lib.modules) mkIf mkMerge; - inherit (lib.generators) mkLuaInline; - inherit (lib.nvim.types) mkGrammarOption deprecatedSingleOrListOf; - inherit (lib.nvim.attrsets) mapListToAttrs; + inherit (lib.nvim.types) mkGrammarOption; inherit (lib.nvim.dag) entryAfter; cfg = config.vim.languages.clang; defaultServers = ["clangd"]; - servers = { - ccls = { - cmd = [(getExe pkgs.ccls)]; - filetypes = ["c" "cpp" "objc" "objcpp" "cuda"]; - offset_encoding = "utf-32"; - root_markers = ["compile_commands.json" ".ccls" ".git"]; - workspace_required = true; - on_attach = mkLuaInline '' - function(client, bufnr) - local function switch_source_header(bufnr) - local method_name = "textDocument/switchSourceHeader" - local params = vim.lsp.util.make_text_document_params(bufnr) - client:request(method_name, params, function(err, result) - if err then - error(tostring(err)) - end - if not result then - vim.notify('corresponding file cannot be determined') - return - end - vim.cmd.edit(vim.uri_to_fname(result)) - end, bufnr) - end - - vim.api.nvim_buf_create_user_command( - bufnr, - "LspCclsSwitchSourceHeader", - function(arg) - switch_source_header(client, 0) - end, - {desc = "Switch between source/header"} - ) - end - ''; - }; - - clangd = { - cmd = ["${pkgs.clang-tools}/bin/clangd"]; - filetypes = ["c" "cpp" "objc" "objcpp" "cuda" "proto"]; - root_markers = [ - ".clangd" - ".clang-tidy" - ".clang-format" - "compile_commands.json" - "compile_flags.txt" - "configure.ac" - ".git" - ]; - capabilities = { - textDocument = { - completion = { - editsNearCursor = true; - }; - }; - offsetEncoding = ["utf-8" "utf-16"]; - }; - on_attach = mkLuaInline '' - function(client, bufnr) - local function switch_source_header(bufnr) - local method_name = "textDocument/switchSourceHeader" - local client = vim.lsp.get_clients({ bufnr = bufnr, name = "clangd", })[1] - if not client then - return vim.notify(('method %s is not supported by any servers active on the current buffer'):format(method_name)) - end - local params = vim.lsp.util.make_text_document_params(bufnr) - client.request(method_name, params, function(err, result) - if err then - error(tostring(err)) - end - if not result then - vim.notify('corresponding file cannot be determined') - return - end - vim.cmd.edit(vim.uri_to_fname(result)) - end, bufnr) - end - - local function symbol_info() - local bufnr = vim.api.nvim_get_current_buf() - local clangd_client = vim.lsp.get_clients({ bufnr = bufnr, name = "clangd" })[1] - if not clangd_client or not clangd_client:supports_method 'textDocument/symbolInfo' then - return vim.notify('Clangd client not found', vim.log.levels.ERROR) - end - local win = vim.api.nvim_get_current_win() - local params = vim.lsp.util.make_position_params(win, clangd_client.offset_encoding) - clangd_client:request('textDocument/symbolInfo', params, function(err, res) - if err or #res == 0 then - -- Clangd always returns an error, there is not reason to parse it - return - end - local container = string.format('container: %s', res[1].containerName) ---@type string - local name = string.format('name: %s', res[1].name) ---@type string - vim.lsp.util.open_floating_preview({ name, container }, "", { - height = 2, - width = math.max(string.len(name), string.len(container)), - focusable = false, - focus = false, - border = 'single', - title = 'Symbol Info', - }) - end, bufnr) - end - - vim.api.nvim_buf_create_user_command( - bufnr, - "ClangdSwitchSourceHeader", - function(arg) - switch_source_header(0) - end, - {desc = "Switch between source/header"} - ) - - vim.api.nvim_buf_create_user_command( - bufnr, - "ClangdShowSymbolInfo", - function(arg) - symbol_info() - end, - {desc = "Show symbol info"} - ) - end - ''; - }; - }; + servers = ["ccls" "clangd"]; defaultDebugger = "lldb-vscode"; debuggers = { @@ -204,7 +79,7 @@ in { servers = mkOption { description = "The clang LSP server to use"; - type = deprecatedSingleOrListOf "vim.language.clang.lsp.servers" (enum (attrNames servers)); + type = listOf (enum servers); default = defaultServers; }; }; @@ -240,12 +115,12 @@ in { }) (mkIf cfg.lsp.enable { - vim.lsp.servers = - mapListToAttrs (name: { - inherit name; - value = servers.${name}; - }) - cfg.lsp.servers; + vim.lsp = { + presets = genAttrs cfg.lsp.servers (_: {enable = true;}); + servers = genAttrs cfg.lsp.servers (_: { + filetypes = ["c" "cpp" "objc" "objcpp" "cuda" "proto"]; + }); + }; }) (mkIf cfg.dap.enable { diff --git a/modules/plugins/languages/clojure.nix b/modules/plugins/languages/clojure.nix index decaf926..1a10fafb 100644 --- a/modules/plugins/languages/clojure.nix +++ b/modules/plugins/languages/clojure.nix @@ -4,25 +4,16 @@ lib, ... }: let - inherit (builtins) attrNames; inherit (lib.options) mkEnableOption mkOption literalExpression; inherit (lib.modules) mkIf mkMerge; - inherit (lib.meta) getExe; + inherit (lib) genAttrs; inherit (lib.types) enum listOf; inherit (lib.nvim.types) mkGrammarOption; - inherit (lib.nvim.attrsets) mapListToAttrs; cfg = config.vim.languages.clojure; defaultServers = ["clojure-lsp"]; - servers = { - clojure-lsp = { - enable = true; - cmd = [(getExe pkgs.clojure-lsp)]; - filetypes = ["clojure" "edn"]; - root_markers = ["project.clj" "deps.edn" "build.boot" "shadow-cljs.edn" ".git" "bb.edn"]; - }; - }; + servers = ["clojure-lsp"]; in { options.vim.languages.clojure = { enable = mkEnableOption "Clojure language support"; @@ -45,7 +36,7 @@ in { defaultText = literalExpression "config.vim.lsp.enable"; }; servers = mkOption { - type = listOf (enum (attrNames servers)); + type = listOf (enum servers); default = defaultServers; description = "Clojure LSP server to use"; }; @@ -54,12 +45,13 @@ in { config = mkIf cfg.enable (mkMerge [ (mkIf cfg.lsp.enable { - vim.lsp.servers = - mapListToAttrs (n: { - name = n; - value = servers.${n}; - }) - cfg.lsp.servers; + vim.lsp = { + presets = genAttrs cfg.lsp.servers (_: {enable = true;}); + servers = genAttrs cfg.lsp.servers (_: { + filetypes = ["clojure" "edn"]; + root_markers = ["deps.edn" "build.boot" "shadow-cljs.edn" "bb.edn"]; + }); + }; }) (mkIf cfg.treesitter.enable { diff --git a/modules/plugins/languages/cmake.nix b/modules/plugins/languages/cmake.nix index a0610d46..a602fddf 100644 --- a/modules/plugins/languages/cmake.nix +++ b/modules/plugins/languages/cmake.nix @@ -7,25 +7,15 @@ inherit (builtins) attrNames; inherit (lib.options) mkEnableOption mkOption literalExpression; inherit (lib.modules) mkIf mkMerge; + inherit (lib) genAttrs; inherit (lib.meta) getExe; inherit (lib.types) enum listOf package; - inherit (lib.nvim.attrsets) mapListToAttrs; inherit (lib.nvim.types) mkGrammarOption; cfg = config.vim.languages.cmake; defaultServers = ["neocmakelsp"]; - servers = { - neocmakelsp = { - enable = true; - cmd = [(getExe pkgs.neocmakelsp) "stdio"]; - filetypes = ["cmake"]; - root_markers = [".gersemirc" ".git" "build" "cmake"]; - capabilities = { - textDocument.completion.completionItem.snippetSupport = true; - }; - }; - }; + servers = ["neocmakelsp"]; defaultFormat = "gersemi"; formats = { @@ -55,7 +45,7 @@ in { defaultText = literalExpression "config.vim.lsp.enable"; }; servers = mkOption { - type = listOf (enum (attrNames servers)); + type = listOf (enum servers); default = defaultServers; description = "CMake LSP servers to use"; }; @@ -90,12 +80,13 @@ in { }) (mkIf cfg.lsp.enable { - vim.lsp.servers = - mapListToAttrs (n: { - name = n; - value = servers.${n}; - }) - cfg.lsp.servers; + vim.lsp = { + presets = genAttrs cfg.lsp.servers (_: {enable = true;}); + servers = genAttrs cfg.lsp.servers (_: { + filetypes = ["cmake"]; + root_markers = ["build" "cmake"]; + }); + }; }) (mkIf cfg.format.enable { diff --git a/modules/plugins/languages/css.nix b/modules/plugins/languages/css.nix index 27516400..045dd6d5 100644 --- a/modules/plugins/languages/css.nix +++ b/modules/plugins/languages/css.nix @@ -6,29 +6,17 @@ }: let inherit (builtins) attrNames; inherit (lib.options) mkEnableOption mkOption literalExpression; + inherit (lib) genAttrs; inherit (lib.meta) getExe; inherit (lib.modules) mkIf mkMerge; - inherit (lib.types) enum; - inherit (lib.nvim.types) mkGrammarOption deprecatedSingleOrListOf; + inherit (lib.types) enum listOf; + inherit (lib.nvim.types) mkGrammarOption deprecatedSingleOrListOf enumWithRename; inherit (lib.nvim.attrsets) mapListToAttrs; cfg = config.vim.languages.css; - defaultServer = ["cssls"]; - servers = { - cssls = { - cmd = ["${pkgs.vscode-langservers-extracted}/bin/vscode-css-language-server" "--stdio"]; - filetypes = ["css" "scss" "less"]; - # needed to enable formatting - init_options = {provideFormatter = true;}; - root_markers = [".git" "package.json"]; - settings = { - css.validate = true; - scss.validate = true; - less.validate = true; - }; - }; - }; + defaultServer = ["vscode-css-language-server"]; + servers = ["vscode-css-language-server"]; defaultFormat = ["prettier"]; formats = { @@ -68,7 +56,12 @@ in { }; servers = mkOption { - type = deprecatedSingleOrListOf "vim.language.css.lsp.servers" (enum (attrNames servers)); + type = listOf (enumWithRename + "vim.languages.css.lsp.servers" + servers + { + cssls = "vscode-css-language-server"; + }); default = defaultServer; description = "CSS LSP server to use"; }; @@ -92,12 +85,17 @@ in { }) (mkIf cfg.lsp.enable { - vim.lsp.servers = - mapListToAttrs (name: { - inherit name; - value = servers.${name}; - }) - cfg.lsp.servers; + vim.lsp = { + presets = genAttrs cfg.lsp.servers (_: {enable = true;}); + servers = genAttrs cfg.lsp.servers (_: { + filetypes = [ + "css" + # TODO: split in their own modules + "scss" + "less" + ]; + }); + }; }) (mkIf cfg.format.enable { diff --git a/modules/plugins/languages/cue.nix b/modules/plugins/languages/cue.nix index b4294ecd..497aca35 100644 --- a/modules/plugins/languages/cue.nix +++ b/modules/plugins/languages/cue.nix @@ -4,16 +4,14 @@ lib, ... }: let - inherit (lib.options) mkEnableOption literalExpression; - inherit (lib.meta) getExe; + inherit (lib.options) mkEnableOption literalExpression mkOption; inherit (lib.modules) mkIf mkMerge; inherit (lib.nvim.types) mkGrammarOption; + inherit (lib.types) enum listOf; + inherit (lib) genAttrs; - lspOptions = { - cmd = [(getExe pkgs.cue) "lsp"]; - filetypes = ["cue"]; - root_markers = ["cue.mod" ".git"]; - }; + defaultServers = ["cue"]; + servers = ["cue"]; cfg = config.vim.languages.cue; in { @@ -38,6 +36,12 @@ in { default = config.vim.lsp.enable; defaultText = literalExpression "config.vim.lsp.enable"; }; + + servers = mkOption { + type = listOf (enum servers); + default = defaultServers; + description = "CUE LSP server to use"; + }; }; }; @@ -48,7 +52,12 @@ in { }) (mkIf cfg.lsp.enable { - vim.lsp.servers.cue = lspOptions; + vim.lsp = { + presets = genAttrs cfg.lsp.servers (_: {enable = true;}); + servers = genAttrs cfg.lsp.servers (_: { + filetypes = ["cue"]; + }); + }; }) ]); } diff --git a/modules/plugins/languages/dart.nix b/modules/plugins/languages/dart.nix index b585da76..54c16e93 100644 --- a/modules/plugins/languages/dart.nix +++ b/modules/plugins/languages/dart.nix @@ -4,42 +4,20 @@ lib, ... }: let - inherit (builtins) attrNames; inherit (lib.modules) mkIf mkMerge; - inherit (lib.meta) getExe; + inherit (lib) genAttrs; inherit (lib.trivial) boolToString; inherit (lib.options) mkEnableOption mkOption literalExpression; - inherit (lib.types) enum package nullOr str bool; + inherit (lib.types) enum package nullOr str bool listOf; inherit (lib.strings) optionalString; - inherit (lib.nvim.types) mkGrammarOption deprecatedSingleOrListOf; + inherit (lib.nvim.types) mkGrammarOption; inherit (lib.nvim.dag) entryAfter; - inherit (lib.nvim.attrsets) mapListToAttrs; cfg = config.vim.languages.dart; ftcfg = cfg.flutter-tools; defaultServers = ["dart"]; - servers = { - dart = { - enable = true; - cmd = [(getExe pkgs.dart) "language-server" "--protocol=lsp"]; - filetypes = ["dart"]; - root_markers = ["pubspec.yaml"]; - init_options = { - onlyAnalyzeProjectsWithOpenFiles = true; - suggestFromUnimportedLibraries = true; - closingLabels = true; - outline = true; - flutterOutline = true; - }; - settings = { - dart = { - completeFunctionCalls = true; - showTodos = true; - }; - }; - }; - }; + servers = ["dart"]; in { options.vim.languages.dart = { enable = mkEnableOption "Dart language support"; @@ -62,7 +40,7 @@ in { defaultText = literalExpression "config.vim.lsp.enable"; }; servers = mkOption { - type = deprecatedSingleOrListOf "vim.language.dart.lsp.servers" (enum (attrNames servers)); + type = listOf (enum servers); default = defaultServers; description = "Dart LSP server to use"; }; @@ -142,12 +120,12 @@ in { }) (mkIf cfg.lsp.enable { - vim.lsp.servers = - mapListToAttrs (n: { - name = n; - value = servers.${n}; - }) - cfg.lsp.servers; + vim.lsp = { + presets = genAttrs cfg.lsp.servers (_: {enable = true;}); + servers = genAttrs cfg.lsp.servers (_: { + filetypes = ["dart"]; + }); + }; }) (mkIf ftcfg.enable { diff --git a/modules/plugins/languages/default.nix b/modules/plugins/languages/default.nix index 3f779dbb..16db0aab 100644 --- a/modules/plugins/languages/default.nix +++ b/modules/plugins/languages/default.nix @@ -45,7 +45,6 @@ in { ./scala.nix ./sql.nix ./svelte.nix - ./tailwind.nix ./terraform.nix ./toml.nix ./ts.nix diff --git a/modules/plugins/languages/elixir.nix b/modules/plugins/languages/elixir.nix index f8191f77..4efb5320 100644 --- a/modules/plugins/languages/elixir.nix +++ b/modules/plugins/languages/elixir.nix @@ -7,38 +7,16 @@ inherit (builtins) attrNames; inherit (lib.options) mkEnableOption mkOption literalExpression; inherit (lib.modules) mkIf mkMerge; - inherit (lib.meta) getExe; - inherit (lib.types) enum; - inherit (lib.generators) mkLuaInline; - inherit (lib.nvim.types) mkGrammarOption deprecatedSingleOrListOf; + inherit (lib) genAttrs; + inherit (lib.types) enum listOf; + inherit (lib.nvim.types) mkGrammarOption deprecatedSingleOrListOf enumWithRename; inherit (lib.nvim.dag) entryAnywhere; inherit (lib.nvim.attrsets) mapListToAttrs; cfg = config.vim.languages.elixir; - defaultServers = ["elixirls"]; - servers = { - elixirls = { - enable = true; - cmd = [(getExe pkgs.elixir-ls)]; - filetypes = ["elixir" "eelixir" "heex" "surface"]; - root_dir = - mkLuaInline - /* - lua - */ - '' - function(bufnr, on_dir) - local fname = vim.api.nvim_buf_get_name(bufnr) - local matches = vim.fs.find({ 'mix.exs' }, { upward = true, limit = 2, path = fname }) - local child_or_root_path, maybe_umbrella_path = unpack(matches) - local root_dir = vim.fs.dirname(maybe_umbrella_path or child_or_root_path) - - on_dir(root_dir) - end - ''; - }; - }; + defaultServers = ["elixir-ls"]; + servers = ["elixir-ls"]; defaultFormat = ["mix"]; formats = { @@ -70,7 +48,12 @@ in { defaultText = literalExpression "config.vim.lsp.enable"; }; servers = mkOption { - type = deprecatedSingleOrListOf "vim.language.elixir.lsp.servers" (enum (attrNames servers)); + type = listOf (enumWithRename + "vim.languages.elixir.lsp.servers" + servers + { + elixirls = "elixir-ls"; + }); default = defaultServers; description = "Elixir LSP server to use"; }; @@ -102,12 +85,12 @@ in { }) (mkIf cfg.lsp.enable { - vim.lsp.servers = - mapListToAttrs (n: { - name = n; - value = servers.${n}; - }) - cfg.lsp.servers; + vim.lsp = { + presets = genAttrs cfg.lsp.servers (_: {enable = true;}); + servers = genAttrs cfg.lsp.servers (_: { + filetypes = ["elixir" "eelixir" "heex" "surface"]; + }); + }; }) (mkIf cfg.format.enable { diff --git a/modules/plugins/languages/elm.nix b/modules/plugins/languages/elm.nix index 9a7c4a17..bf4cb3a9 100644 --- a/modules/plugins/languages/elm.nix +++ b/modules/plugins/languages/elm.nix @@ -4,26 +4,16 @@ lib, ... }: let - inherit (builtins) attrNames; inherit (lib.options) mkEnableOption mkOption literalExpression; inherit (lib.modules) mkIf mkMerge; - inherit (lib.types) enum; - inherit (lib.nvim.types) mkGrammarOption deprecatedSingleOrListOf; - inherit (lib.meta) getExe; - inherit (lib.nvim.attrsets) mapListToAttrs; + inherit (lib.types) enum listOf; + inherit (lib.nvim.types) mkGrammarOption; + inherit (lib) genAttrs; cfg = config.vim.languages.elm; defaultServers = ["elm-language-server"]; - servers = { - elm-language-server = { - enable = true; - cmd = [(getExe pkgs.elmPackages.elm-language-server)]; - filetypes = ["elm"]; - root_markers = ["elm.json"]; - workspace_required = false; - }; - }; + servers = ["elm-language-server"]; in { options.vim.languages.elm = { enable = mkEnableOption "Elm language support"; @@ -47,7 +37,7 @@ in { }; servers = mkOption { - type = deprecatedSingleOrListOf "vim.language.elm.lsp.servers" (enum (attrNames servers)); + type = listOf (enum servers); default = defaultServers; description = "Elm LSP servers to use"; }; @@ -63,13 +53,11 @@ in { }) (mkIf cfg.lsp.enable { - vim = { - lsp.servers = - mapListToAttrs (n: { - name = n; - value = servers.${n}; - }) - cfg.lsp.servers; + vim.lsp = { + presets = genAttrs cfg.lsp.servers (_: {enable = true;}); + servers = genAttrs cfg.lsp.servers (_: { + filetypes = ["elm"]; + }); }; }) ]); diff --git a/modules/plugins/languages/fsharp.nix b/modules/plugins/languages/fsharp.nix index e57eb66d..ac41c399 100644 --- a/modules/plugins/languages/fsharp.nix +++ b/modules/plugins/languages/fsharp.nix @@ -6,50 +6,15 @@ }: let inherit (builtins) attrNames; inherit (lib.options) mkEnableOption mkOption literalExpression; - inherit (lib.types) enum; + inherit (lib.types) enum listOf; + inherit (lib) genAttrs; inherit (lib.meta) getExe; inherit (lib.modules) mkIf mkMerge; - inherit (lib.generators) mkLuaInline; inherit (lib.nvim.types) mkGrammarOption deprecatedSingleOrListOf; inherit (lib.nvim.attrsets) mapListToAttrs; defaultServer = ["fsautocomplete"]; - servers = { - fsautocomplete = { - cmd = [(getExe pkgs.fsautocomplete) "--adaptive-lsp-server-enabled"]; - filetypes = ["fsharp"]; - root_dir = mkLuaInline '' - function(bufnr, on_dir) - on_dir(vim.fs.root(bufnr, function(name, path) - return name == ".git" or name:match("%.sln$") or name:match("%.fsproj$") - end)) - end - ''; - init_options = { - AutomaticWorkspaceInit = true; - }; - settings = { - FSharp = { - keywordsAutocomplete = true; - ExternalAutocomplete = false; - Linter = true; - UnionCaseStubGeneration = true; - UnionCaseStubGenerationBody = ''failwith "Not Implemented"''; - RecordStubGeneration = true; - RecordStubGenerationBody = ''failwith "Not Implemented"''; - InterfaceStubGeneration = true; - InterfaceStubGenerationObjectIdentifier = "this"; - InterfaceStubGenerationMethodBody = ''failwith "Not Implemented"''; - UnusedOpensAnalyzer = true; - UnusedDeclarationsAnalyzer = true; - UseSdkScripts = true; - SimplifyNameAnalyzer = true; - ResolveNamespaces = true; - EnableReferenceCodeLens = true; - }; - }; - }; - }; + servers = ["fsautocomplete"]; defaultFormat = ["fantomas"]; formats = { @@ -82,7 +47,7 @@ in { defaultText = literalExpression "config.vim.lsp.enable"; }; servers = mkOption { - type = deprecatedSingleOrListOf "vim.language.fsharp.lsp.servers" (enum (attrNames servers)); + type = listOf (enum servers); default = defaultServer; description = "F# LSP server to use"; }; @@ -106,12 +71,12 @@ in { }) (mkIf cfg.lsp.enable { - vim.lsp.servers = - mapListToAttrs (name: { - inherit name; - value = servers.${name}; - }) - cfg.lsp.servers; + vim.lsp = { + presets = genAttrs cfg.lsp.servers (_: {enable = true;}); + servers = genAttrs cfg.lsp.servers (_: { + filetypes = ["fsharp"]; + }); + }; }) (mkIf cfg.format.enable { diff --git a/modules/plugins/languages/gleam.nix b/modules/plugins/languages/gleam.nix index 8007c8bc..a79fcb6d 100644 --- a/modules/plugins/languages/gleam.nix +++ b/modules/plugins/languages/gleam.nix @@ -4,25 +4,16 @@ lib, ... }: let - inherit (builtins) attrNames; inherit (lib.options) mkEnableOption mkOption literalExpression; inherit (lib.modules) mkIf mkMerge; - inherit (lib.meta) getExe; - inherit (lib.types) enum; - inherit (lib.nvim.types) mkGrammarOption deprecatedSingleOrListOf; - inherit (lib.nvim.attrsets) mapListToAttrs; + inherit (lib) genAttrs; + inherit (lib.types) enum listOf; + inherit (lib.nvim.types) mkGrammarOption; cfg = config.vim.languages.gleam; defaultServers = ["gleam"]; - servers = { - gleam = { - enable = true; - cmd = [(getExe pkgs.gleam) "lsp"]; - filetypes = ["gleam"]; - root_markers = ["gleam.toml" ".git"]; - }; - }; + servers = ["gleam"]; in { options.vim.languages.gleam = { enable = mkEnableOption "Gleam language support"; @@ -45,7 +36,7 @@ in { defaultText = literalExpression "config.vim.lsp.enable"; }; servers = mkOption { - type = deprecatedSingleOrListOf "vim.language.gleam.lsp.servers" (enum (attrNames servers)); + type = listOf (enum servers); default = defaultServers; description = "Gleam LSP server to use"; }; @@ -59,12 +50,12 @@ in { }) (mkIf cfg.lsp.enable { - vim.lsp.servers = - mapListToAttrs (n: { - name = n; - value = servers.${n}; - }) - cfg.lsp.servers; + vim.lsp = { + presets = genAttrs cfg.lsp.servers (_: {enable = true;}); + servers = genAttrs cfg.lsp.servers (_: { + filetypes = ["gleam"]; + }); + }; }) ]); } diff --git a/modules/plugins/languages/glsl.nix b/modules/plugins/languages/glsl.nix index c4df32e3..15c7072f 100644 --- a/modules/plugins/languages/glsl.nix +++ b/modules/plugins/languages/glsl.nix @@ -4,25 +4,16 @@ pkgs, ... }: let - inherit (builtins) attrNames; inherit (lib.modules) mkIf mkMerge; inherit (lib.nvim.types) mkGrammarOption; inherit (lib.options) mkEnableOption mkOption literalExpression; inherit (lib.types) enum listOf; - inherit (lib.meta) getExe; - inherit (lib.nvim.attrsets) mapListToAttrs; + inherit (lib) genAttrs; cfg = config.vim.languages.glsl; defaultServers = ["glsl_analyzer"]; - servers = { - glsl_analyzer = { - enable = true; - cmd = [(getExe pkgs.glsl_analyzer)]; - filetypes = ["glsl" "vert" "tesc" "tese" "frag" "geom" "comp"]; - root_markers = [".git"]; - }; - }; + servers = ["glsl_analyzer"]; in { options.vim.languages.glsl = { enable = mkEnableOption "GLSL language support"; @@ -46,7 +37,7 @@ in { }; servers = mkOption { - type = listOf (enum (attrNames servers)); + type = listOf (enum servers); default = defaultServers; description = "GLSL LSP server to use"; }; @@ -62,12 +53,12 @@ in { }) (mkIf cfg.lsp.enable { - vim.lsp.servers = - mapListToAttrs (n: { - name = n; - value = servers.${n}; - }) - cfg.lsp.servers; + vim.lsp = { + presets = genAttrs cfg.lsp.servers (_: {enable = true;}); + servers = genAttrs cfg.lsp.servers (_: { + filetypes = ["glsl" "vert" "tesc" "tese" "frag" "geom" "comp"]; + }); + }; }) ]); } diff --git a/modules/plugins/languages/go.nix b/modules/plugins/languages/go.nix index 7c83ebf2..6831fe9c 100644 --- a/modules/plugins/languages/go.nix +++ b/modules/plugins/languages/go.nix @@ -9,8 +9,9 @@ inherit (lib.options) mkEnableOption mkOption literalMD literalExpression; inherit (lib.modules) mkIf mkMerge; inherit (lib.meta) getExe; + inherit (lib) genAttrs; inherit (lib.generators) mkLuaInline; - inherit (lib.types) bool enum package str; + inherit (lib.types) enum package str listOf; inherit (lib.nvim.types) mkGrammarOption diagnostics deprecatedSingleOrListOf mkPluginSetupOption; inherit (lib.nvim.dag) entryAfter; inherit (lib.nvim.attrsets) mapListToAttrs; @@ -18,47 +19,7 @@ cfg = config.vim.languages.go; defaultServers = ["gopls"]; - servers = { - gopls = { - cmd = [(getExe pkgs.gopls)]; - filetypes = ["go" "gomod" "gosum" "gowork" "gotmpl"]; - root_dir = mkLuaInline '' - function(bufnr, on_dir) - local fname = vim.api.nvim_buf_get_name(bufnr) - - local function get_root(fname) - if _G.nvf_gopls_mod_cache and fname:sub(1, #_G.nvf_gopls_mod_cache) == _G.nvf_gopls_mod_cache then - local clients = vim.lsp.get_clients { name = 'gopls' } - if #clients > 0 then - return clients[#clients].config.root_dir - end - end - return vim.fs.root(fname, 'go.work') or vim.fs.root(fname, 'go.mod') or vim.fs.root(fname, '.git') - end - - -- see: https://github.com/neovim/nvim-lspconfig/issues/804 - if _G.nvf_gopls_mod_cache then - on_dir(get_root(fname)) - return - end - local cmd = { 'go', 'env', 'GOMODCACHE' } - local ok, err = pcall(vim.system, cmd, { text = true }, function(output) - if output.code == 0 then - if output.stdout then - _G.nvf_gopls_mod_cache = vim.trim(output.stdout) - end - on_dir(get_root(fname)) - else - vim.schedule(function() - vim.notify(('[gopls] cmd failed with code %d: %s\n%s'):format(output.code, cmd, output.stderr)) - end) - end - end) - if not ok then vim.notify(('[gopls] cmd failed: %s\n%s'):format(cmd, err)) end - end - ''; - }; - }; + servers = ["gopls"]; defaultFormat = ["gofmt"]; formats = { @@ -194,7 +155,7 @@ in { }; servers = mkOption { - type = deprecatedSingleOrListOf "vim.language.go.lsp.servers" (enum (attrNames servers)); + type = listOf (enum servers); default = defaultServers; description = "Go LSP server to use"; }; @@ -319,12 +280,12 @@ in { }) (mkIf cfg.lsp.enable { - vim.lsp.servers = - mapListToAttrs (name: { - inherit name; - value = servers.${name}; - }) - cfg.lsp.servers; + vim.lsp = { + presets = genAttrs cfg.lsp.servers (_: {enable = true;}); + servers = genAttrs cfg.lsp.servers (_: { + filetypes = ["go" "gomod" "gosum" "gowork" "gotmpl"]; + }); + }; }) (mkIf cfg.format.enable { diff --git a/modules/plugins/languages/hcl.nix b/modules/plugins/languages/hcl.nix index fe4a389e..32f4945d 100644 --- a/modules/plugins/languages/hcl.nix +++ b/modules/plugins/languages/hcl.nix @@ -6,30 +6,17 @@ }: let inherit (builtins) attrNames; inherit (lib.options) mkEnableOption mkOption literalExpression; + inherit (lib) genAttrs; inherit (lib.meta) getExe; inherit (lib.modules) mkIf mkMerge; inherit (lib.types) enum listOf; - inherit (lib.nvim.types) mkGrammarOption deprecatedSingleOrListOf; + inherit (lib.nvim.types) mkGrammarOption enumWithRename; inherit (lib.nvim.attrsets) mapListToAttrs; cfg = config.vim.languages.hcl; - defaultServers = ["tofuls-hcl"]; - servers = { - terraformls-hcl = { - enable = true; - cmd = [(getExe pkgs.terraform-ls) "serve"]; - filetypes = ["hcl"]; - root_markers = [".git"]; - }; - tofuls-hcl = { - enable = true; - cmd = [(getExe pkgs.tofu-ls) "serve"]; - filetypes = ["hcl"]; - root_markers = [".terraform" ".git"]; - }; - # TODO: package nomad-lsp and offer as an option here too - }; + defaultServers = ["tofu-ls"]; + servers = ["terraform-ls" "tofu-ls"]; defaultFormat = ["hclfmt"]; formats = { @@ -64,7 +51,13 @@ in { defaultText = literalExpression "config.vim.lsp.enable"; }; servers = mkOption { - type = listOf (enum (attrNames servers)); + type = listOf (enumWithRename + "vim.languages.hcl.lsp.servers" + servers + { + terraformls-hcl = "terraform-ls"; + tofuls-hcl = "tofu-ls"; + }); default = defaultServers; description = "HCL LSP server to use"; }; @@ -116,13 +109,11 @@ in { }) (mkIf cfg.lsp.enable { - vim = { - lsp.servers = - mapListToAttrs (n: { - name = n; - value = servers.${n}; - }) - cfg.lsp.servers; + vim.lsp = { + presets = genAttrs cfg.lsp.servers (_: {enable = true;}); + servers = genAttrs cfg.lsp.servers (_: { + filetypes = ["hcl"]; + }); }; }) diff --git a/modules/plugins/languages/helm.nix b/modules/plugins/languages/helm.nix index c2152b54..68e872c9 100644 --- a/modules/plugins/languages/helm.nix +++ b/modules/plugins/languages/helm.nix @@ -4,41 +4,16 @@ lib, ... }: let - inherit (builtins) attrNames head; inherit (lib.options) literalExpression mkEnableOption mkOption; - inherit (lib.modules) mkDefault mkIf mkMerge; - inherit (lib.meta) getExe; - inherit (lib.types) enum; - inherit (lib.nvim.types) mkGrammarOption deprecatedSingleOrListOf; - inherit (lib.nvim.attrsets) mapListToAttrs; + inherit (lib.modules) mkIf mkMerge; + inherit (lib) genAttrs; + inherit (lib.types) enum listOf; + inherit (lib.nvim.types) mkGrammarOption; cfg = config.vim.languages.helm; - yamlCfg = config.vim.languages.yaml; defaultServers = ["helm-ls"]; - servers = { - helm-ls = { - enable = true; - cmd = [(getExe pkgs.helm-ls) "serve"]; - filetypes = ["helm" "yaml.helm-values"]; - root_markers = ["Chart.yaml"]; - capabilities = { - didChangeWatchedFiles = { - dynamicRegistration = true; - }; - }; - settings = mkIf (yamlCfg.enable && yamlCfg.lsp.enable) { - helm-ls = { - yamlls = { - # Without this being enabled, the YAML language module will look broken in helmfiles - # if both modules are enabled at once. - enabled = mkDefault yamlCfg.lsp.enable; - path = head config.vim.lsp.servers.${head yamlCfg.lsp.servers}.cmd; - }; - }; - }; - }; - }; + servers = ["helm-ls"]; in { options.vim.languages.helm = { enable = mkEnableOption "Helm language support"; @@ -61,7 +36,7 @@ in { defaultText = literalExpression "config.vim.lsp.enable"; }; servers = mkOption { - type = deprecatedSingleOrListOf "vim.language.helm.lsp.servers" (enum (attrNames servers)); + type = listOf (enum servers); default = defaultServers; description = "Helm LSP server to use"; }; @@ -75,12 +50,12 @@ in { }) (mkIf cfg.lsp.enable { - vim.lsp.servers = - mapListToAttrs (n: { - name = n; - value = servers.${n}; - }) - cfg.lsp.servers; + vim.lsp = { + presets = genAttrs cfg.lsp.servers (_: {enable = true;}); + servers = genAttrs cfg.lsp.servers (_: { + filetypes = ["helm" "yaml.helm-values"]; + }); + }; }) { diff --git a/modules/plugins/languages/html.nix b/modules/plugins/languages/html.nix index cba4da6d..7531bdfe 100644 --- a/modules/plugins/languages/html.nix +++ b/modules/plugins/languages/html.nix @@ -8,7 +8,8 @@ inherit (lib.meta) getExe; inherit (lib.options) literalExpression mkEnableOption mkOption; inherit (lib.modules) mkIf mkMerge; - inherit (lib.types) bool enum; + inherit (lib.types) bool enum listOf; + inherit (lib) genAttrs; inherit (lib.lists) optional; inherit (lib.nvim.types) mkGrammarOption diagnostics deprecatedSingleOrListOf; inherit (lib.nvim.dag) entryAnywhere; @@ -17,18 +18,7 @@ cfg = config.vim.languages.html; defaultServers = ["superhtml"]; - servers = { - superhtml = { - cmd = [(getExe pkgs.superhtml) "lsp"]; - filetypes = ["html" "shtml" "htm"]; - root_markers = ["index.html" ".git"]; - }; - emmet-ls = { - cmd = [(getExe pkgs.emmet-ls) "--stdio"]; - filetypes = ["html" "shtml" "htm"]; - root_markers = ["index.html" ".git"]; - }; - }; + servers = ["superhtml" "emmet-ls"]; defaultFormat = ["superhtml"]; formats = { @@ -70,7 +60,7 @@ in { defaultText = literalExpression "config.vim.lsp.enable"; }; servers = mkOption { - type = deprecatedSingleOrListOf "vim.language.html.lsp.servers" (enum (attrNames servers)); + type = listOf (enum servers); default = defaultServers; description = "HTML LSP server to use"; }; @@ -124,12 +114,12 @@ in { }) (mkIf cfg.lsp.enable { - vim.lsp.servers = - mapListToAttrs (n: { - name = n; - value = servers.${n}; - }) - cfg.lsp.servers; + vim.lsp = { + presets = genAttrs cfg.lsp.servers (_: {enable = true;}); + servers = genAttrs cfg.lsp.servers (_: { + filetypes = ["html" "shtml" "xhtml" "htm"]; + }); + }; }) (mkIf (cfg.format.enable && !cfg.lsp.enable) { diff --git a/modules/plugins/languages/java.nix b/modules/plugins/languages/java.nix index d843e2a8..1fad79a3 100644 --- a/modules/plugins/languages/java.nix +++ b/modules/plugins/languages/java.nix @@ -6,60 +6,14 @@ }: let inherit (lib.options) literalExpression mkEnableOption mkOption; inherit (lib.modules) mkIf mkMerge; - inherit (lib.meta) getExe; - inherit (builtins) attrNames; - inherit (lib.types) listOf enum; - inherit (lib.nvim.types) mkGrammarOption; - inherit (lib.nvim.attrsets) mapListToAttrs; - inherit (lib.nvim.dag) entryBefore; - inherit (lib.generators) mkLuaInline; + inherit (lib) genAttrs; + inherit (lib.types) listOf; + inherit (lib.nvim.types) mkGrammarOption enumWithRename; cfg = config.vim.languages.java; - defaultServers = ["jdtls"]; - servers = { - jdtls = { - enable = true; - cmd = - mkLuaInline - /* - lua - */ - '' - { - '${getExe pkgs.jdt-language-server}', - '-configuration', - get_jdtls_config_dir(), - '-data', - get_jdtls_workspace_dir(), - get_jdtls_jvm_args(), - } - ''; - filetypes = ["java"]; - root_markers = [ - # Multi-module projects - ".git" - "build.gradle" - "build.gradle.kts" - # Single-module projects - "build.xml" # Ant - "pom.xml" # Maven - "settings.gradle" # Gradle - "settings.gradle.kts" # Gradle - ]; - init_options = { - workspace = mkLuaInline "get_jdtls_workspace_dir()"; - jvm_args = {}; - os_config = mkLuaInline "nil"; - }; - handlers = { - "textDocument/codeAction" = mkLuaInline "jdtls_on_textdocument_codeaction"; - "textDocument/rename" = mkLuaInline "jdtls_on_textdocument_rename"; - "workspace/applyEdit" = mkLuaInline "jdtls_on_workspace_applyedit"; - "language/status" = mkLuaInline "vim.schedule_wrap(jdtls_on_language_status)"; - }; - }; - }; + defaultServers = ["jdt-language-server"]; + servers = ["jdt-language-server"]; in { options.vim.languages.java = { enable = mkEnableOption "Java language support"; @@ -82,7 +36,12 @@ in { defaultText = literalExpression "config.vim.lsp.enable"; }; servers = mkOption { - type = listOf (enum (attrNames servers)); + type = listOf (enumWithRename + "vim.languages.java.lsp.servers" + servers + { + jdtls = "jdt-language-server"; + }); default = defaultServers; description = "Java LSP server to use"; }; @@ -91,96 +50,12 @@ in { config = mkIf cfg.enable (mkMerge [ (mkIf cfg.lsp.enable { - vim.luaConfigRC.jdtls-util = - entryBefore ["lsp-servers"] - /* - lua - */ - '' - local jdtls_handlers = require 'vim.lsp.handlers' - - local jdtls_env = { - HOME = vim.uv.os_homedir(), - XDG_CACHE_HOME = os.getenv 'XDG_CACHE_HOME', - JDTLS_JVM_ARGS = os.getenv 'JDTLS_JVM_ARGS', - } - - local function get_cache_dir() - return jdtls_env.XDG_CACHE_HOME and jdtls_env.XDG_CACHE_HOME or jdtls_env.HOME .. '/.cache' - end - - local function get_jdtls_cache_dir() - return get_cache_dir() .. '/jdtls' - end - - local function get_jdtls_config_dir() - return get_jdtls_cache_dir() .. '/config' - end - - local function get_jdtls_workspace_dir() - return get_jdtls_cache_dir() .. '/workspace' - end - - local function get_jdtls_jvm_args() - local args = {} - for a in string.gmatch((jdtls_env.JDTLS_JVM_ARGS or '''), '%S+') do - local arg = string.format('--jvm-arg=%s', a) - table.insert(args, arg) - end - return unpack(args) - end - - -- TextDocument version is reported as 0, override with nil so that - -- the client doesn't think the document is newer and refuses to update - -- See: https://github.com/eclipse/eclipse.jdt.ls/issues/1695 - local function jdtls_fix_zero_version(workspace_edit) - if workspace_edit and workspace_edit.documentChanges then - for _, change in pairs(workspace_edit.documentChanges) do - local text_document = change.textDocument - if text_document and text_document.version and text_document.version == 0 then - text_document.version = nil - end - end - end - return workspace_edit - end - - local function jdtls_on_textdocument_codeaction(err, actions, ctx) - for _, action in ipairs(actions) do - -- TODO: (steelsojka) Handle more than one edit? - if action.command == 'java.apply.workspaceEdit' then -- 'action' is Command in java format - action.edit = jdtls_fix_zero_version(action.edit or action.arguments[1]) - elseif type(action.command) == 'table' and action.command.command == 'java.apply.workspaceEdit' then -- 'action' is CodeAction in java format - action.edit = jdtls_fix_zero_version(action.edit or action.command.arguments[1]) - end - end - - jdtls_handlers[ctx.method](err, actions, ctx) - end - - local function jdtls_on_textdocument_rename(err, workspace_edit, ctx) - jdtls_handlers[ctx.method](err, jdtls_fix_zero_version(workspace_edit), ctx) - end - - local function jdtls_on_workspace_applyedit(err, workspace_edit, ctx) - jdtls_handlers[ctx.method](err, jdtls_fix_zero_version(workspace_edit), ctx) - end - - -- Non-standard notification that can be used to display progress - local function jdtls_on_language_status(_, result) - local command = vim.api.nvim_command - command 'echohl ModeMsg' - command(string.format('echo "%s"', result.message)) - command 'echohl None' - end - ''; - - vim.lsp.servers = - mapListToAttrs (n: { - name = n; - value = servers.${n}; - }) - cfg.lsp.servers; + vim.lsp = { + presets = genAttrs cfg.lsp.servers (_: {enable = true;}); + servers = genAttrs cfg.lsp.servers (_: { + filetypes = ["java"]; + }); + }; }) (mkIf cfg.treesitter.enable { diff --git a/modules/plugins/languages/jinja.nix b/modules/plugins/languages/jinja.nix index ce141eb9..a7d677b0 100644 --- a/modules/plugins/languages/jinja.nix +++ b/modules/plugins/languages/jinja.nix @@ -4,26 +4,16 @@ lib, ... }: let - inherit (builtins) attrNames; - inherit (lib.meta) getExe; + inherit (lib) genAttrs; inherit (lib.modules) mkIf mkMerge; inherit (lib.options) literalExpression mkEnableOption mkOption; inherit (lib.types) enum listOf; inherit (lib.nvim.types) mkGrammarOption; - inherit (lib.nvim.attrsets) mapListToAttrs; cfg = config.vim.languages.jinja; + defaultServers = ["jinja-lsp"]; - servers = { - jinja-lsp = { - enable = true; - cmd = [(getExe pkgs.jinja-lsp)]; - filetypes = ["jinja"]; - root_markers = [ - ".git" - ]; - }; - }; + servers = ["jinja-lsp"]; in { options.vim.languages.jinja = { enable = mkEnableOption "Jinja template language support"; @@ -48,7 +38,7 @@ in { }; servers = mkOption { description = "Jinja LSP server to use"; - type = listOf (enum (attrNames servers)); + type = listOf (enum servers); default = defaultServers; }; }; @@ -64,12 +54,12 @@ in { }) (mkIf cfg.lsp.enable { - vim.lsp.servers = - mapListToAttrs (n: { - name = n; - value = servers.${n}; - }) - cfg.lsp.servers; + vim.lsp = { + presets = genAttrs cfg.lsp.servers (_: {enable = true;}); + servers = genAttrs cfg.lsp.servers (_: { + filetypes = ["jinja"]; + }); + }; }) ]); } diff --git a/modules/plugins/languages/jq.nix b/modules/plugins/languages/jq.nix index 149dc5b2..d27a5be5 100644 --- a/modules/plugins/languages/jq.nix +++ b/modules/plugins/languages/jq.nix @@ -8,6 +8,7 @@ inherit (lib.options) literalExpression mkEnableOption mkOption; inherit (lib.modules) mkIf mkMerge; inherit (lib.meta) getExe; + inherit (lib) genAttrs; inherit (lib.types) enum listOf; inherit (lib.nvim.attrsets) mapListToAttrs; inherit (lib.nvim.types) mkGrammarOption; @@ -15,14 +16,7 @@ cfg = config.vim.languages.jq; defaultServers = ["jq-lsp"]; - servers = { - jq-lsp = { - enable = true; - cmd = [(getExe pkgs.jq-lsp)]; - filetypes = ["jq"]; - root_markers = [".git"]; - }; - }; + servers = ["jq-lsp"]; defaultFormat = ["jqfmt"]; formats = { @@ -57,7 +51,7 @@ in { defaultText = literalExpression "config.vim.lsp.enable"; }; servers = mkOption { - type = listOf (enum (attrNames servers)); + type = listOf (enum servers); default = defaultServers; description = "JQ LSP server to use"; }; @@ -88,12 +82,12 @@ in { }) (mkIf cfg.lsp.enable { - vim.lsp.servers = - mapListToAttrs (n: { - name = n; - value = servers.${n}; - }) - cfg.lsp.servers; + vim.lsp = { + presets = genAttrs cfg.lsp.servers (_: {enable = true;}); + servers = genAttrs cfg.lsp.servers (_: { + filetypes = ["jq"]; + }); + }; }) (mkIf cfg.format.enable { diff --git a/modules/plugins/languages/json.nix b/modules/plugins/languages/json.nix index 5e85371a..2c6096f9 100644 --- a/modules/plugins/languages/json.nix +++ b/modules/plugins/languages/json.nix @@ -6,23 +6,17 @@ }: let inherit (builtins) attrNames; inherit (lib.options) mkOption mkEnableOption literalExpression; - inherit (lib.meta) getExe' getExe; + inherit (lib.meta) getExe; inherit (lib.modules) mkIf mkMerge; - inherit (lib.types) enum; - inherit (lib.nvim.types) mkGrammarOption deprecatedSingleOrListOf; + inherit (lib.types) enum listOf; + inherit (lib) genAttrs; + inherit (lib.nvim.types) mkGrammarOption deprecatedSingleOrListOf enumWithRename; inherit (lib.nvim.attrsets) mapListToAttrs; cfg = config.vim.languages.json; - defaultServers = ["jsonls"]; - servers = { - jsonls = { - cmd = [(getExe' pkgs.vscode-langservers-extracted "vscode-json-language-server") "--stdio"]; - filetypes = ["json" "jsonc" "json5"]; - init_options = {provideFormatter = true;}; - root_markers = [".git"]; - }; - }; + defaultServers = ["vscode-json-language-server"]; + servers = ["vscode-json-language-server"]; defaultFormat = ["jsonfmt"]; @@ -57,7 +51,12 @@ in { }; servers = mkOption { - type = deprecatedSingleOrListOf "vim.language.json.lsp.servers" (enum (attrNames servers)); + type = listOf (enumWithRename + "vim.languages.json.lsp.servers" + servers + { + jsonls = "vscode-json-language-server"; + }); default = defaultServers; description = "JSON LSP server to use"; }; @@ -89,12 +88,12 @@ in { }) (mkIf cfg.lsp.enable { - vim.lsp.servers = - mapListToAttrs (name: { - inherit name; - value = servers.${name}; - }) - cfg.lsp.servers; + vim.lsp = { + presets = genAttrs cfg.lsp.servers (_: {enable = true;}); + servers = genAttrs cfg.lsp.servers (_: { + filetypes = ["json" "jsonc" "json5"]; + }); + }; }) (mkIf cfg.format.enable { diff --git a/modules/plugins/languages/julia.nix b/modules/plugins/languages/julia.nix index 7d5785c9..51737d2f 100644 --- a/modules/plugins/languages/julia.nix +++ b/modules/plugins/languages/julia.nix @@ -4,86 +4,16 @@ config, ... }: let - inherit (builtins) attrNames; inherit (lib.options) literalExpression mkEnableOption mkOption; - inherit (lib.types) enum; + inherit (lib.types) listOf; inherit (lib.modules) mkIf mkMerge; - inherit (lib.meta) getExe; - inherit (lib.nvim.types) mkGrammarOption deprecatedSingleOrListOf; - inherit (lib.generators) mkLuaInline; - inherit (lib.nvim.attrsets) mapListToAttrs; - inherit (lib.nvim.dag) entryBefore; - - defaultServers = ["julials"]; - servers = { - julials = { - enable = true; - cmd = - mkLuaInline - /* - lua - */ - '' - { - '${getExe (pkgs.julia.withPackages ["LanguageServer"])}', - '--startup-file=no', - '--history-file=no', - '-e', - [[ - # Load LanguageServer.jl: attempt to load from ~/.julia/environments/nvim-lspconfig - # with the regular load path as a fallback - ls_install_path = joinpath( - get(DEPOT_PATH, 1, joinpath(homedir(), ".julia")), - "environments", "nvim-lspconfig" - ) - pushfirst!(LOAD_PATH, ls_install_path) - using LanguageServer - popfirst!(LOAD_PATH) - depot_path = get(ENV, "JULIA_DEPOT_PATH", "") - project_path = let - dirname(something( - ## 1. Finds an explicitly set project (JULIA_PROJECT) - Base.load_path_expand(( - p = get(ENV, "JULIA_PROJECT", nothing); - p === nothing ? nothing : isempty(p) ? nothing : p - )), - ## 2. Look for a Project.toml file in the current working directory, - ## or parent directories, with $HOME as an upper boundary - Base.current_project(), - ## 3. First entry in the load path - get(Base.load_path(), 1, nothing), - ## 4. Fallback to default global environment, - ## this is more or less unreachable - Base.load_path_expand("@v#.#"), - )) - end - @info "Running language server" VERSION pwd() project_path depot_path - server = LanguageServer.LanguageServerInstance(stdin, stdout, project_path, depot_path) - server.runlinter = true - run(server) - ]], - } - ''; - filetypes = ["julia"]; - root_markers = ["Project.toml" "JuliaProject.toml"]; - on_attach = - mkLuaInline - /* - lua - */ - '' - function(_, bufnr) - vim.api.nvim_buf_create_user_command(bufnr, 'LspJuliaActivateEnv', activate_julia_env, { - desc = 'Activate a Julia environment', - nargs = '?', - complete = 'file', - }) - end - ''; - }; - }; + inherit (lib) genAttrs; + inherit (lib.nvim.types) mkGrammarOption enumWithRename; cfg = config.vim.languages.julia; + + defaultServers = ["julia-languageserver"]; + servers = ["julia-languageserver"]; in { options = { vim.languages.julia = { @@ -107,7 +37,12 @@ in { defaultText = literalExpression "config.vim.lsp.enable"; }; servers = mkOption { - type = deprecatedSingleOrListOf "vim.language.julia.lsp.servers" (enum (attrNames servers)); + type = listOf (enumWithRename + "vim.languages.julia.lsp.servers" + servers + { + julials = "julia-languageserver"; + }); default = defaultServers; description = '' Julia LSP Server to Use @@ -136,70 +71,14 @@ in { }) (mkIf cfg.lsp.enable { - vim.luaConfigRC.julia-util = - entryBefore ["lsp-servers"] - /* - lua - */ - '' - local function activate_julia_env(path) - assert(vim.fn.has 'nvim-0.10' == 1, 'requires Nvim 0.10 or newer') - local bufnr = vim.api.nvim_get_current_buf() - local julials_clients = vim.lsp.get_clients { bufnr = bufnr, name = 'julials' } - assert( - #julials_clients > 0, - 'method julia/activateenvironment is not supported by any servers active on the current buffer' - ) - local function _activate_env(environment) - if environment then - for _, julials_client in ipairs(julials_clients) do - julials_client:notify('julia/activateenvironment', { envPath = environment }) - end - vim.notify('Julia environment activated: \n`' .. environment .. '`', vim.log.levels.INFO) - end - end - if path then - path = vim.fs.normalize(vim.fn.fnamemodify(vim.fn.expand(path), ':p')) - local found_env = false - for _, project_file in ipairs(root_files) do - local file = vim.uv.fs_stat(vim.fs.joinpath(path, project_file)) - if file and file.type then - found_env = true - break - end - end - if not found_env then - vim.notify('Path is not a julia environment: \n`' .. path .. '`', vim.log.levels.WARN) - return - end - _activate_env(path) - else - local depot_paths = vim.env.JULIA_DEPOT_PATH - and vim.split(vim.env.JULIA_DEPOT_PATH, vim.fn.has 'win32' == 1 and ';' or ':') - or { vim.fn.expand '~/.julia' } - local environments = {} - vim.list_extend(environments, vim.fs.find(root_files, { type = 'file', upward = true, limit = math.huge })) - for _, depot_path in ipairs(depot_paths) do - local depot_env = vim.fs.joinpath(vim.fs.normalize(depot_path), 'environments') - vim.list_extend( - environments, - vim.fs.find(function(name, env_path) - return vim.tbl_contains(root_files, name) and string.sub(env_path, #depot_env + 1):match '^/[^/]*$' - end, { path = depot_env, type = 'file', limit = math.huge }) - ) - end - environments = vim.tbl_map(vim.fs.dirname, environments) - vim.ui.select(environments, { prompt = 'Select a Julia environment' }, _activate_env) - end - end - ''; - - vim.lsp.servers = - mapListToAttrs (n: { - name = n; - value = servers.${n}; - }) - cfg.lsp.servers; + vim = { + lsp = { + presets = genAttrs cfg.lsp.servers (_: {enable = true;}); + servers = genAttrs cfg.lsp.servers (_: { + filetypes = ["julia"]; + }); + }; + }; }) ]); } diff --git a/modules/plugins/languages/just.nix b/modules/plugins/languages/just.nix index 210941bd..2570da76 100644 --- a/modules/plugins/languages/just.nix +++ b/modules/plugins/languages/just.nix @@ -4,25 +4,16 @@ pkgs, ... }: let - inherit (builtins) attrNames; inherit (lib.options) literalExpression mkEnableOption mkOption; inherit (lib.modules) mkIf mkMerge; - inherit (lib.meta) getExe; + inherit (lib) genAttrs; inherit (lib.types) enum listOf; - inherit (lib.nvim.attrsets) mapListToAttrs; inherit (lib.nvim.types) mkGrammarOption; cfg = config.vim.languages.just; defaultServers = ["just-lsp"]; - servers = { - just-lsp = { - enable = true; - cmd = [(getExe pkgs.just-lsp)]; - filetypes = ["just"]; - root_markers = [".git" "justfile"]; - }; - }; + servers = ["just-lsp"]; in { options.vim.languages.just = { enable = mkEnableOption "Just support"; @@ -45,7 +36,7 @@ in { defaultText = literalExpression "config.vim.lsp.enable"; }; servers = mkOption { - type = listOf (enum (attrNames servers)); + type = listOf (enum servers); default = defaultServers; description = "Just LSP server to use"; }; @@ -61,12 +52,12 @@ in { }) (mkIf cfg.lsp.enable { - vim.lsp.servers = - mapListToAttrs (n: { - name = n; - value = servers.${n}; - }) - cfg.lsp.servers; + vim.lsp = { + presets = genAttrs cfg.lsp.servers (_: {enable = true;}); + servers = genAttrs cfg.lsp.servers (_: { + filetypes = ["just"]; + }); + }; }) ]); } diff --git a/modules/plugins/languages/kotlin.nix b/modules/plugins/languages/kotlin.nix index 63cbe428..27b9a14b 100644 --- a/modules/plugins/languages/kotlin.nix +++ b/modules/plugins/languages/kotlin.nix @@ -6,44 +6,16 @@ }: let inherit (lib.options) literalExpression mkEnableOption mkOption; inherit (lib.modules) mkIf mkMerge; - inherit (lib.meta) getExe' getExe; - inherit (builtins) attrNames; + inherit (lib.meta) getExe; + inherit (lib) genAttrs; inherit (lib.types) enum listOf; inherit (lib.nvim.types) mkGrammarOption diagnostics; - inherit (lib.generators) mkLuaInline; inherit (lib.nvim.attrsets) mapListToAttrs; cfg = config.vim.languages.kotlin; defaultServers = ["kotlin-language-server"]; - servers = { - kotlin-language-server = { - enable = true; - cmd = [(getExe' pkgs.kotlin-language-server "kotlin-language-server")]; - filetypes = ["kotlin"]; - root_markers = [ - "settings.gradle" # Gradle (multi-project) - "settings.gradle.kts" # Gradle (multi-project) - "build.xml" # Ant - "pom.xml" # Maven - "build.gradle" # Gradle - "build.gradle.kts" # gradle - ]; - init_options = { - storagePath = mkLuaInline " - vim.fs.root(vim.fn.expand '%:p:h', - { - 'settings.gradle', -- Gradle (multi-project) - 'settings.gradle.kts', -- Gradle (multi-project) - 'build.xml', -- Ant - 'pom.xml', -- Maven - 'build.gradle', -- Gradle - 'build.gradle.kts', -- Gradle - } - )"; - }; - }; - }; + servers = ["kotlin-language-server"]; defaultDiagnosticsProvider = ["ktlint"]; diagnosticsProviders = { @@ -73,7 +45,7 @@ in { defaultText = literalExpression "config.vim.lsp.enable"; }; servers = mkOption { - type = listOf (enum (attrNames servers)); + type = listOf (enum servers); default = defaultServers; description = "Kotlin LSP server to use"; }; @@ -112,12 +84,12 @@ in { }) (mkIf cfg.lsp.enable { - vim.lsp.servers = - mapListToAttrs (n: { - name = n; - value = servers.${n}; - }) - cfg.lsp.servers; + vim.lsp = { + presets = genAttrs cfg.lsp.servers (_: {enable = true;}); + servers = genAttrs cfg.lsp.servers (_: { + filetypes = ["kotlin"]; + }); + }; }) ]); } diff --git a/modules/plugins/languages/lua.nix b/modules/plugins/languages/lua.nix index 52d32d6f..aeee8bec 100644 --- a/modules/plugins/languages/lua.nix +++ b/modules/plugins/languages/lua.nix @@ -8,6 +8,7 @@ inherit (lib.options) literalExpression mkEnableOption mkOption; inherit (lib.modules) mkIf mkMerge; inherit (lib.meta) getExe; + inherit (lib) genAttrs; inherit (lib.types) bool enum listOf; inherit (lib.nvim.types) diagnostics mkGrammarOption; inherit (lib.nvim.dag) entryBefore; @@ -16,23 +17,7 @@ cfg = config.vim.languages.lua; defaultServers = ["lua-language-server"]; - servers = { - lua-language-server = { - enable = true; - cmd = [(getExe pkgs.lua-language-server)]; - filetypes = ["lua"]; - root_markers = [ - ".luarc.json" - ".luarc.jsonc" - ".luacheckrc" - ".stylua.toml" - "stylua.toml" - "selene.toml" - "selene.yml" - ".git" - ]; - }; - }; + servers = ["lua-language-server"]; defaultFormat = ["stylua"]; formats = { @@ -77,7 +62,7 @@ in { defaultText = literalExpression "config.vim.lsp.enable"; }; servers = mkOption { - type = listOf (enum (attrNames servers)); + type = listOf (enum servers); default = defaultServers; description = "Lua LSP server to use"; }; @@ -122,12 +107,12 @@ in { (mkIf cfg.enable (mkMerge [ (mkIf cfg.lsp.enable { - vim.lsp.servers = - mapListToAttrs (n: { - name = n; - value = servers.${n}; - }) - cfg.lsp.servers; + vim.lsp = { + presets = genAttrs cfg.lsp.servers (_: {enable = true;}); + servers = genAttrs cfg.lsp.servers (_: { + filetypes = ["lsp"]; + }); + }; }) (mkIf cfg.lsp.lazydev.enable { diff --git a/modules/plugins/languages/markdown.nix b/modules/plugins/languages/markdown.nix index 33078e6d..71773c8a 100644 --- a/modules/plugins/languages/markdown.nix +++ b/modules/plugins/languages/markdown.nix @@ -5,6 +5,7 @@ ... }: let inherit (builtins) attrNames; + inherit (lib) genAttrs; inherit (lib.meta) getExe getExe'; inherit (lib.modules) mkIf mkMerge; inherit (lib.options) literalExpression mkEnableOption mkOption; @@ -17,28 +18,7 @@ cfg = config.vim.languages.markdown; defaultServers = ["marksman"]; - servers = { - marksman = { - enable = true; - cmd = [(getExe pkgs.marksman) "server"]; - filetypes = ["markdown" "mdx"]; - root_markers = [".marksman.toml" ".git"]; - }; - - markdown-oxide = { - enable = true; - cmd = [(getExe pkgs.markdown-oxide)]; - filetypes = ["markdown"]; - root_markers = [".git" ".obsidian" ".moxide.toml"]; - }; - - rumdl = { - enable = true; - cmd = [(getExe pkgs.rumdl) "server"]; - filetypes = ["markdown"]; - root_markers = [".git" ".rumdl.toml" "rumdl.toml" ".config/rumdl.toml" "pyproject.toml"]; - }; - }; + servers = ["marksman" "markdown-oxide" "rumdl"]; defaultFormat = ["deno_fmt"]; formats = { @@ -99,7 +79,7 @@ in { servers = mkOption { description = "Markdown LSP server to use"; - type = deprecatedSingleOrListOf "vim.language.markdown.lsp.servers" (enum (attrNames servers)); + type = listOf (enum servers); default = defaultServers; }; }; @@ -186,12 +166,12 @@ in { }) (mkIf cfg.lsp.enable { - vim.lsp.servers = - mapListToAttrs (n: { - name = n; - value = servers.${n}; - }) - cfg.lsp.servers; + vim.lsp = { + presets = genAttrs cfg.lsp.servers (_: {enable = true;}); + servers = genAttrs cfg.lsp.servers (_: { + filetypes = ["markdown" "mdx"]; + }); + }; }) (mkIf cfg.format.enable { diff --git a/modules/plugins/languages/nim.nix b/modules/plugins/languages/nim.nix index 97bcdd9d..18fb4914 100644 --- a/modules/plugins/languages/nim.nix +++ b/modules/plugins/languages/nim.nix @@ -6,36 +6,16 @@ }: let inherit (builtins) attrNames; inherit (lib.options) mkEnableOption mkOption literalExpression; - inherit (lib.meta) getExe'; inherit (lib.modules) mkIf mkMerge; - inherit (lib.types) enum; + inherit (lib.types) enum listOf; + inherit (lib) genAttrs; inherit (lib.nvim.types) mkGrammarOption deprecatedSingleOrListOf; - inherit (lib.generators) mkLuaInline; inherit (lib.nvim.attrsets) mapListToAttrs; cfg = config.vim.languages.nim; defaultServers = ["nimlsp"]; - servers = { - nimlsp = { - enable = true; - cmd = [(getExe' pkgs.nimlsp "nimlsp")]; - filetypes = ["nim"]; - root_dir = - mkLuaInline - /* - lua - */ - '' - function(bufnr, on_dir) - local fname = vim.api.nvim_buf_get_name(bufnr) - on_dir( - util.root_pattern '*.nimble'(fname) or vim.fs.dirname(vim.fs.find('.git', { path = fname, upward = true })[1]) - ) - end - ''; - }; - }; + servers = ["nimlsp"]; defaultFormat = ["nimpretty"]; formats = { @@ -66,7 +46,7 @@ in { }; servers = mkOption { - type = deprecatedSingleOrListOf "vim.language.nim.lsp.servers" (enum (attrNames servers)); + type = listOf (enum servers); default = defaultServers; description = "Nim LSP server to use"; }; @@ -103,12 +83,12 @@ in { }) (mkIf cfg.lsp.enable { - vim.lsp.servers = - mapListToAttrs (n: { - name = n; - value = servers.${n}; - }) - cfg.lsp.servers; + vim.lsp = { + presets = genAttrs cfg.lsp.servers (_: {enable = true;}); + servers = genAttrs cfg.lsp.servers (_: { + filetypes = ["nim"]; + }); + }; }) (mkIf cfg.format.enable { diff --git a/modules/plugins/languages/nix.nix b/modules/plugins/languages/nix.nix index 29185b12..eac9264e 100644 --- a/modules/plugins/languages/nix.nix +++ b/modules/plugins/languages/nix.nix @@ -5,32 +5,18 @@ ... }: let inherit (builtins) attrNames; - inherit (lib) concatStringsSep; + inherit (lib) concatStringsSep genAttrs; inherit (lib.meta) getExe; inherit (lib.options) mkEnableOption mkOption literalExpression; inherit (lib.modules) mkIf mkMerge; - inherit (lib.types) enum; + inherit (lib.types) enum listOf; inherit (lib.nvim.types) mkGrammarOption diagnostics deprecatedSingleOrListOf; inherit (lib.nvim.attrsets) mapListToAttrs; cfg = config.vim.languages.nix; defaultServers = ["nil"]; - servers = { - nil = { - enable = true; - cmd = [(getExe pkgs.nil)]; - filetypes = ["nix"]; - root_markers = [".git" "flake.nix"]; - }; - - nixd = { - enable = true; - cmd = [(getExe pkgs.nixd)]; - filetypes = ["nix"]; - root_markers = [".git" "flake.nix"]; - }; - }; + servers = ["nil" "nixd"]; defaultFormat = ["alejandra"]; formats = { @@ -91,7 +77,7 @@ in { defaultText = literalExpression "config.vim.lsp.enable"; }; servers = mkOption { - type = deprecatedSingleOrListOf "vim.language.nix.lsp.servers" (enum (attrNames servers)); + type = listOf (enum servers); default = defaultServers; description = "Nix LSP server to use"; }; @@ -147,12 +133,13 @@ in { }) (mkIf cfg.lsp.enable { - vim.lsp.servers = - mapListToAttrs (n: { - name = n; - value = servers.${n}; - }) - cfg.lsp.servers; + vim.lsp = { + presets = genAttrs cfg.lsp.servers (_: {enable = true;}); + servers = genAttrs cfg.lsp.servers (_: { + filetypes = ["nix"]; + root_markers = ["flake.nix"]; + }); + }; }) (mkIf cfg.format.enable { diff --git a/modules/plugins/languages/nu.nix b/modules/plugins/languages/nu.nix index a36e1255..9425da85 100644 --- a/modules/plugins/languages/nu.nix +++ b/modules/plugins/languages/nu.nix @@ -5,32 +5,13 @@ ... }: let inherit (lib.options) mkEnableOption mkOption literalExpression; - inherit (lib.types) enum; + inherit (lib.types) enum listOf; inherit (lib.modules) mkIf mkMerge; - inherit (lib.nvim.types) mkGrammarOption deprecatedSingleOrListOf; - inherit (lib.meta) getExe; - inherit (lib.generators) mkLuaInline; - inherit (lib.nvim.attrsets) mapListToAttrs; - inherit (builtins) attrNames; + inherit (lib.nvim.types) mkGrammarOption; + inherit (lib) genAttrs; defaultServers = ["nushell"]; - servers = { - nushell = { - enable = true; - cmd = [(getExe pkgs.nushell) "--no-config-file" "--lsp"]; - filetypes = ["nu"]; - root_dir = - mkLuaInline - /* - lua - */ - '' - function(bufnr, on_dir) - on_dir(vim.fs.root(bufnr, { '.git' }) or vim.fs.dirname(vim.api.nvim_buf_get_name(bufnr))) - end - ''; - }; - }; + servers = ["nushell"]; cfg = config.vim.languages.nu; in { @@ -56,7 +37,7 @@ in { }; servers = mkOption { - type = deprecatedSingleOrListOf "vim.language.nu.lsp.servers" (enum (attrNames servers)); + type = listOf (enum servers); default = defaultServers; description = "Nu LSP server to use"; }; @@ -70,12 +51,12 @@ in { }) (mkIf cfg.lsp.enable { - vim.lsp.servers = - mapListToAttrs (n: { - name = n; - value = servers.${n}; - }) - cfg.lsp.servers; + vim.lsp = { + presets = genAttrs cfg.lsp.servers (_: {enable = true;}); + servers = genAttrs cfg.lsp.servers (_: { + filetypes = ["nu"]; + }); + }; }) ]); } diff --git a/modules/plugins/languages/ocaml.nix b/modules/plugins/languages/ocaml.nix index 6395fda5..051bef75 100644 --- a/modules/plugins/languages/ocaml.nix +++ b/modules/plugins/languages/ocaml.nix @@ -7,53 +7,16 @@ inherit (builtins) attrNames; inherit (lib.options) mkEnableOption mkOption literalExpression; inherit (lib.modules) mkIf mkMerge; + inherit (lib) genAttrs; inherit (lib.meta) getExe; - inherit (lib.types) enum; + inherit (lib.types) enum listOf; inherit (lib.nvim.types) mkGrammarOption deprecatedSingleOrListOf; - inherit (lib.generators) mkLuaInline; inherit (lib.nvim.attrsets) mapListToAttrs; cfg = config.vim.languages.ocaml; defaultServers = ["ocaml-lsp"]; - servers = { - ocaml-lsp = { - enable = true; - cmd = [(getExe pkgs.ocamlPackages.ocaml-lsp)]; - filetypes = ["ocaml" "menhir" "ocamlinterface" "ocamllex" "reason" "dune"]; - root_dir = - mkLuaInline - /* - lua - */ - '' - function(bufnr, on_dir) - local fname = vim.api.nvim_buf_get_name(bufnr) - on_dir(util.root_pattern('*.opam', 'esy.json', 'package.json', '.git', 'dune-project', 'dune-workspace')(fname)) - end - ''; - get_language_id = - mkLuaInline - /* - lua - */ - '' - function(_, ftype) - local language_id_of = { - menhir = 'ocaml.menhir', - ocaml = 'ocaml', - ocamlinterface = 'ocaml.interface', - ocamllex = 'ocaml.ocamllex', - reason = 'reason', - dune = 'dune', - } - - return language_id_of[ftype] - - end - ''; - }; - }; + servers = ["ocaml-lsp"]; defaultFormat = ["ocamlformat"]; formats = { @@ -84,7 +47,7 @@ in { }; servers = mkOption { - type = deprecatedSingleOrListOf "vim.language.ocaml.lsp.servers" (enum (attrNames servers)); + type = listOf (enum servers); default = defaultServers; description = "OCaml LSP server to use"; }; @@ -102,12 +65,12 @@ in { config = mkIf cfg.enable (mkMerge [ (mkIf cfg.lsp.enable { - vim.lsp.servers = - mapListToAttrs (n: { - name = n; - value = servers.${n}; - }) - cfg.lsp.servers; + vim.lsp = { + presets = genAttrs cfg.lsp.servers (_: {enable = true;}); + servers = genAttrs cfg.lsp.servers (_: { + filetypes = ["ocaml" "menhir" "ocamlinterface" "ocamllex" "reason" "dune"]; + }); + }; }) (mkIf cfg.treesitter.enable { diff --git a/modules/plugins/languages/odin.nix b/modules/plugins/languages/odin.nix index d2bd3c85..25d26df1 100644 --- a/modules/plugins/languages/odin.nix +++ b/modules/plugins/languages/odin.nix @@ -7,34 +7,15 @@ inherit (builtins) attrNames; inherit (lib.options) mkEnableOption mkOption literalExpression; inherit (lib.modules) mkIf mkMerge; - inherit (lib.types) enum package; + inherit (lib.types) enum package listOf; inherit (lib.nvim.dag) entryAfter; - inherit (lib.meta) getExe; - inherit (lib.nvim.types) mkGrammarOption deprecatedSingleOrListOf; - inherit (lib.generators) mkLuaInline; - inherit (lib.nvim.attrsets) mapListToAttrs; + inherit (lib) genAttrs; + inherit (lib.nvim.types) mkGrammarOption; cfg = config.vim.languages.odin; defaultServers = ["ols"]; - servers = { - ols = { - enable = true; - cmd = [(getExe pkgs.ols)]; - filetypes = ["odin"]; - root_dir = - mkLuaInline - /* - lua - */ - '' - function(bufnr, on_dir) - local fname = vim.api.nvim_buf_get_name(bufnr) - on_dir(util.root_pattern('ols.json', '.git', '*.odin')(fname)) - end''; - }; - }; - + servers = ["ols"]; defaultDebugger = "codelldb"; debuggers = { codelldb = { @@ -71,7 +52,7 @@ in { }; servers = mkOption { - type = deprecatedSingleOrListOf "vim.language.odin.lsp.servers" (enum (attrNames servers)); + type = listOf (enum servers); default = defaultServers; description = "Odin LSP server to use"; }; @@ -106,12 +87,12 @@ in { }) (mkIf cfg.lsp.enable { - vim.lsp.servers = - mapListToAttrs (n: { - name = n; - value = servers.${n}; - }) - cfg.lsp.servers; + vim.lsp = { + presets = genAttrs cfg.lsp.servers (_: {enable = true;}); + servers = genAttrs cfg.lsp.servers (_: { + filetypes = ["odin"]; + }); + }; }) (mkIf cfg.dap.enable { diff --git a/modules/plugins/languages/openscad.nix b/modules/plugins/languages/openscad.nix index e1ca096d..4ff18ff8 100644 --- a/modules/plugins/languages/openscad.nix +++ b/modules/plugins/languages/openscad.nix @@ -4,12 +4,10 @@ lib, ... }: let - inherit (builtins) attrNames; inherit (lib.options) mkEnableOption mkOption literalExpression; inherit (lib.modules) mkIf mkMerge; inherit (lib.types) enum listOf; - inherit (lib.meta) getExe; - inherit (lib.nvim.attrsets) mapListToAttrs; + inherit (lib) genAttrs; cfg = config.vim.languages.openscad; /* @@ -22,13 +20,7 @@ */ defaultServers = ["openscad-lsp"]; - servers = { - openscad-lsp = { - enable = true; - cmd = [(getExe pkgs.openscad-lsp) "--stdio"]; - filetypes = ["openscad"]; - }; - }; + servers = ["openscad-lsp"]; in { options.vim.languages.openscad = { enable = mkEnableOption "OpenSCAD language support"; @@ -42,7 +34,7 @@ in { }; servers = mkOption { - type = listOf (enum (attrNames servers)); + type = listOf (enum servers); default = defaultServers; description = "OpenSCAD LSP server to use"; }; @@ -51,12 +43,12 @@ in { config = mkIf cfg.enable (mkMerge [ (mkIf cfg.lsp.enable { - vim.lsp.servers = - mapListToAttrs (n: { - name = n; - value = servers.${n}; - }) - cfg.lsp.servers; + vim.lsp = { + presets = genAttrs cfg.lsp.servers (_: {enable = true;}); + servers = genAttrs cfg.lsp.servers (_: { + filetypes = ["openscad"]; + }); + }; }) ]); } diff --git a/modules/plugins/languages/php.nix b/modules/plugins/languages/php.nix index fb9edd5c..38249ee1 100644 --- a/modules/plugins/languages/php.nix +++ b/modules/plugins/languages/php.nix @@ -6,65 +6,18 @@ }: let inherit (builtins) attrNames toString; inherit (lib.options) mkEnableOption mkOption literalExpression; + inherit (lib) genAttrs; inherit (lib.meta) getExe; inherit (lib.modules) mkIf mkMerge; inherit (lib.types) enum int attrs listOf; inherit (lib.nvim.lua) toLuaObject; - inherit (lib.nvim.types) mkGrammarOption deprecatedSingleOrListOf; + inherit (lib.nvim.types) mkGrammarOption; inherit (lib.nvim.attrsets) mapListToAttrs; - inherit (lib.generators) mkLuaInline; cfg = config.vim.languages.php; defaultServers = ["phpactor"]; - servers = { - phpactor = { - enable = true; - cmd = [(getExe pkgs.phpactor) "language-server"]; - filetypes = ["php"]; - root_markers = [".git" "composer.json" ".phpactor.json" ".phpactor.yml"]; - workspace_required = true; - }; - - phan = { - enable = true; - cmd = [ - (getExe pkgs.php81Packages.phan) - "-m" - "json" - "--no-color" - "--no-progress-bar" - "-x" - "-u" - "-S" - "--language-server-on-stdin" - "--allow-polyfill-parser" - ]; - filetypes = ["php"]; - root_dir = - mkLuaInline - /* - lua - */ - '' - function(bufnr, on_dir) - local fname = vim.api.nvim_buf_get_name(bufnr) - local cwd = assert(vim.uv.cwd()) - local root = vim.fs.root(fname, { 'composer.json', '.git' }) - - -- prefer cwd if root is a descendant - on_dir(root and vim.fs.relpath(cwd, root) and cwd) - end - ''; - }; - - intelephense = { - enable = true; - cmd = [(getExe pkgs.intelephense) "--stdio"]; - filetypes = ["php"]; - root_markers = ["composer.json" ".git"]; - }; - }; + servers = ["phpactor" "phan" "intelephense"]; defaultFormat = ["php_cs_fixer"]; formats = { @@ -103,7 +56,7 @@ in { }; servers = mkOption { - type = deprecatedSingleOrListOf "vim.language.php.lsp.servers" (enum (attrNames servers)); + type = listOf (enum servers); default = defaultServers; description = "PHP LSP server to use"; }; @@ -159,12 +112,13 @@ in { }) (mkIf cfg.lsp.enable { - vim.lsp.servers = - mapListToAttrs (n: { - name = n; - value = servers.${n}; - }) - cfg.lsp.servers; + vim.lsp = { + presets = genAttrs cfg.lsp.servers (_: {enable = true;}); + servers = genAttrs cfg.lsp.servers (_: { + filetypes = ["php"]; + root_markers = ["composer.json"]; + }); + }; }) (mkIf cfg.format.enable { diff --git a/modules/plugins/languages/python.nix b/modules/plugins/languages/python.nix index 44179ab2..5e1eaa7b 100644 --- a/modules/plugins/languages/python.nix +++ b/modules/plugins/languages/python.nix @@ -7,185 +7,18 @@ inherit (builtins) attrNames; inherit (lib.options) mkEnableOption mkOption literalExpression; inherit (lib.lists) flatten; + inherit (lib) genAttrs; inherit (lib.meta) getExe getExe'; inherit (lib.modules) mkIf mkMerge; - inherit (lib.types) enum package bool; + inherit (lib.types) enum package bool listOf; inherit (lib.nvim.attrsets) mapListToAttrs; inherit (lib.nvim.types) deprecatedSingleOrListOf diagnostics; - inherit (lib.generators) mkLuaInline; - inherit (lib.nvim.dag) entryBefore; inherit (lib.trivial) warn; cfg = config.vim.languages.python; defaultServers = ["basedpyright"]; - servers = { - pyrefly = { - enable = true; - cmd = [(getExe pkgs.pyrefly) "lsp"]; - filetypes = ["python"]; - root_markers = [ - "pyproject.toml" - "pyrefly.toml" - "setup.py" - "setup.cfg" - "requirements.txt" - "Pipfile" - ".git" - ]; - }; - - pyright = { - enable = true; - cmd = [(getExe' pkgs.pyright "pyright-langserver") "--stdio"]; - filetypes = ["python"]; - root_markers = [ - "pyproject.toml" - "setup.py" - "setup.cfg" - "requirements.txt" - "Pipfile" - "pyrightconfig.json" - ".git" - ]; - settings = { - python = { - analysis = { - autoSearchPaths = true; - useLibraryCodeForTypes = true; - diagnosticMode = "openFilesOnly"; - }; - }; - }; - on_attach = mkLuaInline '' - function(client, bufnr) - vim.api.nvim_buf_create_user_command(bufnr, 'LspPyrightOrganizeImports', function() - local params = { - command = 'pyright.organizeimports', - arguments = { vim.uri_from_bufnr(bufnr) }, - } - - -- Using client.request() directly because "pyright.organizeimports" is private - -- (not advertised via capabilities), which client:exec_cmd() refuses to call. - -- https://github.com/neovim/neovim/blob/c333d64663d3b6e0dd9aa440e433d346af4a3d81/runtime/lua/vim/lsp/client.lua#L1024-L1030 - client.request('workspace/executeCommand', params, nil, bufnr) - end, { - desc = 'Organize Imports', - }) - vim.api.nvim_buf_create_user_command(bufnr, 'LspPyrightSetPythonPath', set_python_path, { - desc = 'Reconfigure basedpyright with the provided python path', - nargs = 1, - complete = 'file', - }) - end - ''; - }; - - basedpyright = { - enable = true; - cmd = [(getExe' pkgs.basedpyright "basedpyright-langserver") "--stdio"]; - filetypes = ["python"]; - root_markers = [ - "pyproject.toml" - "setup.py" - "setup.cfg" - "requirements.txt" - "Pipfile" - "pyrightconfig.json" - ".git" - ]; - settings = { - basedpyright = { - analysis = { - autoSearchPaths = true; - useLibraryCodeForTypes = true; - diagnosticMode = "openFilesOnly"; - }; - }; - }; - on_attach = mkLuaInline '' - function(client, bufnr) - vim.api.nvim_buf_create_user_command(bufnr, 'LspPyrightOrganizeImports', function() - local params = { - command = 'basedpyright.organizeimports', - arguments = { vim.uri_from_bufnr(bufnr) }, - } - - -- Using client.request() directly because "basedpyright.organizeimports" is private - -- (not advertised via capabilities), which client:exec_cmd() refuses to call. - -- https://github.com/neovim/neovim/blob/c333d64663d3b6e0dd9aa440e433d346af4a3d81/runtime/lua/vim/lsp/client.lua#L1024-L1030 - client.request('workspace/executeCommand', params, nil, bufnr) - end, { - desc = 'Organize Imports', - }) - - vim.api.nvim_buf_create_user_command(bufnr, 'LspPyrightSetPythonPath', set_python_path, { - desc = 'Reconfigure basedpyright with the provided python path', - nargs = 1, - complete = 'file', - }) - end - ''; - }; - - python-lsp-server = { - enable = true; - cmd = [(getExe pkgs.python3Packages.python-lsp-server)]; - filetypes = ["python"]; - root_markers = [ - "pyproject.toml" - "setup.py" - "setup.cfg" - "requirements.txt" - "Pipfile" - ".git" - ]; - }; - - ruff = { - enable = true; - cmd = [(getExe pkgs.ruff) "server"]; - filetypes = ["python"]; - root_markers = [ - "pyproject.toml" - "setup.py" - "setup.cfg" - "requirements.txt" - "Pipfile" - ".git" - ]; - }; - - ty = { - enable = true; - cmd = [(getExe pkgs.ty) "server"]; - filetypes = ["python"]; - root_markers = [ - "pyproject.toml" - "setup.py" - "setup.cfg" - "requirements.txt" - "Pipfile" - ".git" - ]; - }; - - zuban = { - enable = true; - cmd = [(getExe pkgs.zuban) "server"]; - filetypes = ["python"]; - root_markers = [ - "pyproject.toml" - "setup.py" - "setup.cfg" - "requirements.txt" - "Pipfile" - ".git" - "mypy.ini" - ".mypy.ini" - ]; - }; - }; + servers = ["pyrefly" "pyright" "basedpyright" "python-lsp-server" "ruff" "ty" "zuban"]; defaultFormat = ["black"]; formats = { @@ -313,7 +146,7 @@ in { }; servers = mkOption { - type = deprecatedSingleOrListOf "vim.language.python.lsp.servers" (enum (attrNames servers)); + type = listOf (enum servers); default = defaultServers; description = "Python LSP server to use"; }; @@ -382,35 +215,19 @@ in { }) (mkIf cfg.lsp.enable { - vim.luaConfigRC.python-util = - entryBefore ["lsp-servers"] - /* - lua - */ - '' - local function set_python_path(server_name, command) - local path = command.args - local clients = vim.lsp.get_clients { - bufnr = vim.api.nvim_get_current_buf(), - name = server_name, - } - for _, client in ipairs(clients) do - if client.settings then - client.settings.python = vim.tbl_deep_extend('force', client.settings.python or {}, { pythonPath = path }) - else - client.config.settings = vim.tbl_deep_extend('force', client.config.settings, { python = { pythonPath = path } }) - end - client:notify('workspace/didChangeConfiguration', { settings = nil }) - end - end - ''; - - vim.lsp.servers = - mapListToAttrs (n: { - name = n; - value = servers.${n}; - }) - cfg.lsp.servers; + vim.lsp = { + presets = genAttrs cfg.lsp.servers (_: {enable = true;}); + servers = genAttrs cfg.lsp.servers (_: { + filetypes = ["python"]; + root_markers = [ + "Pipfile" + "pyproject.toml" + "requirements.txt" + "setup.cfg" + "setup.py" + ]; + }); + }; }) (mkIf cfg.format.enable { diff --git a/modules/plugins/languages/qml.nix b/modules/plugins/languages/qml.nix index 73d40575..fbba602a 100644 --- a/modules/plugins/languages/qml.nix +++ b/modules/plugins/languages/qml.nix @@ -5,10 +5,10 @@ ... }: let inherit (builtins) attrNames; - inherit (lib.meta) getExe'; inherit (lib.options) mkEnableOption mkOption literalExpression; inherit (lib.modules) mkIf mkMerge; - inherit (lib.types) enum; + inherit (lib) genAttrs; + inherit (lib.types) enum listOf; inherit (lib.nvim.types) mkGrammarOption deprecatedSingleOrListOf; inherit (lib.nvim.attrsets) mapListToAttrs; @@ -17,13 +17,7 @@ qmlPackage = pkgs.kdePackages.qtdeclarative; defaultServers = ["qmlls"]; - servers = { - qmlls = { - cmd = [(getExe' qmlPackage "qmlls")]; - filetypes = ["qml" "qmljs"]; - rootmarkers = [".git"]; - }; - }; + servers = ["qmlls"]; defaultFormat = ["qmlformat"]; formats = { @@ -54,7 +48,7 @@ in { defaultText = literalExpression "config.vim.lsp.enable"; }; servers = mkOption { - type = deprecatedSingleOrListOf "vim.language.qml.lsp.servers" (enum (attrNames servers)); + type = listOf (enum servers); default = defaultServers; description = "QML LSP server to use"; }; @@ -83,13 +77,14 @@ in { grammars = [cfg.treesitter.package]; }; }) + (mkIf cfg.lsp.enable { - vim.lsp.servers = - mapListToAttrs (n: { - name = n; - value = servers.${n}; - }) - cfg.lsp.servers; + vim.lsp = { + presets = genAttrs cfg.lsp.servers (_: {enable = true;}); + servers = genAttrs cfg.lsp.servers (_: { + filetypes = ["qml" "qmljs"]; + }); + }; }) (mkIf (cfg.format.enable && !cfg.lsp.enable) { diff --git a/modules/plugins/languages/r.nix b/modules/plugins/languages/r.nix index 764e0eba..44addba4 100644 --- a/modules/plugins/languages/r.nix +++ b/modules/plugins/languages/r.nix @@ -7,18 +7,13 @@ inherit (builtins) attrNames; inherit (lib.options) mkEnableOption mkOption literalExpression; inherit (lib.modules) mkIf mkMerge; - inherit (lib.types) enum; - inherit (lib.meta) getExe; - inherit (lib.nvim.types) mkGrammarOption deprecatedSingleOrListOf; + inherit (lib.types) enum listOf; + inherit (lib) genAttrs; + inherit (lib.nvim.types) mkGrammarOption deprecatedSingleOrListOf enumWithRename; inherit (lib.nvim.attrsets) mapListToAttrs; - inherit (lib.generators) mkLuaInline; cfg = config.vim.languages.r; - r-with-languageserver = pkgs.rWrapper.override { - packages = [pkgs.rPackages.languageserver]; - }; - defaultFormat = ["format_r"]; formats = { styler = { @@ -47,19 +42,8 @@ }; }; - defaultServers = ["r_language_server"]; - servers = { - r_language_server = { - enable = true; - cmd = [(getExe r-with-languageserver) "--no-echo" "-e" "languageserver::run()"]; - filetypes = ["r" "rmd" "quarto"]; - root_dir = mkLuaInline '' - function(bufnr, on_dir) - on_dir(vim.fs.root(bufnr, '.git') or vim.uv.os_homedir()) - end - ''; - }; - }; + defaultServers = ["r-languageserver"]; + servers = ["r-languageserver"]; in { options.vim.languages.r = { enable = mkEnableOption "R language support"; @@ -83,7 +67,12 @@ in { }; servers = mkOption { - type = deprecatedSingleOrListOf "vim.language.r.lsp.servers" (enum (attrNames servers)); + type = listOf (enumWithRename + "vim.languages.r.lsp.servers" + servers + { + r_language_server = "r-languageserver"; + }); default = defaultServers; description = "R LSP server to use"; }; @@ -127,12 +116,12 @@ in { }) (mkIf cfg.lsp.enable { - vim.lsp.servers = - mapListToAttrs (n: { - name = n; - value = servers.${n}; - }) - cfg.lsp.servers; + vim.lsp = { + presets = genAttrs cfg.lsp.servers (_: {enable = true;}); + servers = genAttrs cfg.lsp.servers (_: { + filetypes = ["r" "rmd" "quarto"]; + }); + }; }) ]); } diff --git a/modules/plugins/languages/ruby.nix b/modules/plugins/languages/ruby.nix index 5ebcdea5..dc6ff702 100644 --- a/modules/plugins/languages/ruby.nix +++ b/modules/plugins/languages/ruby.nix @@ -6,46 +6,17 @@ }: let inherit (builtins) attrNames; inherit (lib.options) mkEnableOption mkOption literalExpression; + inherit (lib) genAttrs; inherit (lib.meta) getExe; inherit (lib.modules) mkIf mkMerge; - inherit (lib.nvim.types) mkGrammarOption diagnostics deprecatedSingleOrListOf; - inherit (lib.types) enum; + inherit (lib.nvim.types) mkGrammarOption diagnostics deprecatedSingleOrListOf enumWithRename; + inherit (lib.types) enum listOf; inherit (lib.nvim.attrsets) mapListToAttrs; cfg = config.vim.languages.ruby; defaultServers = ["solargraph"]; - servers = { - ruby_lsp = { - enable = true; - cmd = [(getExe pkgs.ruby-lsp)]; - filetypes = ["ruby" "eruby"]; - root_markers = ["Gemfile" ".git"]; - init_options = { - formatter = "auto"; - }; - }; - - solargraph = { - enable = true; - cmd = [(getExe pkgs.rubyPackages.solargraph) "stdio"]; - filetypes = ["ruby"]; - root_markers = ["Gemfile" ".git"]; - settings = { - solargraph = { - diagnostics = true; - }; - }; - - flags = { - debounce_text_changes = 150; - }; - - init_options = { - formatting = true; - }; - }; - }; + servers = ["ruby-lsp" "solargraph"]; # testing @@ -85,7 +56,12 @@ in { }; servers = mkOption { - type = deprecatedSingleOrListOf "vim.language.ruby.lsp.servers" (enum (attrNames servers)); + type = listOf (enumWithRename + "vim.languages.ruby.lsp.servers" + servers + { + ruby_lsp = "ruby-lsp"; + }); default = defaultServers; description = "Ruby LSP server to use"; }; @@ -121,12 +97,12 @@ in { }) (mkIf cfg.lsp.enable { - vim.lsp.servers = - mapListToAttrs (n: { - name = n; - value = servers.${n}; - }) - cfg.lsp.servers; + vim.lsp = { + presets = genAttrs cfg.lsp.servers (_: {enable = true;}); + servers = genAttrs cfg.lsp.servers (_: { + filetypes = ["ruby" "eruby"]; + }); + }; }) (mkIf cfg.format.enable { diff --git a/modules/plugins/languages/sql.nix b/modules/plugins/languages/sql.nix index 9aff0029..61ed04b4 100644 --- a/modules/plugins/languages/sql.nix +++ b/modules/plugins/languages/sql.nix @@ -6,33 +6,19 @@ }: let inherit (builtins) attrNames; inherit (lib.options) mkEnableOption mkOption literalExpression; + inherit (lib) genAttrs; inherit (lib.meta) getExe; inherit (lib.modules) mkIf mkMerge; - inherit (lib.types) enum package str; + inherit (lib.types) enum package str listOf; inherit (lib.nvim.types) diagnostics deprecatedSingleOrListOf; inherit (lib.nvim.attrsets) mapListToAttrs; - inherit (lib.generators) mkLuaInline; cfg = config.vim.languages.sql; sqlfluffDefault = pkgs.sqlfluff; sqruffDefault = pkgs.sqruff; defaultServers = ["sqls"]; - servers = { - sqls = { - enable = true; - cmd = [(getExe pkgs.sqls)]; - filetypes = ["sql" "mysql"]; - root_markers = ["config.yml"]; - settings = {}; - on_attach = mkLuaInline '' - function(client, bufnr) - client.server_capabilities.execute_command = true - require'sqls'.setup{} - end - ''; - }; - }; + servers = ["sqls"]; defaultFormat = ["sqlfluff"]; formats = { @@ -97,7 +83,7 @@ in { }; servers = mkOption { - type = deprecatedSingleOrListOf "vim.language.sql.lsp.servers" (enum (attrNames servers)); + type = listOf (enum servers); default = defaultServers; description = "SQL LSP server to use"; }; @@ -142,14 +128,12 @@ in { (mkIf cfg.lsp.enable { vim = { - startPlugins = ["sqls-nvim"]; - - lsp.servers = - mapListToAttrs (n: { - name = n; - value = servers.${n}; - }) - cfg.lsp.servers; + lsp = { + presets = genAttrs cfg.lsp.servers (_: {enable = true;}); + servers = genAttrs cfg.lsp.servers (_: { + filetypes = ["sql" "mysql" "msql" "plsql"]; + }); + }; }; }) diff --git a/modules/plugins/languages/svelte.nix b/modules/plugins/languages/svelte.nix index 73ed8019..10eea320 100644 --- a/modules/plugins/languages/svelte.nix +++ b/modules/plugins/languages/svelte.nix @@ -8,51 +8,16 @@ inherit (builtins) attrNames; inherit (lib.options) mkEnableOption mkOption literalExpression; inherit (lib.modules) mkIf mkMerge; + inherit (lib) genAttrs; inherit (lib.meta) getExe; - inherit (lib.types) enum coercedTo; + inherit (lib.types) enum coercedTo listOf; inherit (lib.nvim.types) mkGrammarOption diagnostics deprecatedSingleOrListOf; inherit (lib.nvim.attrsets) mapListToAttrs; - inherit (lib.generators) mkLuaInline; cfg = config.vim.languages.svelte; - defaultServers = ["svelte"]; - servers = { - svelte = { - enable = true; - cmd = [(getExe pkgs.svelte-language-server) "--stdio"]; - filetypes = ["svelte"]; - root_dir = mkLuaInline '' - function(bufnr, on_dir) - local root_files = { 'package.json', '.git' } - local fname = vim.api.nvim_buf_get_name(bufnr) - -- Svelte LSP only supports file:// schema. https://github.com/sveltejs/language-tools/issues/2777 - if vim.uv.fs_stat(fname) ~= nil then - on_dir(vim.fs.dirname(vim.fs.find(root_files, { path = fname, upward = true })[1])) - end - end - ''; - on_attach = mkLuaInline '' - function(client, bufnr) - vim.api.nvim_create_autocmd('BufWritePost', { - pattern = { '*.js', '*.ts' }, - group = vim.api.nvim_create_augroup('svelte_js_ts_file_watch', {}), - callback = function(ctx) - -- internal API to sync changes that have not yet been saved to the file system - client:notify('$/onDidChangeTsOrJsFile', { uri = ctx.match }) - end, - }) - - vim.api.nvim_buf_create_user_command(bufnr, 'LspMigrateToSvelte5', function() - client:exec_cmd({ - command = 'migrate_to_svelte_5', - arguments = { vim.uri_from_bufnr(bufnr) }, - }) - end, { desc = 'Migrate Component to Svelte 5 Syntax' }) - end - ''; - }; - }; + defaultServers = ["svelte-language-server"]; + servers = ["svelte-language-server"]; defaultFormat = ["prettier"]; formats = let @@ -123,7 +88,7 @@ in { }; servers = mkOption { - type = deprecatedSingleOrListOf "vim.language.svelte.lsp.servers" (enum (attrNames servers)); + type = listOf (enum servers); default = defaultServers; description = "Svelte LSP server to use"; }; @@ -167,12 +132,12 @@ in { }) (mkIf cfg.lsp.enable { - vim.lsp.servers = - mapListToAttrs (n: { - name = n; - value = servers.${n}; - }) - cfg.lsp.servers; + vim.lsp = { + presets = genAttrs cfg.lsp.servers (_: {enable = true;}); + servers = genAttrs cfg.lsp.servers (_: { + filetypes = ["svelte"]; + }); + }; }) (mkIf cfg.format.enable { diff --git a/modules/plugins/languages/terraform.nix b/modules/plugins/languages/terraform.nix index fbcc77da..6269540f 100644 --- a/modules/plugins/languages/terraform.nix +++ b/modules/plugins/languages/terraform.nix @@ -7,28 +7,16 @@ inherit (builtins) attrNames; inherit (lib.options) mkEnableOption mkOption literalExpression; inherit (lib.modules) mkIf mkMerge; + inherit (lib) genAttrs; inherit (lib.meta) getExe; inherit (lib.types) enum listOf; - inherit (lib.nvim.types) mkGrammarOption deprecatedSingleOrListOf; + inherit (lib.nvim.types) mkGrammarOption enumWithRename; inherit (lib.nvim.attrsets) mapListToAttrs; cfg = config.vim.languages.terraform; - defaultServers = ["tofuls-tf"]; - servers = { - terraformls-tf = { - enable = true; - cmd = [(getExe pkgs.terraform-ls) "serve"]; - filetypes = ["terraform" "terraform-vars" "tf"]; - root_markers = [".terraform" ".git"]; - }; - tofuls-tf = { - enable = true; - cmd = [(getExe pkgs.tofu-ls) "serve"]; - filetypes = ["terraform" "terraform-vars" "tf"]; - root_markers = [".terraform" ".git"]; - }; - }; + defaultServers = ["tofu-ls"]; + servers = ["terraform-ls" "tofu-ls"]; defaultFormat = ["tofu-fmt"]; formats = { @@ -65,7 +53,13 @@ in { defaultText = literalExpression "config.vim.lsp.enable"; }; servers = mkOption { - type = listOf (enum (attrNames servers)); + type = listOf (enumWithRename + "vim.languages.terraform.lsp.servers" + servers + { + terraformls-tf = "terraform-ls"; + tofuls-tf = "tofu-ls"; + }); default = defaultServers; description = "Terraform LSP server to use"; }; @@ -93,13 +87,11 @@ in { }) (mkIf cfg.lsp.enable { - vim = { - lsp.servers = - mapListToAttrs (n: { - name = n; - value = servers.${n}; - }) - cfg.lsp.servers; + vim.lsp = { + presets = genAttrs cfg.lsp.servers (_: {enable = true;}); + servers = genAttrs cfg.lsp.servers (_: { + filetypes = ["terraform" "terraform-vars" "tf"]; + }); }; }) diff --git a/modules/plugins/languages/tex.nix b/modules/plugins/languages/tex.nix index 6c22240c..aeedd353 100644 --- a/modules/plugins/languages/tex.nix +++ b/modules/plugins/languages/tex.nix @@ -5,6 +5,7 @@ ... }: let inherit (builtins) attrNames; + inherit (lib) genAttrs; inherit (lib.meta) getExe; inherit (lib.modules) mkIf mkMerge; inherit (lib.options) literalExpression mkEnableOption mkOption; @@ -14,14 +15,7 @@ cfg = config.vim.languages.tex; defaultServers = ["texlab"]; - servers = { - texlab = { - enable = true; - cmd = [(getExe pkgs.texlab) "run"]; - filetypes = ["plaintex" "tex" "bib"]; - root_markers = [".git" ".latexmkrc" "latexmkrc" ".texlabroot" "texlabroot" ".texstudio" "Tectonic.toml"]; - }; - }; + servers = ["texlab"]; defaultFormat = ["tex-fmt"]; formats = { @@ -57,7 +51,7 @@ in { servers = mkOption { description = "TeX LSP server to use"; - type = listOf (enum (attrNames servers)); + type = listOf (enum servers); default = defaultServers; }; }; @@ -88,12 +82,12 @@ in { }) (mkIf cfg.lsp.enable { - vim.lsp.servers = - mapListToAttrs (n: { - name = n; - value = servers.${n}; - }) - cfg.lsp.servers; + vim.lsp = { + presets = genAttrs cfg.lsp.servers (_: {enable = true;}); + servers = genAttrs cfg.lsp.servers (_: { + filetypes = ["plaintex" "tex" "bib"]; + }); + }; }) (mkIf cfg.format.enable { diff --git a/modules/plugins/languages/toml.nix b/modules/plugins/languages/toml.nix index 1ead6c7c..fc7fd930 100644 --- a/modules/plugins/languages/toml.nix +++ b/modules/plugins/languages/toml.nix @@ -5,41 +5,17 @@ ... }: let inherit (builtins) attrNames; + inherit (lib) genAttrs; inherit (lib.meta) getExe; inherit (lib.modules) mkIf mkMerge; inherit (lib.options) mkEnableOption mkOption literalExpression; - inherit (lib.types) enum; + inherit (lib.types) enum listOf; inherit (lib.nvim.types) diagnostics mkGrammarOption deprecatedSingleOrListOf; inherit (lib.nvim.attrsets) mapListToAttrs; cfg = config.vim.languages.toml; defaultServers = ["taplo"]; - servers = { - tombi = { - enable = true; - cmd = [ - (getExe pkgs.tombi) - "lsp" - ]; - filetypes = ["toml"]; - root_markers = [ - "tombi.toml" - ".git" - ]; - }; - taplo = { - enable = true; - cmd = [ - (getExe pkgs.taplo) - "lsp" - "stdio" - ]; - filetypes = ["toml"]; - root_markers = [ - ".git" - ]; - }; - }; + servers = ["taplo" "tombi"]; defaultFormat = ["taplo"]; formats = { @@ -93,7 +69,7 @@ in { servers = mkOption { description = "TOML LSP server to use"; - type = deprecatedSingleOrListOf "vim.language.toml.lsp.servers" (enum (attrNames servers)); + type = listOf (enum servers); default = defaultServers; }; }; @@ -137,12 +113,12 @@ in { }) (mkIf cfg.lsp.enable { - vim.lsp.servers = - mapListToAttrs (n: { - name = n; - value = servers.${n}; - }) - cfg.lsp.servers; + vim.lsp = { + presets = genAttrs cfg.lsp.servers (_: {enable = true;}); + servers = genAttrs cfg.lsp.servers (_: { + filetypes = ["toml"]; + }); + }; }) (mkIf cfg.format.enable { diff --git a/modules/plugins/languages/ts.nix b/modules/plugins/languages/ts.nix index c3e162e0..4c38cba1 100644 --- a/modules/plugins/languages/ts.nix +++ b/modules/plugins/languages/ts.nix @@ -7,183 +7,18 @@ inherit (builtins) attrNames elem; inherit (lib.options) mkEnableOption mkOption literalExpression; inherit (lib.modules) mkIf mkMerge; + inherit (lib) genAttrs; inherit (lib.meta) getExe; - inherit (lib.types) enum package bool; - inherit (lib.generators) mkLuaInline; + inherit (lib.types) enum bool listOf; inherit (lib.nvim.attrsets) mapListToAttrs; inherit (lib.nvim.lua) toLuaObject; - inherit (lib.nvim.types) mkGrammarOption diagnostics mkPluginSetupOption deprecatedSingleOrListOf; - inherit (lib.nvim.dag) entryAnywhere entryBefore; + inherit (lib.nvim.types) mkGrammarOption diagnostics mkPluginSetupOption deprecatedSingleOrListOf enumWithRename; + inherit (lib.nvim.dag) entryAnywhere; cfg = config.vim.languages.ts; - defaultServers = ["ts_ls"]; - servers = let - ts_ls = { - cmd = [(getExe pkgs.typescript-language-server) "--stdio"]; - init_options = {hostInfo = "neovim";}; - filetypes = [ - "javascript" - "javascriptreact" - "javascript.jsx" - "typescript" - "typescriptreact" - "typescript.tsx" - ]; - root_markers = ["tsconfig.json" "jsconfig.json" "package.json" ".git"]; - handlers = { - # handle rename request for certain code actions like extracting functions / types - "_typescript.rename" = mkLuaInline '' - function(_, result, ctx) - local client = assert(vim.lsp.get_client_by_id(ctx.client_id)) - vim.lsp.util.show_document({ - uri = result.textDocument.uri, - range = { - start = result.position, - ['end'] = result.position, - }, - }, client.offset_encoding) - vim.lsp.buf.rename() - return vim.NIL - end - ''; - }; - on_attach = mkLuaInline '' - function(client, bufnr) - -- ts_ls provides `source.*` code actions that apply to the whole file. These only appear in - -- `vim.lsp.buf.code_action()` if specified in `context.only`. - vim.api.nvim_buf_create_user_command(0, 'LspTypescriptSourceAction', function() - local source_actions = vim.tbl_filter(function(action) - return vim.startswith(action, 'source.') - end, client.server_capabilities.codeActionProvider.codeActionKinds) - - vim.lsp.buf.code_action({ - context = { - only = source_actions, - }, - }) - end, {}) - end - ''; - }; - in { - inherit ts_ls; - # Here for backwards compatibility. Still consider tsserver a valid - # configuration in the enum, but assert if it's set to *properly* - # redirect the user to the correct server. - tsserver = ts_ls; - - denols = { - cmd = [(getExe pkgs.deno) "lsp"]; - cmd_env = {NO_COLOR = true;}; - filetypes = [ - "javascript" - "javascriptreact" - "javascript.jsx" - "typescript" - "typescriptreact" - "typescript.tsx" - ]; - root_markers = ["deno.json" "deno.jsonc" ".git"]; - settings = { - deno = { - enable = true; - suggest = { - imports = { - hosts = { - "https://deno.land" = true; - }; - }; - }; - }; - }; - handlers = { - "textDocument/definition" = mkLuaInline "nvf_denols_handler"; - "textDocument/typeDefinition" = mkLuaInline "nvf_denols_handler"; - "textDocument/references" = mkLuaInline "nvf_denols_handler"; - }; - on_attach = mkLuaInline '' - function(client, bufnr) - vim.api.nvim_buf_create_user_command(0, 'LspDenolsCache', function() - client:exec_cmd({ - command = 'deno.cache', - arguments = { {}, vim.uri_from_bufnr(bufnr) }, - }, { bufnr = bufnr }, function(err, _result, ctx) - if err then - local uri = ctx.params.arguments[2] - vim.api.nvim_err_writeln('cache command failed for ' .. vim.uri_to_fname(uri)) - end - end) - end, { - desc = 'Cache a module and all of its dependencies.', - }) - end - ''; - }; - - tsgo = { - cmd = [(getExe pkgs.typescript-go) "--lsp" "--stdio"]; - filetypes = [ - "javascript" - "javascriptreact" - "javascript.jsx" - "typescript" - "typescriptreact" - "typescript.tsx" - ]; - root_markers = ["tsconfig.json" "jsconfig.json" "package.json" ".git"]; - }; - }; - - denols_handlers = '' - local function nvf_denols_virtual_text_document_handler(uri, res, client) - if not res then - return nil - end - - local lines = vim.split(res.result, '\n') - local bufnr = vim.uri_to_bufnr(uri) - - local current_buf = vim.api.nvim_buf_get_lines(bufnr, 0, -1, false) - if #current_buf ~= 0 then - return nil - end - - vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, lines) - vim.api.nvim_set_option_value('readonly', true, { buf = bufnr }) - vim.api.nvim_set_option_value('modified', false, { buf = bufnr }) - vim.api.nvim_set_option_value('modifiable', false, { buf = bufnr }) - vim.lsp.buf_attach_client(bufnr, client.id) - end - - local function nvf_denols_virtual_text_document(uri, client) - local params = { - textDocument = { - uri = uri, - }, - } - local result = client.request_sync('deno/virtualTextDocument', params) - nvf_denols_virtual_text_document_handler(uri, result, client) - end - - local function nvf_denols_handler(err, result, ctx, config) - if not result or vim.tbl_isempty(result) then - return nil - end - - local client = vim.lsp.get_client_by_id(ctx.client_id) - for _, res in pairs(result) do - local uri = res.uri or res.targetUri - if uri:match '^deno:' then - nvf_denols_virtual_text_document(uri, client) - res['uri'] = uri - res['targetUri'] = uri - end - end - - vim.lsp.handlers[ctx.method](err, result, ctx, config) - end - ''; + defaultServers = ["typescript-language-server"]; + servers = ["typescript-language-server" "deno" "typescript-go"]; # TODO: specify packages defaultFormat = ["prettier"]; @@ -264,7 +99,14 @@ in { }; servers = mkOption { - type = deprecatedSingleOrListOf "vim.language.ts.lsp.servers" (enum (attrNames servers)); + type = listOf (enumWithRename + "vim.languages.ts.lsp.servers" + servers + { + ts_ls = "typescript-language-server"; + denols = "deno"; + tsgo = "typescript-go"; + }); default = defaultServers; description = "Typescript/Javascript LSP server to use"; }; @@ -317,6 +159,8 @@ in { }; config = mkIf cfg.enable (mkMerge [ + {vim.globals.markdown_fenced_languages = ["ts=typescript"];} + (mkIf cfg.treesitter.enable { vim.treesitter.enable = true; vim.treesitter.grammars = [ @@ -327,17 +171,22 @@ in { }) (mkIf cfg.lsp.enable { - vim.lsp.servers = - mapListToAttrs (name: { - inherit name; - value = servers.${name}; - }) - cfg.lsp.servers; - }) - - (mkIf (cfg.lsp.enable && elem "denols" cfg.lsp.servers) { - vim.globals.markdown_fenced_languages = ["ts=typescript"]; - vim.luaConfigRC.denols_handlers = entryBefore ["lsp-servers"] denols_handlers; + vim.lsp = { + presets = genAttrs cfg.lsp.servers (_: {enable = true;}); + servers = genAttrs cfg.lsp.servers (_: { + root_markers = ["tsconfig.json"]; + filetypes = [ + "typescript" + # TODO: move to a React module + "typescriptreact" + "typescript.tsx" + "javascriptreact" + "javascript.jsx" + # TODO: move to a JavaScript module + "javascript" + ]; + }); + }; }) (mkIf cfg.format.enable { @@ -380,21 +229,20 @@ in { ''; }) - # Warn the user if they have set the default server name to tsserver to match upstream (us) - # The name "tsserver" has been deprecated in lspconfig, and now should be called ts_ls. This - # is a purely cosmetic change, but emits a warning if not accounted for. + # Warn the user if they have set the default server name to "tsserver" to match upstream (us) + # The name "tsserver" has been deprecated, and now should be called "typescript-language-server". { assertions = [ { assertion = cfg.lsp.enable -> !(elem "tsserver" cfg.lsp.servers); message = '' - As of a recent lspconfig update, the `tsserver` configuration has been renamed - to `ts_ls` to match upstream behaviour of `lspconfig`, and the name `tsserver` - is no longer considered valid by nvf. Please set `vim.languages.ts.lsp.server` - to `"ts_ls"` instead of to `${cfg.lsp.server}` + The name `tsserver` has been deprecated, and now should be called `typescript-language-server`. + Please set `vim.languages.ts.lsp.server` to `["typescript-language-server" ...]` instead of to `["tsserver" ...]` - Please see for more details - about this change. + Please see: + - + - + for more details about this change. ''; } ]; diff --git a/modules/plugins/languages/twig.nix b/modules/plugins/languages/twig.nix index 36e64838..b6a3c530 100644 --- a/modules/plugins/languages/twig.nix +++ b/modules/plugins/languages/twig.nix @@ -7,6 +7,7 @@ inherit (builtins) attrNames; inherit (lib.options) mkEnableOption mkOption literalExpression; inherit (lib.modules) mkIf mkMerge; + inherit (lib) genAttrs; inherit (lib.meta) getExe; inherit (lib.types) listOf enum; inherit (lib.nvim.types) mkGrammarOption diagnostics; @@ -15,14 +16,7 @@ cfg = config.vim.languages.twig; defaultServers = ["twig-language-server"]; - servers = { - twig-language-server = { - enable = true; - cmd = [(getExe pkgs.twig-language-server) "--stdio"]; - filetypes = ["twig"]; - root_markers = [".git"]; - }; - }; + servers = ["twig-language-server"]; defaultFormat = ["djlint"]; formats = { @@ -62,7 +56,7 @@ in { defaultText = literalExpression "config.vim.lsp.enable"; }; servers = mkOption { - type = listOf (enum (attrNames servers)); + type = listOf (enum servers); default = defaultServers; description = "Twig LSP server to use"; }; @@ -104,12 +98,12 @@ in { }) (mkIf cfg.lsp.enable { - vim.lsp.servers = - mapListToAttrs (n: { - name = n; - value = servers.${n}; - }) - cfg.lsp.servers; + vim.lsp = { + presets = genAttrs cfg.lsp.servers (_: {enable = true;}); + servers = genAttrs cfg.lsp.servers (_: { + filetypes = ["twig"]; + }); + }; }) (mkIf cfg.format.enable { diff --git a/modules/plugins/languages/typst.nix b/modules/plugins/languages/typst.nix index 7cada25b..e6b08373 100644 --- a/modules/plugins/languages/typst.nix +++ b/modules/plugins/languages/typst.nix @@ -6,92 +6,21 @@ }: let inherit (lib.options) mkOption mkEnableOption literalExpression; inherit (lib.modules) mkIf mkMerge; - inherit (lib.types) nullOr enum attrsOf listOf package str bool int; + inherit (lib.types) nullOr enum attrsOf listOf str bool int; inherit (lib.attrsets) attrNames; + inherit (lib) genAttrs; inherit (lib.meta) getExe; inherit (lib.nvim.types) mkGrammarOption mkPluginSetupOption deprecatedSingleOrListOf; inherit (lib.nvim.dag) entryAnywhere; inherit (lib.nvim.lua) toLuaObject; inherit (lib.nvim.attrsets) mapListToAttrs; inherit (lib.nvim.binds) mkKeymap; - inherit (lib.generators) mkLuaInline; inherit (config.vim.lib) mkMappingOption; cfg = config.vim.languages.typst; defaultServers = ["tinymist"]; - servers = { - typst_lsp = { - enable = true; - cmd = [(getExe pkgs.typst-lsp)]; - filetypes = ["typst"]; - root_markers = [".git"]; - on_attach = mkLuaInline '' - function(client, bufnr) - -- Disable semantic tokens as a workaround for a semantic token error when using non-english characters - client.server_capabilities.semanticTokensProvider = nil - end - ''; - }; - - tinymist = { - enable = true; - cmd = [(getExe pkgs.tinymist)]; - filetypes = ["typst"]; - root_markers = [".git"]; - on_attach = mkLuaInline '' - function(client, bufnr) - local function create_tinymist_command(command_name, client, bufnr) - local export_type = command_name:match 'tinymist%.export(%w+)' - local info_type = command_name:match 'tinymist%.(%w+)' - if info_type and info_type:match '^get' then - info_type = info_type:gsub('^get', 'Get') - end - local cmd_display = export_type or info_type - local function run_tinymist_command() - local arguments = { vim.api.nvim_buf_get_name(bufnr) } - local title_str = export_type and ('Export ' .. cmd_display) or cmd_display - local function handler(err, res) - if err then - return vim.notify(err.code .. ': ' .. err.message, vim.log.levels.ERROR) - end - vim.notify(export_type and res or vim.inspect(res), vim.log.levels.INFO) - end - if vim.fn.has 'nvim-0.11' == 1 then - return client:exec_cmd({ - title = title_str, - command = command_name, - arguments = arguments, - }, { bufnr = bufnr }, handler) - else - return vim.notify('Tinymist commands require Neovim 0.11+', vim.log.levels.WARN) - end - end - local cmd_name = export_type and ('LspTinymistExport' .. cmd_display) or ('LspTinymist' .. cmd_display) - local cmd_desc = export_type and ('Export to ' .. cmd_display) or ('Get ' .. cmd_display) - return run_tinymist_command, cmd_name, cmd_desc - end - - for _, command in ipairs { - 'tinymist.exportSvg', - 'tinymist.exportPng', - 'tinymist.exportPdf', - 'tinymist.exportMarkdown', - 'tinymist.exportText', - 'tinymist.exportQuery', - 'tinymist.exportAnsiHighlight', - 'tinymist.getServerInfo', - 'tinymist.getDocumentTrace', - 'tinymist.getWorkspaceLabels', - 'tinymist.getDocumentMetrics', - } do - local cmd_func, cmd_name, cmd_desc = create_tinymist_command(command, client, bufnr) - vim.api.nvim_buf_create_user_command(bufnr, cmd_name, cmd_func, { nargs = 0, desc = cmd_desc }) - end - end - ''; - }; - }; + servers = ["tinymist"]; defaultFormat = ["typstyle"]; formats = { @@ -123,7 +52,7 @@ in { }; servers = mkOption { - type = deprecatedSingleOrListOf "vim.language.typst.lsp.servers" (enum (attrNames servers)); + type = listOf (enum servers); default = defaultServers; description = "Typst LSP server to use"; }; @@ -261,12 +190,12 @@ in { }) (mkIf cfg.lsp.enable { - vim.lsp.servers = - mapListToAttrs (n: { - name = n; - value = servers.${n}; - }) - cfg.lsp.servers; + vim.lsp = { + presets = genAttrs cfg.lsp.servers (_: {enable = true;}); + servers = genAttrs cfg.lsp.servers (_: { + filetypes = ["typst"]; + }); + }; }) # Extensions diff --git a/modules/plugins/languages/vala.nix b/modules/plugins/languages/vala.nix index b3376daf..5defc722 100644 --- a/modules/plugins/languages/vala.nix +++ b/modules/plugins/languages/vala.nix @@ -4,64 +4,16 @@ lib, ... }: let - inherit (builtins) attrNames; inherit (lib.options) mkEnableOption mkOption literalExpression; inherit (lib.modules) mkIf mkMerge; - inherit (lib.meta) getExe; - inherit (lib.types) enum; - inherit (lib.nvim.types) mkGrammarOption deprecatedSingleOrListOf; - inherit (lib.nvim.attrsets) mapListToAttrs; - inherit (lib.generators) mkLuaInline; + inherit (lib) genAttrs; + inherit (lib.types) listOf; + inherit (lib.nvim.types) mkGrammarOption enumWithRename; cfg = config.vim.languages.vala; - defaultServers = ["vala_ls"]; - servers = { - vala_ls = { - enable = true; - cmd = [ - (getExe (pkgs.symlinkJoin { - name = "vala-language-server-wrapper"; - paths = [pkgs.vala-language-server]; - meta.mainProgram = "vala-language-server-wrapper"; - buildInputs = [pkgs.makeBinaryWrapper]; - postBuild = '' - wrapProgram $out/bin/vala-language-server \ - --prefix PATH : ${pkgs.uncrustify}/bin - ''; - })) - ]; - filetypes = ["vala" "genie"]; - root_dir = mkLuaInline '' - function(bufnr, on_dir) - local meson_matcher = function(path) - local pattern = 'meson.build' - local f = vim.fn.glob(table.concat({ path, pattern }, '/')) - if f == ''' then - return nil - end - for line in io.lines(f) do - -- skip meson comments - if not line:match '^%s*#.*' then - local str = line:gsub('%s+', ''') - if str ~= ''' then - if str:match '^project%(' then - return path - else - break - end - end - end - end - end - - local fname = vim.api.nvim_buf_get_name(bufnr) - local root = vim.iter(vim.fs.parents(fname)):find(meson_matcher) - on_dir(root or vim.fs.dirname(vim.fs.find('.git', { path = fname, upward = true })[1])) - end - ''; - }; - }; + defaultServers = ["vala-language-server"]; + servers = ["vala-language-server"]; in { options.vim.languages.vala = { enable = mkEnableOption "Vala language support"; @@ -84,7 +36,12 @@ in { defaultText = literalExpression "config.vim.lsp.enable"; }; servers = mkOption { - type = deprecatedSingleOrListOf "vim.language.vala.lsp.servers" (enum (attrNames servers)); + type = listOf (enumWithRename + "vim.languages.vala.lsp.servers" + servers + { + vala_ls = "vala-language-server"; + }); default = defaultServers; description = "Vala LSP server to use"; }; @@ -98,12 +55,12 @@ in { }) (mkIf cfg.lsp.enable { - vim.lsp.servers = - mapListToAttrs (n: { - name = n; - value = servers.${n}; - }) - cfg.lsp.servers; + vim.lsp = { + presets = genAttrs cfg.lsp.servers (_: {enable = true;}); + servers = genAttrs cfg.lsp.servers (_: { + filetypes = ["vala"]; + }); + }; }) ]); } diff --git a/modules/plugins/languages/wgsl.nix b/modules/plugins/languages/wgsl.nix index 016f6c4a..aa99022c 100644 --- a/modules/plugins/languages/wgsl.nix +++ b/modules/plugins/languages/wgsl.nix @@ -4,26 +4,16 @@ pkgs, ... }: let - inherit (builtins) attrNames; inherit (lib.modules) mkIf mkMerge; - inherit (lib.nvim.types) mkGrammarOption deprecatedSingleOrListOf; + inherit (lib.nvim.types) mkGrammarOption; inherit (lib.options) mkEnableOption mkOption literalExpression; - inherit (lib.types) enum; - inherit (lib.meta) getExe; - inherit (lib.nvim.attrsets) mapListToAttrs; + inherit (lib.types) enum listOf; + inherit (lib) genAttrs; cfg = config.vim.languages.wgsl; defaultServers = ["wgsl-analyzer"]; - servers = { - wgsl-analyzer = { - enable = true; - cmd = [(getExe pkgs.wgsl-analyzer)]; - filetypes = ["wgsl"]; - root_markers = [".git"]; - settings = {}; - }; - }; + servers = ["wgsl-analyzer"]; in { options.vim.languages.wgsl = { enable = mkEnableOption "WGSL language support"; @@ -47,7 +37,7 @@ in { }; servers = mkOption { - type = deprecatedSingleOrListOf "vim.language.wgsl.lsp.servers" (enum (attrNames servers)); + type = listOf (enum servers); default = defaultServers; description = "WGSL LSP server to use"; }; @@ -63,12 +53,12 @@ in { }) (mkIf cfg.lsp.enable { - vim.lsp.servers = - mapListToAttrs (n: { - name = n; - value = servers.${n}; - }) - cfg.lsp.servers; + vim.lsp = { + presets = genAttrs cfg.lsp.servers (_: {enable = true;}); + servers = genAttrs cfg.lsp.servers (_: { + filetypes = ["wgsl"]; + }); + }; }) ]); } diff --git a/modules/plugins/languages/xml.nix b/modules/plugins/languages/xml.nix index 7eae0026..217f2949 100644 --- a/modules/plugins/languages/xml.nix +++ b/modules/plugins/languages/xml.nix @@ -4,27 +4,16 @@ lib, ... }: let - inherit (builtins) attrNames; inherit (lib.options) mkOption mkEnableOption literalExpression; - inherit (lib.meta) getExe; inherit (lib.modules) mkIf mkMerge; inherit (lib.types) enum listOf; inherit (lib.nvim.types) mkGrammarOption; - inherit (lib.nvim.attrsets) mapListToAttrs; + inherit (lib) genAttrs; cfg = config.vim.languages.xml; defaultServers = ["lemminx"]; - servers = { - lemminx = { - enable = true; - cmd = [ - (getExe pkgs.lemminx) - ]; - filetypes = ["xml"]; - root_markers = [".git"]; - }; - }; + servers = ["lemminx"]; in { options.vim.languages.xml = { enable = mkEnableOption "XML language support"; @@ -47,7 +36,7 @@ in { defaultText = literalExpression "config.vim.lsp.enable"; }; servers = mkOption { - type = listOf (enum (attrNames servers)); + type = listOf (enum servers); default = defaultServers; description = "XML LSP server to use"; }; @@ -61,12 +50,12 @@ in { }) (mkIf cfg.lsp.enable { - vim.lsp.servers = - mapListToAttrs (name: { - inherit name; - value = servers.${name}; - }) - cfg.lsp.servers; + vim.lsp = { + presets = genAttrs cfg.lsp.servers (_: {enable = true;}); + servers = genAttrs cfg.lsp.servers (_: { + filetypes = ["xml"]; + }); + }; }) ]); } diff --git a/modules/plugins/languages/yaml.nix b/modules/plugins/languages/yaml.nix index 097b98c5..bba0eba3 100644 --- a/modules/plugins/languages/yaml.nix +++ b/modules/plugins/languages/yaml.nix @@ -4,48 +4,16 @@ lib, ... }: let - inherit (builtins) attrNames; - inherit (lib.generators) mkLuaInline; inherit (lib.options) mkEnableOption mkOption literalExpression; inherit (lib.modules) mkIf mkMerge; - inherit (lib.meta) getExe; - inherit (lib.types) enum; - inherit (lib.nvim.types) mkGrammarOption deprecatedSingleOrListOf; - inherit (lib.nvim.attrsets) mapListToAttrs; + inherit (lib) genAttrs; + inherit (lib.types) enum listOf; + inherit (lib.nvim.types) mkGrammarOption; cfg = config.vim.languages.yaml; - on_attach = - if config.vim.languages.helm.lsp.enable && config.vim.languages.helm.enable - then - mkLuaInline '' - function(client, bufnr) - local filetype = vim.bo[bufnr].filetype - if filetype == "helm" then - client.stop() - end - end - '' - else null; - defaultServers = ["yaml-language-server"]; - servers = { - yaml-language-server = { - enable = true; - cmd = [(getExe pkgs.yaml-language-server) "--stdio"]; - filetypes = ["yaml" "yaml.docker-compose" "yaml.gitlab" "yaml.helm-values"]; - root_markers = [".git"]; - inherit on_attach; - # -- https://github.com/redhat-developer/vscode-redhat-telemetry#how-to-disable-telemetry-reporting - settings = { - redhat = { - telemetry = { - enabled = false; - }; - }; - }; - }; - }; + servers = ["yaml-language-server"]; in { options.vim.languages.yaml = { enable = mkEnableOption "YAML language support"; @@ -69,7 +37,7 @@ in { defaultText = literalExpression "config.vim.lsp.enable"; }; servers = mkOption { - type = deprecatedSingleOrListOf "vim.language.yaml.lsp.servers" (enum (attrNames servers)); + type = listOf (enum servers); default = defaultServers; description = "Yaml LSP server to use"; }; @@ -83,12 +51,12 @@ in { }) (mkIf cfg.lsp.enable { - vim.lsp.servers = - mapListToAttrs (n: { - name = n; - value = servers.${n}; - }) - cfg.lsp.servers; + vim.lsp = { + presets = genAttrs cfg.lsp.servers (_: {enable = true;}); + servers = genAttrs cfg.lsp.servers (_: { + filetypes = ["yaml"]; + }); + }; }) ]); } diff --git a/modules/plugins/languages/zig.nix b/modules/plugins/languages/zig.nix index 5e1db977..a9589f9c 100644 --- a/modules/plugins/languages/zig.nix +++ b/modules/plugins/languages/zig.nix @@ -7,23 +7,14 @@ inherit (builtins) attrNames; inherit (lib.options) mkEnableOption mkOption literalExpression; inherit (lib.modules) mkIf mkMerge mkDefault; - inherit (lib.types) bool package enum; - inherit (lib.nvim.types) mkGrammarOption deprecatedSingleOrListOf; - inherit (lib.meta) getExe; - inherit (lib.nvim.attrsets) mapListToAttrs; + inherit (lib) genAttrs; + inherit (lib.types) bool package enum listOf; + inherit (lib.nvim.types) mkGrammarOption; cfg = config.vim.languages.zig; defaultServers = ["zls"]; - servers = { - zls = { - enable = true; - cmd = [(getExe pkgs.zls)]; - filetypes = ["zig" "zir"]; - root_markers = ["zls.json" "build.zig" ".git"]; - workspace_required = false; - }; - }; + servers = ["zls"]; # TODO: dap.adapter.lldb is duplicated when enabling the # vim.languages.clang.dap module. This does not cause @@ -77,7 +68,7 @@ in { }; servers = mkOption { - type = deprecatedSingleOrListOf "vim.language.zig.lsp.servers" (enum (attrNames servers)); + type = listOf (enum servers); default = defaultServers; description = "Zig LSP server to use"; }; @@ -115,13 +106,13 @@ in { (mkIf cfg.lsp.enable { vim = { - lsp.servers = - mapListToAttrs (n: { - name = n; - value = servers.${n}; - }) - cfg.lsp.servers; - + lsp = { + presets = genAttrs cfg.lsp.servers (_: {enable = true;}); + servers = genAttrs cfg.lsp.servers (_: { + root_markers = ["build.zig"]; + filetypes = ["zig" "zir"]; + }); + }; # nvf handles autosaving already globals.zig_fmt_autosave = mkDefault 0; }; diff --git a/modules/plugins/lsp/default.nix b/modules/plugins/lsp/default.nix index ed20685d..6f135858 100644 --- a/modules/plugins/lsp/default.nix +++ b/modules/plugins/lsp/default.nix @@ -4,10 +4,11 @@ ./config.nix ./module.nix + ./presets + ./lspconfig ./lspsaga ./null-ls - ./harper-ls # lsp plugins ./lspsaga diff --git a/modules/plugins/lsp/harper-ls/config.nix b/modules/plugins/lsp/harper-ls/config.nix deleted file mode 100644 index 41a51c62..00000000 --- a/modules/plugins/lsp/harper-ls/config.nix +++ /dev/null @@ -1,57 +0,0 @@ -{ - config, - lib, - pkgs, - ... -}: let - inherit (lib.modules) mkIf; - inherit (lib.meta) getExe; - - cfg = config.vim.lsp; -in { - config = mkIf (cfg.enable && cfg.harper-ls.enable) { - vim.lsp.servers.harper-ls = { - root_markers = [".git" ".harper-dictionary.txt"]; - cmd = [(getExe pkgs.harper) "--stdio"]; - settings = {harper-ls = cfg.harper-ls.settings;}; - filetypes = - # - [ - "asciidoc" - "c" - "clojure" - "cmake" - "cpp" - "cs" - "daml" - "dart" - "gitcommit" - "go" - "haskell" - "html" - "ink" - "java" - "javascript" - "javascriptreact" - "kotlin" - "lhaskell" - "lua" - "mail" - "markdown" - "nix" - "php" - "python" - "ruby" - "rust" - "scala" - "sh" - "swift" - "text" - "toml" - "typescript" - "typescriptreact" - "typst" - ]; - }; - }; -} diff --git a/modules/plugins/lsp/harper-ls/default.nix b/modules/plugins/lsp/harper-ls/default.nix deleted file mode 100644 index 9b4b3ec7..00000000 --- a/modules/plugins/lsp/harper-ls/default.nix +++ /dev/null @@ -1,6 +0,0 @@ -{ - imports = [ - ./harper-ls.nix - ./config.nix - ]; -} diff --git a/modules/plugins/lsp/harper-ls/harper-ls.nix b/modules/plugins/lsp/harper-ls/harper-ls.nix deleted file mode 100644 index 9fab45fe..00000000 --- a/modules/plugins/lsp/harper-ls/harper-ls.nix +++ /dev/null @@ -1,35 +0,0 @@ -{lib, ...}: let - inherit (lib.options) mkOption mkEnableOption; - inherit (lib.types) anything attrsOf; -in { - options.vim.lsp.harper-ls = { - enable = mkEnableOption "Harper grammar checking LSP"; - settings = mkOption { - type = attrsOf anything; - default = {}; - example = { - userDictPath = ""; - workspaceDictPath = ""; - fileDictPath = ""; - linters = { - BoringWords = true; - PossessiveNoun = true; - SentenceCapitalization = false; - SpellCheck = false; - }; - codeActions = { - ForceStable = false; - }; - markdown = { - IgnoreLinkTitle = false; - }; - diagnosticSeverity = "hint"; - isolateEnglish = false; - dialect = "American"; - maxFileLength = 120000; - ignoredLintsPath = {}; - }; - description = "Settings to pass to harper-ls"; - }; - }; -} diff --git a/modules/plugins/lsp/presets/arduino-language-server.nix b/modules/plugins/lsp/presets/arduino-language-server.nix new file mode 100644 index 00000000..af492255 --- /dev/null +++ b/modules/plugins/lsp/presets/arduino-language-server.nix @@ -0,0 +1,46 @@ +{ + config, + lib, + pkgs, + ... +}: let + inherit (lib.meta) getExe getExe'; + inherit (lib.modules) mkIf; + inherit (lib.nvim.types) mkLspPresetEnableOption; + inherit (lib.generators) mkLuaInline; + + cfg = config.vim.lsp.presets.arduino-language-server; +in { + options.vim.lsp.presets.arduino-language-server = { + enable = mkLspPresetEnableOption "arduino-language-server" "Arduino" []; + }; + + config = mkIf cfg.enable { + vim.lsp.servers.arduino-language-server = { + enable = true; + cmd = [ + (getExe pkgs.arduino-language-server) + "-clangd" + (getExe' pkgs.clang-tools "clangd") + "-cli" + (getExe pkgs.arduino-cli) + "-cli-config" + "$HOME/.arduino15/arduino-cli.yaml" + ]; + root_dir = mkLuaInline '' + function(bufnr, on_dir) + local fname = vim.api.nvim_buf_get_name(bufnr) + on_dir(util.root_pattern("*.ino")(fname)) + end + ''; + capabilities = { + textDocument = { + semanticTokens = mkLuaInline "vim.NIL"; + }; + workspace = { + semanticTokens = mkLuaInline "vim.NIL"; + }; + }; + }; + }; +} diff --git a/modules/plugins/lsp/presets/asm-lsp.nix b/modules/plugins/lsp/presets/asm-lsp.nix new file mode 100644 index 00000000..da2d187e --- /dev/null +++ b/modules/plugins/lsp/presets/asm-lsp.nix @@ -0,0 +1,24 @@ +{ + config, + lib, + pkgs, + ... +}: let + inherit (lib.meta) getExe; + inherit (lib.modules) mkIf; + inherit (lib.nvim.types) mkLspPresetEnableOption; + + cfg = config.vim.lsp.presets.asm-lsp; +in { + options.vim.lsp.presets.asm-lsp = { + enable = mkLspPresetEnableOption "asm-lsp" "Assembly" []; + }; + + config = mkIf cfg.enable { + vim.lsp.servers.asm-lsp = { + enable = true; + cmd = [(getExe pkgs.asm-lsp)]; + root_markers = [".git" ".asm-lsp.toml"]; + }; + }; +} diff --git a/modules/plugins/lsp/presets/astro-language-server.nix b/modules/plugins/lsp/presets/astro-language-server.nix new file mode 100644 index 00000000..fdf96ccd --- /dev/null +++ b/modules/plugins/lsp/presets/astro-language-server.nix @@ -0,0 +1,35 @@ +{ + config, + lib, + pkgs, + ... +}: let + inherit (lib.meta) getExe; + inherit (lib.modules) mkIf; + inherit (lib.nvim.types) mkLspPresetEnableOption; + inherit (lib.generators) mkLuaInline; + + cfg = config.vim.lsp.presets.astro-language-server; +in { + options.vim.lsp.presets.astro-language-server = { + enable = mkLspPresetEnableOption "astro-language-server" "Astro" []; + }; + + config = mkIf cfg.enable { + vim.lsp.servers.astro-language-server = { + enable = true; + cmd = [(getExe pkgs.astro-language-server) "--stdio"]; + root_markers = [".git" "package.json" "tsconfig.json" "jsconfig.json"]; + init_options = { + typescript = {}; + }; + before_init = mkLuaInline '' + function(_, config) + if config.init_options and config.init_options.typescript and not config.init_options.typescript.tsdk then + config.init_options.typescript.tsdk = util.get_typescript_server_path(config.root_dir) + end + end + ''; + }; + }; +} diff --git a/modules/plugins/lsp/presets/basedpyright.nix b/modules/plugins/lsp/presets/basedpyright.nix new file mode 100644 index 00000000..3ea7b547 --- /dev/null +++ b/modules/plugins/lsp/presets/basedpyright.nix @@ -0,0 +1,77 @@ +{ + config, + lib, + pkgs, + ... +}: let + inherit (lib.meta) getExe'; + inherit (lib.modules) mkIf; + inherit (lib.nvim.types) mkLspPresetEnableOption; + inherit (lib.generators) mkLuaInline; + inherit (lib.nvim.dag) entryBefore; + + cfg = config.vim.lsp.presets.basedpyright; +in { + options.vim.lsp.presets.basedpyright = { + enable = mkLspPresetEnableOption "basedpyright" "Based Pyright" []; + }; + + config = mkIf cfg.enable { + vim = { + lsp.servers.basedpyright = { + enable = true; + cmd = [(getExe' pkgs.basedpyright "basedpyright-langserver") "--stdio"]; + root_markers = [".git" "pyrightconfig.json"]; + settings = { + basedpyright = { + analysis = { + autoSearchPaths = true; + useLibraryCodeForTypes = true; + diagnosticMode = "openFilesOnly"; + }; + }; + }; + on_attach = mkLuaInline '' + function(client, bufnr) + vim.api.nvim_buf_create_user_command(bufnr, 'LspPyrightOrganizeImports', function() + local params = { + command = 'basedpyright.organizeimports', + arguments = { vim.uri_from_bufnr(bufnr) }, + } + + -- Using client.request() directly because "basedpyright.organizeimports" is private + -- (not advertised via capabilities), which client:exec_cmd() refuses to call. + -- https://github.com/neovim/neovim/blob/c333d64663d3b6e0dd9aa440e433d346af4a3d81/runtime/lua/vim/lsp/client.lua#L1024-L1030 + client.request('workspace/executeCommand', params, nil, bufnr) + end, { + desc = 'Organize Imports', + }) + + vim.api.nvim_buf_create_user_command(bufnr, 'LspPyrightSetPythonPath', basedpyright_set_python_path, { + desc = 'Reconfigure basedpyright with the provided python path', + nargs = 1, + complete = 'file', + }) + end + ''; + }; + luaConfigRC.basedpyright-util = entryBefore ["lsp-servers"] '' + local function basedpyright_set_python_path(server_name, command) + local path = command.args + local clients = vim.lsp.get_clients { + bufnr = vim.api.nvim_get_current_buf(), + name = server_name, + } + for _, client in ipairs(clients) do + if client.settings then + client.settings.python = vim.tbl_deep_extend('force', client.settings.python or {}, { pythonPath = path }) + else + client.config.settings = vim.tbl_deep_extend('force', client.config.settings, { python = { pythonPath = path } }) + end + client:notify('workspace/didChangeConfiguration', { settings = nil }) + end + end + ''; + }; + }; +} diff --git a/modules/plugins/lsp/presets/bash-language-server.nix b/modules/plugins/lsp/presets/bash-language-server.nix new file mode 100644 index 00000000..786a1638 --- /dev/null +++ b/modules/plugins/lsp/presets/bash-language-server.nix @@ -0,0 +1,30 @@ +{ + config, + lib, + pkgs, + ... +}: let + inherit (lib.meta) getExe; + inherit (lib.modules) mkIf; + inherit (lib.nvim.types) mkLspPresetEnableOption; + inherit (lib.generators) mkLuaInline; + + cfg = config.vim.lsp.presets.bash-language-server; +in { + options.vim.lsp.presets.bash-language-server = { + enable = mkLspPresetEnableOption "bash-language-server" "Bash" []; + }; + + config = mkIf cfg.enable { + vim.lsp.servers.bash-language-server = { + enable = true; + cmd = [(getExe pkgs.bash-language-server) "start"]; + root_markers = [".git"]; + settings = { + basheIde = { + globPattern = mkLuaInline "vim.env.GLOB_PATTERN or '*@(.sh|.inc|.bash|.command)'"; + }; + }; + }; + }; +} diff --git a/modules/plugins/lsp/presets/ccls.nix b/modules/plugins/lsp/presets/ccls.nix new file mode 100644 index 00000000..5f46a2ba --- /dev/null +++ b/modules/plugins/lsp/presets/ccls.nix @@ -0,0 +1,54 @@ +{ + config, + lib, + pkgs, + ... +}: let + inherit (lib.meta) getExe; + inherit (lib.modules) mkIf; + inherit (lib.nvim.types) mkLspPresetEnableOption; + inherit (lib.generators) mkLuaInline; + + cfg = config.vim.lsp.presets.ccls; +in { + options.vim.lsp.presets.ccls = { + enable = mkLspPresetEnableOption "ccls" "CC" []; + }; + + config = mkIf cfg.enable { + vim.lsp.servers.ccls = { + enable = true; + cmd = [(getExe pkgs.ccls)]; + offset_encoding = "utf-32"; + root_markers = [".git" ".ccls" "compile_commands.json"]; + workspace_required = true; + on_attach = mkLuaInline '' + function(client, bufnr) + local function switch_source_header(bufnr) + local method_name = "textDocument/switchSourceHeader" + local params = vim.lsp.util.make_text_document_params(bufnr) + client:request(method_name, params, function(err, result) + if err then + error(tostring(err)) + end + if not result then + vim.notify('corresponding file cannot be determined') + return + end + vim.cmd.edit(vim.uri_to_fname(result)) + end, bufnr) + end + + vim.api.nvim_buf_create_user_command( + bufnr, + "LspCclsSwitchSourceHeader", + function(arg) + switch_source_header(client, 0) + end, + {desc = "Switch between source/header"} + ) + end + ''; + }; + }; +} diff --git a/modules/plugins/lsp/presets/clangd.nix b/modules/plugins/lsp/presets/clangd.nix new file mode 100644 index 00000000..49bffb04 --- /dev/null +++ b/modules/plugins/lsp/presets/clangd.nix @@ -0,0 +1,107 @@ +{ + config, + lib, + pkgs, + ... +}: let + inherit (lib.meta) getExe'; + inherit (lib.modules) mkIf; + inherit (lib.nvim.types) mkLspPresetEnableOption; + inherit (lib.generators) mkLuaInline; + + cfg = config.vim.lsp.presets.clangd; +in { + options.vim.lsp.presets.clangd = { + enable = mkLspPresetEnableOption "clangd" "Clangd" []; + }; + + config = mkIf cfg.enable { + vim.lsp.servers.clangd = { + enable = true; + cmd = [(getExe' pkgs.clang-tools "clangd")]; + root_markers = [ + ".git" + ".clangd" + ".clang-tidy" + ".clang-format" + "compile_commands.json" + "compile_flags.txt" + "configure.ac" + ]; + capabilities = { + textDocument = { + completion = { + editsNearCursor = true; + }; + }; + offsetEncoding = ["utf-8" "utf-16"]; + }; + on_attach = mkLuaInline '' + function(client, bufnr) + local function switch_source_header(bufnr) + local method_name = "textDocument/switchSourceHeader" + local client = vim.lsp.get_clients({ bufnr = bufnr, name = "clangd", })[1] + if not client then + return vim.notify(('method %s is not supported by any servers active on the current buffer'):format(method_name)) + end + local params = vim.lsp.util.make_text_document_params(bufnr) + client.request(method_name, params, function(err, result) + if err then + error(tostring(err)) + end + if not result then + vim.notify('corresponding file cannot be determined') + return + end + vim.cmd.edit(vim.uri_to_fname(result)) + end, bufnr) + end + + local function symbol_info() + local bufnr = vim.api.nvim_get_current_buf() + local clangd_client = vim.lsp.get_clients({ bufnr = bufnr, name = "clangd" })[1] + if not clangd_client or not clangd_client:supports_method 'textDocument/symbolInfo' then + return vim.notify('Clangd client not found', vim.log.levels.ERROR) + end + local win = vim.api.nvim_get_current_win() + local params = vim.lsp.util.make_position_params(win, clangd_client.offset_encoding) + clangd_client:request('textDocument/symbolInfo', params, function(err, res) + if err or #res == 0 then + -- Clangd always returns an error, there is not reason to parse it + return + end + local container = string.format('container: %s', res[1].containerName) ---@type string + local name = string.format('name: %s', res[1].name) ---@type string + vim.lsp.util.open_floating_preview({ name, container }, "", { + height = 2, + width = math.max(string.len(name), string.len(container)), + focusable = false, + focus = false, + border = 'single', + title = 'Symbol Info', + }) + end, bufnr) + end + + vim.api.nvim_buf_create_user_command( + bufnr, + "ClangdSwitchSourceHeader", + function(arg) + switch_source_header(0) + end, + {desc = "Switch between source/header"} + ) + + vim.api.nvim_buf_create_user_command( + bufnr, + "ClangdShowSymbolInfo", + function(arg) + symbol_info() + end, + {desc = "Show symbol info"} + ) + end + ''; + }; + }; +} diff --git a/modules/plugins/lsp/presets/clojure-lsp.nix b/modules/plugins/lsp/presets/clojure-lsp.nix new file mode 100644 index 00000000..a51276d5 --- /dev/null +++ b/modules/plugins/lsp/presets/clojure-lsp.nix @@ -0,0 +1,24 @@ +{ + config, + lib, + pkgs, + ... +}: let + inherit (lib.meta) getExe; + inherit (lib.modules) mkIf; + inherit (lib.nvim.types) mkLspPresetEnableOption; + + cfg = config.vim.lsp.presets.clojure-lsp; +in { + options.vim.lsp.presets.clojure-lsp = { + enable = mkLspPresetEnableOption "clojure-lsp" "Clojure" []; + }; + + config = mkIf cfg.enable { + vim.lsp.servers.clojure-lsp = { + enable = true; + cmd = [(getExe pkgs.clojure-lsp)]; + root_markers = [".git" "project.clj"]; + }; + }; +} diff --git a/modules/plugins/lsp/presets/cue.nix b/modules/plugins/lsp/presets/cue.nix new file mode 100644 index 00000000..433792f2 --- /dev/null +++ b/modules/plugins/lsp/presets/cue.nix @@ -0,0 +1,24 @@ +{ + config, + lib, + pkgs, + ... +}: let + inherit (lib.meta) getExe; + inherit (lib.modules) mkIf; + inherit (lib.nvim.types) mkLspPresetEnableOption; + + cfg = config.vim.lsp.presets.cue; +in { + options.vim.lsp.presets.cue = { + enable = mkLspPresetEnableOption "cue" "Cue" []; + }; + + config = mkIf cfg.enable { + vim.lsp.servers.cue = { + enable = true; + cmd = [(getExe pkgs.cue) "lsp"]; + root_markers = [".git" "cue.mod"]; + }; + }; +} diff --git a/modules/plugins/lsp/presets/dart.nix b/modules/plugins/lsp/presets/dart.nix new file mode 100644 index 00000000..f99275ba --- /dev/null +++ b/modules/plugins/lsp/presets/dart.nix @@ -0,0 +1,37 @@ +{ + config, + lib, + pkgs, + ... +}: let + inherit (lib.meta) getExe; + inherit (lib.modules) mkIf; + inherit (lib.nvim.types) mkLspPresetEnableOption; + + cfg = config.vim.lsp.presets.dart; +in { + options.vim.lsp.presets.dart = { + enable = mkLspPresetEnableOption "dart" "Dart" []; + }; + + config = mkIf cfg.enable { + vim.lsp.servers.dart = { + enable = true; + cmd = [(getExe pkgs.dart) "language-server" "--protocol=lsp"]; + root_markers = [".git" "pubspec.yaml"]; + init_options = { + onlyAnalyzeProjectsWithOpenFiles = true; + suggestFromUnimportedLibraries = true; + closingLabels = true; + outline = true; + flutterOutline = true; + }; + settings = { + dart = { + completeFunctionCalls = true; + showTodos = true; + }; + }; + }; + }; +} diff --git a/modules/plugins/lsp/presets/default.nix b/modules/plugins/lsp/presets/default.nix new file mode 100644 index 00000000..caf26d7c --- /dev/null +++ b/modules/plugins/lsp/presets/default.nix @@ -0,0 +1,75 @@ +{ + imports = [ + ./arduino-language-server.nix + ./asm-lsp.nix + ./astro-language-server.nix + ./basedpyright.nix + ./bash-language-server.nix + ./ccls.nix + ./clangd.nix + ./clojure-lsp.nix + ./cue.nix + ./dart.nix + ./deno.nix + ./elixir-ls.nix + ./elm-language-server.nix + ./emmet-ls.nix + ./fsautocomplete.nix + ./gleam.nix + ./glsl_analyzer.nix + ./gopls.nix + ./harper.nix + ./helm-ls.nix + ./intelephense.nix + ./jdt-language-server.nix + ./jinja-lsp.nix + ./jq-lsp.nix + ./julia-languageserver.nix + ./just-lsp.nix + ./kotlin-language-server.nix + ./lemminx.nix + ./lua-language-server.nix + ./markdown-oxide.nix + ./marksman.nix + ./neocmakelsp.nix + ./nil.nix + ./nimlsp.nix + ./nixd.nix + ./nushell.nix + ./ocaml-lsp.nix + ./ols.nix + ./openscad-lsp.nix + ./phan.nix + ./phpactor.nix + ./pyrefly.nix + ./pyright.nix + ./python-lsp-server.nix + ./qmlls.nix + ./r-languageserver.nix + ./ruby-lsp.nix + ./ruff.nix + ./rumdl.nix + ./solargraph.nix + ./sqls.nix + ./superhtml.nix + ./svelte-language-server.nix + ./tailwindcss-language-server.nix + ./taplo.nix + ./terraform-ls.nix + ./texlab.nix + ./tinymist.nix + ./tofu-ls.nix + ./tombi.nix + ./twig-language-server.nix + ./ty.nix + ./typescript-go.nix + ./typescript-language-server.nix + ./vala-language-server.nix + ./vscode-css-language-server.nix + ./vscode-json-language-server.nix + ./wgsl-analyzer.nix + ./yaml-language-server.nix + ./zls.nix + ./zuban.nix + ]; +} diff --git a/modules/plugins/lsp/presets/deno.nix b/modules/plugins/lsp/presets/deno.nix new file mode 100644 index 00000000..637d219d --- /dev/null +++ b/modules/plugins/lsp/presets/deno.nix @@ -0,0 +1,111 @@ +{ + config, + lib, + pkgs, + ... +}: let + inherit (lib.meta) getExe; + inherit (lib.modules) mkIf; + inherit (lib.nvim.types) mkLspPresetEnableOption; + inherit (lib.generators) mkLuaInline; + + cfg = config.vim.lsp.presets.deno; +in { + options.vim.lsp.presets.deno = { + enable = mkLspPresetEnableOption "deno" "Deno" []; + }; + + config = mkIf cfg.enable { + vim.lsp.servers.deno = { + enable = true; + cmd = [(getExe pkgs.deno) "lsp"]; + cmd_env = {NO_COLOR = true;}; + root_markers = ["deno.json" "deno.jsonc" ".git"]; + settings = { + deno = { + enable = true; + suggest = { + imports = { + hosts = { + "https://deno.land" = true; + }; + }; + }; + }; + }; + handlers = let + handler = mkLuaInline '' + function(err, result, ctx, config) + + local function nvf_denols_virtual_text_document_handler(uri, res, client) + if not res then + return nil + end + + local lines = vim.split(res.result, '\n') + local bufnr = vim.uri_to_bufnr(uri) + + local current_buf = vim.api.nvim_buf_get_lines(bufnr, 0, -1, false) + if #current_buf ~= 0 then + return nil + end + + vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, lines) + vim.api.nvim_set_option_value('readonly', true, { buf = bufnr }) + vim.api.nvim_set_option_value('modified', false, { buf = bufnr }) + vim.api.nvim_set_option_value('modifiable', false, { buf = bufnr }) + vim.lsp.buf_attach_client(bufnr, client.id) + end + + local function nvf_denols_virtual_text_document(uri, client) + local params = { + textDocument = { + uri = uri, + }, + } + local result = client.request_sync('deno/virtualTextDocument', params) + nvf_denols_virtual_text_document_handler(uri, result, client) + end + + if not result or vim.tbl_isempty(result) then + return nil + end + + local client = vim.lsp.get_client_by_id(ctx.client_id) + for _, res in pairs(result) do + local uri = res.uri or res.targetUri + if uri:match '^deno:' then + nvf_denols_virtual_text_document(uri, client) + res['uri'] = uri + res['targetUri'] = uri + end + end + + vim.lsp.handlers[ctx.method](err, result, ctx, config) + end + ''; + in { + "textDocument/definition" = handler; + "textDocument/typeDefinition" = handler; + "textDocument/references" = handler; + }; + on_attach = mkLuaInline '' + function(client, bufnr) + vim.api.nvim_buf_create_user_command(0, 'LspDenolsCache', function() + client:exec_cmd({ + command = 'deno.cache', + arguments = { {}, vim.uri_from_bufnr(bufnr) }, + }, { bufnr = bufnr }, function(err, _result, ctx) + if err then + local uri = ctx.params.arguments[2] + vim.api.nvim_err_writeln('cache command failed for ' .. vim.uri_to_fname(uri)) + end + end) + end, { + desc = 'Cache a module and all of its dependencies.', + }) + end + ''; + }; + }; +} diff --git a/modules/plugins/lsp/presets/elixir-ls.nix b/modules/plugins/lsp/presets/elixir-ls.nix new file mode 100644 index 00000000..f4b16268 --- /dev/null +++ b/modules/plugins/lsp/presets/elixir-ls.nix @@ -0,0 +1,34 @@ +{ + config, + lib, + pkgs, + ... +}: let + inherit (lib.meta) getExe; + inherit (lib.modules) mkIf; + inherit (lib.nvim.types) mkLspPresetEnableOption; + inherit (lib.generators) mkLuaInline; + + cfg = config.vim.lsp.presets.elixir-ls; +in { + options.vim.lsp.presets.elixir-ls = { + enable = mkLspPresetEnableOption "elixir-ls" "Elixir" []; + }; + + config = mkIf cfg.enable { + vim.lsp.servers.elixir-ls = { + enable = true; + cmd = [(getExe pkgs.elixir-ls)]; + root_dir = mkLuaInline '' + function(bufnr, on_dir) + local fname = vim.api.nvim_buf_get_name(bufnr) + local matches = vim.fs.find({ 'mix.exs' }, { upward = true, limit = 2, path = fname }) + local child_or_root_path, maybe_umbrella_path = unpack(matches) + local root_dir = vim.fs.dirname(maybe_umbrella_path or child_or_root_path) + + on_dir(root_dir) + end + ''; + }; + }; +} diff --git a/modules/plugins/lsp/presets/elm-language-server.nix b/modules/plugins/lsp/presets/elm-language-server.nix new file mode 100644 index 00000000..ee3c97fb --- /dev/null +++ b/modules/plugins/lsp/presets/elm-language-server.nix @@ -0,0 +1,25 @@ +{ + config, + lib, + pkgs, + ... +}: let + inherit (lib.meta) getExe; + inherit (lib.modules) mkIf; + inherit (lib.nvim.types) mkLspPresetEnableOption; + + cfg = config.vim.lsp.presets.elm-language-server; +in { + options.vim.lsp.presets.elm-language-server = { + enable = mkLspPresetEnableOption "elm-language-server" "Elm" []; + }; + + config = mkIf cfg.enable { + vim.lsp.servers.elm-language-server = { + enable = true; + cmd = [(getExe pkgs.elmPackages.elm-language-server)]; + root_markers = [".git" "elm.json"]; + workspace_required = false; + }; + }; +} diff --git a/modules/plugins/lsp/presets/emmet-ls.nix b/modules/plugins/lsp/presets/emmet-ls.nix new file mode 100644 index 00000000..42e6fd1f --- /dev/null +++ b/modules/plugins/lsp/presets/emmet-ls.nix @@ -0,0 +1,24 @@ +{ + config, + lib, + pkgs, + ... +}: let + inherit (lib.meta) getExe; + inherit (lib.modules) mkIf; + inherit (lib.nvim.types) mkLspPresetEnableOption; + + cfg = config.vim.lsp.presets.emmet-ls; +in { + options.vim.lsp.presets.emmet-ls = { + enable = mkLspPresetEnableOption "emmet-ls" "Emmet" []; + }; + + config = mkIf cfg.enable { + vim.lsp.servers.emmet-ls = { + enable = true; + cmd = [(getExe pkgs.emmet-ls) "--stdio"]; + root_markers = [".git"]; + }; + }; +} diff --git a/modules/plugins/lsp/presets/fsautocomplete.nix b/modules/plugins/lsp/presets/fsautocomplete.nix new file mode 100644 index 00000000..d5b95de1 --- /dev/null +++ b/modules/plugins/lsp/presets/fsautocomplete.nix @@ -0,0 +1,54 @@ +{ + config, + lib, + pkgs, + ... +}: let + inherit (lib.meta) getExe; + inherit (lib.modules) mkIf; + inherit (lib.nvim.types) mkLspPresetEnableOption; + inherit (lib.generators) mkLuaInline; + + cfg = config.vim.lsp.presets.fsautocomplete; +in { + options.vim.lsp.presets.fsautocomplete = { + enable = mkLspPresetEnableOption "fsautocomplete" "F# Autocomplete" []; + }; + + config = mkIf cfg.enable { + vim.lsp.servers.fsautocomplete = { + enable = true; + cmd = [(getExe pkgs.fsautocomplete) "--adaptive-lsp-server-enabled"]; + root_dir = mkLuaInline '' + function(bufnr, on_dir) + on_dir(vim.fs.root(bufnr, function(name, path) + return name == ".git" or name:match("%.sln$") or name:match("%.fsproj$") + end)) + end + ''; + init_options = { + AutomaticWorkspaceInit = true; + }; + settings = { + FSharp = { + keywordsAutocomplete = true; + ExternalAutocomplete = false; + Linter = true; + UnionCaseStubGeneration = true; + UnionCaseStubGenerationBody = ''failwith "Not Implemented"''; + RecordStubGeneration = true; + RecordStubGenerationBody = ''failwith "Not Implemented"''; + InterfaceStubGeneration = true; + InterfaceStubGenerationObjectIdentifier = "this"; + InterfaceStubGenerationMethodBody = ''failwith "Not Implemented"''; + UnusedOpensAnalyzer = true; + UnusedDeclarationsAnalyzer = true; + UseSdkScripts = true; + SimplifyNameAnalyzer = true; + ResolveNamespaces = true; + EnableReferenceCodeLens = true; + }; + }; + }; + }; +} diff --git a/modules/plugins/lsp/presets/gleam.nix b/modules/plugins/lsp/presets/gleam.nix new file mode 100644 index 00000000..46b21e87 --- /dev/null +++ b/modules/plugins/lsp/presets/gleam.nix @@ -0,0 +1,24 @@ +{ + config, + lib, + pkgs, + ... +}: let + inherit (lib.meta) getExe; + inherit (lib.modules) mkIf; + inherit (lib.nvim.types) mkLspPresetEnableOption; + + cfg = config.vim.lsp.presets.gleam; +in { + options.vim.lsp.presets.gleam = { + enable = mkLspPresetEnableOption "gleam" "Gleam" []; + }; + + config = mkIf cfg.enable { + vim.lsp.servers.gleam = { + enable = true; + cmd = [(getExe pkgs.gleam) "lsp"]; + root_markers = [".git" "gleam.toml"]; + }; + }; +} diff --git a/modules/plugins/lsp/presets/glsl_analyzer.nix b/modules/plugins/lsp/presets/glsl_analyzer.nix new file mode 100644 index 00000000..9b7798de --- /dev/null +++ b/modules/plugins/lsp/presets/glsl_analyzer.nix @@ -0,0 +1,24 @@ +{ + config, + lib, + pkgs, + ... +}: let + inherit (lib.meta) getExe; + inherit (lib.modules) mkIf; + inherit (lib.nvim.types) mkLspPresetEnableOption; + + cfg = config.vim.lsp.presets.glsl_analyzer; +in { + options.vim.lsp.presets.glsl_analyzer = { + enable = mkLspPresetEnableOption "glsl_analyzer" "GLSL Analyzer" []; + }; + + config = mkIf cfg.enable { + vim.lsp.servers.glsl_analyzer = { + enable = true; + cmd = [(getExe pkgs.glsl_analyzer)]; + root_markers = [".git"]; + }; + }; +} diff --git a/modules/plugins/lsp/presets/gopls.nix b/modules/plugins/lsp/presets/gopls.nix new file mode 100644 index 00000000..9432dcd8 --- /dev/null +++ b/modules/plugins/lsp/presets/gopls.nix @@ -0,0 +1,59 @@ +{ + config, + lib, + pkgs, + ... +}: let + inherit (lib.meta) getExe; + inherit (lib.modules) mkIf; + inherit (lib.nvim.types) mkLspPresetEnableOption; + inherit (lib.generators) mkLuaInline; + + cfg = config.vim.lsp.presets.gopls; +in { + options.vim.lsp.presets.gopls = { + enable = mkLspPresetEnableOption "gopls" "Go" []; + }; + + config = mkIf cfg.enable { + vim.lsp.servers.gopls = { + enable = true; + cmd = [(getExe pkgs.gopls)]; + root_dir = mkLuaInline '' + function(bufnr, on_dir) + local fname = vim.api.nvim_buf_get_name(bufnr) + + local function get_root(fname) + if _G.nvf_gopls_mod_cache and fname:sub(1, #_G.nvf_gopls_mod_cache) == _G.nvf_gopls_mod_cache then + local clients = vim.lsp.get_clients { name = 'gopls' } + if #clients > 0 then + return clients[#clients].config.root_dir + end + end + return vim.fs.root(fname, 'go.work') or vim.fs.root(fname, 'go.mod') or vim.fs.root(fname, '.git') + end + + -- see: https://github.com/neovim/nvim-lspconfig/issues/804 + if _G.nvf_gopls_mod_cache then + on_dir(get_root(fname)) + return + end + local cmd = { 'go', 'env', 'GOMODCACHE' } + local ok, err = pcall(vim.system, cmd, { text = true }, function(output) + if output.code == 0 then + if output.stdout then + _G.nvf_gopls_mod_cache = vim.trim(output.stdout) + end + on_dir(get_root(fname)) + else + vim.schedule(function() + vim.notify(('[gopls] cmd failed with code %d: %s\n%s'):format(output.code, cmd, output.stderr)) + end) + end + end) + if not ok then vim.notify(('[gopls] cmd failed: %s\n%s'):format(cmd, err)) end + end + ''; + }; + }; +} diff --git a/modules/plugins/lsp/presets/harper.nix b/modules/plugins/lsp/presets/harper.nix new file mode 100644 index 00000000..9fce2230 --- /dev/null +++ b/modules/plugins/lsp/presets/harper.nix @@ -0,0 +1,54 @@ +{ + config, + lib, + pkgs, + ... +}: let + inherit (lib.meta) getExe; + inherit (lib.modules) mkIf; + inherit (lib.nvim.types) mkLspPresetEnableOption; + + cfg = config.vim.lsp.presets.harper; + filetypes = [ + # + "asciidoc" + "c" + "clojure" + "cmake" + "cpp" + "cs" + "daml" + "dart" + "gitcommit" + "go" + "haskell" + "html" + "ink" + "java" + "javascript" + "javascriptreact" + "kotlin" + "lhaskell" + "lua" + "mail" + "markdown" + "nix" + "php" + "python" + "ruby" + "rust" + ]; +in { + options.vim.lsp.presets.harper = { + enable = mkLspPresetEnableOption "harper" "Harper" filetypes; + }; + + config = mkIf cfg.enable { + vim.lsp.servers.harper = { + enable = true; + cmd = [(getExe pkgs.harper) "--stdio"]; + root_markers = [".git" ".harper-dictionary.txt"]; + inherit filetypes; + }; + }; +} diff --git a/modules/plugins/lsp/presets/helm-ls.nix b/modules/plugins/lsp/presets/helm-ls.nix new file mode 100644 index 00000000..e0398f8e --- /dev/null +++ b/modules/plugins/lsp/presets/helm-ls.nix @@ -0,0 +1,29 @@ +{ + config, + lib, + pkgs, + ... +}: let + inherit (lib.meta) getExe; + inherit (lib.modules) mkIf; + inherit (lib.nvim.types) mkLspPresetEnableOption; + + cfg = config.vim.lsp.presets.helm-ls; +in { + options.vim.lsp.presets.helm-ls = { + enable = mkLspPresetEnableOption "helm-ls" "Helm" []; + }; + + config = mkIf cfg.enable { + vim.lsp.servers.helm-ls = { + enable = true; + cmd = [(getExe pkgs.helm-ls) "serve"]; + root_markers = [".git" "Chart.yaml"]; + capabilities = { + didChangeWatchedFiles = { + dynamicRegistration = true; + }; + }; + }; + }; +} diff --git a/modules/plugins/lsp/presets/intelephense.nix b/modules/plugins/lsp/presets/intelephense.nix new file mode 100644 index 00000000..a15c039e --- /dev/null +++ b/modules/plugins/lsp/presets/intelephense.nix @@ -0,0 +1,24 @@ +{ + config, + lib, + pkgs, + ... +}: let + inherit (lib.meta) getExe; + inherit (lib.modules) mkIf; + inherit (lib.nvim.types) mkLspPresetEnableOption; + + cfg = config.vim.lsp.presets.intelephense; +in { + options.vim.lsp.presets.intelephense = { + enable = mkLspPresetEnableOption "intelephense" "Intelephense" []; + }; + + config = mkIf cfg.enable { + vim.lsp.servers.intelephense = { + enable = true; + cmd = [(getExe pkgs.intelephense) "--stdio"]; + root_markers = [".git"]; + }; + }; +} diff --git a/modules/plugins/lsp/presets/jdt-language-server.nix b/modules/plugins/lsp/presets/jdt-language-server.nix new file mode 100644 index 00000000..c00125c9 --- /dev/null +++ b/modules/plugins/lsp/presets/jdt-language-server.nix @@ -0,0 +1,136 @@ +{ + config, + lib, + pkgs, + ... +}: let + inherit (lib.meta) getExe; + inherit (lib.modules) mkIf; + inherit (lib.nvim.types) mkLspPresetEnableOption; + inherit (lib.generators) mkLuaInline; + inherit (lib.nvim.dag) entryBefore; + + cfg = config.vim.lsp.presets.jdt-language-server; +in { + options.vim.lsp.presets.jdt-language-server = { + enable = mkLspPresetEnableOption "jdt-language-server" "Eclipse JDT" []; + }; + + config = mkIf cfg.enable { + vim = { + lsp.servers.jdt-language-server = { + enable = true; + cmd = mkLuaInline '' + { + '${getExe pkgs.jdt-language-server}', + '-configuration', + get_jdtls_config_dir(), + '-data', + get_jdtls_workspace_dir(), + get_jdtls_jvm_args(), + } + ''; + root_markers = [ + # Multi-module projects + ".git" + "build.gradle" + "build.gradle.kts" + # Single-module projects + "build.xml" # Ant + "pom.xml" # Maven + "settings.gradle" # Gradle + "settings.gradle.kts" # Gradle + ]; + init_options = { + workspace = mkLuaInline "get_jdtls_workspace_dir()"; + jvm_args = {}; + os_config = mkLuaInline "nil"; + }; + handlers = { + "textDocument/codeAction" = mkLuaInline "jdtls_on_textdocument_codeaction"; + "textDocument/rename" = mkLuaInline "jdtls_on_textdocument_rename"; + "workspace/applyEdit" = mkLuaInline "jdtls_on_workspace_applyedit"; + "language/status" = mkLuaInline "vim.schedule_wrap(jdtls_on_language_status)"; + }; + }; + luaConfigRC.jdtls-util = entryBefore ["lsp-servers"] '' + local jdtls_handlers = require 'vim.lsp.handlers' + + local jdtls_env = { + HOME = vim.uv.os_homedir(), + XDG_CACHE_HOME = os.getenv 'XDG_CACHE_HOME', + JDTLS_JVM_ARGS = os.getenv 'JDTLS_JVM_ARGS', + } + + local function get_cache_dir() + return jdtls_env.XDG_CACHE_HOME and jdtls_env.XDG_CACHE_HOME or jdtls_env.HOME .. '/.cache' + end + + local function get_jdtls_cache_dir() + return get_cache_dir() .. '/jdtls' + end + + local function get_jdtls_config_dir() + return get_jdtls_cache_dir() .. '/config' + end + + local function get_jdtls_workspace_dir() + return get_jdtls_cache_dir() .. '/workspace' + end + + local function get_jdtls_jvm_args() + local args = {} + for a in string.gmatch((jdtls_env.JDTLS_JVM_ARGS or '''), '%S+') do + local arg = string.format('--jvm-arg=%s', a) + table.insert(args, arg) + end + return unpack(args) + end + + -- TextDocument version is reported as 0, override with nil so that + -- the client doesn't think the document is newer and refuses to update + -- See: https://github.com/eclipse/eclipse.jdt.ls/issues/1695 + local function jdtls_fix_zero_version(workspace_edit) + if workspace_edit and workspace_edit.documentChanges then + for _, change in pairs(workspace_edit.documentChanges) do + local text_document = change.textDocument + if text_document and text_document.version and text_document.version == 0 then + text_document.version = nil + end + end + end + return workspace_edit + end + + local function jdtls_on_textdocument_codeaction(err, actions, ctx) + for _, action in ipairs(actions) do + -- TODO: (steelsojka) Handle more than one edit? + if action.command == 'java.apply.workspaceEdit' then -- 'action' is Command in java format + action.edit = jdtls_fix_zero_version(action.edit or action.arguments[1]) + elseif type(action.command) == 'table' and action.command.command == 'java.apply.workspaceEdit' then -- 'action' is CodeAction in java format + action.edit = jdtls_fix_zero_version(action.edit or action.command.arguments[1]) + end + end + + jdtls_handlers[ctx.method](err, actions, ctx) + end + + local function jdtls_on_textdocument_rename(err, workspace_edit, ctx) + jdtls_handlers[ctx.method](err, jdtls_fix_zero_version(workspace_edit), ctx) + end + + local function jdtls_on_workspace_applyedit(err, workspace_edit, ctx) + jdtls_handlers[ctx.method](err, jdtls_fix_zero_version(workspace_edit), ctx) + end + + -- Non-standard notification that can be used to display progress + local function jdtls_on_language_status(_, result) + local command = vim.api.nvim_command + command 'echohl ModeMsg' + command(string.format('echo "%s"', result.message)) + command 'echohl None' + end + ''; + }; + }; +} diff --git a/modules/plugins/lsp/presets/jinja-lsp.nix b/modules/plugins/lsp/presets/jinja-lsp.nix new file mode 100644 index 00000000..a60ea7ef --- /dev/null +++ b/modules/plugins/lsp/presets/jinja-lsp.nix @@ -0,0 +1,24 @@ +{ + config, + lib, + pkgs, + ... +}: let + inherit (lib.meta) getExe; + inherit (lib.modules) mkIf; + inherit (lib.nvim.types) mkLspPresetEnableOption; + + cfg = config.vim.lsp.presets.jinja-lsp; +in { + options.vim.lsp.presets.jinja-lsp = { + enable = mkLspPresetEnableOption "jinja-lsp" "Jinja" []; + }; + + config = mkIf cfg.enable { + vim.lsp.servers.jinja-lsp = { + enable = true; + cmd = [(getExe pkgs.jinja-lsp)]; + root_markers = [".git"]; + }; + }; +} diff --git a/modules/plugins/lsp/presets/jq-lsp.nix b/modules/plugins/lsp/presets/jq-lsp.nix new file mode 100644 index 00000000..2f695a68 --- /dev/null +++ b/modules/plugins/lsp/presets/jq-lsp.nix @@ -0,0 +1,24 @@ +{ + config, + lib, + pkgs, + ... +}: let + inherit (lib.meta) getExe; + inherit (lib.modules) mkIf; + inherit (lib.nvim.types) mkLspPresetEnableOption; + + cfg = config.vim.lsp.presets.jq-lsp; +in { + options.vim.lsp.presets.jq-lsp = { + enable = mkLspPresetEnableOption "jq-lsp" "JQ" []; + }; + + config = mkIf cfg.enable { + vim.lsp.servers.jq-lsp = { + enable = true; + cmd = [(getExe pkgs.jq-lsp)]; + root_markers = [".git"]; + }; + }; +} diff --git a/modules/plugins/lsp/presets/julia-languageserver.nix b/modules/plugins/lsp/presets/julia-languageserver.nix new file mode 100644 index 00000000..61b5d290 --- /dev/null +++ b/modules/plugins/lsp/presets/julia-languageserver.nix @@ -0,0 +1,129 @@ +{ + config, + lib, + pkgs, + ... +}: let + inherit (lib.meta) getExe; + inherit (lib.modules) mkIf; + inherit (lib.nvim.types) mkLspPresetEnableOption; + inherit (lib.generators) mkLuaInline; + inherit (lib.nvim.dag) entryBefore; + + cfg = config.vim.lsp.presets.julia-languageserver; +in { + options.vim.lsp.presets.julia-languageserver = { + enable = mkLspPresetEnableOption "julia-languageserver" "Julia" []; + }; + + config = mkIf cfg.enable { + vim = { + lsp.servers.julia-languageserver = { + enable = true; + root_markers = ["Project.toml" "JuliaProject.toml"]; + cmd = mkLuaInline '' + { + '${getExe (pkgs.julia.withPackages ["LanguageServer"])}', + '--startup-file=no', + '--history-file=no', + '-e', + [[ + # Load LanguageServer.jl: attempt to load from ~/.julia/environments/nvim-lspconfig + # with the regular load path as a fallback + ls_install_path = joinpath( + get(DEPOT_PATH, 1, joinpath(homedir(), ".julia")), + "environments", "nvim-lspconfig" + ) + pushfirst!(LOAD_PATH, ls_install_path) + using LanguageServer + popfirst!(LOAD_PATH) + depot_path = get(ENV, "JULIA_DEPOT_PATH", "") + project_path = let + dirname(something( + ## 1. Finds an explicitly set project (JULIA_PROJECT) + Base.load_path_expand(( + p = get(ENV, "JULIA_PROJECT", nothing); + p === nothing ? nothing : isempty(p) ? nothing : p + )), + ## 2. Look for a Project.toml file in the current working directory, + ## or parent directories, with $HOME as an upper boundary + Base.current_project(), + ## 3. First entry in the load path + get(Base.load_path(), 1, nothing), + ## 4. Fallback to default global environment, + ## this is more or less unreachable + Base.load_path_expand("@v#.#"), + )) + end + @info "Running language server" VERSION pwd() project_path depot_path + server = LanguageServer.LanguageServerInstance(stdin, stdout, project_path, depot_path) + server.runlinter = true + run(server) + ]], + } + ''; + on_attach = mkLuaInline '' + function(_, bufnr) + vim.api.nvim_buf_create_user_command(bufnr, 'LspJuliaActivateEnv', activate_julia_env, { + desc = 'Activate a Julia environment', + nargs = '?', + complete = 'file', + }) + end + ''; + }; + luaConfigRC.julia-util = entryBefore ["lsp-servers"] '' + local function activate_julia_env(path) + assert(vim.fn.has 'nvim-0.10' == 1, 'requires Nvim 0.10 or newer') + local bufnr = vim.api.nvim_get_current_buf() + local julials_clients = vim.lsp.get_clients { bufnr = bufnr, name = 'julials' } + assert( + #julials_clients > 0, + 'method julia/activateenvironment is not supported by any servers active on the current buffer' + ) + local function _activate_env(environment) + if environment then + for _, julials_client in ipairs(julials_clients) do + julials_client:notify('julia/activateenvironment', { envPath = environment }) + end + vim.notify('Julia environment activated: \n`' .. environment .. '`', vim.log.levels.INFO) + end + end + if path then + path = vim.fs.normalize(vim.fn.fnamemodify(vim.fn.expand(path), ':p')) + local found_env = false + for _, project_file in ipairs(root_files) do + local file = vim.uv.fs_stat(vim.fs.joinpath(path, project_file)) + if file and file.type then + found_env = true + break + end + end + if not found_env then + vim.notify('Path is not a julia environment: \n`' .. path .. '`', vim.log.levels.WARN) + return + end + _activate_env(path) + else + local depot_paths = vim.env.JULIA_DEPOT_PATH + and vim.split(vim.env.JULIA_DEPOT_PATH, vim.fn.has 'win32' == 1 and ';' or ':') + or { vim.fn.expand '~/.julia' } + local environments = {} + vim.list_extend(environments, vim.fs.find(root_files, { type = 'file', upward = true, limit = math.huge })) + for _, depot_path in ipairs(depot_paths) do + local depot_env = vim.fs.joinpath(vim.fs.normalize(depot_path), 'environments') + vim.list_extend( + environments, + vim.fs.find(function(name, env_path) + return vim.tbl_contains(root_files, name) and string.sub(env_path, #depot_env + 1):match '^/[^/]*$' + end, { path = depot_env, type = 'file', limit = math.huge }) + ) + end + environments = vim.tbl_map(vim.fs.dirname, environments) + vim.ui.select(environments, { prompt = 'Select a Julia environment' }, _activate_env) + end + end + ''; + }; + }; +} diff --git a/modules/plugins/lsp/presets/just-lsp.nix b/modules/plugins/lsp/presets/just-lsp.nix new file mode 100644 index 00000000..acb48c80 --- /dev/null +++ b/modules/plugins/lsp/presets/just-lsp.nix @@ -0,0 +1,24 @@ +{ + config, + lib, + pkgs, + ... +}: let + inherit (lib.meta) getExe; + inherit (lib.modules) mkIf; + inherit (lib.nvim.types) mkLspPresetEnableOption; + + cfg = config.vim.lsp.presets.just-lsp; +in { + options.vim.lsp.presets.just-lsp = { + enable = mkLspPresetEnableOption "just-lsp" "Just" []; + }; + + config = mkIf cfg.enable { + vim.lsp.servers.just-lsp = { + enable = true; + cmd = [(getExe pkgs.just-lsp)]; + root_markers = [".git" "Justfile" "justfile"]; + }; + }; +} diff --git a/modules/plugins/lsp/presets/kotlin-language-server.nix b/modules/plugins/lsp/presets/kotlin-language-server.nix new file mode 100644 index 00000000..0c68b3bb --- /dev/null +++ b/modules/plugins/lsp/presets/kotlin-language-server.nix @@ -0,0 +1,46 @@ +{ + config, + lib, + pkgs, + ... +}: let + inherit (lib.meta) getExe; + inherit (lib.modules) mkIf; + inherit (lib.nvim.types) mkLspPresetEnableOption; + inherit (lib.generators) mkLuaInline; + + cfg = config.vim.lsp.presets.kotlin-language-server; +in { + options.vim.lsp.presets.kotlin-language-server = { + enable = mkLspPresetEnableOption "kotlin-language-server" "Kotlin" []; + }; + + config = mkIf cfg.enable { + vim.lsp.servers.kotlin-language-server = { + enable = true; + cmd = [(getExe pkgs.kotlin-language-server)]; + root_markers = [ + "settings.gradle" # Gradle (multi-project) + "settings.gradle.kts" # Gradle (multi-project) + "build.xml" # Ant + "pom.xml" # Maven + "build.gradle" # Gradle + "build.gradle.kts" # gradle + ]; + init_options = { + storagePath = mkLuaInline '' + vim.fs.root(vim.fn.expand '%:p:h', + { + 'settings.gradle', -- Gradle (multi-project) + 'settings.gradle.kts', -- Gradle (multi-project) + 'build.xml', -- Ant + 'pom.xml', -- Maven + 'build.gradle', -- Gradle + 'build.gradle.kts', -- Gradle + } + ) + ''; + }; + }; + }; +} diff --git a/modules/plugins/lsp/presets/lemminx.nix b/modules/plugins/lsp/presets/lemminx.nix new file mode 100644 index 00000000..b8cbf0bd --- /dev/null +++ b/modules/plugins/lsp/presets/lemminx.nix @@ -0,0 +1,24 @@ +{ + config, + lib, + pkgs, + ... +}: let + inherit (lib.meta) getExe; + inherit (lib.modules) mkIf; + inherit (lib.nvim.types) mkLspPresetEnableOption; + + cfg = config.vim.lsp.presets.lemminx; +in { + options.vim.lsp.presets.lemminx = { + enable = mkLspPresetEnableOption "lemminx" "Lemminx" []; + }; + + config = mkIf cfg.enable { + vim.lsp.servers.lemminx = { + enable = true; + cmd = [(getExe pkgs.lemminx)]; + root_markers = [".git"]; + }; + }; +} diff --git a/modules/plugins/lsp/presets/lua-language-server.nix b/modules/plugins/lsp/presets/lua-language-server.nix new file mode 100644 index 00000000..f5e13447 --- /dev/null +++ b/modules/plugins/lsp/presets/lua-language-server.nix @@ -0,0 +1,33 @@ +{ + config, + lib, + pkgs, + ... +}: let + inherit (lib.meta) getExe; + inherit (lib.modules) mkIf; + inherit (lib.nvim.types) mkLspPresetEnableOption; + + cfg = config.vim.lsp.presets.lua-language-server; +in { + options.vim.lsp.presets.lua-language-server = { + enable = mkLspPresetEnableOption "lua-language-server" "Lua" []; + }; + + config = mkIf cfg.enable { + vim.lsp.servers.lua-language-server = { + enable = true; + cmd = [(getExe pkgs.lua-language-server)]; + root_markers = [ + ".luarc.json" + ".luarc.jsonc" + ".luacheckrc" + ".stylua.toml" + "stylua.toml" + "selene.toml" + "selene.yml" + ".git" + ]; + }; + }; +} diff --git a/modules/plugins/lsp/presets/markdown-oxide.nix b/modules/plugins/lsp/presets/markdown-oxide.nix new file mode 100644 index 00000000..8eadd99b --- /dev/null +++ b/modules/plugins/lsp/presets/markdown-oxide.nix @@ -0,0 +1,24 @@ +{ + config, + lib, + pkgs, + ... +}: let + inherit (lib.meta) getExe; + inherit (lib.modules) mkIf; + inherit (lib.nvim.types) mkLspPresetEnableOption; + + cfg = config.vim.lsp.presets.markdown-oxide; +in { + options.vim.lsp.presets.markdown-oxide = { + enable = mkLspPresetEnableOption "markdown-oxide" "Markdown Oxide" []; + }; + + config = mkIf cfg.enable { + vim.lsp.servers.markdown-oxide = { + enable = true; + cmd = [(getExe pkgs.markdown-oxide)]; + root_markers = [".git" ".moxide.toml" ".obsidian"]; + }; + }; +} diff --git a/modules/plugins/lsp/presets/marksman.nix b/modules/plugins/lsp/presets/marksman.nix new file mode 100644 index 00000000..ce40190e --- /dev/null +++ b/modules/plugins/lsp/presets/marksman.nix @@ -0,0 +1,24 @@ +{ + config, + lib, + pkgs, + ... +}: let + inherit (lib.meta) getExe; + inherit (lib.modules) mkIf; + inherit (lib.nvim.types) mkLspPresetEnableOption; + + cfg = config.vim.lsp.presets.marksman; +in { + options.vim.lsp.presets.marksman = { + enable = mkLspPresetEnableOption "marksman" "Marksman" []; + }; + + config = mkIf cfg.enable { + vim.lsp.servers.marksman = { + enable = true; + cmd = [(getExe pkgs.marksman) "server"]; + root_markers = [".git" ".marksman.toml"]; + }; + }; +} diff --git a/modules/plugins/lsp/presets/neocmakelsp.nix b/modules/plugins/lsp/presets/neocmakelsp.nix new file mode 100644 index 00000000..730857ce --- /dev/null +++ b/modules/plugins/lsp/presets/neocmakelsp.nix @@ -0,0 +1,27 @@ +{ + config, + lib, + pkgs, + ... +}: let + inherit (lib.meta) getExe; + inherit (lib.modules) mkIf; + inherit (lib.nvim.types) mkLspPresetEnableOption; + + cfg = config.vim.lsp.presets.neocmakelsp; +in { + options.vim.lsp.presets.neocmakelsp = { + enable = mkLspPresetEnableOption "neocmakelsp" "NeoCmake" []; + }; + + config = mkIf cfg.enable { + vim.lsp.servers.neocmakelsp = { + enable = true; + cmd = [(getExe pkgs.neocmakelsp) "stdio"]; + root_markers = [".git" ".gersemirc"]; + capabilities = { + textDocument.completion.completionItem.snippetSupport = true; + }; + }; + }; +} diff --git a/modules/plugins/lsp/presets/nil.nix b/modules/plugins/lsp/presets/nil.nix new file mode 100644 index 00000000..f27adedb --- /dev/null +++ b/modules/plugins/lsp/presets/nil.nix @@ -0,0 +1,24 @@ +{ + config, + lib, + pkgs, + ... +}: let + inherit (lib.meta) getExe; + inherit (lib.modules) mkIf; + inherit (lib.nvim.types) mkLspPresetEnableOption; + + cfg = config.vim.lsp.presets.nil; +in { + options.vim.lsp.presets.nil = { + enable = mkLspPresetEnableOption "nil" "Nil" []; + }; + + config = mkIf cfg.enable { + vim.lsp.servers.nil = { + enable = true; + cmd = [(getExe pkgs.nil)]; + root_markers = [".git"]; + }; + }; +} diff --git a/modules/plugins/lsp/presets/nimlsp.nix b/modules/plugins/lsp/presets/nimlsp.nix new file mode 100644 index 00000000..f8f376f8 --- /dev/null +++ b/modules/plugins/lsp/presets/nimlsp.nix @@ -0,0 +1,32 @@ +{ + config, + lib, + pkgs, + ... +}: let + inherit (lib.meta) getExe; + inherit (lib.modules) mkIf; + inherit (lib.nvim.types) mkLspPresetEnableOption; + inherit (lib.generators) mkLuaInline; + + cfg = config.vim.lsp.presets.nimlsp; +in { + options.vim.lsp.presets.nimlsp = { + enable = mkLspPresetEnableOption "nimlsp" "Nim" []; + }; + + config = mkIf cfg.enable { + vim.lsp.servers.nimlsp = { + enable = true; + cmd = [(getExe pkgs.nimlsp)]; + root_dir = mkLuaInline '' + function(bufnr, on_dir) + local fname = vim.api.nvim_buf_get_name(bufnr) + on_dir( + util.root_pattern '*.nimble'(fname) or vim.fs.dirname(vim.fs.find('.git', { path = fname, upward = true })[1]) + ) + end + ''; + }; + }; +} diff --git a/modules/plugins/lsp/presets/nixd.nix b/modules/plugins/lsp/presets/nixd.nix new file mode 100644 index 00000000..a8202c61 --- /dev/null +++ b/modules/plugins/lsp/presets/nixd.nix @@ -0,0 +1,24 @@ +{ + config, + lib, + pkgs, + ... +}: let + inherit (lib.meta) getExe; + inherit (lib.modules) mkIf; + inherit (lib.nvim.types) mkLspPresetEnableOption; + + cfg = config.vim.lsp.presets.nixd; +in { + options.vim.lsp.presets.nixd = { + enable = mkLspPresetEnableOption "nixd" "Nixd" []; + }; + + config = mkIf cfg.enable { + vim.lsp.servers.nixd = { + enable = true; + cmd = [(getExe pkgs.nixd)]; + root_markers = [".git"]; + }; + }; +} diff --git a/modules/plugins/lsp/presets/nushell.nix b/modules/plugins/lsp/presets/nushell.nix new file mode 100644 index 00000000..485d2990 --- /dev/null +++ b/modules/plugins/lsp/presets/nushell.nix @@ -0,0 +1,29 @@ +{ + config, + lib, + pkgs, + ... +}: let + inherit (lib.meta) getExe; + inherit (lib.modules) mkIf; + inherit (lib.nvim.types) mkLspPresetEnableOption; + inherit (lib.generators) mkLuaInline; + + cfg = config.vim.lsp.presets.nushell; +in { + options.vim.lsp.presets.nushell = { + enable = mkLspPresetEnableOption "nushell" "NuShell" []; + }; + + config = mkIf cfg.enable { + vim.lsp.servers.nushell = { + enable = true; + cmd = [(getExe pkgs.nushell) "--no-config-file" "--lsp"]; + root_dir = mkLuaInline '' + function(bufnr, on_dir) + on_dir(vim.fs.root(bufnr, { '.git' }) or vim.fs.dirname(vim.api.nvim_buf_get_name(bufnr))) + end + ''; + }; + }; +} diff --git a/modules/plugins/lsp/presets/ocaml-lsp.nix b/modules/plugins/lsp/presets/ocaml-lsp.nix new file mode 100644 index 00000000..a98ba8dd --- /dev/null +++ b/modules/plugins/lsp/presets/ocaml-lsp.nix @@ -0,0 +1,44 @@ +{ + config, + lib, + pkgs, + ... +}: let + inherit (lib.meta) getExe; + inherit (lib.modules) mkIf; + inherit (lib.nvim.types) mkLspPresetEnableOption; + inherit (lib.generators) mkLuaInline; + + cfg = config.vim.lsp.presets.ocaml-lsp; +in { + options.vim.lsp.presets.ocaml-lsp = { + enable = mkLspPresetEnableOption "ocaml-lsp" "OCaml" []; + }; + + config = mkIf cfg.enable { + vim.lsp.servers.ocaml-lsp = { + enable = true; + cmd = [(getExe pkgs.ocamlPackages.ocaml-lsp)]; + root_dir = mkLuaInline '' + function(bufnr, on_dir) + local fname = vim.api.nvim_buf_get_name(bufnr) + on_dir(util.root_pattern('*.opam', 'esy.json', 'package.json', '.git', 'dune-project', 'dune-workspace')(fname)) + end + ''; + get_language_id = mkLuaInline '' + function(_, ftype) + local language_id_of = { + menhir = 'ocaml.menhir', + ocaml = 'ocaml', + ocamlinterface = 'ocaml.interface', + ocamllex = 'ocaml.ocamllex', + reason = 'reason', + dune = 'dune', + } + + return language_id_of[ftype] + end + ''; + }; + }; +} diff --git a/modules/plugins/lsp/presets/ols.nix b/modules/plugins/lsp/presets/ols.nix new file mode 100644 index 00000000..0f2dc4d0 --- /dev/null +++ b/modules/plugins/lsp/presets/ols.nix @@ -0,0 +1,29 @@ +{ + config, + lib, + pkgs, + ... +}: let + inherit (lib.meta) getExe; + inherit (lib.modules) mkIf; + inherit (lib.nvim.types) mkLspPresetEnableOption; + inherit (lib.generators) mkLuaInline; + + cfg = config.vim.lsp.presets.ols; +in { + options.vim.lsp.presets.ols = { + enable = mkLspPresetEnableOption "ols" "Odin" []; + }; + + config = mkIf cfg.enable { + vim.lsp.servers.ols = { + enable = true; + cmd = [(getExe pkgs.ols)]; + root_dir = mkLuaInline '' + function(bufnr, on_dir) + local fname = vim.api.nvim_buf_get_name(bufnr) + on_dir(util.root_pattern('ols.json', '.git', '*.odin')(fname)) + end''; + }; + }; +} diff --git a/modules/plugins/lsp/presets/openscad-lsp.nix b/modules/plugins/lsp/presets/openscad-lsp.nix new file mode 100644 index 00000000..78392f3e --- /dev/null +++ b/modules/plugins/lsp/presets/openscad-lsp.nix @@ -0,0 +1,24 @@ +{ + config, + lib, + pkgs, + ... +}: let + inherit (lib.meta) getExe; + inherit (lib.modules) mkIf; + inherit (lib.nvim.types) mkLspPresetEnableOption; + + cfg = config.vim.lsp.presets.openscad-lsp; +in { + options.vim.lsp.presets.openscad-lsp = { + enable = mkLspPresetEnableOption "openscad-lsp" "Open SCAD" []; + }; + + config = mkIf cfg.enable { + vim.lsp.servers.openscad-lsp = { + enable = true; + cmd = [(getExe pkgs.openscad-lsp) "--stdio"]; + root_markers = [".git"]; + }; + }; +} diff --git a/modules/plugins/lsp/presets/phan.nix b/modules/plugins/lsp/presets/phan.nix new file mode 100644 index 00000000..c259d4fb --- /dev/null +++ b/modules/plugins/lsp/presets/phan.nix @@ -0,0 +1,45 @@ +{ + config, + lib, + pkgs, + ... +}: let + inherit (lib.meta) getExe; + inherit (lib.modules) mkIf; + inherit (lib.nvim.types) mkLspPresetEnableOption; + inherit (lib.generators) mkLuaInline; + + cfg = config.vim.lsp.presets.phan; +in { + options.vim.lsp.presets.phan = { + enable = mkLspPresetEnableOption "phan" "Phan" []; + }; + + config = mkIf cfg.enable { + vim.lsp.servers.phan = { + enable = true; + cmd = [ + (getExe pkgs.php85Packages.phan) + "-m" + "json" + "--no-color" + "--no-progress-bar" + "-x" + "-u" + "-S" + "--language-server-on-stdin" + "--allow-polyfill-parser" + ]; + root_dir = mkLuaInline '' + function(bufnr, on_dir) + local fname = vim.api.nvim_buf_get_name(bufnr) + local cwd = assert(vim.uv.cwd()) + local root = vim.fs.root(fname, { 'composer.json', '.git' }) + + -- prefer cwd if root is a descendant + on_dir(root and vim.fs.relpath(cwd, root) and cwd) + end + ''; + }; + }; +} diff --git a/modules/plugins/lsp/presets/phpactor.nix b/modules/plugins/lsp/presets/phpactor.nix new file mode 100644 index 00000000..3bcd062f --- /dev/null +++ b/modules/plugins/lsp/presets/phpactor.nix @@ -0,0 +1,25 @@ +{ + config, + lib, + pkgs, + ... +}: let + inherit (lib.meta) getExe; + inherit (lib.modules) mkIf; + inherit (lib.nvim.types) mkLspPresetEnableOption; + + cfg = config.vim.lsp.presets.phpactor; +in { + options.vim.lsp.presets.phpactor = { + enable = mkLspPresetEnableOption "phpactor" "PHPActor" []; + }; + + config = mkIf cfg.enable { + vim.lsp.servers.phpactor = { + enable = true; + cmd = [(getExe pkgs.phpactor) "language-server"]; + root_markers = [".git" ".phpactor.json" ".phpactor.yml"]; + workspace_required = true; + }; + }; +} diff --git a/modules/plugins/lsp/presets/pyrefly.nix b/modules/plugins/lsp/presets/pyrefly.nix new file mode 100644 index 00000000..30623c34 --- /dev/null +++ b/modules/plugins/lsp/presets/pyrefly.nix @@ -0,0 +1,24 @@ +{ + config, + lib, + pkgs, + ... +}: let + inherit (lib.meta) getExe; + inherit (lib.modules) mkIf; + inherit (lib.nvim.types) mkLspPresetEnableOption; + + cfg = config.vim.lsp.presets.pyrefly; +in { + options.vim.lsp.presets.pyrefly = { + enable = mkLspPresetEnableOption "pyrefly" "Pyrefly" []; + }; + + config = mkIf cfg.enable { + vim.lsp.servers.pyrefly = { + enable = true; + cmd = [(getExe pkgs.pyrefly) "lsp"]; + root_markers = [".git" "pyrefly.toml"]; + }; + }; +} diff --git a/modules/plugins/lsp/presets/pyright.nix b/modules/plugins/lsp/presets/pyright.nix new file mode 100644 index 00000000..69122718 --- /dev/null +++ b/modules/plugins/lsp/presets/pyright.nix @@ -0,0 +1,76 @@ +{ + config, + lib, + pkgs, + ... +}: let + inherit (lib.meta) getExe'; + inherit (lib.modules) mkIf; + inherit (lib.nvim.types) mkLspPresetEnableOption; + inherit (lib.generators) mkLuaInline; + inherit (lib.nvim.dag) entryBefore; + + cfg = config.vim.lsp.presets.pyright; +in { + options.vim.lsp.presets.pyright = { + enable = mkLspPresetEnableOption "pyright" "Pyright" []; + }; + + config = mkIf cfg.enable { + vim = { + lsp.servers.pyright = { + enable = true; + cmd = [(getExe' pkgs.pyright "pyright-langserver") "--stdio"]; + root_markers = [".git" "pyrightconfig.json"]; + settings = { + python = { + analysis = { + autoSearchPaths = true; + useLibraryCodeForTypes = true; + diagnosticMode = "openFilesOnly"; + }; + }; + }; + on_attach = mkLuaInline '' + function(client, bufnr) + vim.api.nvim_buf_create_user_command(bufnr, 'LspPyrightOrganizeImports', function() + local params = { + command = 'pyright.organizeimports', + arguments = { vim.uri_from_bufnr(bufnr) }, + } + + -- Using client.request() directly because "pyright.organizeimports" is private + -- (not advertised via capabilities), which client:exec_cmd() refuses to call. + -- https://github.com/neovim/neovim/blob/c333d64663d3b6e0dd9aa440e433d346af4a3d81/runtime/lua/vim/lsp/client.lua#L1024-L1030 + client.request('workspace/executeCommand', params, nil, bufnr) + end, { + desc = 'Organize Imports', + }) + vim.api.nvim_buf_create_user_command(bufnr, 'LspPyrightSetPythonPath', pyright_set_python_path, { + desc = 'Reconfigure pyright with the provided python path', + nargs = 1, + complete = 'file', + }) + end + ''; + }; + luaConfigRC.pyright-util = entryBefore ["lsp-servers"] '' + local function pyright_set_python_path(server_name, command) + local path = command.args + local clients = vim.lsp.get_clients { + bufnr = vim.api.nvim_get_current_buf(), + name = server_name, + } + for _, client in ipairs(clients) do + if client.settings then + client.settings.python = vim.tbl_deep_extend('force', client.settings.python or {}, { pythonPath = path }) + else + client.config.settings = vim.tbl_deep_extend('force', client.config.settings, { python = { pythonPath = path } }) + end + client:notify('workspace/didChangeConfiguration', { settings = nil }) + end + end + ''; + }; + }; +} diff --git a/modules/plugins/lsp/presets/python-lsp-server.nix b/modules/plugins/lsp/presets/python-lsp-server.nix new file mode 100644 index 00000000..2d6a41de --- /dev/null +++ b/modules/plugins/lsp/presets/python-lsp-server.nix @@ -0,0 +1,24 @@ +{ + config, + lib, + pkgs, + ... +}: let + inherit (lib.meta) getExe; + inherit (lib.modules) mkIf; + inherit (lib.nvim.types) mkLspPresetEnableOption; + + cfg = config.vim.lsp.presets.python-lsp-server; +in { + options.vim.lsp.presets.python-lsp-server = { + enable = mkLspPresetEnableOption "python-lsp-server" "Python" []; + }; + + config = mkIf cfg.enable { + vim.lsp.servers.python-lsp-server = { + enable = true; + cmd = [(getExe pkgs.python3Packages.python-lsp-server)]; + root_markers = [".git"]; + }; + }; +} diff --git a/modules/plugins/lsp/presets/qmlls.nix b/modules/plugins/lsp/presets/qmlls.nix new file mode 100644 index 00000000..9c39b9e6 --- /dev/null +++ b/modules/plugins/lsp/presets/qmlls.nix @@ -0,0 +1,24 @@ +{ + config, + lib, + pkgs, + ... +}: let + inherit (lib.meta) getExe'; + inherit (lib.modules) mkIf; + inherit (lib.nvim.types) mkLspPresetEnableOption; + + cfg = config.vim.lsp.presets.qmlls; +in { + options.vim.lsp.presets.qmlls = { + enable = mkLspPresetEnableOption "qmlls" "QML" []; + }; + + config = mkIf cfg.enable { + vim.lsp.servers.qmlls = { + enable = true; + cmd = [(getExe' pkgs.kdePackages.qtdeclarative "qmlls")]; + root_markers = [".git"]; + }; + }; +} diff --git a/modules/plugins/lsp/presets/r-languageserver.nix b/modules/plugins/lsp/presets/r-languageserver.nix new file mode 100644 index 00000000..ed126f05 --- /dev/null +++ b/modules/plugins/lsp/presets/r-languageserver.nix @@ -0,0 +1,37 @@ +{ + config, + lib, + pkgs, + ... +}: let + inherit (lib.meta) getExe; + inherit (lib.modules) mkIf; + inherit (lib.nvim.types) mkLspPresetEnableOption; + inherit (lib.generators) mkLuaInline; + + cfg = config.vim.lsp.presets.r-languageserver; +in { + options.vim.lsp.presets.r-languageserver = { + enable = mkLspPresetEnableOption "r-languageserver" "R" []; + }; + + config = mkIf cfg.enable { + vim.lsp.servers.r-languageserver = { + enable = true; + cmd = [ + (getExe (pkgs.rWrapper.override { + packages = [pkgs.rPackages.languageserver]; + })) + "--no-echo" + "-e" + "languageserver::run()" + ]; + root_markers = [".git"]; + root_dir = mkLuaInline '' + function(bufnr, on_dir) + on_dir(vim.fs.root(bufnr, '.git') or vim.uv.os_homedir()) + end + ''; + }; + }; +} diff --git a/modules/plugins/lsp/presets/ruby-lsp.nix b/modules/plugins/lsp/presets/ruby-lsp.nix new file mode 100644 index 00000000..eb9ffb1d --- /dev/null +++ b/modules/plugins/lsp/presets/ruby-lsp.nix @@ -0,0 +1,27 @@ +{ + config, + lib, + pkgs, + ... +}: let + inherit (lib.meta) getExe; + inherit (lib.modules) mkIf; + inherit (lib.nvim.types) mkLspPresetEnableOption; + + cfg = config.vim.lsp.presets.ruby-lsp; +in { + options.vim.lsp.presets.ruby-lsp = { + enable = mkLspPresetEnableOption "ruby-lsp" "Ruby" []; + }; + + config = mkIf cfg.enable { + vim.lsp.servers.ruby-lsp = { + enable = true; + cmd = [(getExe pkgs.ruby-lsp)]; + root_markers = [".git"]; + init_options = { + formatter = "auto"; + }; + }; + }; +} diff --git a/modules/plugins/lsp/presets/ruff.nix b/modules/plugins/lsp/presets/ruff.nix new file mode 100644 index 00000000..aadabc26 --- /dev/null +++ b/modules/plugins/lsp/presets/ruff.nix @@ -0,0 +1,24 @@ +{ + config, + lib, + pkgs, + ... +}: let + inherit (lib.meta) getExe; + inherit (lib.modules) mkIf; + inherit (lib.nvim.types) mkLspPresetEnableOption; + + cfg = config.vim.lsp.presets.ruff; +in { + options.vim.lsp.presets.ruff = { + enable = mkLspPresetEnableOption "ruff" "Ruff" []; + }; + + config = mkIf cfg.enable { + vim.lsp.servers.ruff = { + enable = true; + cmd = [(getExe pkgs.ruff) "server"]; + root_markers = [".git"]; + }; + }; +} diff --git a/modules/plugins/lsp/presets/rumdl.nix b/modules/plugins/lsp/presets/rumdl.nix new file mode 100644 index 00000000..3486d540 --- /dev/null +++ b/modules/plugins/lsp/presets/rumdl.nix @@ -0,0 +1,24 @@ +{ + config, + lib, + pkgs, + ... +}: let + inherit (lib.meta) getExe; + inherit (lib.modules) mkIf; + inherit (lib.nvim.types) mkLspPresetEnableOption; + + cfg = config.vim.lsp.presets.rumdl; +in { + options.vim.lsp.presets.rumdl = { + enable = mkLspPresetEnableOption "rumdl" "Rumdl" []; + }; + + config = mkIf cfg.enable { + vim.lsp.servers.rumdl = { + enable = true; + cmd = [(getExe pkgs.rumdl) "server"]; + root_markers = [".git" ".rumdl.toml" "rumdl.toml" ".config/rumdl.toml" "pyproject.toml"]; + }; + }; +} diff --git a/modules/plugins/lsp/presets/solargraph.nix b/modules/plugins/lsp/presets/solargraph.nix new file mode 100644 index 00000000..131cbfc2 --- /dev/null +++ b/modules/plugins/lsp/presets/solargraph.nix @@ -0,0 +1,35 @@ +{ + config, + lib, + pkgs, + ... +}: let + inherit (lib.meta) getExe; + inherit (lib.modules) mkIf; + inherit (lib.nvim.types) mkLspPresetEnableOption; + + cfg = config.vim.lsp.presets.solargraph; +in { + options.vim.lsp.presets.solargraph = { + enable = mkLspPresetEnableOption "solargraph" "Solargraph" []; + }; + + config = mkIf cfg.enable { + vim.lsp.servers.solargraph = { + enable = true; + cmd = [(getExe pkgs.rubyPackages.solargraph) "stdio"]; + root_markers = [".git"]; + settings = { + solargraph = { + diagnostics = true; + }; + }; + flags = { + debounce_text_changes = 150; + }; + init_options = { + formatting = true; + }; + }; + }; +} diff --git a/modules/plugins/lsp/presets/sqls.nix b/modules/plugins/lsp/presets/sqls.nix new file mode 100644 index 00000000..b15df552 --- /dev/null +++ b/modules/plugins/lsp/presets/sqls.nix @@ -0,0 +1,34 @@ +{ + config, + lib, + pkgs, + ... +}: let + inherit (lib.meta) getExe; + inherit (lib.modules) mkIf; + inherit (lib.nvim.types) mkLspPresetEnableOption; + inherit (lib.generators) mkLuaInline; + + cfg = config.vim.lsp.presets.sqls; +in { + options.vim.lsp.presets.sqls = { + enable = mkLspPresetEnableOption "sqls" "SQL" []; + }; + + config = mkIf cfg.enable { + vim = { + startPlugins = ["sqls-nvim"]; + lsp.servers.sqls = { + enable = true; + cmd = [(getExe pkgs.sqls)]; + root_markers = ["config.yml"]; + on_attach = mkLuaInline '' + function(client, bufnr) + client.server_capabilities.execute_command = true + require'sqls'.setup{} + end + ''; + }; + }; + }; +} diff --git a/modules/plugins/lsp/presets/superhtml.nix b/modules/plugins/lsp/presets/superhtml.nix new file mode 100644 index 00000000..e32907ef --- /dev/null +++ b/modules/plugins/lsp/presets/superhtml.nix @@ -0,0 +1,24 @@ +{ + config, + lib, + pkgs, + ... +}: let + inherit (lib.meta) getExe; + inherit (lib.modules) mkIf; + inherit (lib.nvim.types) mkLspPresetEnableOption; + + cfg = config.vim.lsp.presets.superhtml; +in { + options.vim.lsp.presets.superhtml = { + enable = mkLspPresetEnableOption "superhtml" "SuperHTML" []; + }; + + config = mkIf cfg.enable { + vim.lsp.servers.superhtml = { + enable = true; + cmd = [(getExe pkgs.superhtml) "lsp"]; + root_markers = [".git"]; + }; + }; +} diff --git a/modules/plugins/lsp/presets/svelte-language-server.nix b/modules/plugins/lsp/presets/svelte-language-server.nix new file mode 100644 index 00000000..2ba922af --- /dev/null +++ b/modules/plugins/lsp/presets/svelte-language-server.nix @@ -0,0 +1,53 @@ +{ + config, + lib, + pkgs, + ... +}: let + inherit (lib.meta) getExe; + inherit (lib.modules) mkIf; + inherit (lib.nvim.types) mkLspPresetEnableOption; + inherit (lib.generators) mkLuaInline; + + cfg = config.vim.lsp.presets.svelte-language-server; +in { + options.vim.lsp.presets.svelte-language-server = { + enable = mkLspPresetEnableOption "svelte-language-server" "Svelte" []; + }; + + config = mkIf cfg.enable { + vim.lsp.servers.svelte-language-server = { + enable = true; + cmd = [(getExe pkgs.svelte-language-server) "--stdio"]; + root_dir = mkLuaInline '' + function(bufnr, on_dir) + local root_files = { 'package.json', '.git' } + local fname = vim.api.nvim_buf_get_name(bufnr) + -- Svelte LSP only supports file:// schema. https://github.com/sveltejs/language-tools/issues/2777 + if vim.uv.fs_stat(fname) ~= nil then + on_dir(vim.fs.dirname(vim.fs.find(root_files, { path = fname, upward = true })[1])) + end + end + ''; + on_attach = mkLuaInline '' + function(client, bufnr) + vim.api.nvim_create_autocmd('BufWritePost', { + pattern = { '*.js', '*.ts' }, + group = vim.api.nvim_create_augroup('svelte_js_ts_file_watch', {}), + callback = function(ctx) + -- internal API to sync changes that have not yet been saved to the file system + client:notify('$/onDidChangeTsOrJsFile', { uri = ctx.match }) + end, + }) + + vim.api.nvim_buf_create_user_command(bufnr, 'LspMigrateToSvelte5', function() + client:exec_cmd({ + command = 'migrate_to_svelte_5', + arguments = { vim.uri_from_bufnr(bufnr) }, + }) + end, { desc = 'Migrate Component to Svelte 5 Syntax' }) + end + ''; + }; + }; +} diff --git a/modules/plugins/languages/tailwind.nix b/modules/plugins/lsp/presets/tailwindcss-language-server.nix similarity index 54% rename from modules/plugins/languages/tailwind.nix rename to modules/plugins/lsp/presets/tailwindcss-language-server.nix index da2a514e..846a063d 100644 --- a/modules/plugins/languages/tailwind.nix +++ b/modules/plugins/lsp/presets/tailwindcss-language-server.nix @@ -1,81 +1,83 @@ { config, - pkgs, lib, + pkgs, ... }: let - inherit (builtins) attrNames; - inherit (lib.options) mkEnableOption mkOption literalExpression; - inherit (lib.modules) mkIf mkMerge; inherit (lib.meta) getExe; - inherit (lib.types) enum; - inherit (lib.nvim.attrsets) mapListToAttrs; - inherit (lib.nvim.types) deprecatedSingleOrListOf; + inherit (lib.modules) mkIf; + inherit (lib.nvim.types) mkLspPresetEnableOption; inherit (lib.generators) mkLuaInline; - cfg = config.vim.languages.tailwind; + cfg = config.vim.lsp.presets.tailwindcss-language-server; - defaultServers = ["tailwindcss"]; - servers = { - tailwindcss = { + filetypes = [ + # html + "aspnetcorerazor" + "astro" + "astro-markdown" + "blade" + "clojure" + "django-html" + "htmldjango" + "edge" + "eelixir" + "elixir" + "ejs" + "erb" + "eruby" + "gohtml" + "gohtmltmpl" + "haml" + "handlebars" + "hbs" + "html" + "htmlangular" + "html-eex" + "heex" + "jade" + "leaf" + "liquid" + "markdown" + "mdx" + "mustache" + "njk" + "nunjucks" + "php" + "razor" + "slim" + "twig" + # css + "css" + "less" + "postcss" + "sass" + "scss" + "stylus" + "sugarss" + # js + "javascript" + "javascriptreact" + "reason" + "rescript" + "typescript" + "typescriptreact" + # mixed + "vue" + "svelte" + "templ" + ]; +in { + options.vim.lsp.presets.tailwindcss-language-server = { + enable = mkLspPresetEnableOption "tailwindcss-language-server" "Tailwind CSS" filetypes; + }; + + config = mkIf cfg.enable { + vim.lsp.servers.tailwindcss-language-server = { enable = true; cmd = [(getExe pkgs.tailwindcss-language-server) "--stdio"]; - filetypes = [ - # html - "aspnetcorerazor" - "astro" - "astro-markdown" - "blade" - "clojure" - "django-html" - "htmldjango" - "edge" - "eelixir" - "elixir" - "ejs" - "erb" - "eruby" - "gohtml" - "gohtmltmpl" - "haml" - "handlebars" - "hbs" - "html" - "htmlangular" - "html-eex" - "heex" - "jade" - "leaf" - "liquid" - "markdown" - "mdx" - "mustache" - "njk" - "nunjucks" - "php" - "razor" - "slim" - "twig" - # css - "css" - "less" - "postcss" - "sass" - "scss" - "stylus" - "sugarss" - # js - "javascript" - "javascriptreact" - "reason" - "rescript" - "typescript" - "typescriptreact" - # mixed - "vue" - "svelte" - "templ" - ]; + root_markers = [".git"]; + inherit filetypes; settings = { tailwindCSS = { validate = true; @@ -105,19 +107,6 @@ }; }; }; - before_init = mkLuaInline '' - function(_, config) - if not config.settings then - config.settings = {} - end - if not config.settings.editor then - config.settings.editor = {} - end - if not config.settings.editor.tabSize then - config.settings.editor.tabSize = vim.lsp.util.get_effective_tabstop() - end - end - ''; workspace_required = true; root_dir = mkLuaInline '' function(bufnr, on_dir) @@ -144,36 +133,20 @@ on_dir(vim.fs.dirname(vim.fs.find(root_files, { path = fname, upward = true })[1])) end ''; + + before_init = mkLuaInline '' + function(_, config) + if not config.settings then + config.settings = {} + end + if not config.settings.editor then + config.settings.editor = {} + end + if not config.settings.editor.tabSize then + config.settings.editor.tabSize = vim.lsp.util.get_effective_tabstop() + end + end + ''; }; }; -in { - options.vim.languages.tailwind = { - enable = mkEnableOption "Tailwindcss language support"; - - lsp = { - enable = - mkEnableOption "Tailwindcss LSP support" - // { - default = config.vim.lsp.enable; - defaultText = literalExpression "config.vim.lsp.enable"; - }; - - servers = mkOption { - type = deprecatedSingleOrListOf "vim.language.tailwind.lsp.servers" (enum (attrNames servers)); - default = defaultServers; - description = "Tailwindcss LSP server to use"; - }; - }; - }; - - config = mkIf cfg.enable (mkMerge [ - (mkIf cfg.lsp.enable { - vim.lsp.servers = - mapListToAttrs (n: { - name = n; - value = servers.${n}; - }) - cfg.lsp.servers; - }) - ]); } diff --git a/modules/plugins/lsp/presets/taplo.nix b/modules/plugins/lsp/presets/taplo.nix new file mode 100644 index 00000000..9908b9c6 --- /dev/null +++ b/modules/plugins/lsp/presets/taplo.nix @@ -0,0 +1,24 @@ +{ + config, + lib, + pkgs, + ... +}: let + inherit (lib.meta) getExe; + inherit (lib.modules) mkIf; + inherit (lib.nvim.types) mkLspPresetEnableOption; + + cfg = config.vim.lsp.presets.taplo; +in { + options.vim.lsp.presets.taplo = { + enable = mkLspPresetEnableOption "taplo" "Taplo" []; + }; + + config = mkIf cfg.enable { + vim.lsp.servers.taplo = { + enable = true; + cmd = [(getExe pkgs.taplo) "lsp" "stdio"]; + root_markers = [".git"]; + }; + }; +} diff --git a/modules/plugins/lsp/presets/terraform-ls.nix b/modules/plugins/lsp/presets/terraform-ls.nix new file mode 100644 index 00000000..fce5d2fe --- /dev/null +++ b/modules/plugins/lsp/presets/terraform-ls.nix @@ -0,0 +1,24 @@ +{ + config, + lib, + pkgs, + ... +}: let + inherit (lib.meta) getExe; + inherit (lib.modules) mkIf; + inherit (lib.nvim.types) mkLspPresetEnableOption; + + cfg = config.vim.lsp.presets.terraform-ls; +in { + options.vim.lsp.presets.terraform-ls = { + enable = mkLspPresetEnableOption "terraform-ls" "Terraform" []; + }; + + config = mkIf cfg.enable { + vim.lsp.servers.terraform-ls = { + enable = true; + cmd = [(getExe pkgs.terraform-ls) "serve"]; + root_markers = [".git"]; + }; + }; +} diff --git a/modules/plugins/lsp/presets/texlab.nix b/modules/plugins/lsp/presets/texlab.nix new file mode 100644 index 00000000..5739253e --- /dev/null +++ b/modules/plugins/lsp/presets/texlab.nix @@ -0,0 +1,24 @@ +{ + config, + lib, + pkgs, + ... +}: let + inherit (lib.meta) getExe; + inherit (lib.modules) mkIf; + inherit (lib.nvim.types) mkLspPresetEnableOption; + + cfg = config.vim.lsp.presets.texlab; +in { + options.vim.lsp.presets.texlab = { + enable = mkLspPresetEnableOption "texlab" "TeXLab" []; + }; + + config = mkIf cfg.enable { + vim.lsp.servers.texlab = { + enable = true; + cmd = [(getExe pkgs.texlab) "run"]; + root_markers = [".git" ".latexmkrc" "latexmkrc" ".texlabroot" "texlabroot" ".texstudio" "Tectonic.toml"]; + }; + }; +} diff --git a/modules/plugins/lsp/presets/tinymist.nix b/modules/plugins/lsp/presets/tinymist.nix new file mode 100644 index 00000000..8f8684f2 --- /dev/null +++ b/modules/plugins/lsp/presets/tinymist.nix @@ -0,0 +1,76 @@ +{ + config, + lib, + pkgs, + ... +}: let + inherit (lib.meta) getExe; + inherit (lib.modules) mkIf; + inherit (lib.nvim.types) mkLspPresetEnableOption; + inherit (lib.generators) mkLuaInline; + + cfg = config.vim.lsp.presets.tinymist; +in { + options.vim.lsp.presets.tinymist = { + enable = mkLspPresetEnableOption "tinymist" "Tinymist" []; + }; + + config = mkIf cfg.enable { + vim.lsp.servers.tinymist = { + enable = true; + cmd = [(getExe pkgs.tinymist)]; + root_markers = [".git"]; + on_attach = mkLuaInline '' + function(client, bufnr) + local function create_tinymist_command(command_name, client, bufnr) + local export_type = command_name:match 'tinymist%.export(%w+)' + local info_type = command_name:match 'tinymist%.(%w+)' + if info_type and info_type:match '^get' then + info_type = info_type:gsub('^get', 'Get') + end + local cmd_display = export_type or info_type + local function run_tinymist_command() + local arguments = { vim.api.nvim_buf_get_name(bufnr) } + local title_str = export_type and ('Export ' .. cmd_display) or cmd_display + local function handler(err, res) + if err then + return vim.notify(err.code .. ': ' .. err.message, vim.log.levels.ERROR) + end + vim.notify(export_type and res or vim.inspect(res), vim.log.levels.INFO) + end + if vim.fn.has 'nvim-0.11' == 1 then + return client:exec_cmd({ + title = title_str, + command = command_name, + arguments = arguments, + }, { bufnr = bufnr }, handler) + else + return vim.notify('Tinymist commands require Neovim 0.11+', vim.log.levels.WARN) + end + end + local cmd_name = export_type and ('LspTinymistExport' .. cmd_display) or ('LspTinymist' .. cmd_display) + local cmd_desc = export_type and ('Export to ' .. cmd_display) or ('Get ' .. cmd_display) + return run_tinymist_command, cmd_name, cmd_desc + end + + for _, command in ipairs { + 'tinymist.exportSvg', + 'tinymist.exportPng', + 'tinymist.exportPdf', + 'tinymist.exportMarkdown', + 'tinymist.exportText', + 'tinymist.exportQuery', + 'tinymist.exportAnsiHighlight', + 'tinymist.getServerInfo', + 'tinymist.getDocumentTrace', + 'tinymist.getWorkspaceLabels', + 'tinymist.getDocumentMetrics', + } do + local cmd_func, cmd_name, cmd_desc = create_tinymist_command(command, client, bufnr) + vim.api.nvim_buf_create_user_command(bufnr, cmd_name, cmd_func, { nargs = 0, desc = cmd_desc }) + end + end + ''; + }; + }; +} diff --git a/modules/plugins/lsp/presets/tofu-ls.nix b/modules/plugins/lsp/presets/tofu-ls.nix new file mode 100644 index 00000000..0532471e --- /dev/null +++ b/modules/plugins/lsp/presets/tofu-ls.nix @@ -0,0 +1,24 @@ +{ + config, + lib, + pkgs, + ... +}: let + inherit (lib.meta) getExe; + inherit (lib.modules) mkIf; + inherit (lib.nvim.types) mkLspPresetEnableOption; + + cfg = config.vim.lsp.presets.tofu-ls; +in { + options.vim.lsp.presets.tofu-ls = { + enable = mkLspPresetEnableOption "tofu-ls" "OpenTofu" []; + }; + + config = mkIf cfg.enable { + vim.lsp.servers.tofu-ls = { + enable = true; + cmd = [(getExe pkgs.tofu-ls) "serve"]; + root_markers = [".git"]; + }; + }; +} diff --git a/modules/plugins/lsp/presets/tombi.nix b/modules/plugins/lsp/presets/tombi.nix new file mode 100644 index 00000000..868abeb6 --- /dev/null +++ b/modules/plugins/lsp/presets/tombi.nix @@ -0,0 +1,24 @@ +{ + config, + lib, + pkgs, + ... +}: let + inherit (lib.meta) getExe; + inherit (lib.modules) mkIf; + inherit (lib.nvim.types) mkLspPresetEnableOption; + + cfg = config.vim.lsp.presets.tombi; +in { + options.vim.lsp.presets.tombi = { + enable = mkLspPresetEnableOption "tombi" "Tombi (AI Slop)" []; + }; + + config = mkIf cfg.enable { + vim.lsp.servers.tombi = { + enable = true; + cmd = [(getExe pkgs.tombi) "lsp"]; + root_markers = [".git" "tombi.toml"]; + }; + }; +} diff --git a/modules/plugins/lsp/presets/twig-language-server.nix b/modules/plugins/lsp/presets/twig-language-server.nix new file mode 100644 index 00000000..1668310c --- /dev/null +++ b/modules/plugins/lsp/presets/twig-language-server.nix @@ -0,0 +1,24 @@ +{ + config, + lib, + pkgs, + ... +}: let + inherit (lib.meta) getExe; + inherit (lib.modules) mkIf; + inherit (lib.nvim.types) mkLspPresetEnableOption; + + cfg = config.vim.lsp.presets.twig-language-server; +in { + options.vim.lsp.presets.twig-language-server = { + enable = mkLspPresetEnableOption "twig-language-server" "Twig" []; + }; + + config = mkIf cfg.enable { + vim.lsp.servers.twig-language-server = { + enable = true; + cmd = [(getExe pkgs.twig-language-server) "--stdio"]; + root_markers = [".git"]; + }; + }; +} diff --git a/modules/plugins/lsp/presets/ty.nix b/modules/plugins/lsp/presets/ty.nix new file mode 100644 index 00000000..8468dde9 --- /dev/null +++ b/modules/plugins/lsp/presets/ty.nix @@ -0,0 +1,24 @@ +{ + config, + lib, + pkgs, + ... +}: let + inherit (lib.meta) getExe; + inherit (lib.modules) mkIf; + inherit (lib.nvim.types) mkLspPresetEnableOption; + + cfg = config.vim.lsp.presets.ty; +in { + options.vim.lsp.presets.ty = { + enable = mkLspPresetEnableOption "ty" "ty" []; + }; + + config = mkIf cfg.enable { + vim.lsp.servers.ty = { + enable = true; + cmd = [(getExe pkgs.ty) "server"]; + root_markers = [".git"]; + }; + }; +} diff --git a/modules/plugins/lsp/presets/typescript-go.nix b/modules/plugins/lsp/presets/typescript-go.nix new file mode 100644 index 00000000..121fad29 --- /dev/null +++ b/modules/plugins/lsp/presets/typescript-go.nix @@ -0,0 +1,24 @@ +{ + config, + lib, + pkgs, + ... +}: let + inherit (lib.meta) getExe; + inherit (lib.modules) mkIf; + inherit (lib.nvim.types) mkLspPresetEnableOption; + + cfg = config.vim.lsp.presets.typescript-go; +in { + options.vim.lsp.presets.typescript-go = { + enable = mkLspPresetEnableOption "typescript-go" "experimental TypeScript Go" []; + }; + + config = mkIf cfg.enable { + vim.lsp.servers.typescript-go = { + enable = true; + cmd = [(getExe pkgs.typescript-go) "--lsp" "--stdio"]; + root_markers = [".git" "package.json"]; + }; + }; +} diff --git a/modules/plugins/lsp/presets/typescript-language-server.nix b/modules/plugins/lsp/presets/typescript-language-server.nix new file mode 100644 index 00000000..efd95cc0 --- /dev/null +++ b/modules/plugins/lsp/presets/typescript-language-server.nix @@ -0,0 +1,60 @@ +{ + config, + lib, + pkgs, + ... +}: let + inherit (lib.meta) getExe; + inherit (lib.modules) mkIf; + inherit (lib.nvim.types) mkLspPresetEnableOption; + inherit (lib.generators) mkLuaInline; + + cfg = config.vim.lsp.presets.typescript-language-server; +in { + options.vim.lsp.presets.typescript-language-server = { + enable = mkLspPresetEnableOption "typescript-language-server" "TypeScript" []; + }; + + config = mkIf cfg.enable { + vim.lsp.servers.typescript-language-server = { + enable = true; + cmd = [(getExe pkgs.typescript-language-server) "--stdio"]; + root_markers = [".git" "package.json"]; + init_options = {hostInfo = "neovim";}; + handlers = { + # handle rename request for certain code actions like extracting functions / types + "_typescript.rename" = mkLuaInline '' + function(_, result, ctx) + local client = assert(vim.lsp.get_client_by_id(ctx.client_id)) + vim.lsp.util.show_document({ + uri = result.textDocument.uri, + range = { + start = result.position, + ['end'] = result.position, + }, + }, client.offset_encoding) + vim.lsp.buf.rename() + return vim.NIL + end + ''; + }; + on_attach = mkLuaInline '' + function(client, bufnr) + -- ts_ls provides `source.*` code actions that apply to the whole file. These only appear in + -- `vim.lsp.buf.code_action()` if specified in `context.only`. + vim.api.nvim_buf_create_user_command(0, 'LspTypescriptSourceAction', function() + local source_actions = vim.tbl_filter(function(action) + return vim.startswith(action, 'source.') + end, client.server_capabilities.codeActionProvider.codeActionKinds) + + vim.lsp.buf.code_action({ + context = { + only = source_actions, + }, + }) + end, {}) + end + ''; + }; + }; +} diff --git a/modules/plugins/lsp/presets/vala-language-server.nix b/modules/plugins/lsp/presets/vala-language-server.nix new file mode 100644 index 00000000..f7dbc600 --- /dev/null +++ b/modules/plugins/lsp/presets/vala-language-server.nix @@ -0,0 +1,35 @@ +{ + config, + lib, + pkgs, + ... +}: let + inherit (lib.meta) getExe; + inherit (lib.modules) mkIf; + inherit (lib.nvim.types) mkLspPresetEnableOption; + + cfg = config.vim.lsp.presets.vala-language-server; +in { + options.vim.lsp.presets.vala-language-server = { + enable = mkLspPresetEnableOption "vala-language-server" "Vala" []; + }; + + config = mkIf cfg.enable { + vim.lsp.servers.vala-language-server = { + enable = true; + # We are wrapping the LSP with uncrustify in the path, + # because it is an optional dependency to support formatting + # + cmd = [ + (getExe (pkgs.symlinkJoin { + name = "vala-language-server-wrapper"; + paths = [pkgs.vala-language-server]; + meta.mainProgram = "vala-language-server"; + buildInputs = [pkgs.makeBinaryWrapper]; + postBuild = "wrapProgram $out/bin/vala-language-server --prefix PATH : ${pkgs.uncrustify}/bin"; + })) + ]; + root_markers = [".git"]; + }; + }; +} diff --git a/modules/plugins/lsp/presets/vscode-css-language-server.nix b/modules/plugins/lsp/presets/vscode-css-language-server.nix new file mode 100644 index 00000000..39196aa8 --- /dev/null +++ b/modules/plugins/lsp/presets/vscode-css-language-server.nix @@ -0,0 +1,30 @@ +{ + config, + lib, + pkgs, + ... +}: let + inherit (lib.meta) getExe'; + inherit (lib.modules) mkIf; + inherit (lib.nvim.types) mkLspPresetEnableOption; + + cfg = config.vim.lsp.presets.vscode-css-language-server; +in { + options.vim.lsp.presets.vscode-css-language-server = { + enable = mkLspPresetEnableOption "vscode-css-language-server" "VSCode CSS" []; + }; + + config = mkIf cfg.enable { + vim.lsp.servers.vscode-css-language-server = { + enable = true; + cmd = [(getExe' pkgs.vscode-langservers-extracted "vscode-css-language-server") "--stdio"]; + root_markers = [".git" "package.json"]; + init_options = {provideFormatter = true;}; + settings = { + css.validate = true; + scss.validate = true; + less.validate = true; + }; + }; + }; +} diff --git a/modules/plugins/lsp/presets/vscode-json-language-server.nix b/modules/plugins/lsp/presets/vscode-json-language-server.nix new file mode 100644 index 00000000..9a3ff2dd --- /dev/null +++ b/modules/plugins/lsp/presets/vscode-json-language-server.nix @@ -0,0 +1,25 @@ +{ + config, + lib, + pkgs, + ... +}: let + inherit (lib.meta) getExe'; + inherit (lib.modules) mkIf; + inherit (lib.nvim.types) mkLspPresetEnableOption; + + cfg = config.vim.lsp.presets.vscode-json-language-server; +in { + options.vim.lsp.presets.vscode-json-language-server = { + enable = mkLspPresetEnableOption "vscode-json-language-server" "VSCode JSON" []; + }; + + config = mkIf cfg.enable { + vim.lsp.servers.vscode-json-language-server = { + enable = true; + cmd = [(getExe' pkgs.vscode-langservers-extracted "vscode-json-language-server") "--stdio"]; + root_markers = [".git"]; + init_options = {provideFormatter = true;}; + }; + }; +} diff --git a/modules/plugins/lsp/presets/wgsl-analyzer.nix b/modules/plugins/lsp/presets/wgsl-analyzer.nix new file mode 100644 index 00000000..523212c4 --- /dev/null +++ b/modules/plugins/lsp/presets/wgsl-analyzer.nix @@ -0,0 +1,24 @@ +{ + config, + lib, + pkgs, + ... +}: let + inherit (lib.meta) getExe; + inherit (lib.modules) mkIf; + inherit (lib.nvim.types) mkLspPresetEnableOption; + + cfg = config.vim.lsp.presets.wgsl-analyzer; +in { + options.vim.lsp.presets.wgsl-analyzer = { + enable = mkLspPresetEnableOption "wgsl-analyzer" "WGSL Analyzer" []; + }; + + config = mkIf cfg.enable { + vim.lsp.servers.wgsl-analyzer = { + enable = true; + cmd = [(getExe pkgs.wgsl-analyzer)]; + root_markers = [".git"]; + }; + }; +} diff --git a/modules/plugins/lsp/presets/yaml-language-server.nix b/modules/plugins/lsp/presets/yaml-language-server.nix new file mode 100644 index 00000000..58204a21 --- /dev/null +++ b/modules/plugins/lsp/presets/yaml-language-server.nix @@ -0,0 +1,32 @@ +{ + config, + lib, + pkgs, + ... +}: let + inherit (lib.meta) getExe; + inherit (lib.modules) mkIf; + inherit (lib.nvim.types) mkLspPresetEnableOption; + + cfg = config.vim.lsp.presets.yaml-language-server; +in { + options.vim.lsp.presets.yaml-language-server = { + enable = mkLspPresetEnableOption "yaml-language-server" "YAML" []; + }; + + config = mkIf cfg.enable { + vim.lsp.servers.yaml-language-server = { + enable = true; + cmd = [(getExe pkgs.yaml-language-server) "--stdio"]; + root_markers = [".git"]; + settings = { + # https://github.com/redhat-developer/vscode-redhat-telemetry#how-to-disable-telemetry-reporting + redhat = { + telemetry = { + enabled = false; + }; + }; + }; + }; + }; +} diff --git a/modules/plugins/lsp/presets/zls.nix b/modules/plugins/lsp/presets/zls.nix new file mode 100644 index 00000000..a9b4d92b --- /dev/null +++ b/modules/plugins/lsp/presets/zls.nix @@ -0,0 +1,25 @@ +{ + config, + lib, + pkgs, + ... +}: let + inherit (lib.meta) getExe; + inherit (lib.modules) mkIf; + inherit (lib.nvim.types) mkLspPresetEnableOption; + + cfg = config.vim.lsp.presets.zls; +in { + options.vim.lsp.presets.zls = { + enable = mkLspPresetEnableOption "zls" "Zig" []; + }; + + config = mkIf cfg.enable { + vim.lsp.servers.zls = { + enable = true; + cmd = [(getExe pkgs.zls)]; + root_markers = [".git" "zls.json"]; + workspace_required = false; + }; + }; +} diff --git a/modules/plugins/lsp/presets/zuban.nix b/modules/plugins/lsp/presets/zuban.nix new file mode 100644 index 00000000..b7cc7f2d --- /dev/null +++ b/modules/plugins/lsp/presets/zuban.nix @@ -0,0 +1,24 @@ +{ + config, + lib, + pkgs, + ... +}: let + inherit (lib.meta) getExe; + inherit (lib.modules) mkIf; + inherit (lib.nvim.types) mkLspPresetEnableOption; + + cfg = config.vim.lsp.presets.zuban; +in { + options.vim.lsp.presets.zuban = { + enable = mkLspPresetEnableOption "zuban" "Zuban" []; + }; + + config = mkIf cfg.enable { + vim.lsp.servers.zuban = { + enable = true; + cmd = [(getExe pkgs.zuban) "server"]; + root_markers = [".git"]; + }; + }; +}