plugins/lsp/volar: add ts-ls integration

This commit is contained in:
Austin Horstman 2024-09-20 20:40:56 -05:00
parent 384f97cf50
commit a8ab73432a
No known key found for this signature in database
2 changed files with 89 additions and 1 deletions

View file

@ -691,6 +691,32 @@ let
"nodePackages"
"@volar/vue-language-server"
];
extraOptions = {
tslsIntegration = mkOption {
type = types.bool;
description = ''
Enable integration with TypeScript language server.
'';
default = true;
example = false;
};
};
extraConfig = cfg: {
plugins.lsp.servers.ts-ls = lib.mkIf (cfg.enable && cfg.tslsIntegration) {
filetypes = [ "vue" ];
extraOptions = {
init_options = {
plugins = [
{
name = "@vue/typescript-plugin";
location = "${lib.getBin cfg.package}/lib/node_modules/@vue/language-server";
languages = [ "vue" ];
}
];
};
};
};
};
}
{
name = "yamlls";

View file

@ -1,4 +1,4 @@
{ pkgs, ... }:
{ lib, pkgs, ... }:
{
empty = {
plugins.lsp.enable = true;
@ -222,4 +222,66 @@
};
};
};
volar-tsls-integration =
{ config, ... }:
{
plugins.lsp = {
enable = true;
servers = {
volar.enable = true;
ts-ls = {
enable = true;
filetypes = [ "typescript" ];
};
};
};
assertions = [
{
assertion = lib.any (x: x == "vue") config.plugins.lsp.servers.ts-ls.filetypes;
message = "Expected `vue` filetype configuration.";
}
{
assertion = lib.any (
x: x.name == "@vue/typescript-plugin"
) config.plugins.lsp.servers.ts-ls.extraOptions.init_options.plugins;
message = "Expected `@vue/typescript-plugin` plugin.";
}
{
assertion = lib.any (x: x == "typescript") config.plugins.lsp.servers.ts-ls.filetypes;
message = "Expected `typescript` filetype configuration.";
}
];
};
tsls-filetypes =
{ config, ... }:
{
plugins.lsp = {
enable = true;
servers = {
ts-ls = {
enable = true;
};
};
};
assertions = [
{
assertion = lib.all (x: x != "vue") config.plugins.lsp.servers.ts-ls.filetypes;
message = "Did not expect `vue` filetype configuration.";
}
(lib.mkIf (config.plugins.lsp.servers.ts-ls.extraOptions ? init_options) {
assertion = lib.all (
x: x.name != "@vue/typescript-plugin"
) config.plugins.lsp.servers.ts-ls.extraOptions.init_options.plugins;
message = "Did not expect `@vue/typescript-plugin` plugin.";
})
{
assertion = lib.any (x: x == "typescript") config.plugins.lsp.servers.ts-ls.filetypes;
message = "Expected `typescript` filetype configuration.";
}
];
};
}