2023-04-17 21:38:57 +00:00
|
|
|
{
|
|
|
|
config,
|
2024-03-08 17:34:19 +00:00
|
|
|
pkgs,
|
2023-04-17 21:38:57 +00:00
|
|
|
lib,
|
|
|
|
...
|
2023-11-08 02:16:46 +00:00
|
|
|
}: let
|
2024-05-06 19:22:43 +00:00
|
|
|
inherit (builtins) attrNames concatLists;
|
2024-05-07 21:22:12 +00:00
|
|
|
inherit (lib.modules) mkIf mkMerge;
|
2024-03-08 17:34:19 +00:00
|
|
|
inherit (lib.options) mkEnableOption mkOption;
|
|
|
|
inherit (lib.lists) isList;
|
|
|
|
inherit (lib.types) bool enum either package listOf str;
|
|
|
|
inherit (lib.nvim.lua) expToLua;
|
|
|
|
inherit (lib.nvim.types) mkGrammarOption;
|
2023-11-08 02:16:46 +00:00
|
|
|
|
2023-04-17 21:38:57 +00:00
|
|
|
cfg = config.vim.languages.markdown;
|
2024-01-18 16:28:46 +00:00
|
|
|
defaultServer = "marksman";
|
|
|
|
servers = {
|
|
|
|
marksman = {
|
|
|
|
package = pkgs.marksman;
|
|
|
|
lspConfig = ''
|
|
|
|
lspconfig.marksman.setup{
|
|
|
|
capabilities = capabilities;
|
|
|
|
on_attach = default_on_attach;
|
|
|
|
cmd = ${
|
|
|
|
if isList cfg.lsp.package
|
2024-03-08 17:34:19 +00:00
|
|
|
then expToLua cfg.lsp.package
|
2024-01-18 16:28:46 +00:00
|
|
|
else ''{"${cfg.lsp.package}/bin/marksman", "server"}''
|
|
|
|
},
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
2024-05-06 19:22:43 +00:00
|
|
|
|
|
|
|
defaultFormat = "denofmt";
|
|
|
|
formats = {
|
|
|
|
denofmt = {
|
|
|
|
package = pkgs.deno;
|
|
|
|
nullConfig = ''
|
|
|
|
table.insert(
|
|
|
|
ls_sources,
|
|
|
|
null_ls.builtins.formatting.deno_fmt.with({
|
2024-05-07 21:31:23 +00:00
|
|
|
filetypes = ${expToLua (concatLists [cfg.format.extraFiletypes ["markdown"]])},
|
2024-05-06 19:22:43 +00:00
|
|
|
command = "${cfg.format.package}/bin/deno",
|
|
|
|
})
|
|
|
|
)
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
2023-04-17 21:38:57 +00:00
|
|
|
in {
|
|
|
|
options.vim.languages.markdown = {
|
2023-06-05 20:10:25 +00:00
|
|
|
enable = mkEnableOption "Markdown markup language support";
|
2023-04-17 21:38:57 +00:00
|
|
|
|
2023-04-17 21:55:27 +00:00
|
|
|
treesitter = {
|
|
|
|
enable = mkOption {
|
2024-03-08 17:34:19 +00:00
|
|
|
type = bool;
|
2023-04-17 21:55:27 +00:00
|
|
|
default = config.vim.languages.enableTreesitter;
|
2024-05-07 21:22:12 +00:00
|
|
|
description = "Enable Markdown treesitter";
|
2023-04-17 21:55:27 +00:00
|
|
|
};
|
2024-03-08 17:34:19 +00:00
|
|
|
mdPackage = mkGrammarOption pkgs "markdown";
|
|
|
|
mdInlinePackage = mkGrammarOption pkgs "markdown-inline";
|
2023-04-17 21:55:27 +00:00
|
|
|
};
|
2024-01-18 16:28:46 +00:00
|
|
|
|
|
|
|
lsp = {
|
|
|
|
enable = mkEnableOption "Enable Markdown LSP support" // {default = config.vim.languages.enableLSP;};
|
|
|
|
|
|
|
|
server = mkOption {
|
2024-03-08 17:34:19 +00:00
|
|
|
type = enum (attrNames servers);
|
2024-01-18 16:28:46 +00:00
|
|
|
default = defaultServer;
|
2024-05-07 21:22:12 +00:00
|
|
|
description = "Markdown LSP server to use";
|
2024-01-18 16:28:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
package = mkOption {
|
2024-03-08 17:34:19 +00:00
|
|
|
type = either package (listOf str);
|
2024-01-18 16:28:46 +00:00
|
|
|
default = servers.${cfg.lsp.server}.package;
|
2024-05-07 21:22:12 +00:00
|
|
|
example = ''[lib.getExe pkgs.jdt-language-server " - data " " ~/.cache/jdtls/workspace "]'';
|
|
|
|
description = "Markdown LSP server package, or the command to run as a list of strings";
|
2024-01-18 16:28:46 +00:00
|
|
|
};
|
|
|
|
};
|
2024-05-06 19:22:43 +00:00
|
|
|
|
|
|
|
format = {
|
|
|
|
enable = mkEnableOption "Markdown formatting" // {default = config.vim.languages.enableFormat;};
|
|
|
|
|
|
|
|
type = mkOption {
|
|
|
|
type = enum (attrNames formats);
|
|
|
|
default = defaultFormat;
|
2024-05-07 21:31:23 +00:00
|
|
|
description = "Markdown formatter to use";
|
2024-05-06 19:22:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
package = mkOption {
|
|
|
|
type = package;
|
|
|
|
default = formats.${cfg.format.type}.package;
|
2024-05-07 21:31:23 +00:00
|
|
|
description = "Markdown formatter package";
|
2024-05-06 19:22:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extraFiletypes = mkOption {
|
|
|
|
type = listOf str;
|
|
|
|
default = [];
|
2024-05-07 21:31:23 +00:00
|
|
|
description = "Extra filetypes to format with the Markdown formatter";
|
2024-05-06 19:22:43 +00:00
|
|
|
};
|
|
|
|
};
|
2023-04-17 21:38:57 +00:00
|
|
|
};
|
2024-05-07 21:22:12 +00:00
|
|
|
|
|
|
|
config = mkIf cfg.enable (mkMerge [
|
|
|
|
(mkIf cfg.treesitter.enable {
|
|
|
|
vim.treesitter.enable = true;
|
|
|
|
vim.treesitter.grammars = [cfg.treesitter.mdPackage cfg.treesitter.mdInlinePackage];
|
|
|
|
})
|
|
|
|
|
|
|
|
(mkIf cfg.lsp.enable {
|
|
|
|
vim.lsp.lspconfig.enable = true;
|
|
|
|
vim.lsp.lspconfig.sources.markdown-lsp = servers.${cfg.lsp.server}.lspConfig;
|
|
|
|
})
|
|
|
|
|
|
|
|
(mkIf cfg.format.enable {
|
|
|
|
vim.lsp.null-ls.enable = true;
|
|
|
|
vim.lsp.null-ls.sources.markdown-format = formats.${cfg.format.type}.nullConfig;
|
|
|
|
})
|
|
|
|
]);
|
2023-04-17 21:38:57 +00:00
|
|
|
}
|