From 52d94343778cf4ba2248cf74bc058566f7aa0cd4 Mon Sep 17 00:00:00 2001 From: Mia Date: Fri, 26 Dec 2025 01:05:14 +0100 Subject: [PATCH 1/5] ts: add vue support for ts_ls --- modules/plugins/languages/ts.nix | 118 ++++++++++++++++++++++++++----- 1 file changed, 99 insertions(+), 19 deletions(-) diff --git a/modules/plugins/languages/ts.nix b/modules/plugins/languages/ts.nix index e5dc8d13..b094f756 100644 --- a/modules/plugins/languages/ts.nix +++ b/modules/plugins/languages/ts.nix @@ -17,11 +17,27 @@ cfg = config.vim.languages.ts; - defaultServers = ["ts_ls"]; + defaultServers = [ + "ts_ls" + "vue_ls" + ]; servers = let ts_ls = { - cmd = [(getExe pkgs.typescript-language-server) "--stdio"]; - init_options = {hostInfo = "neovim";}; + cmd = [ + (getExe pkgs.typescript-language-server) + "--stdio" + ]; + init_options = { + hostInfo = "neovim"; + plugins = [ + { + name = "@vue/typescript-plugin"; + location = "${pkgs.vue-language-server}/lib/language-tools/packages/language-server"; + languages = ["vue"]; + configNamespace = "typescript"; + } + ]; + }; filetypes = [ "javascript" "javascriptreact" @@ -29,6 +45,7 @@ "typescript" "typescriptreact" "typescript.tsx" + "vue" ]; root_markers = ["tsconfig.json" "jsconfig.json" "package.json" ".git"]; handlers = { @@ -48,23 +65,32 @@ end ''; }; - on_attach = mkLuaInline '' - function(client, bufnr) - -- ts_ls provides `source.*` code actions that apply to the whole file. These only appear in - -- `vim.lsp.buf.code_action()` if specified in `context.only`. - vim.api.nvim_buf_create_user_command(0, 'LspTypescriptSourceAction', function() - local source_actions = vim.tbl_filter(function(action) - return vim.startswith(action, 'source.') - end, client.server_capabilities.codeActionProvider.codeActionKinds) + on_attach = + mkLuaInline + # lua + '' + function(client, bufnr) + -- ts_ls provides `source.*` code actions that apply to the whole file. These only appear in + -- `vim.lsp.buf.code_action()` if specified in `context.only`. + vim.api.nvim_buf_create_user_command(0, 'LspTypescriptSourceAction', function() + local source_actions = vim.tbl_filter(function(action) + return vim.startswith(action, 'source.') + end, client.server_capabilities.codeActionProvider.codeActionKinds) - vim.lsp.buf.code_action({ - context = { - only = source_actions, - }, - }) - end, {}) - end - ''; + vim.lsp.buf.code_action({ + context = { + only = source_actions, + }, + }) + end, {}) + + if vim.bo.filetype == 'vue' then + client.server_capabilities.semanticTokensProvider.full = false + else + client.server_capabilities.semanticTokensProvider.full = true + end + end + ''; }; in { inherit ts_ls; @@ -73,6 +99,60 @@ # redirect the user to the correct server. tsserver = ts_ls; + vue_ls = { + cmd = [ + (getExe pkgs.vue-language-server) + "--stdio" + ]; + filetypes = [ + "vue" + ]; + root_markers = [ + "tsconfig.json" + "jsconfig.json" + "package.json" + ".git" + ]; + on_init = + mkLuaInline + # lua + '' + function(client) + client.handlers['tsserver/request'] = function(_, result, context) + local ts_clients = vim.lsp.get_clients({ bufnr = context.bufnr, name = 'ts_ls' }) + local clients = {} + + vim.list_extend(clients, ts_clients) + + if #clients == 0 then + vim.notify('Could not find `vtsls` or `ts_ls` lsp client, `vue_ls` would not work without it.', vim.log.levels.ERROR) + return + end + local ts_client = clients[1] + + local param = unpack(result) + local id, command, payload = unpack(param) + ts_client:exec_cmd({ + title = 'vue_request_forward', -- You can give title anything as it's used to represent a command in the UI, `:h Client:exec_cmd` + command = 'typescript.tsserverRequest', + arguments = { + command, + payload, + }, + }, { bufnr = context.bufnr }, function(_, r) + local response = r and r.body + -- TODO: handle error or response nil here, e.g. logging + -- NOTE: Do NOT return if there's an error or no response, just return nil back to the vue_ls to prevent memory leak + local response_data = { { id, response } } + + ---@diagnostic disable-next-line: param-type-mismatch + client:notify('tsserver/response', response_data) + end) + end + end + ''; + }; + denols = { cmd = [(getExe pkgs.deno) "lsp"]; cmd_env = {NO_COLOR = true;}; From a792378b46b3adfe2848ba9624a819757200494e Mon Sep 17 00:00:00 2001 From: Mia Date: Fri, 26 Dec 2025 01:19:59 +0100 Subject: [PATCH 2/5] ts_ls: add comments for vue integration and adhere to code style --- modules/plugins/languages/ts.nix | 110 +++++++++++++++---------------- 1 file changed, 53 insertions(+), 57 deletions(-) diff --git a/modules/plugins/languages/ts.nix b/modules/plugins/languages/ts.nix index b094f756..cce08fc7 100644 --- a/modules/plugins/languages/ts.nix +++ b/modules/plugins/languages/ts.nix @@ -65,32 +65,30 @@ end ''; }; - on_attach = - mkLuaInline - # lua - '' - function(client, bufnr) - -- ts_ls provides `source.*` code actions that apply to the whole file. These only appear in - -- `vim.lsp.buf.code_action()` if specified in `context.only`. - vim.api.nvim_buf_create_user_command(0, 'LspTypescriptSourceAction', function() - local source_actions = vim.tbl_filter(function(action) - return vim.startswith(action, 'source.') - end, client.server_capabilities.codeActionProvider.codeActionKinds) + on_attach = mkLuaInline '' + function(client, bufnr) + -- ts_ls provides `source.*` code actions that apply to the whole file. These only appear in + -- `vim.lsp.buf.code_action()` if specified in `context.only`. + vim.api.nvim_buf_create_user_command(0, 'LspTypescriptSourceAction', function() + local source_actions = vim.tbl_filter(function(action) + return vim.startswith(action, 'source.') + end, client.server_capabilities.codeActionProvider.codeActionKinds) - vim.lsp.buf.code_action({ - context = { - only = source_actions, - }, - }) - end, {}) + vim.lsp.buf.code_action({ + context = { + only = source_actions, + }, + }) + end, {}) - if vim.bo.filetype == 'vue' then - client.server_capabilities.semanticTokensProvider.full = false - else - client.server_capabilities.semanticTokensProvider.full = true - end + -- make sure that vue-language-server handles semantic tokens when we are in a vue file + if vim.bo.filetype == 'vue' then + client.server_capabilities.semanticTokensProvider.full = false + else + client.server_capabilities.semanticTokensProvider.full = true end - ''; + end + ''; }; in { inherit ts_ls; @@ -113,44 +111,42 @@ "package.json" ".git" ]; - on_init = - mkLuaInline - # lua - '' - function(client) - client.handlers['tsserver/request'] = function(_, result, context) - local ts_clients = vim.lsp.get_clients({ bufnr = context.bufnr, name = 'ts_ls' }) - local clients = {} + on_init = mkLuaInline '' + -- forward typescript blocks to ts_ls or vtsls depending on which is available first + function(client) + client.handlers['tsserver/request'] = function(_, result, context) + local ts_clients = vim.lsp.get_clients({ bufnr = context.bufnr, name = 'ts_ls' }) + local clients = {} - vim.list_extend(clients, ts_clients) + vim.list_extend(clients, ts_clients) - if #clients == 0 then - vim.notify('Could not find `vtsls` or `ts_ls` lsp client, `vue_ls` would not work without it.', vim.log.levels.ERROR) - return - end - local ts_client = clients[1] - - local param = unpack(result) - local id, command, payload = unpack(param) - ts_client:exec_cmd({ - title = 'vue_request_forward', -- You can give title anything as it's used to represent a command in the UI, `:h Client:exec_cmd` - command = 'typescript.tsserverRequest', - arguments = { - command, - payload, - }, - }, { bufnr = context.bufnr }, function(_, r) - local response = r and r.body - -- TODO: handle error or response nil here, e.g. logging - -- NOTE: Do NOT return if there's an error or no response, just return nil back to the vue_ls to prevent memory leak - local response_data = { { id, response } } - - ---@diagnostic disable-next-line: param-type-mismatch - client:notify('tsserver/response', response_data) - end) + if #clients == 0 then + vim.notify('Could not find `vtsls` or `ts_ls` lsp client, `vue_ls` would not work without it.', vim.log.levels.ERROR) + return end + local ts_client = clients[1] + + local param = unpack(result) + local id, command, payload = unpack(param) + ts_client:exec_cmd({ + title = 'vue_request_forward', -- You can give title anything as it's used to represent a command in the UI, `:h Client:exec_cmd` + command = 'typescript.tsserverRequest', + arguments = { + command, + payload, + }, + }, { bufnr = context.bufnr }, function(_, r) + local response = r and r.body + -- TODO: handle error or response nil here, e.g. logging + -- NOTE: Do NOT return if there's an error or no response, just return nil back to the vue_ls to prevent memory leak + local response_data = { { id, response } } + + ---@diagnostic disable-next-line: param-type-mismatch + client:notify('tsserver/response', response_data) + end) end - ''; + end + ''; }; denols = { From d9b09df599d56aee30ffdb1bb30af67999bdf89d Mon Sep 17 00:00:00 2001 From: Mia Date: Fri, 26 Dec 2025 21:08:01 +0100 Subject: [PATCH 3/5] vue: create independent language module for vue --- configuration.nix | 1 + modules/plugins/languages/default.nix | 1 + modules/plugins/languages/ts.nix | 77 ++--------- modules/plugins/languages/vue.nix | 184 ++++++++++++++++++++++++++ 4 files changed, 198 insertions(+), 65 deletions(-) create mode 100644 modules/plugins/languages/vue.nix diff --git a/configuration.nix b/configuration.nix index cc314288..3cea589c 100644 --- a/configuration.nix +++ b/configuration.nix @@ -94,6 +94,7 @@ isMaximal: { tailwind.enable = false; svelte.enable = false; + vue.enable = false; # Nim LSP is broken on Darwin and therefore # should be disabled by default. Users may still enable diff --git a/modules/plugins/languages/default.nix b/modules/plugins/languages/default.nix index fd45758f..0cfefa99 100644 --- a/modules/plugins/languages/default.nix +++ b/modules/plugins/languages/default.nix @@ -49,6 +49,7 @@ in { ./yaml.nix ./ruby.nix ./just.nix + ./vue.nix # This is now a hard deprecation. (mkRenamedOptionModule ["vim" "languages" "enableLSP"] ["vim" "lsp" "enable"]) diff --git a/modules/plugins/languages/ts.nix b/modules/plugins/languages/ts.nix index cce08fc7..6cc1892b 100644 --- a/modules/plugins/languages/ts.nix +++ b/modules/plugins/languages/ts.nix @@ -8,7 +8,8 @@ inherit (lib.options) mkEnableOption mkOption; inherit (lib.modules) mkIf mkMerge; inherit (lib.meta) getExe; - inherit (lib.types) enum package bool; + inherit (lib) optional; + inherit (lib.types) enum bool; inherit (lib.generators) mkLuaInline; inherit (lib.nvim.attrsets) mapListToAttrs; inherit (lib.nvim.lua) toLuaObject; @@ -17,10 +18,7 @@ cfg = config.vim.languages.ts; - defaultServers = [ - "ts_ls" - "vue_ls" - ]; + defaultServers = ["ts_ls"]; servers = let ts_ls = { cmd = [ @@ -29,14 +27,15 @@ ]; init_options = { hostInfo = "neovim"; - plugins = [ - { - name = "@vue/typescript-plugin"; - location = "${pkgs.vue-language-server}/lib/language-tools/packages/language-server"; - languages = ["vue"]; - configNamespace = "typescript"; - } - ]; + plugins = + [] + ++ (optional config.vim.languages.vue.lsp.enable + { + name = "@vue/typescript-plugin"; + location = "${pkgs.vue-language-server}/lib/language-tools/packages/language-server"; + languages = ["vue"]; + configNamespace = "typescript"; + }); }; filetypes = [ "javascript" @@ -97,58 +96,6 @@ # redirect the user to the correct server. tsserver = ts_ls; - vue_ls = { - cmd = [ - (getExe pkgs.vue-language-server) - "--stdio" - ]; - filetypes = [ - "vue" - ]; - root_markers = [ - "tsconfig.json" - "jsconfig.json" - "package.json" - ".git" - ]; - on_init = mkLuaInline '' - -- forward typescript blocks to ts_ls or vtsls depending on which is available first - function(client) - client.handlers['tsserver/request'] = function(_, result, context) - local ts_clients = vim.lsp.get_clients({ bufnr = context.bufnr, name = 'ts_ls' }) - local clients = {} - - vim.list_extend(clients, ts_clients) - - if #clients == 0 then - vim.notify('Could not find `vtsls` or `ts_ls` lsp client, `vue_ls` would not work without it.', vim.log.levels.ERROR) - return - end - local ts_client = clients[1] - - local param = unpack(result) - local id, command, payload = unpack(param) - ts_client:exec_cmd({ - title = 'vue_request_forward', -- You can give title anything as it's used to represent a command in the UI, `:h Client:exec_cmd` - command = 'typescript.tsserverRequest', - arguments = { - command, - payload, - }, - }, { bufnr = context.bufnr }, function(_, r) - local response = r and r.body - -- TODO: handle error or response nil here, e.g. logging - -- NOTE: Do NOT return if there's an error or no response, just return nil back to the vue_ls to prevent memory leak - local response_data = { { id, response } } - - ---@diagnostic disable-next-line: param-type-mismatch - client:notify('tsserver/response', response_data) - end) - end - end - ''; - }; - denols = { cmd = [(getExe pkgs.deno) "lsp"]; cmd_env = {NO_COLOR = true;}; diff --git a/modules/plugins/languages/vue.nix b/modules/plugins/languages/vue.nix new file mode 100644 index 00000000..4d329e1f --- /dev/null +++ b/modules/plugins/languages/vue.nix @@ -0,0 +1,184 @@ +{ + config, + pkgs, + lib, + ... +}: let + inherit (builtins) attrNames; + inherit (lib.options) mkEnableOption mkOption; + inherit (lib.modules) mkIf mkMerge; + inherit (lib.meta) getExe; + inherit (lib.types) enum listOf; + inherit (lib.generators) mkLuaInline; + inherit (lib.nvim.attrsets) mapListToAttrs; + inherit (lib.nvim.types) mkGrammarOption diagnostics; + + cfg = config.vim.languages.vue; + + defaultServers = [ + "vue_ls" + ]; + servers = { + vue_ls = { + cmd = [ + (getExe pkgs.vue-language-server) + "--stdio" + ]; + filetypes = [ + "vue" + ]; + root_markers = [ + "tsconfig.json" + "jsconfig.json" + "package.json" + ".git" + ]; + on_init = mkLuaInline '' + -- forward typescript blocks to ts_ls or vtsls depending on which is available first + function(client) + client.handlers['tsserver/request'] = function(_, result, context) + local ts_clients = vim.lsp.get_clients({ bufnr = context.bufnr, name = 'ts_ls' }) + local clients = {} + + vim.list_extend(clients, ts_clients) + + if #clients == 0 then + vim.notify('Could not find `vtsls` or `ts_ls` lsp client, `vue_ls` would not work without it.', vim.log.levels.ERROR) + return + end + local ts_client = clients[1] + + local param = unpack(result) + local id, command, payload = unpack(param) + ts_client:exec_cmd({ + title = 'vue_request_forward', -- You can give title anything as it's used to represent a command in the UI, `:h Client:exec_cmd` + command = 'typescript.tsserverRequest', + arguments = { + command, + payload, + }, + }, { bufnr = context.bufnr }, function(_, r) + local response = r and r.body + -- TODO: handle error or response nil here, e.g. logging + -- NOTE: Do NOT return if there's an error or no response, just return nil back to the vue_ls to prevent memory leak + local response_data = { { id, response } } + + ---@diagnostic disable-next-line: param-type-mismatch + client:notify('tsserver/response', response_data) + end) + end + end + ''; + }; + }; + defaultFormat = ["prettier"]; + formats = { + prettier = { + command = getExe pkgs.nodePackages.prettier; + options.ft_parsers.vue = "vue"; + }; + }; + defaultDiagnosticsProvider = ["eslint_d"]; + diagnosticsProviders = { + eslint_d = let + pkg = pkgs.eslint_d; + in { + package = pkg; + config = { + cmd = getExe pkg; + required_files = [ + "eslint.config.js" + "eslint.config.mjs" + ".eslintrc" + ".eslintrc.json" + ".eslintrc.js" + ".eslintrc.yml" + ]; + }; + }; + }; + formatType = + enum (attrNames formats); +in { + _file = ./vue.nix; + options.vim.languages.vue = { + enable = mkEnableOption "Vue language support"; + + treesitter = { + enable = mkEnableOption "Vue treesitter" // {default = config.vim.languages.enableTreesitter;}; + + vuePackage = mkGrammarOption pkgs "vue"; + }; + + lsp = { + enable = mkEnableOption "Vue LSP support" // {default = config.vim.lsp.enable;}; + + servers = mkOption { + type = listOf (enum (attrNames servers)); + default = defaultServers; + description = "Vue LSP server to use"; + }; + }; + + format = { + enable = mkEnableOption "Vue formatting" // {default = config.vim.languages.enableFormat;}; + + type = mkOption { + type = formatType; + default = defaultFormat; + description = "Vue formatter to use"; + }; + }; + + extraDiagnostics = { + enable = mkEnableOption "extra Vue diagnostics" // {default = config.vim.languages.enableExtraDiagnostics;}; + + types = diagnostics { + langDesc = "Vue"; + inherit diagnosticsProviders; + inherit defaultDiagnosticsProvider; + }; + }; + }; + + config = mkIf cfg.enable (mkMerge [ + (mkIf cfg.treesitter.enable { + vim.treesitter.enable = true; + vim.treesitter.grammars = [cfg.treesitter.vuePackage]; + }) + + (mkIf cfg.lsp.enable { + vim.lsp.servers = + mapListToAttrs (n: { + name = n; + value = servers.${n}; + }) + cfg.lsp.servers; + }) + + (mkIf cfg.format.enable { + vim.formatter.conform-nvim = { + enable = true; + setupOpts = { + formatters_by_ft.vue = cfg.format.type; + formatters = + mapListToAttrs (name: { + inherit name; + value = formats.${name}; + }) + cfg.format.type; + }; + }; + }) + + (mkIf cfg.extraDiagnostics.enable { + vim.diagnostics.nvim-lint = { + enable = true; + linters_by_ft.vue = cfg.extraDiagnostics.types; + linters = + mkMerge (map (name: {${name} = diagnosticsProviders.${name}.config;}) + cfg.extraDiagnostics.types); + }; + }) + ]); +} From 686e586b1926ba2e0e9be0041ce41975ad40f3e5 Mon Sep 17 00:00:00 2001 From: Mia Date: Fri, 26 Dec 2025 21:10:40 +0100 Subject: [PATCH 4/5] vue: fix formatting for vue and ts language module --- modules/plugins/languages/ts.nix | 5 +---- modules/plugins/languages/vue.nix | 13 +++---------- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/modules/plugins/languages/ts.nix b/modules/plugins/languages/ts.nix index 6cc1892b..6521d384 100644 --- a/modules/plugins/languages/ts.nix +++ b/modules/plugins/languages/ts.nix @@ -21,10 +21,7 @@ defaultServers = ["ts_ls"]; servers = let ts_ls = { - cmd = [ - (getExe pkgs.typescript-language-server) - "--stdio" - ]; + cmd = [(getExe pkgs.typescript-language-server) "--stdio"]; init_options = { hostInfo = "neovim"; plugins = diff --git a/modules/plugins/languages/vue.nix b/modules/plugins/languages/vue.nix index 4d329e1f..051d3605 100644 --- a/modules/plugins/languages/vue.nix +++ b/modules/plugins/languages/vue.nix @@ -15,18 +15,11 @@ cfg = config.vim.languages.vue; - defaultServers = [ - "vue_ls" - ]; + defaultServers = ["vue_ls"]; servers = { vue_ls = { - cmd = [ - (getExe pkgs.vue-language-server) - "--stdio" - ]; - filetypes = [ - "vue" - ]; + cmd = [(getExe pkgs.vue-language-server) "--stdio"]; + filetypes = ["vue"]; root_markers = [ "tsconfig.json" "jsconfig.json" From 6e50b1f0172809fabcb7ec994d9ad05c9acaea80 Mon Sep 17 00:00:00 2001 From: Mia Date: Fri, 26 Dec 2025 21:13:36 +0100 Subject: [PATCH 5/5] chore: add release note for vue language support --- docs/manual/release-notes/rl-0.9.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/manual/release-notes/rl-0.9.md b/docs/manual/release-notes/rl-0.9.md index 16bc1cf0..3445b91c 100644 --- a/docs/manual/release-notes/rl-0.9.md +++ b/docs/manual/release-notes/rl-0.9.md @@ -6,3 +6,7 @@ - Fix `vim.tabline.nvimBufferline` where `setupOpts.options.hover` requires `vim.opt.mousemoveevent` to be set. + +[miaapancake](https://github.com/miaapancake) + +- Add vue language support.