2023-06-03 14:18:26 +00:00
|
|
|
{
|
|
|
|
pkgs,
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
with lib;
|
|
|
|
with builtins; let
|
|
|
|
cfg = config.vim.languages.svelte;
|
|
|
|
|
|
|
|
defaultServer = "svelte";
|
|
|
|
servers = {
|
|
|
|
svelte = {
|
|
|
|
package = pkgs.nodePackages.svelte-language-server;
|
|
|
|
lspConfig = ''
|
|
|
|
lspconfig.svelte.setup {
|
|
|
|
capabilities = capabilities;
|
|
|
|
on_attach = attach_keymaps,
|
2023-09-18 23:40:56 +00:00
|
|
|
cmd = ${
|
|
|
|
if isList cfg.lsp.package
|
|
|
|
then nvim.lua.expToLua cfg.lsp.package
|
|
|
|
else ''{"${cfg.lsp.package}/bin/svelteserver", "--stdio"}''
|
|
|
|
}
|
2023-06-03 14:18:26 +00:00
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
# TODO: specify packages
|
|
|
|
defaultFormat = "prettier";
|
|
|
|
formats = {
|
|
|
|
prettier = {
|
|
|
|
package = pkgs.nodePackages.prettier;
|
|
|
|
nullConfig = ''
|
|
|
|
table.insert(
|
|
|
|
ls_sources,
|
|
|
|
null_ls.builtins.formatting.prettier.with({
|
|
|
|
command = "${cfg.format.package}/bin/prettier",
|
|
|
|
})
|
|
|
|
)
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
# TODO: specify packages
|
|
|
|
defaultDiagnostics = ["eslint_d"];
|
|
|
|
diagnostics = {
|
|
|
|
eslint_d = {
|
|
|
|
package = pkgs.nodePackages.eslint_d;
|
|
|
|
nullConfig = pkg: ''
|
|
|
|
table.insert(
|
|
|
|
ls_sources,
|
|
|
|
null_ls.builtins.diagnostics.eslint_d.with({
|
|
|
|
command = "${lib.getExe pkg}",
|
|
|
|
})
|
|
|
|
)
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
in {
|
|
|
|
options.vim.languages.svelte = {
|
|
|
|
enable = mkEnableOption "Svelte language support";
|
|
|
|
|
|
|
|
treesitter = {
|
2023-06-05 20:10:25 +00:00
|
|
|
enable = mkEnableOption "Enable Svelte treesitter" // {default = config.vim.languages.enableTreesitter;};
|
|
|
|
|
2023-06-03 14:18:26 +00:00
|
|
|
sveltePackage = nvim.types.mkGrammarOption pkgs "svelte";
|
|
|
|
};
|
|
|
|
|
|
|
|
lsp = {
|
2023-06-05 20:10:25 +00:00
|
|
|
enable = mkEnableOption "Enable Svelte LSP support" // {default = config.vim.languages.enableLSP;};
|
|
|
|
|
2023-06-03 14:18:26 +00:00
|
|
|
server = mkOption {
|
|
|
|
description = "Svelte LSP server to use";
|
|
|
|
type = with types; enum (attrNames servers);
|
|
|
|
default = defaultServer;
|
|
|
|
};
|
2023-06-05 20:10:25 +00:00
|
|
|
|
2023-06-03 14:18:26 +00:00
|
|
|
package = mkOption {
|
2023-09-22 22:28:39 +00:00
|
|
|
description = "Svelte LSP server package, or the command to run as a list of strings";
|
|
|
|
example = ''[lib.getExe pkgs.jdt-language-server "-data" "~/.cache/jdtls/workspace"]'';
|
2023-09-18 23:40:56 +00:00
|
|
|
type = with types; either package (listOf str);
|
2023-06-03 14:18:26 +00:00
|
|
|
default = servers.${cfg.lsp.server}.package;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
format = {
|
2023-06-05 20:10:25 +00:00
|
|
|
enable = mkEnableOption "Enable Svelte formatting" // {default = config.vim.languages.enableFormat;};
|
|
|
|
|
2023-06-03 14:18:26 +00:00
|
|
|
type = mkOption {
|
|
|
|
description = "Svelte formatter to use";
|
|
|
|
type = with types; enum (attrNames formats);
|
|
|
|
default = defaultFormat;
|
|
|
|
};
|
2023-06-05 20:10:25 +00:00
|
|
|
|
2023-06-03 14:18:26 +00:00
|
|
|
package = mkOption {
|
|
|
|
description = "Svelte formatter package";
|
|
|
|
type = types.package;
|
|
|
|
default = formats.${cfg.format.type}.package;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
extraDiagnostics = {
|
2023-06-05 20:10:25 +00:00
|
|
|
enable = mkEnableOption "Enable extra Svelte diagnostics" // {default = config.vim.languages.enableExtraDiagnostics;};
|
|
|
|
|
2023-06-03 14:18:26 +00:00
|
|
|
types = lib.nvim.types.diagnostics {
|
|
|
|
langDesc = "Svelte";
|
|
|
|
inherit diagnostics;
|
|
|
|
inherit defaultDiagnostics;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable (mkMerge [
|
|
|
|
(mkIf cfg.treesitter.enable {
|
|
|
|
vim.treesitter.enable = true;
|
|
|
|
vim.treesitter.grammars = [cfg.treesitter.sveltePackage];
|
|
|
|
})
|
|
|
|
|
|
|
|
(mkIf cfg.lsp.enable {
|
|
|
|
vim.lsp.lspconfig.enable = true;
|
|
|
|
vim.lsp.lspconfig.sources.svelte-lsp = servers.${cfg.lsp.server}.lspConfig;
|
|
|
|
})
|
|
|
|
|
|
|
|
(mkIf cfg.format.enable {
|
|
|
|
vim.lsp.null-ls.enable = true;
|
|
|
|
vim.lsp.null-ls.sources.svelte-format = formats.${cfg.format.type}.nullConfig;
|
|
|
|
})
|
|
|
|
|
|
|
|
(mkIf cfg.extraDiagnostics.enable {
|
|
|
|
vim.lsp.null-ls.enable = true;
|
|
|
|
vim.lsp.null-ls.sources = lib.nvim.languages.diagnosticsToLua {
|
|
|
|
lang = "svelte";
|
|
|
|
config = cfg.extraDiagnostics.types;
|
|
|
|
inherit diagnostics;
|
|
|
|
};
|
|
|
|
})
|
|
|
|
]);
|
|
|
|
}
|