JetBrains / sbt-idea-plugin

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

value parsing is not a member of com.intellij.lang.properties for com.intellij.lang.properties.parsing.PropertiesTokenTypes.VALUE_CHARACTERS #125

Closed AlexWeinstein92 closed 5 months ago

AlexWeinstein92 commented 5 months ago

I am trying to initialize a repository in Scala3 using sbt-idea-plugin following the only example on Github that I can find for Scala 3: https://github.com/azolotko/sbt-idea-example-scala3

However, this repo does not seem to have been updated since September. I think it is only slightly outdated because I am able to compile with only one issue:

value parsing is not a member of com.intellij.lang.properties
import com.intellij.lang.properties.parsing.PropertiesTokenTypes.VALUE_CHARACTERS

Which is necessary for the following section of code found in completion.SimpleCompletionContributor:

class SimpleCompletionContributor() extends CompletionContributor {
  extend(
    CompletionType.BASIC,
    PlatformPatterns.psiElement(VALUE_CHARACTERS),
    new CompletionProvider[CompletionParameters]() {
      override def addCompletions(parameters: CompletionParameters, context: ProcessingContext, result: CompletionResultSet): Unit =
        result.addElement(LookupElementBuilder.create("HELLO"))
    }
  )
}

If this part of the API has been altered in the last 8 months or so, please advise. If you have no clue why this is failing, or it is out your area of expertise, please advise who or what type of expert to bring this to.

And thanks for the good work!

AlexWeinstein92 commented 5 months ago

I have figured out the cause of this issue, but not how to solve: there are conflicting binaries brought in in my imports...

Jetbrains:com.intellij.properties:231.9011.34 contains com.intellij.lang.properties.parsing in its jar, where PropertiesTokenTypes exists.

But in my Scala file, when I command+click into com.intellij.lang.properties, it takes me to the util.jar of org.jetbrains:INTELLIJ-SDK:231.9011.34, at com.intellij.lang.properties.charset.

So it seems there is a mix up in terms of what is being imported by com.intellij.lang.properties...

unkarjedy commented 5 months ago

Hello.

Root package com.intellij.lang.properties is present in multiple jars. com.intellij.lang.properties.parsing.PropertiesTokenTypes is available in the "properties" plugin. To add a dependency on the plugin you need to add this to your module:

.settings(
  intellijPlugins ++= Seq(
    "com.intellij.properties".toPlugin
  )
)

It will appear in the project structure and be available in your code

image
unkarjedy commented 5 months ago

I hope this helps. If you have any other questions related to IntelliJ Scala Plugin / sbt-idea-plugin, you are welcome to our Discord

AlexWeinstein92 commented 5 months ago

@unkarjedy this did not help with my issue - I already had .toPlugin set in by build.sbt.

The precise issue seems to be that the SDK's com.intellij.lang.properties.charset seems to be overriding the import path for com.intellij.lang.properties.parsing.PropertiesTokenTypes - that is to say, the SDK's util.jar contains com.intellij.lang.properties and ends up being found instead of the plugin's properties.jar which also contains com.intellij.lang.properties...

As a bit of commentary on why I cannot solve: if these were both coming in through build.sbt settings, I could change the order such that the plugin overrides the SDk. But the SDK is not coming in from settings, rather it uses addSbtPlugin in plugins.sbt

unkarjedy commented 5 months ago

Ok, I see the linked project and can reproduce the issue. https://github.com/ossuminc/riddl-idea-plugin/

image

Same with compiler-based highlighting disabled

image
unkarjedy commented 5 months ago

Interestingly, the issue goes away if you use Scala 2

val scalaVer = "2.13.14"
Global / scalaVersion := scalaVer
Global / scalacOptions ++= Seq("-Xsource:3")
unkarjedy commented 5 months ago

@AlexWeinstein92 It seems something is wrong with your SBT project setup. I am not familiar with com.ossuminc.* SBT plugins and don't know what are these: com.ossuminc.sbt.OssumIncPlugin.autoImport.Module or com.ossuminc.sbt.OssumIncPlugin.autoImport.Root. but the resulting sbt structure is strange. Source directories kinda overlap:

