You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The CircleCI YAML Language Server uses the standardized [JSON schema](https://json-schema.org/) to help perform basic structural validations and documentation hover hints the CircleCI YAML files. Our schema lives in `schema.json` and is utilized in multiple different places both inside and outside the codebase.
138
137
139
-
This is a **two-tier schema system**:
138
+
### Use Cases for `schema.json`
140
139
141
-
### `schema.json`
140
+
-**External Tools**: This `schema.json` is notably used by the Red Hat YAML extension. Most VSCode users who open YAML files will have this extension installed. This extension by default will pull in schemas from [schemastore.org](https://www.schemastore.org/api/json/catalog.json). This extension on its own can detect if a user is reading a CircleCI config, then it will automatically pull in our `schema.json` by looking at schemastore, which in turn pulls the latest version of `schema.json` from the main branch of this repository.
141
+
- The Red Hat YAML language gets the schema.json from this URL: `https://raw.githubusercontent.com/CircleCI-Public/circleci-yaml-language-server/refs/heads/main/schema.json`
142
142
143
-
**Primary Purpose**: Validates the YAML is valid according to our CircleCI rules
143
+
> [!NOTE]
144
+
> A user without the CircleCI VS Code extension installed, and just the Red Hat YAML language server
145
+
> installed, still benefits from this `schema.json`. The Red Hat YAML Language server on its own will provide:
146
+
>
147
+
> 1. schema validation
148
+
> 2. a hover provider in VS Code for documentation hints
149
+
>
150
+
> The benefit of installing the CircleCI Extension in VSCode is that it also pulls in the Go binary, providing more
151
+
> complex validations against a user's CircleCI config that aren't possible with JSON Schema alone.
144
152
145
-
**Used By**:
146
-
147
-
-**Go Language Server Binary**: The main language server reads this schema via the `SCHEMA_LOCATION` environment variable
153
+
-**CircleCI Go Language Server Binary**: The main language server reads this schema via the `SCHEMA_LOCATION` environment variable. The Go language server binary uses a JSON schema validation library and validates the config against the schema.
154
+
- As mentioned above, JSON Schema validation is also handled the Red Hat YAML language server. Our language server is intended to work standalone (but still be compatible with other language servers), so we also perform JSON schema validation in case the user only has our language server installed.
148
155
- Location: `pkg/services/diagnostics.go`, `pkg/services/validate.go`, etc.
149
156
150
-
-**External Tools**: Used by the Red Hat YAML extension. This extension looks at [schemastore.org](https://www.schemastore.org/api/json/catalog.json), which reads the latest schema.json from this repo.
-**VSCode Extension**: Downloaded from GitHub releases page and bundled with the extension
154
-
- Location in our private VSCode extension
157
+
-**CircleCI VSCode Extension**: CircleCI's closed-source VS Code extension will automatically pull in the latest version of the CircleCI language server from the GitHub releases page. The VS Code extension has some logic such that:
158
+
1. if it detects that the Red Hat YAML Language Server extension is not installed, it will register a hover provider
159
+
so that when the user hovers over the YAML code, it will provide hover hints from the `schema.json` it downloaded
160
+
from the CircleCI language server's releases page
161
+
2. if it detects the Red Hat YAML Language Server extension, it will defer the hover hints to the Red Hat
162
+
YAML Language Server, otherwise the user would see two instances of the hover hints.
155
163
156
164
-**Go Tests**: Used for validation testing
157
165
- Location: `pkg/services/diagnostics_test.go`
158
-
159
-
**Characteristics**:
160
-
161
-
- JSON Schema draft-07
162
-
163
-
### `publicschema.json`
164
-
165
-
**Primary Purpose**: Documentation for IDE hover features
0 commit comments