Skip to content

Commit d5273cd

Browse files
committed
update HACKING.md with a nicer overview of our schemas and where they get used
1 parent 79578e1 commit d5273cd

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed

HACKING.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,87 @@ task prepare:vscode
124124
3. Next, open a VSCode instance at the root of the project, open the
125125
`Run and Debug` tab and run it via the `Run Extension` on the dropdown menu
126126
at the top of the tab.
127+
128+
## Understanding the Schema Files
129+
130+
The CircleCI YAML Language Server uses **two different schema files** for different purposes:
131+
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 |
136+
137+
### Architecture
138+
139+
This is a **two-tier schema system**:
140+
141+
### `schema.json`
142+
143+
**Primary Purpose**: Validates the YAML is valid according to our CircleCI rules
144+
145+
**Used By**:
146+
147+
- **Go Language Server Binary**: The main language server reads this schema via the `SCHEMA_LOCATION` environment variable
148+
- Location: `pkg/services/diagnostics.go`, `pkg/services/validate.go`, etc.
149+
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
155+
156+
- **Go Tests**: Used for validation testing
157+
- 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.

0 commit comments

Comments
 (0)