show sourceDirectories
[info] src / Compile / sourceDirectories
[info]  List(riddl-idea-plugin/src/src/main/scala, riddl-idea-plugin/src/src/main/scala-3, riddl-idea-plugin/src/src/main/java, riddl-idea-plugin/src/target/scala-3.4.1/src_managed/main)
[info] Compile / sourceDirectories
[info]  List(riddl-idea-plugin/src/main/scala, riddl-idea-plugin/src/main/scala-3, riddl-idea-plugin/src/main/java, riddl-idea-plugin/target/scala-3.4.1/src_managed/main)
[IJ]riddl-idea-plugin(root) : main : 0.0.0-5-0a897025-20240502-2057>

You can also see it if you try to create directory at src dir - it suggests creating another src with main/scala inside:

image image

So, the sources in your current src/main/scala don't belong to module src they belong to the root. If you move the sources to a proper directory, compilation works fine both from IDEA and SBT. (though there are some other valid unrelated compilation errors)

image
unkarjedy commented 5 months ago

Please use Scala 3.3.3 version - the same as used in IntelliJ Scala: https://github.com/JetBrains/intellij-scala/blob/idea241.x/project/dependencies.scala#L8 Otherwise, there might be some unexpected errors at runtime. Also, please ensure that your plugin doesn't bundle jar with Scala 3 library.

AlexWeinstein92 commented 5 months ago

@unkarjedy thank you for your detailed feedback!

I am using tools provided by https://github.com/ossuminc for both setting up my project & using the RIDDL language tools.

It turns out I had indeed set it up to be a module at root instead of just root. I have fixed that bug and now am getting the following errors when I run the project with code for displaying RIDDL compilation in the tool window - a new IntelliJ window opens, as it did without the ossuminc libs, which are written in 3.4.1, but without my custom Tool window.

The original import error is gone, but now I have a possible incompatibility issue. Please advise

2024-05-06 12:52:05,349 [  13296]   WARN - #c.i.o.e.s.p.m.ExternalProjectsDataStorage - ExternalProjectsDataStorage deserialization: Cannot find class `org.jetbrains.sbt.project.data.SbtBuildModuleData`
2024-05-06 12:52:06,084 [  14031]   WARN - #c.i.o.w.i.ToolWindowImpl - ToolWindow icons should be 13x13, but got: 16x16. Please fix ToolWindow (ID:  Language Servers) or icon RasterizedImageDataLoader(classLoader=com.intellij.util.lang.PathClassLoader@7cf10a6f, path=webreferences/server.svg)
2024-05-06 12:52:09,768 [  17715]   WARN - #c.i.u.x.Binding - No accessors for org.jetbrains.kotlin.cli.common.arguments.InternalArgument. This means that state class cannot be serialized properly. Please see https://jb.gg/ij-psoc
2024-05-06 12:52:13,836 [  21783]   WARN - #o.j.k.i.s.r.KotlinCompilerReferenceIndexStorage - kotlin-data-container is not found
2024-05-06 12:52:24,169 [  32116] SEVERE - #c.i.u.c.QueueProcessor - Cannot invoke "com.intellij.openapi.application.Application.getService(java.lang.Class)" because the return value of "com.intellij.openapi.application.ApplicationManager.getApplication()" is null
java.lang.NullPointerException: Cannot invoke "com.intellij.openapi.application.Application.getService(java.lang.Class)" because the return value of "com.intellij.openapi.application.ApplicationManager.getApplication()" is null
    at com.intellij.openapi.progress.ProgressManager.getInstance(ProgressManager.java:37)
    at com.intellij.openapi.progress.util.ProgressIndicatorUtils.checkCancelledEvenWithPCEDisabled(ProgressIndicatorUtils.java:433)
    at com.intellij.openapi.progress.util.ProgressIndicatorUtils.awaitWithCheckCanceled(ProgressIndicatorUtils.java:447)
    at com.intellij.openapi.application.impl.NonBlockingReadActionImpl$Submission.executeSynchronously(NonBlockingReadActionImpl.java:518)
    at com.intellij.openapi.application.impl.NonBlockingReadActionImpl.executeSynchronously(NonBlockingReadActionImpl.java:220)
    at com.intellij.framework.detection.impl.FrameworkDetectionManager.doRunDetection(FrameworkDetectionManager.java:168)
    at com.intellij.framework.detection.impl.FrameworkDetectionManager$1.run(FrameworkDetectionManager.java:46)
    at com.intellij.util.ui.update.ContextAwareUpdate.run$lambda$1$lambda$0(ContextAwareUpdate.kt:49)
    at com.intellij.util.concurrency.ChildContext$runAsCoroutine$1.invoke(propagation.kt:81)
    at com.intellij.util.concurrency.ChildContext$runAsCoroutine$1.invoke(propagation.kt:81)
    at com.intellij.util.concurrency.ChildContext.runAsCoroutine(propagation.kt:86)
    at com.intellij.util.concurrency.ChildContext.runAsCoroutine(propagation.kt:81)
    at com.intellij.util.ui.update.ContextAwareUpdate.run(ContextAwareUpdate.kt:48)
    at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:354)
    at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:344)
    at com.intellij.util.ui.update.MergingUpdateQueue.doFlush(MergingUpdateQueue.java:301)
    at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:283)
    at com.intellij.util.ui.update.MergingUpdateQueue.run(MergingUpdateQueue.java:250)
    at com.intellij.util.concurrency.ChildContext$runAsCoroutine$1.invoke(propagation.kt:81)
    at com.intellij.util.concurrency.ChildContext$runAsCoroutine$1.invoke(propagation.kt:81)
    at com.intellij.util.concurrency.ChildContext.runAsCoroutine(propagation.kt:86)
    at com.intellij.util.concurrency.ChildContext.runAsCoroutine(propagation.kt:81)
    at com.intellij.util.Alarm$Request.lambda$runSafely$0(Alarm.java:369)
    at com.intellij.util.concurrency.QueueProcessor.runSafely(QueueProcessor.java:253)
    at com.intellij.util.Alarm$Request.runSafely(Alarm.java:369)
    at com.intellij.util.Alarm$Request.run(Alarm.java:356)
    at com.intellij.util.concurrency.Propagation.contextAwareCallable$lambda$2(propagation.kt:357)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at com.intellij.util.concurrency.SchedulingWrapper$MyScheduledFutureTask.run(SchedulingWrapper.java:272)
    at com.intellij.util.concurrency.BoundedTaskExecutor.doRun(BoundedTaskExecutor.java:244)
    at com.intellij.util.concurrency.BoundedTaskExecutor.access$200(BoundedTaskExecutor.java:30)
    at com.intellij.util.concurrency.BoundedTaskExecutor$1.executeFirstTaskAndHelpQueue(BoundedTaskExecutor.java:222)
    at com.intellij.util.ConcurrencyUtil.runUnderThreadName(ConcurrencyUtil.java:218)
    at com.intellij.util.concurrency.BoundedTaskExecutor$1.run(BoundedTaskExecutor.java:210)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
    at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:702)
    at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:699)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
    at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1.run(Executors.java:699)
    at java.base/java.lang.Thread.run(Thread.java:840)
