Skip to content

Conversation

delucis
Copy link
Member

@delucis delucis commented Sep 24, 2025

Changes

This PR adds some logic to try and simplify use of Astro-generated JSON schemas for data files in content collections. We document these schemas, but the VS Code config to use them isn’t so lovely.

Sharing mainly for feedback at this point as there are several less than optimal things here, and I may be doing things wrong in any case.

Notes:

  • AFAICT there is no way to set the json.schemas/yaml.schemas settings in an ephemeral “per session” way. We can only update a user’s workspace config directly (i.e. the one that lives in .vscode/settings.json in a project). That’s pretty annoying as it means the generated changes this added logic creates would show up in e.g. git diffs. All the worse because…

  • Currently I’m using the .astro/collections/collections.json metadata file we generate for the “content intellisense” experimental feature. But this doesn’t give me e.g. globs for which files are impacted. This makes the auto-updated settings verbose, because we list all impacted files, and will mean every new file incurs a change to settings.json to commit. Here’s an example of enabling this in the Astro Docs repo which uses YAML files for i18n:

       "yaml.schemas": {
         "./.astro/collections/i18n.schema.json": [
           "/src/content/i18n/ar.yml",
           "/src/content/i18n/de.yml",
           "/src/content/i18n/es.yml",
           "/src/content/i18n/en.yml",
           "/src/content/i18n/hi.yml",
           "/src/content/i18n/fr.yml",
           "/src/content/i18n/it.yml",
           "/src/content/i18n/ko.yml",
           "/src/content/i18n/ja.yml",
           "/src/content/i18n/pl.yml",
           "/src/content/i18n/ru.yml",
           "/src/content/i18n/zh-cn.yml",
           "/src/content/i18n/zh-tw.yml",
           "/src/content/i18n/pt-br.yml",
           "__astro__"
         ]
       }

    If configuring this manually you’d usually do this instead, which is much cleaner:

     "yaml.schemas": {
       "./.astro/collections/i18n.schema.json": "/src/content/i18n/*.yml"
     }
  • Because we write to a user’s config, we need a way to distinguish auto-generated and user-authored config to avoid overwriting a user’s settings. There’s no really good way to do this. I’ve hacked around it here by adding an __astro__ boolean property for JSON schema entries, and adding __astro__ as the last entry to each array for YAML schemas. Pretty gross.

Anyway, mainly sharing so this isn’t lost on my hard drive. If anyone has ideas of how to make this less rubbish, feel free to share!

Testing

Manually tested in VS Code.

Docs

TO DO

Copy link

changeset-bot bot commented Sep 24, 2025

⚠️ No Changeset found

Latest commit: 92867ad

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant