From 0fdfb9bf3b419dba3b1ccd2728ed6a366866a942 Mon Sep 17 00:00:00 2001 From: MaxMur <31189199+TheMaxMur@users.noreply.github.com> Date: Sun, 2 Mar 2025 16:59:32 +0300 Subject: [PATCH] languages/yaml: Init (#676) --- docs/release-notes/rl-0.8.md | 4 ++ modules/plugins/languages/default.nix | 1 + modules/plugins/languages/yaml.nix | 72 +++++++++++++++++++++++++++ 3 files changed, 77 insertions(+) create mode 100644 modules/plugins/languages/yaml.nix diff --git a/docs/release-notes/rl-0.8.md b/docs/release-notes/rl-0.8.md index 0440f38f..d81b142f 100644 --- a/docs/release-notes/rl-0.8.md +++ b/docs/release-notes/rl-0.8.md @@ -192,3 +192,7 @@ - Add formatters for go: [gofmt](https://go.dev/blog/gofmt), [golines](https://github.com/segmentio/golines) and [gofumpt](https://github.com/mvdan/gofumpt) + +[MaxMur](https://github.com/TheMaxMur) + +- Add YAML support under `vim.languages.yaml`. diff --git a/modules/plugins/languages/default.nix b/modules/plugins/languages/default.nix index 219e04fb..08d676b9 100644 --- a/modules/plugins/languages/default.nix +++ b/modules/plugins/languages/default.nix @@ -39,6 +39,7 @@ in { ./nu.nix ./odin.nix ./wgsl.nix + ./yaml.nix ./ruby.nix ]; diff --git a/modules/plugins/languages/yaml.nix b/modules/plugins/languages/yaml.nix new file mode 100644 index 00000000..2892f607 --- /dev/null +++ b/modules/plugins/languages/yaml.nix @@ -0,0 +1,72 @@ +{ + pkgs, + config, + lib, + ... +}: let + inherit (builtins) attrNames; + inherit (lib.options) mkEnableOption mkOption; + inherit (lib.modules) mkIf mkMerge; + inherit (lib.lists) isList; + inherit (lib.types) enum either listOf package str; + inherit (lib.nvim.types) mkGrammarOption; + inherit (lib.nvim.lua) expToLua; + + cfg = config.vim.languages.yaml; + + defaultServer = "yaml-language-server"; + servers = { + yaml-language-server = { + package = pkgs.nodePackages.yaml-language-server; + lspConfig = '' + lspconfig.yamlls.setup { + capabilities = capabilities; + on_attach = default_on_attach; + cmd = ${ + if isList cfg.lsp.package + then expToLua cfg.lsp.package + else ''{"${cfg.lsp.package}/bin/yaml-language-server", "--stdio"}'' + }, + } + ''; + }; + }; +in { + options.vim.languages.yaml = { + enable = mkEnableOption "YAML language support"; + + treesitter = { + enable = mkEnableOption "YAML treesitter"; + + package = mkGrammarOption pkgs "yaml"; + }; + + lsp = { + enable = mkEnableOption "YAML LSP support"; + + server = mkOption { + type = enum (attrNames servers); + default = defaultServer; + description = "YAML LSP server to use"; + }; + + package = mkOption { + type = either package (listOf str); + default = servers.${cfg.lsp.server}.package; + description = "YAML LSP server package"; + }; + }; + }; + + config = mkIf cfg.enable (mkMerge [ + (mkIf cfg.treesitter.enable { + vim.treesitter.enable = true; + vim.treesitter.grammars = [cfg.treesitter.package]; + }) + + (mkIf cfg.lsp.enable { + vim.lsp.lspconfig.enable = true; + vim.lsp.lspconfig.sources.yaml-lsp = servers.${cfg.lsp.server}.lspConfig; + }) + ]); +}