Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Ignore non-Minecraft JSON files #1758

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

Conversation

SPGoding
Copy link
Member

@SPGoding SPGoding commented Feb 16, 2025

(This PR could have each commit individually merged instead of a squash merge since I separated units of change into four individually revertable commits. Well after a git rebase --autosquash -i 3ea96b that is)

This PR adds an additional uriPredicate option to LanguageOptions during language registration. The json language definition has been updated to include a uriPredicate to ensure the JSON file actually belongs to a data pack or a resource pack. This check is more accurate than the DocumentFilter implemented client side in the VS Code extension as it takes the roots and the available file categories into consideration. Additions have also been made to Project.shouldExclude() to make sure unsupported files never go into the document life cycle.

This PR also fixes two bugs I noticed while making the changes.

Files of `.json` extension now must also pass a URI predicate check
before they are considered to be `json` language and be supported
by Spyglass.
Comment on lines 290 to 293
getTrackedFiles(): string[] {
const extensions: string[] = this.meta.getSupportedFileExtensions()
this.logger.info(`[Project#getTrackedFiles] Supported file extensions: ${extensions}`)
const supportedFiles = [...this.#dependencyFiles ?? [], ...this.#watchedFiles]
.filter((file) => extensions.includes(fileUtil.extname(file) ?? ''))
this.logger.info(
`[Project#getTrackedFiles] Listed ${supportedFiles.length} supported files`,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The extension check here has been removed as all files in #dependencyFiles and #watchedFiles should now all be of supported languages already.

Files of unsupported languages should now never enter into the Spyglass
document lifecycle.
candidateResources.push([res, identifier])
}
}
const candidateResources = getCandidateResourcesForRel(rel)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic between const parts = res.split('/') and here is also duplicated in getCandidateResourcesForRel

Copy link
Member Author

@SPGoding SPGoding Feb 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's cuz we use the value of namespace below and I did not want to make getCandidateResourcesForRel() return two things (getCandidateResourcesAndNamespaceForRel()?).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I see. Though it already returns a list of two things: function getCandidateResourcesForRel(rel: string): [res: Resource, identifier: string][], so maybe it wouldn't be that bad to have it also return the namespace in that tuple (or change to an object)?

@misode misode changed the title Ignore non-Minecraft JSON files 🐛 Ignore non-Minecraft JSON files Feb 19, 2025
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.

2 participants