Add logic for auto-updating schema config from collection metadata #1023
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 tosettings.json
to commit. Here’s an example of enabling this in the Astro Docs repo which uses YAML files for i18n:If configuring this manually you’d usually do this instead, which is much cleaner:
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