From 269f2245f44338f6e542a0cc3de40f3c75e7600f Mon Sep 17 00:00:00 2001 From: Gaetan Lepage Date: Sat, 24 May 2025 14:28:35 +0200 Subject: [PATCH] plugins/yaml-companion: init --- plugins/by-name/yaml-companion/default.nix | 53 +++++++++++ .../by-name/yaml-companion/default.nix | 93 +++++++++++++++++++ 2 files changed, 146 insertions(+) create mode 100644 plugins/by-name/yaml-companion/default.nix create mode 100644 tests/test-sources/plugins/by-name/yaml-companion/default.nix diff --git a/plugins/by-name/yaml-companion/default.nix b/plugins/by-name/yaml-companion/default.nix new file mode 100644 index 00000000..665d2f9d --- /dev/null +++ b/plugins/by-name/yaml-companion/default.nix @@ -0,0 +1,53 @@ +{ + lib, + config, + ... +}: +lib.nixvim.plugins.mkNeovimPlugin { + name = "yaml-companion"; + packPathName = "yaml-companion.nvim"; + package = "yaml-companion-nvim"; + + maintainers = [ lib.maintainers.GaetanLepage ]; + + settingsExample = { + schemas = [ + { + name = "Argo CD Application"; + uri = "https://raw.githubusercontent.com/datreeio/CRDs-catalog/main/argoproj.io/application_v1alpha1.json"; + } + { + name = "SealedSecret"; + uri = "https://raw.githubusercontent.com/datreeio/CRDs-catalog/main/bitnami.com/sealedsecret_v1alpha1.json"; + } + ]; + lspconfig = { + settings = { + yaml = { + format.enable = false; + schemaStore = { + enable = false; + url = ""; + }; + schemas = lib.nixvim.nestedLiteralLua "require('schemastore').yaml.schemas()"; + }; + }; + }; + }; + + callSetup = false; + extraConfig = cfg: { + warnings = lib.nixvim.mkWarnings "plugins.yaml-companion" [ + { + when = !config.plugins.lsp.enable; + message = "This plugin requires the `plugins.lsp.servers.yamlls` module to be enabled."; + } + ]; + + plugins = { + lsp.servers.yamlls.extraOptions = lib.nixvim.mkRaw "require('yaml-companion').setup(${lib.nixvim.toLuaObject cfg.settings})"; + + telescope.enabledExtensions = [ "yaml_schema" ]; + }; + }; +} diff --git a/tests/test-sources/plugins/by-name/yaml-companion/default.nix b/tests/test-sources/plugins/by-name/yaml-companion/default.nix new file mode 100644 index 00000000..fcf959ca --- /dev/null +++ b/tests/test-sources/plugins/by-name/yaml-companion/default.nix @@ -0,0 +1,93 @@ +{ lib, pkgs, ... }: +{ + empty = { + plugins = { + lsp = { + enable = true; + servers.yamlls.enable = true; + }; + + yaml-companion.enable = true; + }; + }; + + defaults = { + plugins = { + lsp = { + enable = true; + servers.yamlls.enable = true; + }; + + yaml-companion = { + enable = true; + + settings = { + builtin_matchers = { + kubernetes.enabled = true; + cloud_init.enabled = true; + }; + schemas = [ ]; + lspconfig = { + flags = { + debounce_text_changes = 150; + }; + settings = { + redhat.telemetry.enabled = false; + yaml = { + validate = true; + format.enable = true; + hover = true; + schemaStore = { + enable = true; + url = "https://www.schemastore.org/api/json/catalog.json"; + }; + schemaDownload.enable = true; + schemas = [ ]; + trace.server = "debug"; + }; + }; + }; + }; + }; + }; + }; + + example = { + extraPlugins = [ pkgs.vimPlugins.SchemaStore-nvim ]; + plugins = { + lsp = { + enable = true; + servers.yamlls.enable = true; + }; + + yaml-companion = { + enable = true; + + settings = { + schemas = [ + { + name = "Argo CD Application"; + uri = "https://raw.githubusercontent.com/datreeio/CRDs-catalog/main/argoproj.io/application_v1alpha1.json"; + } + { + name = "SealedSecret"; + uri = "https://raw.githubusercontent.com/datreeio/CRDs-catalog/main/bitnami.com/sealedsecret_v1alpha1.json"; + } + ]; + lspconfig = { + settings = { + yaml = { + format.enable = false; + schemaStore = { + enable = false; + url = ""; + }; + schemas = lib.nixvim.mkRaw "require('schemastore').yaml.schemas()"; + }; + }; + }; + }; + }; + }; + }; +}