Support media gallery - #2
Merged
Merged
Conversation
- Add `addToMediaGallery` command to insert media entries into gallery modules. - Introduce `moveFileToGalleryDirectory` command to relocate files into the appropriate gallery directory. - Create `findMediaGalleryIssues` function to validate media references against gallery schemas. - Implement tests for gallery entry generation and insertion logic. - Enhance completion providers to filter and provide context for media files based on gallery status. - Update server to include media gallery validation diagnostics in document validation process.
There was a problem hiding this comment.
Pull request overview
This PR adds media gallery awareness to the Val VS Code extension/language server, including diagnostics + quick-fixes for unregistered gallery items and improved path completions scoped to a referenced gallery.
Changes:
- Add server-side validation to detect when
c.image/c.filereferences a media gallery but the referenced asset is not registered or not in the gallery directory. - Add client quick-fixes to (a) insert a metadata entry into the gallery module and (b) move an asset into the configured gallery directory and update references.
- Improve completion providers by resolving the schema at the cursor’s field-path (including richtext
href) and filtering image/file path completions to the referenced gallery directory.
Reviewed changes
Copilot reviewed 14 out of 17 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| server/src/server.ts | Runs new media gallery validation and emits LSP diagnostics with fix data. |
| server/src/metadataUtils.ts | Adjusts image-size input type for updated dependency behavior. |
| server/src/metadataUtils.test.ts | Updates tests to match new image-size input handling. |
| server/src/mediaGalleryValidation.ts | Implements (source,schema) walker to produce media gallery diagnostics. |
| server/src/mediaGalleryValidation.test.ts | Adds tests for the media gallery diagnostics walker. |
| server/src/completionProviders.ts | Uses field-path schema resolution; filters file/image completions to referenced gallery directory. |
| server/src/completionFieldSchema.ts | New helpers to derive field paths from AST and resolve schema at that path (incl. richtext href). |
| server/src/completionFieldSchema.test.ts | Adds unit tests for schema resolution helpers. |
| server/package.json | Bumps @valbuild/* dependencies to versions that support media gallery behavior. |
| server/package-lock.json | Lockfile updates from dependency bumps (incl. transitive deps). |
| package-lock.json | Root lockfile version bump. |
| client/src/extension.ts | Registers new commands and adds quick-fix actions for media gallery diagnostics. |
| client/src/commands/moveFileToGalleryDirectory.ts | New command to move an asset into the gallery directory and update the reference. |
| client/src/commands/addToMediaGallery.ts | New command to insert a gallery entry with inferred metadata into the referenced gallery module. |
| client/src/commands/addToMediaGallery.test.ts | Unit tests for helper functions used by the gallery insertion command. |
| client/package.json | Bumps @valbuild/core to match server/core expectations. |
| client/package-lock.json | Lockfile updates for client dependency bump. |
Files not reviewed (2)
- client/package-lock.json: Language not supported
- server/package-lock.json: Language not supported
Comments suppressed due to low confidence (1)
client/src/commands/addToMediaGallery.ts:177
getImageMetadata/getFileMetadataultimately callpath.join(rootPath, relativePath)(client/src/metadataUtils.ts). Ifdata.pathis a Val-style path starting with/public/...,path.jointreats it as absolute and ignoresrootPath, so metadata lookup will likely fail. Consider stripping the leading/(for FS resolution only) or updating metadataUtils to treat leading-slash Val paths as project-root relative.
const mediaType = data.mediaType ?? "images";
const rawMetadata =
mediaType === "images"
? getImageMetadata(data.path, uri)
: getFileMetadata(data.path, uri);
const metadata = stripAlt(rawMetadata as Record<string, string | number>);
if (Object.keys(metadata).length === 0) {
vscode.window.showErrorMessage(
`Could not read metadata for ${data.path}. Make sure the file exists at ${path.join(valRoot, ...data.path.split("/"))}.`,
);
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
… modulePathMap - Validate that paths from .val source stay inside the project root before any fs operation in addToMediaGallery / moveFileToGalleryDirectory. - Use FILE_REF_PROP instead of the literal "_ref" in media gallery diagnostics. - Hoist modulePathMap so it's computed once per validate pass instead of twice. - Tighten server engines.node to >=20.19.0 to match chokidar v5.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
No description provided.