Skip to content

Commit

Permalink
Fix references to client code not being resolved in fabric.mod.json
Browse files Browse the repository at this point in the history
For some obscure reasons I couldn't figure out, it did not work in some cases before
  • Loading branch information
RedNesto committed Dec 5, 2024
1 parent 5521181 commit c73d3e7
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 30 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
- In this case, the creator will now select the latest version available for the latest Minecraft version supported by Parchment
- [#2408](https://github.com/minecraft-dev/MinecraftDev/issues/2408) External translation annotations are not attached
- This happens because IntelliJ IDEA disables external annotations by default in 2024.3, which we rely on for this feature, an opt-out setting has been added to force-enable external annotations in Minecraft projects.
- Cases where references to client sources in fabric.mod.json were not resolved

## [1.8.2] - 2024-10-05

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,11 @@
package com.demonwav.mcdev.platform.fabric.reference

import com.demonwav.mcdev.platform.fabric.util.FabricConstants
import com.demonwav.mcdev.platform.mcp.fabricloom.FabricLoomData
import com.intellij.openapi.module.ModuleManager
import com.intellij.openapi.module.ModuleUtilCore
import com.intellij.openapi.project.Project
import com.intellij.openapi.roots.ProjectRootManager
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.psi.ResolveScopeEnlarger
import com.intellij.psi.search.GlobalSearchScope
import com.intellij.psi.search.SearchScope
import org.jetbrains.plugins.gradle.util.GradleUtil

class FabricModJsonResolveScopeEnlarger : ResolveScopeEnlarger() {

Expand All @@ -41,30 +36,6 @@ class FabricModJsonResolveScopeEnlarger : ResolveScopeEnlarger() {

val module = ModuleUtilCore.findModuleForFile(file, project)
?: return null
val loomData = GradleUtil.findGradleModuleData(module)?.children
?.find { it.key == FabricLoomData.KEY }?.data as? FabricLoomData
?: return null
val modSourceSets = loomData.modSourceSets
?: return null

val moduleScopes = mutableListOf<GlobalSearchScope>()
val moduleManager = ModuleManager.getInstance(project)
val parentPath = module.name.substringBeforeLast('.')
val rootType = ProjectRootManager.getInstance(project).fileIndex.getContainingSourceRootType(file)
?: return null
for ((_, sourceSets) in modSourceSets) {
for (sourceSet in sourceSets) {
val childModule = moduleManager.findModuleByName("$parentPath.$sourceSet")
if (childModule != null) {
moduleScopes.add(childModule.getModuleScope(rootType.isForTests))
}
}
}

if (moduleScopes.isEmpty()) {
return null
}

return GlobalSearchScope.union(moduleScopes)
return module.moduleWithDependentsScope.union(module.moduleTestsWithDependentsScope)
}
}

0 comments on commit c73d3e7

Please sign in to comment.