Skip to content
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

Support Mixins in Kotlin #1974

Closed
solonovamax opened this issue Mar 15, 2023 · 2 comments
Closed

Support Mixins in Kotlin #1974

solonovamax opened this issue Mar 15, 2023 · 2 comments

Comments

@solonovamax
Copy link

Minecraft Development for IntelliJ plugin version

2022.3-1.6.1

Description of the feature request

It would be great if there was support for mixins in kotlin.

Note: this is not a duplicate of #722, as that issue does not discuss support for mixins, only supporting kotlin when creating a project.

Currently, when you write a mixin in Java, the following is displayed:
image

However, if the same mixin is converted to kotlin, the gutter icons are removed, and you cannot control + click on the method text to navigate to the original function:
image

Note: mixin support can be added for kotlin sources by using kapt in the buildscript. For example:

dependencies {
    kapt("net.fabricmc:sponge-mixin:0.12.4+mixin.0.8.5")
}

Although not officially supported by the mixin framework, this does still work, and it is quite useful to write mixins in kotlin, rather than having to do the following everywhere:

YourModInstance.INSTANCE.something.whatever()

or

SomeKotlinObject.INSTANCE.whatever()

Ideally, the following features would be appreciated for kotlin mixins:

  • adding kotlin mixins to config
  • gutter icons for navigating to definitions
  • navigation to method definition
  • detecting & correcting incorrect method arguments
  • injects completion
  • folding method references

I don't believe it should be too difficult to support this, as the code already exists for the Java implementation, and ideally you can just reuse it. However, I have never worked with the IntelliJ plugin api, so I could be incorrect.

@Earthcomputer
Copy link
Member

The problem with writing Mixins in Kotlin is that the Kotlin compiler generates a bunch of extra crap which goes on to confuse the Mixin applicator. The reason Kotlin Mixins are bad practice is not because of some vague statement that Mixins are supposed to be written in Java, it does really cause problems in practice, and this is why I don't want to encourage this bad practice in mcdev. I would even go so far as to generate a warning when a Mixin is written in Kotlin.

@PierreDuverger
Copy link

PierreDuverger commented Apr 7, 2023

Hi, I agree with @Earthcomputer, Mixin was designed for java in the first place, so it make unstable the use of kotlin with mixins for the reasons said (it still possible, but you may encounter errors, and cannot profit of the processor and plugin feature).
I recommand to create a service class/object (wrote with kotlin) that contains all the logic, and use it in your java mixin instead .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants