From 078688bb9fa29cae40c9a1f294a5265709b99c55 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Sun, 16 Feb 2025 12:48:40 +0300 Subject: [PATCH] lib/languages: add `lspOptions` submodule type for freeform LSP config --- lib/languages.nix | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/lib/languages.nix b/lib/languages.nix index a202ff14..19171cc8 100644 --- a/lib/languages.nix +++ b/lib/languages.nix @@ -1,9 +1,10 @@ -# From home-manager: https://github.com/nix-community/home-manager/blob/master/modules/lib/booleans.nix {lib}: let inherit (builtins) isString getAttr; inherit (lib.options) mkOption; - inherit (lib.types) bool; + inherit (lib.types) listOf bool str submodule attrsOf anything; + inherit (lib.generators) mkLuaInline; inherit (lib.nvim.attrsets) mapListToAttrs; + inherit (lib.nvim.types) luaInline; in { diagnosticsToLua = { lang, @@ -32,4 +33,31 @@ in { type = bool; description = "Turn on ${desc} for enabled languages by default"; }; + + lspOptions = submodule { + freeformType = attrsOf anything; + options = { + capabilities = mkOption { + type = luaInline; + default = mkLuaInline "capabilities"; + description = "LSP capabilitiess to pass to lspconfig"; + }; + + on_attach = mkOption { + type = luaInline; + default = mkLuaInline "default_on_attach"; + description = "Function to execute when an LSP server attaches to a buffer"; + }; + + filetypes = mkOption { + type = listOf str; + description = "Filetypes to auto-attach LSP in"; + }; + + cmd = mkOption { + type = listOf str; + description = "Command used to start the LSP server"; + }; + }; + }; }