languages/html: add HTML LSP

This commit is contained in:
NotAShelf 2024-10-16 04:19:32 +03:00
parent 79447a0024
commit c4dbf87dee
No known key found for this signature in database
GPG key ID: AF26552424E53993

View file

@ -4,17 +4,54 @@
lib, lib,
... ...
}: let }: let
inherit (lib.options) mkEnableOption mkOption; inherit (builtins) attrNames;
inherit (lib.options) mkOption mkEnableOption;
inherit (lib.modules) mkIf mkMerge; inherit (lib.modules) mkIf mkMerge;
inherit (lib.types) bool; inherit (lib.lists) optional isList;
inherit (lib.lists) optional; inherit (lib.types) enum either package listOf str bool;
inherit (lib.nvim.types) mkGrammarOption; inherit (lib.nvim.types) mkGrammarOption;
inherit (lib.nvim.lua) expToLua;
inherit (lib.nvim.dag) entryAnywhere; inherit (lib.nvim.dag) entryAnywhere;
cfg = config.vim.languages.html; cfg = config.vim.languages.html;
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"}''
};
}
'';
};
};
in { in {
options.vim.languages.html = { options.vim.languages.html = {
enable = mkEnableOption "HTML language support"; enable = mkEnableOption "HTML language support";
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";
};
};
treesitter = { treesitter = {
enable = mkEnableOption "HTML treesitter support" // {default = config.vim.languages.enableTreesitter;}; enable = mkEnableOption "HTML treesitter support" // {default = config.vim.languages.enableTreesitter;};
package = mkGrammarOption pkgs "html"; package = mkGrammarOption pkgs "html";
@ -27,6 +64,11 @@ in {
}; };
config = mkIf cfg.enable (mkMerge [ config = mkIf cfg.enable (mkMerge [
(mkIf cfg.lsp.enable {
vim.lsp.lspconfig.enable = true;
vim.lsp.lspconfig.sources.html-lsp = servers.${cfg.lsp.server}.lspConfig;
})
(mkIf cfg.treesitter.enable { (mkIf cfg.treesitter.enable {
vim = { vim = {
startPlugins = optional cfg.treesitter.autotagHtml "nvim-ts-autotag"; startPlugins = optional cfg.treesitter.autotagHtml "nvim-ts-autotag";