someone-stole-my-name/yaml-companion.nvim

github github
utility
star 45
stars
alert-circle 0
open issues
users 1
subscribers
git-branch 1
forks
CREATED

2022-04-28

UPDATED

9 days ago


yaml-companion.nvim Build

telescope statusbar

⚡️ Requirements

✨ Features

  • Builtin Kubernetes manifest autodetection
  • Select specific JSON schema per buffer
  • Get the in-use schema
  • Extensible autodetection + Schema Store support

📦 Installation

Install the plugin and load the telescope extension with your preferred package manager:

Packer

use {
  "someone-stole-my-name/yaml-companion.nvim",
  requires = {
      { "neovim/nvim-lspconfig" },
      { "nvim-lua/plenary.nvim" },
      { "nvim-telescope/telescope.nvim" },
  },
  config = function()
    require("telescope").load_extension("yaml_schema")
  end,
}

⚙️ Configuration

yaml-companion comes with the following defaults:

{
  -- Built in file matchers
  builtin_matchers = {
    -- Detects Kubernetes files based on content
    kubernetes = { enabled = true },
  },

  -- Additional schemas available in Telescope picker
  schemas = {
    result = {
      --{
      --  name = "Kubernetes 1.22.4",
      --  uri = "https://raw.githubusercontent.com/yannh/kubernetes-json-schema/master/v1.22.4-standalone-strict/all.json",
      --},
    },
  },

  -- Pass any additional options that will be merged in the final LSP config
  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" },
      },
    },
  },
}
local cfg = require("yaml-companion").setup({
  -- Add any options here, or leave empty to use the default settings
  -- lspconfig = {
  --   cmd = {"yaml-language-server"}
  -- },
})
require("lspconfig")["yamlls"].setup(cfg)

🚀 Usage

Select a schema for the current buffer

No mappings included, you need to map it yourself or call it manually:

:Telescope yaml_schema

Alternatively, you can use vim.ui.select to use the picker of your choice. In that case, you can bind/call the function:

require("yaml-companion").open_ui_select()

Get the schema name for the current buffer

You can show the current schema in your statusline using a function like:

function foo()
  local schema = require("yaml-companion").get_buf_schema(0)
  if schema then
    return schema.result[1].name
  end
  return ""
end