JetBrains / sbt-idea-plugin

Develop IntelliJ plugins with Scala and SBT
Apache License 2.0
97 stars 28 forks source link

Companion object cannot be referenced in plugin.xml using its name #127

Closed zhutmost closed 4 months ago

zhutmost commented 4 months ago

I am writing a custom FileType for a custom language. According to the sample Java code in the tutorial by JetBrains, I use a companion object to store the INSTANCE object:

class VerilogFileType extends LanguageFileType(VerilogLanguage.INSTANCE) {
  ...... // other code
}

object VerilogFileType {
  val INSTANCE = new VerilogFileType
}

and I add it to the plugin.xml:

        <fileType
            name="SystemVerilog"
            implementationClass="some.package.VerilogFileType" // here!
            fieldName="INSTANCE"
            language="SystemVerilog"
            extensions="sv;svh"/>

However, scala will rename the companion object (add a dollar "$" after its name) during compiling. So, the above code cannot work. To solution is to correct the plugin.xml, like this:

<fileType
   ...
            implementationClass="some.package.VerilogFileType$" // here a $ added!
   ....
/>

Now we can successfully generate a correct plugin zip.

zhutmost commented 4 months ago

Although we can workaround the problem, the Intellij IDEA will report unnecessary warning messages.

image

I think this can be fixed.

unkarjedy commented 4 months ago

We also observe this issue in Scala Plugin.

image

But it's not an issue with sbt-idea-plugin, it's an issue with IntelliJ DevKit plugin. Could you please report it at https://youtrack.jetbrains.com/newIssue?project=IJPL&draftId=25-5362851 and set the subsystem DevKit?