neovim-flake/modules/plugins/languages/html.nix

88 lines
2.4 KiB
Nix
Raw Permalink Normal View History

2023-04-18 00:05:18 +02:00
{
config,
pkgs,
2023-04-18 00:05:18 +02:00
lib,
...
}: let
2024-10-16 03:19:32 +02:00
inherit (builtins) attrNames;
inherit (lib.options) mkOption mkEnableOption;
inherit (lib.modules) mkIf mkMerge;
2024-10-16 03:19:32 +02:00
inherit (lib.lists) optional isList;
inherit (lib.types) enum either package listOf str bool;
inherit (lib.nvim.types) mkGrammarOption;
2024-10-16 03:19:32 +02:00
inherit (lib.nvim.lua) expToLua;
inherit (lib.nvim.dag) entryAnywhere;
2023-04-18 00:05:18 +02:00
cfg = config.vim.languages.html;
2024-10-16 03:19:32 +02:00
defaultServer = "html";
servers = {
html = {
package = pkgs.vscode-langservers-extracted;
lspConfig = ''
lspconfig.html.setup{
capabilities = capabilities;
on_attach = default_on_attach;
cmd = ${
if isList cfg.lsp.package
then expToLua cfg.lsp.package
else ''{"${cfg.lsp.package}/bin/vscode-html-language-server", "--stdio"}''
};
}
'';
};
};
2023-04-18 00:05:18 +02:00
in {
options.vim.languages.html = {
enable = mkEnableOption "HTML language support";
2024-10-16 03:19:32 +02:00
lsp = {
enable = mkEnableOption "Enable HTML LSP support" // {default = config.vim.languages.enableLSP;};
server = mkOption {
type = enum (attrNames servers);
default = defaultServer;
description = "HTML LSP server to use";
};
package = mkOption {
type = either package (listOf str);
default = pkgs.vscode-langservers-extracted;
description = "html-language-server package, or the command to run as a list of strings";
};
};
2023-04-18 00:05:18 +02:00
treesitter = {
enable = mkEnableOption "HTML treesitter support" // {default = config.vim.languages.enableTreesitter;};
package = mkGrammarOption pkgs "html";
2023-04-18 00:05:18 +02:00
autotagHtml = mkOption {
description = "Enable autoclose/autorename of html tags (nvim-ts-autotag)";
type = bool;
2023-04-18 00:05:18 +02:00
default = true;
};
};
};
config = mkIf cfg.enable (mkMerge [
2024-10-16 03:19:32 +02:00
(mkIf cfg.lsp.enable {
vim.lsp.lspconfig.enable = true;
vim.lsp.lspconfig.sources.html-lsp = servers.${cfg.lsp.server}.lspConfig;
})
2023-04-18 00:05:18 +02:00
(mkIf cfg.treesitter.enable {
vim = {
startPlugins = optional cfg.treesitter.autotagHtml "nvim-ts-autotag";
2023-04-18 00:05:18 +02:00
treesitter = {
enable = true;
grammars = [cfg.treesitter.package];
};
2023-04-18 00:05:18 +02:00
pluginRC.html-autotag = mkIf cfg.treesitter.autotagHtml (entryAnywhere ''
require('nvim-ts-autotag').setup()
'');
};
2023-04-18 00:05:18 +02:00
})
]);
}