Skip to content

Commit 64c6fbb

Browse files
committed
Use remote schema URL for config outputs
- Add SCHEMA_URL constant in config.rs to hold the remote schema URL - Emit a schema header for TOML and YAML outputs using SCHEMA_URL - Inject a $schema property into JSON output - Default to TOML when the file extension is unknown - Update .peas.toml to reference the remote schema URL - Extend schemas/peas.json with a $schema field description - Update README to document automatic in-file directives and URL
1 parent ad3d79e commit 64c6fbb

File tree

4 files changed

+67
-19
lines changed

4 files changed

+67
-19
lines changed

.peas.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#:schema ./schemas/peas.json
1+
#:schema https://raw.githubusercontent.com/asaaki/peas/refs/heads/main/schemas/peas.json
22

33
[peas]
44
path = ".peas"

README.md

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -228,34 +228,54 @@ use_type_emojis = false # Enable emoji icons for ticket types in TUI
228228

229229
### Editor Support (JSON Schema)
230230

231-
A JSON Schema is available at `schemas/peas.json` for editor autocompletion and validation.
231+
A JSON Schema is available for editor autocompletion and validation. New projects created with `peas init` automatically include the schema directive.
232232

233-
**In-file directive (works with Taplo and Tombi):**
233+
**Schema URL:** `https://raw.githubusercontent.com/asaaki/peas/refs/heads/main/schemas/peas.json`
234234

235-
Add this comment at the top of your `.peas.toml`:
235+
**In-file directives (automatically added by `peas init`):**
236+
237+
TOML (Taplo/Tombi):
236238
```toml
237-
#:schema ./schemas/peas.json
239+
#:schema https://raw.githubusercontent.com/asaaki/peas/refs/heads/main/schemas/peas.json
238240

239241
[peas]
240242
prefix = "peas-"
241243
```
242244

245+
YAML (yaml-language-server):
246+
```yaml
247+
# yaml-language-server: $schema=https://raw.githubusercontent.com/asaaki/peas/refs/heads/main/schemas/peas.json
248+
249+
peas:
250+
prefix: "peas-"
251+
```
252+
253+
JSON:
254+
```json
255+
{
256+
"$schema": "https://raw.githubusercontent.com/asaaki/peas/refs/heads/main/schemas/peas.json",
257+
"peas": {
258+
"prefix": "peas-"
259+
}
260+
}
261+
```
262+
243263
**Zed with Tombi extension:**
244264

245-
Add to your `tombi.toml` (or project settings):
265+
The in-file directive works automatically. Alternatively, add to your `tombi.toml`:
246266
```toml
247267
[[schemas]]
248-
path = "./schemas/peas.json"
268+
url = "https://raw.githubusercontent.com/asaaki/peas/refs/heads/main/schemas/peas.json"
249269
include = [".peas.toml"]
250270
```
251271

252272
**VS Code with Even Better TOML (Taplo):**
253273

254-
Add to your `.vscode/settings.json`:
274+
The in-file directive works automatically. Alternatively, add to `.vscode/settings.json`:
255275
```json
256276
{
257277
"evenBetterToml.schema.associations": {
258-
".peas.toml": "./schemas/peas.json"
278+
".peas.toml": "https://raw.githubusercontent.com/asaaki/peas/refs/heads/main/schemas/peas.json"
259279
}
260280
}
261281
```
@@ -264,15 +284,11 @@ Add to your `.vscode/settings.json`:
264284
```json
265285
{
266286
"yaml.schemas": {
267-
"./schemas/peas.json": [".peas.yml", ".peas.yaml"]
287+
"https://raw.githubusercontent.com/asaaki/peas/refs/heads/main/schemas/peas.json": [".peas.yml", ".peas.yaml"]
268288
}
269289
}
270290
```
271291

272-
**Neovim with taplo/yaml-language-server:**
273-
274-
Configure your LSP to associate the schema with `.peas.*` files.
275-
276292
## File Format
277293

278294
Peas are stored as markdown files with TOML frontmatter (YAML and JSON also supported):

schemas/peas.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
"type": "object",
77
"additionalProperties": false,
88
"properties": {
9+
"$schema": {
10+
"type": "string",
11+
"description": "JSON Schema URL for editor support",
12+
"format": "uri"
13+
},
914
"peas": {
1015
"type": "object",
1116
"description": "Core peas settings",

src/config.rs

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ use crate::storage::FrontmatterFormat;
33
use serde::{Deserialize, Serialize};
44
use std::path::{Path, PathBuf};
55

6+
/// URL to the JSON Schema for peas configuration files
7+
pub const SCHEMA_URL: &str =
8+
"https://raw.githubusercontent.com/asaaki/peas/refs/heads/main/schemas/peas.json";
9+
610
/// ID generation mode for tickets
711
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)]
812
#[serde(rename_all = "lowercase")]
@@ -163,13 +167,36 @@ impl PeasConfig {
163167
// Determine format based on file extension, default to TOML
164168
let content = if let Some(ext) = path.extension().and_then(|s| s.to_str()) {
165169
match ext {
166-
"toml" => toml::to_string_pretty(self)?,
167-
"json" => serde_json::to_string_pretty(self)?,
168-
"yml" | "yaml" => serde_yaml::to_string(self)?,
169-
_ => toml::to_string_pretty(self)?, // Default to TOML
170+
"toml" => {
171+
let toml_content = toml::to_string_pretty(self)?;
172+
format!("#:schema {}\n\n{}", SCHEMA_URL, toml_content)
173+
}
174+
"json" => {
175+
// Add $schema property to JSON output
176+
let mut json_value = serde_json::to_value(self)?;
177+
if let serde_json::Value::Object(ref mut map) = json_value {
178+
map.insert(
179+
"$schema".to_string(),
180+
serde_json::Value::String(SCHEMA_URL.to_string()),
181+
);
182+
}
183+
serde_json::to_string_pretty(&json_value)?
184+
}
185+
"yml" | "yaml" => {
186+
let yaml_content = serde_yaml::to_string(self)?;
187+
format!(
188+
"# yaml-language-server: $schema={}\n\n{}",
189+
SCHEMA_URL, yaml_content
190+
)
191+
}
192+
_ => {
193+
let toml_content = toml::to_string_pretty(self)?;
194+
format!("#:schema {}\n\n{}", SCHEMA_URL, toml_content)
195+
}
170196
}
171197
} else {
172-
toml::to_string_pretty(self)? // Default to TOML
198+
let toml_content = toml::to_string_pretty(self)?;
199+
format!("#:schema {}\n\n{}", SCHEMA_URL, toml_content)
173200
};
174201
std::fs::write(path, content)?;
175202
Ok(())

0 commit comments

Comments
 (0)