From c4dbf87dee54b915d25083a785597883c6e0859e Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Wed, 16 Oct 2024 04:19:32 +0300 Subject: [PATCH] languages/html: add HTML LSP --- modules/plugins/languages/html.nix | 48 ++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/modules/plugins/languages/html.nix b/modules/plugins/languages/html.nix index 0bef276..749347c 100644 --- a/modules/plugins/languages/html.nix +++ b/modules/plugins/languages/html.nix @@ -4,17 +4,54 @@ lib, ... }: let - inherit (lib.options) mkEnableOption mkOption; + inherit (builtins) attrNames; + inherit (lib.options) mkOption mkEnableOption; inherit (lib.modules) mkIf mkMerge; - inherit (lib.types) bool; - inherit (lib.lists) optional; + inherit (lib.lists) optional isList; + inherit (lib.types) enum either package listOf str bool; inherit (lib.nvim.types) mkGrammarOption; + inherit (lib.nvim.lua) expToLua; inherit (lib.nvim.dag) entryAnywhere; 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 { options.vim.languages.html = { 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 = { enable = mkEnableOption "HTML treesitter support" // {default = config.vim.languages.enableTreesitter;}; package = mkGrammarOption pkgs "html"; @@ -27,6 +64,11 @@ in { }; 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 { vim = { startPlugins = optional cfg.treesitter.autotagHtml "nvim-ts-autotag";