-
Notifications
You must be signed in to change notification settings - Fork 36
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
base: main
Are you sure you want to change the base?
Changes from 6 commits
6b55c75
fcc9f00
30f732b
526a13c
4f6df16
eb768b4
4c667d0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ import type { | |
UriBinder, | ||
UriBinderContext, | ||
UriBuilder, | ||
UriPredicate, | ||
} from '@spyglassmc/core' | ||
import { | ||
ErrorSeverity, | ||
|
@@ -210,6 +211,53 @@ export function* getRoots( | |
return undefined | ||
} | ||
|
||
function getCandidateResourcesForRel(rel: string): [res: Resource, identifier: string][] { | ||
const parts = rel.split('/') | ||
if (parts.length < 3) { | ||
return [] | ||
} | ||
const [pack, _namespace, ...rest] = parts | ||
if (pack !== 'data' && pack !== 'assets') { | ||
return [] | ||
} | ||
const candidateResources: [Resource, string][] = [] | ||
if (rest.length === 1) { | ||
const resources = Resources.get('') | ||
for (const res of resources ?? []) { | ||
if (res.pack !== pack) { | ||
continue | ||
} | ||
let identifier = rest[0] | ||
if (!identifier.endsWith(res.ext)) { | ||
continue | ||
} | ||
identifier = identifier.slice(0, -res.ext.length) | ||
if (res.identifier && identifier !== res.identifier) { | ||
continue | ||
} | ||
candidateResources.push([res, identifier]) | ||
} | ||
} | ||
for (let i = 1; i < rest.length; i += 1) { | ||
const resources = Resources.get(rest.slice(0, i).join('/')) | ||
for (const res of resources ?? []) { | ||
if (res.pack !== pack) { | ||
continue | ||
} | ||
let identifier = rest.slice(i).join('/') | ||
if (!identifier.endsWith(res.ext)) { | ||
continue | ||
} | ||
identifier = identifier.slice(0, -res.ext.length) | ||
if (res.identifier && identifier !== res.identifier) { | ||
continue | ||
} | ||
candidateResources.push([res, identifier]) | ||
} | ||
} | ||
return candidateResources | ||
} | ||
|
||
export function dissectUri(uri: string, ctx: UriBinderContext) { | ||
const rels = getRels(uri, ctx.roots) | ||
const release = ctx.project['loadedVersion'] as ReleaseVersion | undefined | ||
|
@@ -226,41 +274,7 @@ export function dissectUri(uri: string, ctx: UriBinderContext) { | |
if (pack !== 'data' && pack !== 'assets') { | ||
continue | ||
} | ||
const candidateResources: [Resource, string][] = [] | ||
if (rest.length === 1) { | ||
const resources = Resources.get('') | ||
for (const res of resources ?? []) { | ||
if (res.pack !== pack) { | ||
continue | ||
} | ||
let identifier = rest[0] | ||
if (!identifier.endsWith(res.ext)) { | ||
continue | ||
} | ||
identifier = identifier.slice(0, -res.ext.length) | ||
if (res.identifier && identifier !== res.identifier) { | ||
continue | ||
} | ||
candidateResources.push([res, identifier]) | ||
} | ||
} | ||
for (let i = 1; i < rest.length; i += 1) { | ||
const resources = Resources.get(rest.slice(0, i).join('/')) | ||
for (const res of resources ?? []) { | ||
if (res.pack !== pack) { | ||
continue | ||
} | ||
let identifier = rest.slice(i).join('/') | ||
if (!identifier.endsWith(res.ext)) { | ||
continue | ||
} | ||
identifier = identifier.slice(0, -res.ext.length) | ||
if (res.identifier && identifier !== res.identifier) { | ||
continue | ||
} | ||
candidateResources.push([res, identifier]) | ||
} | ||
} | ||
const candidateResources = getCandidateResourcesForRel(rel) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The logic between There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's cuz we use the value of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm I see. Though it already returns a list of two things: |
||
if (candidateResources.length === 0) { | ||
continue | ||
} | ||
|
@@ -386,3 +400,13 @@ export function registerUriBuilders(meta: MetaRegistry) { | |
meta.registerUriBuilder(category, uriBuilder(resources)) | ||
} | ||
} | ||
|
||
/** | ||
* Returns true for JSON file URIs that belong to any known resource category. No version check is | ||
* performed as we would like to provide errors even for files in the wrong folder or files for the | ||
* wrong version. | ||
*/ | ||
export const jsonUriPredicate: UriPredicate = (uri, ctx) => { | ||
const rels = [...getRels(uri, ctx.roots)] | ||
return rels.some((rel) => getCandidateResourcesForRel(rel).length > 0) | ||
} |
There was a problem hiding this comment.
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.