From 536c4905f2ff0b935abd8a89dd42ab51032747ae Mon Sep 17 00:00:00 2001 From: "m.kindritskiy" Date: Mon, 7 Oct 2024 22:57:10 +0300 Subject: [PATCH] add schema.json file to support autocommpletion and validation --- docs/docs/ide_support.md | 50 +++++++++++- docs/static/schema.json | 170 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 219 insertions(+), 1 deletion(-) create mode 100644 docs/static/schema.json diff --git a/docs/docs/ide_support.md b/docs/docs/ide_support.md index a271efd2..24c0579c 100644 --- a/docs/docs/ide_support.md +++ b/docs/docs/ide_support.md @@ -13,4 +13,52 @@ Provides autocomplete and filetype support. Provides autocomplete and filetype support. -[Plugin site](https://github.com/mpanarin/lets-mode) \ No newline at end of file +[Plugin site](https://github.com/mpanarin/lets-mode) + +### JSON Schema + +In order to get autocomplete and filetype support in any editor, you can use the JSON schema file provided by Lets. + +#### VSCode + +To use the JSON schema in VSCode, you can use the [YAML extension](https://marketplace.visualstudio.com/items?itemName=redhat.vscode-yaml). + +Add the following to your `settings.json`: + +```json +{ + "yaml.schemas": { + "https://lets-cli.org/schema.json": [ + "**/lets.yaml", + "**/lets*.yaml", + ] + } +} +``` + +#### Neovim + +To use the JSON schema in Neovim, you can use the `nvim-lspconfig` with `SchemaStore` plugin. + +In your `nvim-lspconfig` configuration, add the following: + +```lua +servers = { + yamlls = { + on_new_config = function(new_config) + local yaml_schemas = require("schemastore").yaml.schemas({ + extra = { + { + description = "Lets JSON schema", + fileMatch = { "lets.yaml", "lets*.yaml" }, + name = "lets.schema.json", + url = "https://lets-cli.org/schema.json", + }, + }, + }) + new_config.settings.yaml.schemas = vim.tbl_deep_extend("force", new_config.settings.yaml.schemas or {}, yaml_schemas) + end, + }, +} +``` + diff --git a/docs/static/schema.json b/docs/static/schema.json new file mode 100644 index 00000000..4a8b034a --- /dev/null +++ b/docs/static/schema.json @@ -0,0 +1,170 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "Lets yaml schema", + "description": "Schema for Lets files.", + "type": "object", + "properties": { + "version": { + "type": "string", + "description": "The version of the configuration." + }, + "shell": { + "type": "string", + "description": "The shell to use for commands." + }, + "mixins": { + "type": "array", + "description": "List of mixin files to include.", + "items": { + "type": "string" + } + }, + "env": { + "$ref": "#/definitions/env" + }, + "before": { + "type": "string", + "description": "Commands to run before the main script." + }, + "init": { + "type": "string", + "description": "Init script will be executed only once before any commands." + }, + "commands": { + "type": "object", + "description": "Set of commands to execute.", + "patternProperties": { + "^[a-zA-Z][a-zA-Z0-9_:-]*$": { + "type": "object", + "properties": { + "description": { + "type": "string", + "description": "A description of the command." + }, + "options": { + "type": "string", + "description": "Options for the command in docopt format." + }, + "cmd": { + "oneOf": [ + { + "type": "string", + "description": "Command as a string." + }, + { + "type": "array", + "description": "Command as a list of strings.", + "items": { + "type": "string" + } + }, + { + "type": "object", + "description": "Command as an object with key as named command and value as a script", + "patternProperties": { + "^[a-zA-Z_][a-zA-Z0-9_]*$": { + "oneOf": [ + { + "type": "string", + "description": "Command as a string." + }, + { + "type": "array", + "description": "Command as a list of strings.", + "items": { + "type": "string" + } + } + ] + } + } + } + ] + }, + "depends": { + "type": "array", + "items": { + "type": "string" + } + }, + "persist_checksum": { + "type": "boolean" + }, + "checksum": { + "type": "array", + "items": { + "type": "string" + } + }, + "env": { + "$ref": "#/definitions/env" + }, + "after": { + "type": "string", + "description": "A shell sctipt to run after the command." + }, + "work_dir": { + "type": "string", + "description": "A directory to run the command in." + } + }, + "required": [ + "cmd" + ] + } + } + } + }, + "required": [ + "commands" + ], + "definitions": { + "env": { + "type": "object", + "description": "Environment variables to set.", + "patternProperties": { + "^[a-zA-Z_][a-zA-Z0-9_]*$": { + "oneOf": [ + { + "type": "string", + "description": "Simple environment variable with a string value." + }, + { + "type": "object", + "description": "Environment variable with a 'sh' key to run a shell command.", + "properties": { + "sh": { + "type": "string", + "description": "Shell command to execute." + } + }, + "required": [ + "sh" + ], + "additionalProperties": false + }, + { + "type": "object", + "description": "Environment variable with a 'checksum' key to calculate checksum of all provided files.", + "properties": { + "checksum": { + "type": "array", + "items": { + "type": "string" + }, + "description": "List of files to calculate checksum." + } + }, + "required": [ + "checksum" + ], + "additionalProperties": false + } + ] + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false +}