languages: convert modules to new LSP option set format
Some checks failed
Check for typos in the source tree / check-typos (push) Has been cancelled

This commit is contained in:
raf 2025-02-16 12:49:10 +03:00
commit 5bc627f4e4
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF
10 changed files with 406 additions and 180 deletions

View file

@ -4,12 +4,34 @@
lib,
...
}: let
inherit (builtins) attrNames;
inherit (lib.options) mkEnableOption mkOption;
inherit (lib.modules) mkIf mkMerge;
inherit (lib.types) package;
inherit (lib.types) enum either listOf package str;
inherit (lib.lists) isList;
inherit (lib.meta) getExe;
inherit (lib.generators) mkLuaInline;
inherit (lib.nvim.lua) expToLua toLuaObject;
inherit (lib.nvim.languages) lspOptions;
inherit (lib.nvim.types) mkGrammarOption;
cfg = config.vim.languages.assembly;
defaultServer = "asm_lsp";
servers = {
asm_lsp = {
package = pkgs.asm-lsp;
options = {
capabilities = mkLuaInline "capabilities";
on_attach = mkLuaInline "default_on_attach";
filetypes = ["asm" "vasm"];
cmd =
if isList cfg.lsp.package
then expToLua cfg.lsp.package
else ["${getExe cfg.lsp.package}"];
};
};
};
in {
options.vim.languages.assembly = {
enable = mkEnableOption "Assembly support";
@ -22,28 +44,46 @@ in {
lsp = {
enable = mkEnableOption "Assembly LSP support (asm-lsp)" // {default = config.vim.languages.enableLSP;};
server = mkOption {
description = "Assembly LSP server to use";
type = enum (attrNames servers);
default = defaultServer;
};
package = mkOption {
type = package;
default = pkgs.asm-lsp;
description = "asm-lsp package";
description = "asm-lsp LSP server package, or the command to run as a list of strings";
example = ''[lib.getExe pkgs.asm-lsp "--quiet"]'';
type = either package (listOf str);
default = servers.${cfg.lsp.server}.package;
};
options = mkOption {
type = lspOptions;
default = servers.${cfg.lsp.server}.options;
description = ''
LSP options for Assembly language support.
This option is freeform, you may add options that are not set by default
and they will be merged into the final table passed to lspconfig.
'';
};
};
};
config = mkIf cfg.enable (mkMerge [
(mkIf cfg.treesitter.enable {
vim.treesitter.enable = true;
vim.treesitter.grammars = [cfg.treesitter.package];
vim.treesitter = {
enable = true;
grammars = [cfg.treesitter.package];
};
})
(mkIf cfg.lsp.enable {
vim.lsp.lspconfig.enable = true;
vim.lsp.lspconfig.sources.asm-lsp = ''
lspconfig.asm_lsp.setup {
capabilities = capabilities,
on_attach = default_on_attach,
cmd = {"${cfg.lsp.package}/bin/asm-lsp"},
}
'';
vim.lsp.lspconfig = {
enable = true;
sources.asm-lsp = ''
lspconfig.${toLuaObject cfg.lsp.server}.setup(${toLuaObject cfg.lsp.options})
'';
};
})
]);
}