2023-04-17 20:27:27 +00:00
|
|
|
{
|
|
|
|
pkgs,
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
with lib;
|
|
|
|
with builtins; let
|
|
|
|
cfg = config.vim.languages.ts;
|
|
|
|
|
|
|
|
defaultServer = "tsserver";
|
|
|
|
servers = {
|
|
|
|
tsserver = {
|
|
|
|
package = pkgs.nodePackages.typescript-language-server;
|
|
|
|
lspConfig = ''
|
|
|
|
lspconfig.tsserver.setup {
|
|
|
|
capabilities = capabilities;
|
|
|
|
on_attach = attach_keymaps,
|
|
|
|
cmd = { "${cfg.lsp.package}/bin/typescript-language-server", "--stdio" }
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
2023-07-29 20:34:21 +00:00
|
|
|
denols = {
|
|
|
|
package = pkgs.deno;
|
|
|
|
lspConfig = ''
|
|
|
|
vim.g.markdown_fenced_languages = { "ts=typescript" }
|
|
|
|
lspconfig.denols.setup {
|
|
|
|
capabilities = capabilities;
|
|
|
|
on_attach = attach_keymaps,
|
|
|
|
cmd = { "${cfg.lsp.package}/bin/deno", "lsp" }
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
2023-04-17 20:27:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
# TODO: specify packages
|
2023-07-13 20:19:15 +00:00
|
|
|
defaultFormat = "prettier";
|
2023-04-17 20:27:27 +00:00
|
|
|
formats = {
|
|
|
|
prettier = {
|
|
|
|
package = pkgs.nodePackages.prettier;
|
|
|
|
nullConfig = ''
|
|
|
|
table.insert(
|
|
|
|
ls_sources,
|
|
|
|
null_ls.builtins.formatting.prettier.with({
|
|
|
|
command = "${cfg.format.package}/bin/prettier",
|
|
|
|
})
|
|
|
|
)
|
|
|
|
'';
|
|
|
|
};
|
2023-07-11 19:54:22 +00:00
|
|
|
prettierd = {
|
|
|
|
package = pkgs.prettierd;
|
|
|
|
nullConfig = ''
|
|
|
|
table.insert(
|
|
|
|
ls_sources,
|
|
|
|
null_ls.builtins.formatting.prettier.with({
|
|
|
|
command = "${cfg.format.package}/bin/prettierd",
|
|
|
|
})
|
|
|
|
)
|
|
|
|
'';
|
|
|
|
};
|
2023-04-17 20:27:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
# TODO: specify packages
|
2023-05-12 18:30:37 +00:00
|
|
|
defaultDiagnostics = ["eslint_d"];
|
2023-04-17 20:27:27 +00:00
|
|
|
diagnostics = {
|
2023-05-12 18:30:37 +00:00
|
|
|
eslint_d = {
|
|
|
|
package = pkgs.nodePackages.eslint_d;
|
2023-04-17 20:27:27 +00:00
|
|
|
nullConfig = pkg: ''
|
|
|
|
table.insert(
|
|
|
|
ls_sources,
|
2023-05-12 18:30:37 +00:00
|
|
|
null_ls.builtins.diagnostics.eslint_d.with({
|
|
|
|
command = "${lib.getExe pkg}",
|
2023-04-17 20:27:27 +00:00
|
|
|
})
|
|
|
|
)
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
in {
|
|
|
|
options.vim.languages.ts = {
|
2023-04-18 17:11:06 +00:00
|
|
|
enable = mkEnableOption "Typescript/Javascript language support";
|
2023-04-17 20:27:27 +00:00
|
|
|
|
|
|
|
treesitter = {
|
2023-06-05 20:10:25 +00:00
|
|
|
enable = mkEnableOption "Enable Typescript/Javascript treesitter" // {default = config.vim.languages.enableTreesitter;};
|
2023-04-17 21:55:27 +00:00
|
|
|
tsPackage = nvim.types.mkGrammarOption pkgs "tsx";
|
|
|
|
jsPackage = nvim.types.mkGrammarOption pkgs "javascript";
|
2023-04-17 20:27:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
lsp = {
|
2023-06-05 20:10:25 +00:00
|
|
|
enable = mkEnableOption "Enable Typescript/Javascript LSP support" // {default = config.vim.languages.enableLSP;};
|
|
|
|
|
2023-04-17 20:27:27 +00:00
|
|
|
server = mkOption {
|
|
|
|
description = "Typescript/Javascript LSP server to use";
|
|
|
|
type = with types; enum (attrNames servers);
|
|
|
|
default = defaultServer;
|
|
|
|
};
|
2023-06-05 20:10:25 +00:00
|
|
|
|
2023-04-17 20:27:27 +00:00
|
|
|
package = mkOption {
|
|
|
|
description = "Typescript/Javascript LSP server package";
|
|
|
|
type = types.package;
|
|
|
|
default = servers.${cfg.lsp.server}.package;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
format = {
|
2023-06-05 20:10:25 +00:00
|
|
|
enable = mkEnableOption "Enable Typescript/Javascript formatting" // {default = config.vim.languages.enableFormat;};
|
|
|
|
|
2023-04-17 20:27:27 +00:00
|
|
|
type = mkOption {
|
|
|
|
description = "Typescript/Javascript formatter to use";
|
|
|
|
type = with types; enum (attrNames formats);
|
|
|
|
default = defaultFormat;
|
|
|
|
};
|
2023-06-05 20:10:25 +00:00
|
|
|
|
2023-04-17 20:27:27 +00:00
|
|
|
package = mkOption {
|
|
|
|
description = "Typescript/Javascript formatter package";
|
|
|
|
type = types.package;
|
|
|
|
default = formats.${cfg.format.type}.package;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
extraDiagnostics = {
|
2023-06-05 20:10:25 +00:00
|
|
|
enable = mkEnableOption "Enable extra Typescript/Javascript diagnostics" // {default = config.vim.languages.enableExtraDiagnostics;};
|
|
|
|
|
2023-04-17 20:27:27 +00:00
|
|
|
types = lib.nvim.types.diagnostics {
|
|
|
|
langDesc = "Typescript/Javascript";
|
|
|
|
inherit diagnostics;
|
|
|
|
inherit defaultDiagnostics;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable (mkMerge [
|
|
|
|
(mkIf cfg.treesitter.enable {
|
|
|
|
vim.treesitter.enable = true;
|
|
|
|
vim.treesitter.grammars = [cfg.treesitter.tsPackage cfg.treesitter.jsPackage];
|
|
|
|
})
|
|
|
|
|
|
|
|
(mkIf cfg.lsp.enable {
|
|
|
|
vim.lsp.lspconfig.enable = true;
|
|
|
|
vim.lsp.lspconfig.sources.ts-lsp = servers.${cfg.lsp.server}.lspConfig;
|
|
|
|
})
|
|
|
|
|
|
|
|
(mkIf cfg.format.enable {
|
|
|
|
vim.lsp.null-ls.enable = true;
|
|
|
|
vim.lsp.null-ls.sources.ts-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 = "ts";
|
|
|
|
config = cfg.extraDiagnostics.types;
|
|
|
|
inherit diagnostics;
|
|
|
|
};
|
|
|
|
})
|
|
|
|
]);
|
|
|
|
}
|