Skip to content

Commit

Permalink
Add config to enable/disable mcdoc caching
Browse files Browse the repository at this point in the history
  • Loading branch information
misode committed Dec 10, 2024
1 parent 0fe6f00 commit 5895265
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
7 changes: 7 additions & 0 deletions packages/core/src/service/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ export interface EnvConfig {
>
permissionLevel: 1 | 2 | 3 | 4
plugins: string[]
/**
* Whether to enable caching of mcdoc simplified types.
*
* May become corrupt after changing game versions, so this is currently disabled by default.
*/
enableMcdocCaching: boolean
/**
* Makes the file-watcher use polling to watch for file changes.
* Comes at a performance cost for very large datapacks.
Expand Down Expand Up @@ -362,6 +368,7 @@ export const VanillaConfig: Config = {
permissionLevel: 2,
plugins: [],
mcmetaSummaryOverrides: {},
enableMcdocCaching: false,
useFilePolling: false,
},
format: {
Expand Down
8 changes: 4 additions & 4 deletions packages/mcdoc/src/runtime/checker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,7 @@ function simplifyReference<T>(
context.ctx.logger.warn(`Tried to access unknown reference ${typeDef.path}`)
return { typeDef: { kind: 'union', members: [] } }
}
if (data.simplifiedTypeDef) {
if (context.ctx.config.env.enableMcdocCaching && data.simplifiedTypeDef) {
return { typeDef: data.simplifiedTypeDef }
}
const simplifiedResult = simplify(data.typeDef, context)
Expand All @@ -833,7 +833,7 @@ function simplifyReference<T>(
attributes: [...typeDef.attributes, ...simplifiedResult.typeDef.attributes ?? []],
}
}
if (!simplifiedResult.dynamicData) {
if (context.ctx.config.env.enableMcdocCaching && !simplifiedResult.dynamicData) {
symbol.amend({
data: {
data: {
Expand Down Expand Up @@ -903,7 +903,7 @@ function resolveIndices<T>(
let dynamicData = false
let values: SimplifiedMcdocTypeNoUnion[] = []
function pushValue(key: string, data: TypeDefSymbolData) {
if (data.simplifiedTypeDef) {
if (context.ctx.config.env.enableMcdocCaching && data.simplifiedTypeDef) {
if (data.simplifiedTypeDef.kind === 'union') {
values.push(...data.simplifiedTypeDef.members)
} else {
Expand All @@ -913,7 +913,7 @@ function resolveIndices<T>(
const simplifiedResult = simplify(data.typeDef, context)
if (simplifiedResult.dynamicData) {
dynamicData = true
} else if (symbolQuery) {
} else if (context.ctx.config.env.enableMcdocCaching && symbolQuery) {
symbolQuery.member(
key,
s =>
Expand Down

0 comments on commit 5895265

Please sign in to comment.