Skip to content

00dani/SchemaStore.vim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SchemaStore.vim

This is a simple package that makes the SchemaStore.org JSON Schema catalog available for use in Vimscript. Basically it's just a Vimscript port of the Lua plugin SchemaStore.nvim and is useful for the same purposes.

The code which retrieves the catalog from SchemaStore.org is written in Vim9 script, but for end users this plugin is compatible with older Vim versions, as well as with Neovim.

Install

Add 00dani/SchemaStore.vim to your Vim plugins in whatever way you prefer. For example, with vim-plug:

Plug '00dani/SchemaStore.vim'

Or with minpac:

call minpac#add('00dani/SchemaStore.vim')

Usage

You can retrieve the SchemaStore.org catalog from your vimrc by calling either of these autoload functions (they're synonyms):

let g:schemata = SchemaStore#Schemata()
let g:schemas  = SchemaStore#Schemas()

Alternatively, if you're using Vim9 script and would prefer to use an import, that's supported too:

vim9script
import "SchemaStore.vim"
const schemata = SchemaStore.schemata
const schemas  = SchemaStore.schemas

Note that the importable module is written in Vim9 script and will not work on Vims lacking support for it, even if they support the import syntax. If you need to support older Vims (or Neovim), then use the autoload functions.

The SchemaStore.org catalog is most useful in tandem with a Language Server Protocol client plugin, such as ALE, vim-lsp, or yegappan/lsp for Vim9. I use yegappan/lsp and configure it to use SchemaStore.org's catalog by writing:

vim9script
g:LspAddServer([{
    name: 'vscode-json-language-server',
    filetype: ['json', 'jsonc'],
    path: expand('~/.local/bin/vscode-json-language-server'),
    args: ['--stdio'],
    workspaceConfig: {json: {
      format: {enable: true},
      validate: {enable: true},
      schemas: g:SchemaStore#Schemata(),
    }},
}])

Each LSP plugin is configured in a slightly different way, so check your plugin's documentation, but the general idea will be the same.