-
Notifications
You must be signed in to change notification settings - Fork 230
Expand file tree
/
Copy pathFabricModJsonResolveScopeEnlarger.kt
More file actions
66 lines (57 loc) · 2.58 KB
/
Copy pathFabricModJsonResolveScopeEnlarger.kt
File metadata and controls
66 lines (57 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
* Minecraft Development for IntelliJ
*
* https://mcdev.io/
*
* Copyright (C) 2024 minecraft-dev
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, version 3.0 only.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.demonwav.mcdev.platform.fabric.reference
import com.demonwav.mcdev.platform.fabric.util.FabricConstants
import com.demonwav.mcdev.platform.mcp.aw.AwFileType
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.vfs.VirtualFile
import com.intellij.psi.ResolveScopeEnlarger
import com.intellij.psi.search.SearchScope
import org.jetbrains.plugins.gradle.util.GradleUtil
class FabricModJsonResolveScopeEnlarger : ResolveScopeEnlarger() {
override fun getAdditionalResolveScope(file: VirtualFile, project: Project): SearchScope? {
if (file.name == FabricConstants.FABRIC_MOD_JSON) {
val module = ModuleUtilCore.findModuleForFile(file, project)
?: return null
return module.moduleWithDependentsScope.union(module.moduleTestsWithDependentsScope)
}
if (file.fileType is AwFileType) {
var module = ModuleUtilCore.findModuleForFile(file, project)
?: return null
val loomData = GradleUtil.findGradleModuleData(module)?.children
?.find { it.key == FabricLoomData.KEY }?.data as? FabricLoomData
?: return null
var moduleManager = ModuleManager.getInstance(project)
var baseModuleName = module.name.substringBeforeLast('.')
var scope = module.moduleWithLibrariesScope
for ((_, sourceSets) in loomData.modSourceSets.orEmpty()) {
for (name in sourceSets) {
val otherModule = moduleManager.findModuleByName("$baseModuleName.$name") ?: continue
scope = scope.union(otherModule.moduleWithLibrariesScope)
}
}
return scope
}
return null
}
}