Skip to content

Commit

Permalink
Merge branch '2023.3' into 2024.1
Browse files Browse the repository at this point in the history
  • Loading branch information
RedNesto committed Feb 8, 2024
2 parents 0e680c6 + bb41432 commit eaa630f
Show file tree
Hide file tree
Showing 14 changed files with 80 additions and 73 deletions.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ license {
style["bnf"] = HeaderStyle.BLOCK_COMMENT.format

val endings = listOf("java", "kt", "kts", "groovy", "gradle.kts", "xml", "properties", "html", "flex", "bnf")
exclude("META-INF/plugin.xml") // https://youtrack.jetbrains.com/issue/IDEA-345026
include(endings.map { "**/*.$it" })

exclude("com/demonwav/mcdev/platform/mixin/invalidInjectorMethodSignature/*.java")
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ kotlin.code.style=official
ideaVersion = 241.10840-EAP-CANDIDATE-SNAPSHOT
ideaVersionName = 2024.1

coreVersion = 1.7.1
coreVersion = 1.7.2
downloadIdeaSources = true

pluginTomlVersion = 241.10840.7
Expand Down
7 changes: 3 additions & 4 deletions src/main/kotlin/creator/MinecraftModuleBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import com.demonwav.mcdev.creator.buildsystem.BuildSystemPropertiesStep
import com.demonwav.mcdev.creator.platformtype.PlatformTypeStep
import com.demonwav.mcdev.creator.step.NewProjectWizardChainStep.Companion.nextStep
import com.demonwav.mcdev.creator.step.TemplateOutdatedStep
import com.demonwav.mcdev.platform.MinecraftModuleType
import com.intellij.ide.projectWizard.ProjectSettingsStep
import com.intellij.ide.util.projectWizard.WizardContext
import com.intellij.ide.wizard.AbstractNewProjectWizardBuilder
Expand All @@ -37,9 +36,9 @@ import com.intellij.openapi.roots.ModifiableRootModel

class MinecraftModuleBuilder : AbstractNewProjectWizardBuilder() {

override fun getPresentableName() = MinecraftModuleType.NAME
override fun getPresentableName() = "Minecraft"
override fun getNodeIcon() = PlatformAssets.MINECRAFT_ICON
override fun getGroupName() = MinecraftModuleType.NAME
override fun getGroupName() = "Minecraft"
override fun getBuilderId() = "MINECRAFT_MODULE"
override fun getDescription() = MCDevBundle("creator.ui.create_minecraft_project")

Expand All @@ -51,7 +50,7 @@ class MinecraftModuleBuilder : AbstractNewProjectWizardBuilder() {
}
}

override fun getParentGroup() = MinecraftModuleType.NAME
override fun getParentGroup() = "Minecraft"

override fun createStep(context: WizardContext) = RootNewProjectWizardStep(context)
.nextStep(::NewProjectWizardBaseStep)
Expand Down
10 changes: 5 additions & 5 deletions src/main/kotlin/facet/MinecraftFacet.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import com.demonwav.mcdev.platform.AbstractModuleType
import com.demonwav.mcdev.platform.PlatformType
import com.demonwav.mcdev.util.SourceType
import com.demonwav.mcdev.util.filterNotNull
import com.demonwav.mcdev.util.invokeAndWait
import com.demonwav.mcdev.util.mapFirstNotNull
import com.google.common.collect.HashMultimap
import com.intellij.facet.Facet
Expand All @@ -36,6 +35,7 @@ import com.intellij.facet.FacetTypeId
import com.intellij.facet.FacetTypeRegistry
import com.intellij.ide.projectView.ProjectView
import com.intellij.openapi.application.runReadAction
import com.intellij.openapi.application.runWriteAction
import com.intellij.openapi.application.runWriteActionAndWait
import com.intellij.openapi.module.Module
import com.intellij.openapi.module.ModuleGrouper
Expand Down Expand Up @@ -77,9 +77,9 @@ class MinecraftFacet(
roots.clear()
}

fun refresh() {
fun refresh() = runWriteActionAndWait {
if (module.isDisposed) {
return
return@runWriteActionAndWait
}

// Don't allow parent types with child types in auto detected set
Expand Down Expand Up @@ -122,9 +122,9 @@ class MinecraftFacet(
ProjectView.getInstance(module.project).refresh()
}

private fun updateRoots() = invokeAndWait {
private fun updateRoots() = runWriteAction {
if (module.isDisposed) {
return@invokeAndWait
return@runWriteAction
}

roots.clear()
Expand Down
26 changes: 17 additions & 9 deletions src/main/kotlin/facet/MinecraftFacetDetector.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,16 @@ import com.intellij.openapi.startup.ProjectActivity
import com.intellij.openapi.util.Key
import com.intellij.platform.ide.progress.withBackgroundProgress
import com.intellij.platform.util.progress.forEachWithProgress
import com.intellij.util.concurrency.NonUrgentExecutor
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.asCoroutineDispatcher
import kotlinx.coroutines.cancelAndJoin
import kotlinx.coroutines.job
import kotlinx.coroutines.launch
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import org.jetbrains.plugins.gradle.util.GradleUtil

class MinecraftFacetDetector : ProjectActivity {
Expand All @@ -69,15 +73,13 @@ class MinecraftFacetDetector : ProjectActivity {

override suspend fun execute(project: Project) {
val detectorService = project.service<FacetDetectorScopeProvider>()
detectorService.currentJob?.cancelAndJoin()
withBackgroundProgress(project, "Detecting Minecraft Frameworks", cancellable = false) {
detectorService.currentJob = coroutineContext.job
MinecraftModuleRootListener.doCheck(project)
}
MinecraftModuleRootListener.doCheckUnderProgress(project, detectorService)
}

@Service(Service.Level.PROJECT)
private class FacetDetectorScopeProvider(val scope: CoroutineScope) {
val dispatcher = NonUrgentExecutor.getInstance().asCoroutineDispatcher()
val lock = Mutex()
var currentJob: Job? = null
}

Expand All @@ -89,12 +91,18 @@ class MinecraftFacetDetector : ProjectActivity {

val project = event.source as? Project ?: return
val detectorService = project.service<FacetDetectorScopeProvider>()
detectorService.scope.launch {
detectorService.currentJob?.cancelAndJoin()
withBackgroundProgress(project, "Detecting Minecraft Frameworks", cancellable = false) {
detectorService.scope.launch(detectorService.dispatcher) {
doCheckUnderProgress(project, detectorService)
}
}

suspend fun doCheckUnderProgress(project: Project, detectorService: FacetDetectorScopeProvider) {
withBackgroundProgress(project, "Detecting Minecraft Frameworks", cancellable = false) {
detectorService.lock.withLock {
detectorService.currentJob?.cancelAndJoin()
detectorService.currentJob = coroutineContext.job
doCheck(project)
}
doCheck(project)
}
}

Expand Down
43 changes: 0 additions & 43 deletions src/main/kotlin/platform/MinecraftModuleType.kt

This file was deleted.

2 changes: 2 additions & 0 deletions src/main/kotlin/platform/forge/creator/gradle-steps.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import com.demonwav.mcdev.creator.step.LicenseStep
import com.demonwav.mcdev.creator.step.NewProjectWizardChainStep.Companion.nextStep
import com.demonwav.mcdev.creator.step.UseMixinsStep
import com.demonwav.mcdev.util.MinecraftTemplates
import com.demonwav.mcdev.util.MinecraftVersions
import com.demonwav.mcdev.util.SemanticVersion
import com.intellij.ide.wizard.NewProjectWizardStep
import com.intellij.openapi.application.WriteAction
Expand Down Expand Up @@ -102,6 +103,7 @@ class ForgeGradleFilesStep(parent: NewProjectWizardStep) : AbstractLongRunningAs
"AUTHOR_LIST" to authors.joinToString(", "),
"LICENSE" to license.id,
"HAS_DATA" to "true",
"MERGE_RESOURCES_AND_CLASSES" to (mcVersion >= MinecraftVersions.MC1_20_3),
)

if (javaVersion != null) {
Expand Down
6 changes: 4 additions & 2 deletions src/main/kotlin/platform/mcp/actions/SrgActionBase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import com.intellij.psi.PsiElement
import com.intellij.psi.PsiIdentifier
import com.intellij.psi.PsiMember
import com.intellij.psi.PsiReference
import com.intellij.psi.util.createSmartPointer
import com.intellij.ui.LightColors
import com.intellij.ui.awt.RelativePoint
import java.awt.Point
Expand Down Expand Up @@ -88,9 +89,10 @@ abstract class SrgActionBase : AnAction() {

val project = e.project ?: return

val elementPointer = getDataFromActionEvent(e)?.element?.createSmartPointer()
val editor = getDataFromActionEvent(e)?.editor
invokeLater {
val element = getDataFromActionEvent(e)?.element
val editor = getDataFromActionEvent(e)?.editor
val element = elementPointer?.element
if (element != null && editor != null) {
val pos = editor.offsetToVisualPosition(element.textRange.endOffset - element.textLength / 2)
val at = RelativePoint(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,30 @@ class NewInsnSelectorParser : MixinSelectorParser {
if (!at.hasQualifiedName(AT)) return null
if (at.findAttributeValue("value")?.constantStringValue != "NEW") return null

return NewInsnSelector(value)
val strippedValue = value.replace(" ", "")
return if (strippedValue.startsWith('(')) {
NewInsnDescriptorSelector(strippedValue)
} else {
NewInsnTypeSelector(strippedValue)
}
}
}

private class NewInsnSelector(
private class NewInsnTypeSelector(
override val owner: String,
) : MixinSelector {
override fun matchField(owner: String, name: String, desc: String) = false

override fun matchMethod(owner: String, name: String, desc: String): Boolean {
return name == "<init>" && owner == this.owner
}

override val fieldDescriptor = null
override val methodDescriptor = null
override val displayName = owner
}

private class NewInsnDescriptorSelector(
override val methodDescriptor: String,
) : MixinSelector {
override fun matchField(owner: String, name: String, desc: String): Boolean = false
Expand Down
5 changes: 5 additions & 0 deletions src/main/kotlin/platform/mixin/reference/MixinSelectors.kt
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,11 @@ class MixinMemberParser : MixinSelectorParser {
}

owner = internalOwner.replace('/', '.')

// if owner is all there is to the selector, match anything with the owner
if (pos == reference.length - 1) {
return MemberReference("", null, owner, matchAllNames = true, matchAllDescs = true)
}
} else {
// No owner/qualifier specified
pos = -1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private class GetterReference(element: PsiLanguageInjectionHost) : PsiReferenceB
}

override fun getVariants(): Array<Any> {
val literal = element.toUElementOfType<ULiteralExpression>() ?: return ArrayUtil.EMPTY_OBJECT_ARRAY
val literal = element.toUElement() ?: return ArrayUtil.EMPTY_OBJECT_ARRAY
val (eventClass, _) = literal.uastEventListener
?: return ArrayUtil.EMPTY_OBJECT_ARRAY
val methodByClass = mutableMapOf<String, Pair<PsiMethod, PsiClass>>()
Expand Down
9 changes: 5 additions & 4 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
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/>.
along with this program. If not, see https://www.gnu.org/licenses/.
-->

<idea-plugin require-restart="true">
Expand Down Expand Up @@ -81,7 +81,7 @@
<extensionPoint name="injectionPoint" beanClass="com.demonwav.mcdev.platform.mixin.handlers.injectionPoint.InjectionPointInfo" dynamic="true">
<with attribute="implementation" implements="com.demonwav.mcdev.platform.mixin.handlers.injectionPoint.InjectionPoint"/>
</extensionPoint>
<extensionPoint name="injectionPointAnnotation" beanClass="com.demonwav.mcdev.platform.mixin.handlers.injectionPoint.InjectionPointAnnotation" />
<extensionPoint name="injectionPointAnnotation" beanClass="com.demonwav.mcdev.platform.mixin.handlers.injectionPoint.InjectionPointAnnotation" dynamic="true" />
</extensionPoints>

<extensions defaultExtensionNs="com.demonwav.minecraft-dev">
Expand Down Expand Up @@ -181,11 +181,11 @@
<!--region NO PLATFORM-->
<!---->

<moduleType id="MINECRAFT_MODULE_TYPE" implementationClass="com.demonwav.mcdev.platform.MinecraftModuleType"/>
<moduleBuilder id="MINECRAFT_MODULE" builderClass="com.demonwav.mcdev.creator.MinecraftModuleBuilder"/>
<facetType implementation="com.demonwav.mcdev.facet.MinecraftFacetType" />
<postStartupActivity implementation="com.demonwav.mcdev.facet.MinecraftFacetDetector"/>
<notificationGroup id="Minecraft project creator" displayType="STICKY_BALLOON"/>
<notificationGroup id="Minecraft facet" displayType="STICKY_BALLOON"/>

<!-- File templates are for project creations -->
<fileTemplateGroup implementation="com.demonwav.mcdev.util.MinecraftTemplates"/>
Expand Down Expand Up @@ -266,6 +266,7 @@
<annotator language="MCLang" implementationClass="com.demonwav.mcdev.translations.intentions.TranslationFileAnnotator"/>
<annotator language="JSON" implementationClass="com.demonwav.mcdev.translations.intentions.TranslationFileAnnotator"/>
<intentionAction>
<language>JAVA</language>
<className>com.demonwav.mcdev.translations.intentions.ConvertToTranslationIntention</className>
<category>Minecraft</category>
<descriptionDirectoryName>convertToTranslation</descriptionDirectoryName>
Expand Down Expand Up @@ -354,7 +355,7 @@
<!--endregion-->

<!--region NEOFORGE-->
<dependencySupport coordinate="net.neoforge:neoforge" kind="java"/>
<dependencySupport coordinate="net.neoforged:neoforge" kind="java"/>

<fileIconProvider implementation="com.demonwav.mcdev.platform.neoforge.NeoForgeFileIconProvider"/>
<implicitUsageProvider implementation="com.demonwav.mcdev.platform.neoforge.insight.NeoForgeImplicitUsageProvider" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,22 @@ minecraft {
// You can set various levels here.
// Please read: https://stackoverflow.com/questions/2031163/when-to-use-the-different-log-levels
property 'forge.logging.console.level', 'debug'
#if (!${MERGE_RESOURCES_AND_CLASSES})

mods {
"${mod_id}" {
source sourceSets.main
}
}
#end
}

#if (${GAME_TEST_FRAMEWORK})
client {
#if (${GAME_TEST_FRAMEWORK})
// Comma-separated list of namespaces to load gametests from. Empty = all namespaces.
property 'forge.enabledGameTestNamespaces', mod_id
}
#end
}

server {
#if (${GAME_TEST_FRAMEWORK})
Expand Down Expand Up @@ -217,6 +225,7 @@ tasks.named('jar', Jar).configure {
tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8' // Use the UTF-8 charset for Java compilation
}
#if (${MERGE_RESOURCES_AND_CLASSES})

// Merge the resources and classes into the same directory.
// This is done because java expects modules to be in a single directory.
Expand All @@ -227,3 +236,4 @@ sourceSets.each {
it.output.resourcesDir = dir
it.java.destinationDirectory = dir
}
#end
3 changes: 3 additions & 0 deletions src/main/resources/messages/MinecraftDevelopment.properties
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ error_reporter.report.error=Error Submitting Issue: {0}.
error_reporter.report.error.action=Open an issue on the GitHub issue tracker

facet.editor.name=Minecraft Module Settings
facet.reimport.failed.title=Minecraft facet refresh
facet.reimport.failed.content.no_error=Failed to start project refresh, please refresh your project manually.
facet.reimport.failed.content.with_error=Failed to start project refresh, please refresh your project manually. Cause: {0}

generate.event_listener.title=Generate Event Listener
generate.event_listener.settings=Event Listener Settings
Expand Down

0 comments on commit eaa630f

Please sign in to comment.