2024-05-06 12:52:24,171 [  32118] SEVERE - #c.i.u.c.QueueProcessor - IntelliJ IDEA 2024.1.1  Build #IU-241.15989.150
2024-05-06 12:52:24,171 [  32118] SEVERE - #c.i.u.c.QueueProcessor - JDK: 17.0.10; VM: OpenJDK 64-Bit Server VM; Vendor: JetBrains s.r.o.
2024-05-06 12:52:24,172 [  32119] SEVERE - #c.i.u.c.QueueProcessor - OS: Mac OS X
AlexWeinstein92 commented 5 months ago

Importing Kotlin from here did the trick getting the tool window back :) https://github.com/JetBrains/sbt-kotlin-plugin

AlexWeinstein92 commented 5 months ago

@unkarjedy I am coming back to this thread because you seem to be knowledgeable enough for this ongoing issue...

There is no way to use riddl without scala3, and I am seeing kotlin-data-container is not found along with java.lang.NoClassDefFoundError when trying to use the ossum TopLevelParser for riddl. It takes a URI.

The parser is for sure in the classpath. My colleague, who develops all of ossum's packages himself, thinks this is an issue with Jetbrains' PluginClassLoader, but I think it may be a kotlin-JVM-Scala3 interop issue, or maybe something gradle can do that sbt can't for example.. I knew nothing about Kotlin until I had to research it for this issue so feedback from an expert would be greatly appreciated.

If it's impossible to make this work, I want to know ASAP so I can look for alternatives instead of wasting company time & my energy. But I understand if deeper investigation is required on my part.

AlexWeinstein92 commented 5 months ago

See here for more details https://github.com/JetBrains/sbt-idea-plugin/issues/126