2023-04-18 00:05:18 +02:00
|
|
|
{
|
|
|
|
config,
|
2024-03-09 06:49:22 +01:00
|
|
|
pkgs,
|
2023-04-18 00:05:18 +02:00
|
|
|
lib,
|
|
|
|
...
|
2023-11-08 03:16:46 +01:00
|
|
|
}: let
|
2024-10-16 03:19:32 +02:00
|
|
|
inherit (builtins) attrNames;
|
|
|
|
inherit (lib.options) mkOption mkEnableOption;
|
2024-03-09 06:49:22 +01:00
|
|
|
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;
|
2024-03-09 06:49:22 +01:00
|
|
|
inherit (lib.nvim.types) mkGrammarOption;
|
2024-10-16 03:19:32 +02:00
|
|
|
inherit (lib.nvim.lua) expToLua;
|
2024-03-09 06:49:22 +01:00
|
|
|
inherit (lib.nvim.dag) entryAnywhere;
|
2023-11-08 03:16:46 +01:00
|
|
|
|
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 = {
|
2024-03-09 06:49:22 +01:00
|
|
|
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)";
|
2024-03-09 06:49:22 +01:00
|
|
|
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 {
|
2024-03-09 06:49:22 +01:00
|
|
|
vim = {
|
|
|
|
startPlugins = optional cfg.treesitter.autotagHtml "nvim-ts-autotag";
|
2023-04-18 00:05:18 +02:00
|
|
|
|
2024-03-09 06:49:22 +01:00
|
|
|
treesitter = {
|
|
|
|
enable = true;
|
|
|
|
grammars = [cfg.treesitter.package];
|
|
|
|
};
|
2023-04-18 00:05:18 +02:00
|
|
|
|
2024-07-20 10:30:48 +02:00
|
|
|
pluginRC.html-autotag = mkIf cfg.treesitter.autotagHtml (entryAnywhere ''
|
2024-03-09 06:49:22 +01:00
|
|
|
require('nvim-ts-autotag').setup()
|
|
|
|
'');
|
|
|
|
};
|
2023-04-18 00:05:18 +02:00
|
|
|
})
|
|
|
|
]);
|
|
|
|
}
|