-
Notifications
You must be signed in to change notification settings - Fork 206
Support for comprehension calls in Scala #151
-
Is your feature request related to a problem? Please describe.
As the readme states that Scala is supported on version 3 and it isn't marked as partial, I was in doubt if this is actually a bug or an unsupported language feature due to some specific feature.
Describe the solution you'd like
If a function is called from withing a for comprehension, the call should be presented in the diagram just as a direct call would.
Take this example:
class B() { def bar() = Option("bar") } class A(b: B) { def foo() = { val r = "foo" + b.bar().getOrElse("?") r } def foo2() = { val r = for { x <- b.bar() } yield "foo" + x r.getOrElse("?") } }
The diagram for foo() shows the bar() call but the diagram for foo2() goes directly to the getOrElse.
This way, the plugin loses a lot of its usefulness when you have functional code that makes heavy use of this language feature.
Describe alternatives you've considered
Can't see alternatives in this case except the feature needs to be implemented, fixed if it was supposed to work already, or a warning added that it is not supported due to some limitation if there is some unavoidable one.
Additional context
Tested 3.0.0-alpha.1
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1
Replies: 3 comments
-
I move your request here for discussions. Your description and code pattern are very good example.
Beta Was this translation helpful? Give feedback.
All reactions
-
I found the issue based on you example code. the code
val r = for { x <- b.bar() } yield "foo" + x
Are not support yet.
Why?
The generate solution is based on the UAST api, witch is one for four(Java, Scala, Kotlin, groovy) solution. The description on IDEA document: https://plugins.jetbrains.com/docs/intellij/uast.html#which-languages-are-supported
Java: full support
Kotlin: full support
Scala: beta, but full support
Groovy: declarations only, method bodies not supported
But, the UAST tree of the function foo2 is
UMethod (name = foo2)
UBlockExpression
UDeclarationsExpression
ULocalVariable (name = r)
UastEmptyExpression(type = PsiType:Option<String>)
UReturnExpression
UQualifiedReferenceExpression
USimpleNameReferenceExpression (identifier = r)
UMethodCall(name = getOrElse)
UIdentifier (Identifier (getOrElse))
ULiteralExpression (value = "?")
you can see, the var r for {...} yield ... was represent with UastEmptyExpression, the generate can not generate the method call b.bar() based on it.
May be it is the UAST api weak, I will report to IDEA for some help.
Beta Was this translation helpful? Give feedback.
All reactions
-
It seems that the issue is related to the Scala language feature not being fully supported by the plugin, and the solution proposed is to update the plugin to show function calls within for comprehensions in the diagram.
Beta Was this translation helpful? Give feedback.