From c2780f497b2e3c867d8a039974c4d10c1b3dfd55 Mon Sep 17 00:00:00 2001 From: Soliprem Date: Sat, 2 Nov 2024 00:10:21 +0100 Subject: [PATCH 1/6] vala: init --- configuration.nix | 1 + modules/plugins/languages/default.nix | 1 + modules/plugins/languages/vala.nix | 109 ++++++++++++++++++ .../preview/markdown-preview/config.nix | 7 +- 4 files changed, 115 insertions(+), 3 deletions(-) create mode 100644 modules/plugins/languages/vala.nix diff --git a/configuration.nix b/configuration.nix index b5683ea..a3ab7bf 100644 --- a/configuration.nix +++ b/configuration.nix @@ -73,6 +73,7 @@ isMaximal: { }; csharp.enable = isMaximal; julia.enable = isMaximal; + vala.enable = isMaximal; }; visuals = { diff --git a/modules/plugins/languages/default.nix b/modules/plugins/languages/default.nix index a0a5791..1ec2b68 100644 --- a/modules/plugins/languages/default.nix +++ b/modules/plugins/languages/default.nix @@ -14,6 +14,7 @@ in { ./lua.nix ./markdown.nix ./nim.nix + ./vala.nix ./nix.nix ./ocaml.nix ./php.nix diff --git a/modules/plugins/languages/vala.nix b/modules/plugins/languages/vala.nix new file mode 100644 index 0000000..efec6eb --- /dev/null +++ b/modules/plugins/languages/vala.nix @@ -0,0 +1,109 @@ +{ + config, + pkgs, + lib, + ... +}: let + inherit (builtins) attrNames; + inherit (lib.options) mkEnableOption mkOption; + inherit (lib.meta) getExe; + inherit (lib.nvim.languages) diagnosticsToLua; + inherit (lib.modules) mkIf mkMerge; + inherit (lib.lists) isList; + inherit (lib.types) enum either listOf package str; + inherit (lib.nvim.types) mkGrammarOption diagnostics; + inherit (lib.nvim.lua) expToLua; + + cfg = config.vim.languages.vala; + + defaultServer = "vala_ls"; + servers = { + vala_ls = { + package = pkgs.vala-language-server; + lspConfig = '' + lspconfig.vala_ls.setup { + capabilities = capabilities; + on_attach = default_on_attach; + cmd = ${ + if isList cfg.lsp.package + then expToLua cfg.lsp.package + else ''{"${cfg.lsp.package}/bin/vala-language-server"}'' + }, + } + ''; + }; + }; + + defaultDiagnosticsProvider = ["vala-lint"]; + diagnosticsProviders = { + vala-lint = { + package = pkgs.vala-lint; + nullConfig = pkg: '' + table.insert( + ls_sources, + null_ls.builtins.diagnostics.eslint_d.with({ + command = "${getExe pkg}", + }) + ) + ''; + }; + }; +in { + options.vim.languages.vala = { + enable = mkEnableOption "Vala language support"; + + treesitter = { + enable = mkEnableOption "Vala treesitter" // {default = config.vim.languages.enableTreesitter;}; + + package = mkGrammarOption pkgs "vala"; + }; + + lsp = { + enable = mkEnableOption "Vala LSP support" // {default = config.vim.languages.enableLSP;}; + + server = mkOption { + description = "Vala LSP server to use"; + type = enum (attrNames servers); + default = defaultServer; + }; + + package = mkOption { + description = "Vala LSP server package, or the command to run as a list of strings"; + example = ''[lib.getExe pkgs.jdt-language-server " - data " " ~/.cache/jdtls/workspace "]''; + type = either package (listOf str); + default = servers.${cfg.lsp.server}.package; + }; + }; + + extraDiagnostics = { + enable = mkEnableOption "extra Vala diagnostics" // {default = config.vim.languages.enableExtraDiagnostics;}; + + types = diagnostics { + langDesc = "Vala"; + inherit diagnosticsProviders; + inherit defaultDiagnosticsProvider; + }; + }; + }; + + config = mkIf cfg.enable (mkMerge [ + (mkIf cfg.treesitter.enable { + vim.treesitter.enable = true; + vim.treesitter.grammars = [cfg.treesitter.package]; + }) + + (mkIf cfg.extraDiagnostics.enable { + vim.lsp.null-ls.enable = true; + vim.lsp.null-ls.sources = diagnosticsToLua { + lang = "Vala"; + config = cfg.extraDiagnostics.types; + inherit diagnosticsProviders; + }; + }) + + (mkIf cfg.lsp.enable { + vim.lsp.lspconfig.enable = true; + vim.lsp.lspconfig.sources.vala_ls = servers.${cfg.lsp.server}.lspConfig; + }) + ]); +} diff --git a/modules/plugins/utility/preview/markdown-preview/config.nix b/modules/plugins/utility/preview/markdown-preview/config.nix index 8349d3f..635a8a4 100644 --- a/modules/plugins/utility/preview/markdown-preview/config.nix +++ b/modules/plugins/utility/preview/markdown-preview/config.nix @@ -4,8 +4,9 @@ lib, ... }: let - inherit (lib.strings) concatMapStringsSep; + inherit (lib.strings) stringLength concatMapStringsSep; inherit (lib.modules) mkIf; + cfg = config.vim.utility.preview.markdownPreview; in { config = mkIf cfg.enable { @@ -18,8 +19,8 @@ in { mkdp_filetypes = [(concatMapStringsSep ", " (x: "'" + x + "'") cfg.filetypes)]; mkdp_command_for_global = cfg.alwaysAllowPreview; mkdp_open_to_the_world = cfg.broadcastServer; - mkdp_open_ip = cfg.customIP; - mkdp_port = cfg.customPort; + mkdp_open_ip = mkIf (stringLength cfg.customIP > 0) cfg.customIP; + mkdp_port = mkIf (stringLength cfg.customPort > 0) cfg.customPort; }; }; } From 438ea0939e468835cb6f64a390c64222c85fd848 Mon Sep 17 00:00:00 2001 From: Soliprem Date: Sun, 3 Nov 2024 12:49:15 +0100 Subject: [PATCH 2/6] vala: applying reviews --- modules/plugins/languages/vala.nix | 9 ++++----- .../plugins/utility/preview/markdown-preview/config.nix | 7 +++---- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/modules/plugins/languages/vala.nix b/modules/plugins/languages/vala.nix index efec6eb..58955fa 100644 --- a/modules/plugins/languages/vala.nix +++ b/modules/plugins/languages/vala.nix @@ -20,6 +20,8 @@ servers = { vala_ls = { package = pkgs.vala-language-server; + runtimeInputs = pkgs.uncrustify; + internalFormatter = true; lspConfig = '' lspconfig.vala_ls.setup { capabilities = capabilities; @@ -41,7 +43,7 @@ nullConfig = pkg: '' table.insert( ls_sources, - null_ls.builtins.diagnostics.eslint_d.with({ + null_ls.builtins.diagnostics.vala_lint.with({ command = "${getExe pkg}", }) ) @@ -54,13 +56,11 @@ in { treesitter = { enable = mkEnableOption "Vala treesitter" // {default = config.vim.languages.enableTreesitter;}; - package = mkGrammarOption pkgs "vala"; }; lsp = { enable = mkEnableOption "Vala LSP support" // {default = config.vim.languages.enableLSP;}; - server = mkOption { description = "Vala LSP server to use"; type = enum (attrNames servers); @@ -69,7 +69,7 @@ in { package = mkOption { description = "Vala LSP server package, or the command to run as a list of strings"; - example = ''[lib.getExe pkgs.jdt-language-server " - data " " ~/.cache/jdtls/workspace "]''; + example = ''[lib.getExe pkgs.vala-language-server]''; type = either package (listOf str); default = servers.${cfg.lsp.server}.package; }; @@ -77,7 +77,6 @@ in { extraDiagnostics = { enable = mkEnableOption "extra Vala diagnostics" // {default = config.vim.languages.enableExtraDiagnostics;}; - types = diagnostics { langDesc = "Vala"; inherit diagnosticsProviders; diff --git a/modules/plugins/utility/preview/markdown-preview/config.nix b/modules/plugins/utility/preview/markdown-preview/config.nix index 635a8a4..8349d3f 100644 --- a/modules/plugins/utility/preview/markdown-preview/config.nix +++ b/modules/plugins/utility/preview/markdown-preview/config.nix @@ -4,9 +4,8 @@ lib, ... }: let - inherit (lib.strings) stringLength concatMapStringsSep; + inherit (lib.strings) concatMapStringsSep; inherit (lib.modules) mkIf; - cfg = config.vim.utility.preview.markdownPreview; in { config = mkIf cfg.enable { @@ -19,8 +18,8 @@ in { mkdp_filetypes = [(concatMapStringsSep ", " (x: "'" + x + "'") cfg.filetypes)]; mkdp_command_for_global = cfg.alwaysAllowPreview; mkdp_open_to_the_world = cfg.broadcastServer; - mkdp_open_ip = mkIf (stringLength cfg.customIP > 0) cfg.customIP; - mkdp_port = mkIf (stringLength cfg.customPort > 0) cfg.customPort; + mkdp_open_ip = cfg.customIP; + mkdp_port = cfg.customPort; }; }; } From 76c7d358950b9cf282a18359ee5e399e35fbf296 Mon Sep 17 00:00:00 2001 From: Soliprem Date: Sun, 3 Nov 2024 13:26:57 +0100 Subject: [PATCH 3/6] vala: making formatter work --- modules/plugins/languages/vala.nix | 44 ++++-------------------------- 1 file changed, 6 insertions(+), 38 deletions(-) diff --git a/modules/plugins/languages/vala.nix b/modules/plugins/languages/vala.nix index 58955fa..a708c19 100644 --- a/modules/plugins/languages/vala.nix +++ b/modules/plugins/languages/vala.nix @@ -7,11 +7,10 @@ inherit (builtins) attrNames; inherit (lib.options) mkEnableOption mkOption; inherit (lib.meta) getExe; - inherit (lib.nvim.languages) diagnosticsToLua; inherit (lib.modules) mkIf mkMerge; inherit (lib.lists) isList; inherit (lib.types) enum either listOf package str; - inherit (lib.nvim.types) mkGrammarOption diagnostics; + inherit (lib.nvim.types) mkGrammarOption; inherit (lib.nvim.lua) expToLua; cfg = config.vim.languages.vala; @@ -19,8 +18,10 @@ defaultServer = "vala_ls"; servers = { vala_ls = { - package = pkgs.vala-language-server; - runtimeInputs = pkgs.uncrustify; + package = pkgs.writeShellScriptBin "vala-language-server-wrapper" '' + export PATH="${lib.makeBinPath [pkgs.uncrustify]}:$PATH" + exec ${pkgs.vala-language-server}/bin/vala-language-server "$@" + ''; internalFormatter = true; lspConfig = '' lspconfig.vala_ls.setup { @@ -29,27 +30,12 @@ cmd = ${ if isList cfg.lsp.package then expToLua cfg.lsp.package - else ''{"${cfg.lsp.package}/bin/vala-language-server"}'' + else ''{"${cfg.lsp.package}/bin/vala-language-server-wrapper"}'' }, } ''; }; }; - - defaultDiagnosticsProvider = ["vala-lint"]; - diagnosticsProviders = { - vala-lint = { - package = pkgs.vala-lint; - nullConfig = pkg: '' - table.insert( - ls_sources, - null_ls.builtins.diagnostics.vala_lint.with({ - command = "${getExe pkg}", - }) - ) - ''; - }; - }; in { options.vim.languages.vala = { enable = mkEnableOption "Vala language support"; @@ -74,15 +60,6 @@ in { default = servers.${cfg.lsp.server}.package; }; }; - - extraDiagnostics = { - enable = mkEnableOption "extra Vala diagnostics" // {default = config.vim.languages.enableExtraDiagnostics;}; - types = diagnostics { - langDesc = "Vala"; - inherit diagnosticsProviders; - inherit defaultDiagnosticsProvider; - }; - }; }; config = mkIf cfg.enable (mkMerge [ @@ -91,15 +68,6 @@ in { vim.treesitter.grammars = [cfg.treesitter.package]; }) - (mkIf cfg.extraDiagnostics.enable { - vim.lsp.null-ls.enable = true; - vim.lsp.null-ls.sources = diagnosticsToLua { - lang = "Vala"; - config = cfg.extraDiagnostics.types; - inherit diagnosticsProviders; - }; - }) - (mkIf cfg.lsp.enable { vim.lsp.lspconfig.enable = true; vim.lsp.lspconfig.sources.vala_ls = servers.${cfg.lsp.server}.lspConfig; From f6d3a11f33fe7aff285c0f2c293cb8bc9d073f7e Mon Sep 17 00:00:00 2001 From: Soliprem Date: Sun, 3 Nov 2024 13:27:57 +0100 Subject: [PATCH 4/6] vala: cleaning up useless import --- modules/plugins/languages/vala.nix | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/plugins/languages/vala.nix b/modules/plugins/languages/vala.nix index a708c19..3e77320 100644 --- a/modules/plugins/languages/vala.nix +++ b/modules/plugins/languages/vala.nix @@ -6,7 +6,6 @@ }: let inherit (builtins) attrNames; inherit (lib.options) mkEnableOption mkOption; - inherit (lib.meta) getExe; inherit (lib.modules) mkIf mkMerge; inherit (lib.lists) isList; inherit (lib.types) enum either listOf package str; From 8eb4f87969687392b65418c36452007d4e288664 Mon Sep 17 00:00:00 2001 From: Soliprem Date: Sun, 3 Nov 2024 19:44:35 +0100 Subject: [PATCH 5/6] vala: wrapping uncrustify --- modules/plugins/languages/vala.nix | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/modules/plugins/languages/vala.nix b/modules/plugins/languages/vala.nix index 3e77320..da65a37 100644 --- a/modules/plugins/languages/vala.nix +++ b/modules/plugins/languages/vala.nix @@ -17,10 +17,15 @@ defaultServer = "vala_ls"; servers = { vala_ls = { - package = pkgs.writeShellScriptBin "vala-language-server-wrapper" '' - export PATH="${lib.makeBinPath [pkgs.uncrustify]}:$PATH" - exec ${pkgs.vala-language-server}/bin/vala-language-server "$@" - ''; + package = pkgs.symlinkJoin { + name = "vala-language-server-wrapper"; + paths = [pkgs.vala-language-server]; + buildInputs = [pkgs.makeBinaryWrapper]; + postBuild = '' + wrapProgram $out/bin/vala-language-server \ + --prefix PATH : ${pkgs.uncrustify}/bin + ''; + }; internalFormatter = true; lspConfig = '' lspconfig.vala_ls.setup { @@ -29,7 +34,7 @@ cmd = ${ if isList cfg.lsp.package then expToLua cfg.lsp.package - else ''{"${cfg.lsp.package}/bin/vala-language-server-wrapper"}'' + else ''{"${cfg.lsp.package}/bin/vala-language-server"}'' }, } ''; @@ -54,7 +59,6 @@ in { package = mkOption { description = "Vala LSP server package, or the command to run as a list of strings"; - example = ''[lib.getExe pkgs.vala-language-server]''; type = either package (listOf str); default = servers.${cfg.lsp.server}.package; }; From 896db7175765965b773aa0335517dcc4249ae63f Mon Sep 17 00:00:00 2001 From: Soliprem Date: Sun, 3 Nov 2024 19:50:35 +0100 Subject: [PATCH 6/6] vala: added changelog entry --- docs/release-notes/rl-0.7.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/release-notes/rl-0.7.md b/docs/release-notes/rl-0.7.md index 351a0dc..87df91e 100644 --- a/docs/release-notes/rl-0.7.md +++ b/docs/release-notes/rl-0.7.md @@ -292,6 +292,7 @@ To migrate to `nixfmt`, simply change `vim.languages.nix.format.type` to - Add LSP, diagnostics, formatter and Treesitter support for Kotlin under `vim.languages.kotlin` - changed default keybinds for leap.nvim to avoid altering expected behavior +- Add LSP, formatter and Treesitter support for Vala under `vim.languages.vala` [Bloxx12](https://github.com/Bloxx12)