Skip to content

Commit 9dc80f2

Browse files
authored
feat: Consolidate schemas into just schema.json (#377)
1 parent f01b675 commit 9dc80f2

26 files changed

+588
-2497
lines changed

.circleci/config.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,6 @@ jobs:
329329
at: ~/
330330
- install-vscode-extensions-deps
331331
- run: cp schema.json editors/vscode
332-
- run: cp publicschema.json editors/vscode
333332
- run: cp -R bin editors/vscode/bin
334333
- run:
335334
name: Build VSIX

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
"--port",
5858
"10001",
5959
"--schema",
60-
"${workspaceFolder}/publicschema.json"
60+
"${workspaceFolder}/schema.json"
6161
]
6262
},
6363
{

HACKING.md

Lines changed: 30 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,13 @@ For example, I've the following in my `.emacs.d/init.el`:
106106

107107
## Testing within VSCode
108108

109-
This repository embed a VSCode extension (located at `editors/vscode`) so you
110-
can test your code within the editor.
109+
This repository embeds a mini VSCode extension (located at `editors/vscode`) so you
110+
can test your changes to the language server using VS Code locally.
111111

112112
1. In order to run the extension, you must first prepare installation. This
113113
command will install the necessary node packages and build the extension:
114114

115-
```
115+
```bash
116116
task prepare:vscode
117117
```
118118

@@ -125,86 +125,41 @@ task prepare:vscode
125125
`Run and Debug` tab and run it via the `Run Extension` on the dropdown menu
126126
at the top of the tab.
127127

128-
## Understanding the Schema Files
129-
130-
The CircleCI YAML Language Server uses **two different schema files** for different purposes:
128+
> [!NOTE]
129+
> Do not do `Run Extension (user extensions enabled)`. Running with no other extensions enabled
130+
> could cause confusion. Specifically, if you had the Red Hat YAML Language Server extension
131+
> installed, it would display hover hints from the JSON schema from schemastore, rather than the local schema.json
132+
> that you will often be making changes to locally and want to test.
131133
132-
| File | Purpose | Used By |
133-
| ------------------- | -------------------------------------------- | ------------------------------------------- |
134-
| `schema.json` | Core validation and language server features | Go language server binary, external tools |
135-
| `publicschema.json` | Rich hover documentation | VSCode extension TypeScript hover providers |
134+
## Understanding the `schema.json` file
136135

137-
### Architecture
136+
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.
138137

139-
This is a **two-tier schema system**:
138+
### Use Cases for `schema.json`
140139

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`
142142

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.
144152
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.
148155
- Location: `pkg/services/diagnostics.go`, `pkg/services/validate.go`, etc.
149156

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.
151-
- URL: `https://raw.githubusercontent.com/CircleCI-Public/circleci-yaml-language-server/refs/heads/main/schema.json`
152-
153-
- **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.
155163

156164
- **Go Tests**: Used for validation testing
157165
- 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
166-
167-
**Used By**:
168-
169-
- **VSCode Extension Hover Provider**
170-
- Location: `circleci-vscode-extension/packages/vscode-extension/src/lsp/hover.ts:62-67`
171-
172-
**Characteristics**:
173-
174-
- JSON Schema draft-04
175-
- Includes inline CircleCI documentation URLs (e.g., `https://circleci.com/docs/configuration-reference#...`)
176-
- **Never used by the Go language server**
177-
178-
### Why Two Schemas?
179-
180-
The separation exists because:
181-
182-
- The Go language server needs a comprehensive schema for validation that handles all edge cases
183-
- The hover provider needs clean documentation with links to CircleCI docs
184-
185-
### Development Guidelines
186-
187-
#### When to Update `schema.json`
188-
189-
Update this schema when:
190-
191-
- Adding or modifying CircleCI config validation rules
192-
- Changing supported configuration keys or values
193-
- Adding new CircleCI features that affect config structure
194-
- Fixing validation bugs
195-
196-
#### When to Update `publicschema.json`
197-
198-
Update this schema when:
199-
200-
- Improving hover documentation text
201-
- Adding or updating links to CircleCI documentation
202-
- Changing the structure of hover hints
203-
- Making documentation more user-friendly
204-
205-
#### Keeping Schemas in Sync
206-
207-
> ⚠️ [!IMPORTANT]
208-
> Both schemas should represent the same CircleCI configuration format. When you update one schema's structure, you likely need to update the other.
209-
210-
**Best Practice**: Make structural changes to both schemas in the same PR to prevent drift.

Taskfile.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ tasks:
6060
- ./bin/start_server
6161
env:
6262
PORT: "{{.PORT | default 10001}}"
63-
SCHEMA_LOCATION: ./publicschema.json
63+
SCHEMA_LOCATION: ./schema.json
6464

6565
init:
6666
- go mod download

editors/vscode/.vscodeignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,3 @@
66
!package.json
77
!package-lock.json
88
!schema.json
9-
!publicschema.json

editors/vscode/out/extension.js

Lines changed: 0 additions & 73 deletions
This file was deleted.

editors/vscode/out/extension.js.map

Lines changed: 0 additions & 1 deletion
This file was deleted.

editors/vscode/out/hover.js

Lines changed: 0 additions & 77 deletions
This file was deleted.

editors/vscode/out/hover.js.map

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)