Skip to content

Commit

Permalink
Merge pull request #266 from lets-cli/add-jsonschema-file
Browse files Browse the repository at this point in the history
add schema.json file to support autocommpletion and validation
  • Loading branch information
kindermax authored Oct 7, 2024
2 parents 8e0055c + 536c490 commit fceb103
Show file tree
Hide file tree
Showing 2 changed files with 219 additions and 1 deletion.
50 changes: 49 additions & 1 deletion docs/docs/ide_support.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,52 @@ Provides autocomplete and filetype support.

Provides autocomplete and filetype support.

[Plugin site](https://github.com/mpanarin/lets-mode)
[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,
},
}
```

170 changes: 170 additions & 0 deletions docs/static/schema.json
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit fceb103

Please sign in to comment.