argoproj / argo-schema-generator

Tool that generates a kustomize schema file for Argo CD, Argo Rollouts, Argo Workflows, and Argo Events
28 stars 12 forks source link

Argo CD schema in Neovim #9

Open jessebot opened 2 months ago

jessebot commented 2 months ago

Hi friends!

In Neovim, I use nvim-lspconfig for my language servers. In particular, I use yamlls as my YAML language server for validating YAML against JSON schemas (more info here). Here's a preview of what it looks like while I'm using the datreeio/CRDs-catalog Argo json schemas:

-- Setup the language servers so that they're available for our LSP client.
local lspconfig = require('lspconfig')
local capabilities = require('cmp_nvim_lsp').default_capabilities()

-- yaml
-- https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#yamlls
lspconfig.yamlls.setup {
  settings = {
    yaml = {
      schemas = {
        ["https://raw.githubusercontent.com/datreeio/CRDs-catalog/main/argoproj.io/application_v1alpha1.json"] = "/*argocd_app.yaml",
        ["https://raw.githubusercontent.com/datreeio/CRDs-catalog/main/argoproj.io/applicationset_v1alpha1.json"] = "/*argocd_appset.yaml",
        ["https://raw.githubusercontent.com/datreeio/CRDs-catalog/main/argoproj.io/appproject_v1alpha1.json"] = "/*argocd_project.yaml"
            },
    }},
    capabilities = capabilities
}

Here's what it looks like in the editor when I open a file ending argocd_appset.yaml and I start typing a known property, such as spec.template.metadata and then hit tab (it shows as a property that I can use):

Screenshot of neovim showing tabbing on the `spec.template.metadata` with a small popup that says Property

If I try to change the JSON schema to this repo's schema called argo_cd_kustomize_schema.json, the lua code for Neovim looks like this:

lspconfig.yamlls.setup {
  settings = {
    yaml = {
      schemas = {
        ["https://raw.githubusercontent.com/argoproj/argo-schema-generator/main/schema/argo_cd_kustomize_schema.json"] = "/*argocd_appset.yaml",
            },
    }},
    capabilities = capabilities
}

And here's what it looks like in neovim:

Screenshot of neovim showing an error on the first yaml line of the same file. error below this image.

It seems to throw an error that was hidden, so I pulled up trouble, my diagnostics tool at the bottom of the screen and it seems to throw an error that requires me to scroll, so sorry it didn't make it into the screenshot 😅:

$ref '/definitions/io.k8s.apimachinery.pkg.util.intstr.IntOrString' in 'https://raw.githubusercontent.com/argoproj/argo-schema-generator/main/schema/argo_cd_kustomize_schema.json' can not be resolved. YAML (768) [2, 1]

If I look at the top of the datreeio appset json schema, I see this:

click me to see applicationset_v1alpha1 ```json { "properties": { "apiVersion": { "type": "string" }, "kind": { "type": "string" }, "metadata": { "type": "object" }, "spec": { "properties": { "applyNestedSelectors": { "type": "boolean" }, "generators": { "items": { "properties": { "clusterDecisionResource": { "properties": { "configMapRef": { "type": "string" }, ```

however the top of the argo-schema-generator schema looks like this:

click me for argo_cd_kustomize_schema.json ```json { "definitions": { "io.argoproj.argocd.v1alpha1.AWSAuthConfig": { "description": "AWSAuthConfig is an AWS IAM authentication configuration", "type": "object", "properties": { "clusterName": { "description": "ClusterName contains AWS cluster name", "type": "string" }, "profile": { "description": "Profile contains optional role ARN. If set then AWS IAM Authenticator uses the profile to perform cluster operations instead of the default AWS credential provider chain.", "type": "string" }, "roleARN": { "description": "RoleARN contains optional role ARN. If set then AWS IAM Authenticator assume a role to perform cluster operations instead of the default AWS credential provider chain.", "type": "string" } }, "x-kubernetes-group-version-kind": [ { "group": "argoproj.io", "kind": "AWSAuthConfig", "version": "v1alpha1" } ] }, "io.argoproj.argocd.v1alpha1.AppProject": { "description": "AppProject provides a logical grouping of applications, providing controls for: * where the apps may deploy to (cluster whitelist) * what may be deployed (repository whitelist, resource whitelist/blacklist) * who can access these applications (roles, OIDC group claims bindings) * and what they can do (RBAC policies) * automation access to these roles (JWT tokens)", "type": "object", "required": [ "metadata", "spec" ], "properties": { "apiVersion": { "description": "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources", "type": "string" }, ```

Has anyone gotten this to work in neovim? If so, which plugin did you use? Any tips or suggestions here?

Thanks for any help anyone can provide 🙏