Skip to content

cwrau/yaml-schema-detect.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 

Repository files navigation

yaml-schema-detect.nvim

A Neovim plugin that automatically detects and applies YAML schemas for your YAML files using yaml-language-server (yamlls). It can automatically fetch and apply Custom Resource Definition (CRD) schemas from your current Kubernetes cluster.

Features

  • Automatic YAML schema detection for your files
  • Seamless integration with yaml-language-server
  • Dynamic schema switching based on file content
  • Support for multiple YAML schemas
  • Buffer-specific schema management
  • Automatic fetching of Kubernetes CRD schemas from your current cluster
  • Real-time schema validation against your cluster's CRDs

Prerequisites

Installation

Using packer.nvim:

use {
  'cwrau/yaml-schema-detect.nvim',
  requires = {
    'nvim-lua/plenary.nvim',
  }
}

Using lazy.nvim:

{
  'cwrau/yaml-schema-detect.nvim',
  ---@module "yaml-schema-detect"
  ---@type YamlSchemaDetectOptions
  opts = {}, -- use default options
  dependencies = {
    'nvim-lua/plenary.nvim',
  },
  ft = { "yaml" },
}

Configuration

Plugin ships with some sensible defaults which you can tweak in your own way.

{
  disable_keymap = false,
  keymap = {
    refresh = "<leader>xr",
    cleanup = "<leader>xyc",
    info = "<leader>xyi",
  },
}

Using lazy.nvim:

Disable default keybindings entirely:

{
  'cwrau/yaml-schema-detect.nvim',
  ---@module "yaml-schema-detect"
  ---@type YamlSchemaDetectOptions
  opts = {
    disable_keymap = true,
  },
  dependencies = {
    'nvim-lua/plenary.nvim',
  },
  ft = { "yaml" },
}

Change and toggle default keybindings:

{
  'cwrau/yaml-schema-detect.nvim',
  ---@module "yaml-schema-detect"
  ---@type YamlSchemaDetectOptions
  opts = {
    keymap = {
      refresh = "<leader>yr",
      cleanup = "<leader>yc",
      info = false,
    },
  },
  dependencies = {
    'nvim-lua/plenary.nvim',
  },
  ft = { "yaml" },
}

Usage

The plugin works automatically once installed and configured. It will:

  1. Detect the appropriate YAML schema for your files
  2. Update yaml-language-server settings accordingly
  3. Provide schema-aware completions and validations

How It Works

The plugin analyses your YAML files and dynamically updates the yaml-language-server configuration to use the most appropriate schema based on the file content and context. For Kubernetes Custom Resources, it automatically connects to your current cluster to fetch the corresponding CRD schemas, ensuring your YAML files are validated against the actual CRD definitions in your cluster.

About

auto schema detection for yamlls

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages