Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Support for comprehension calls in Scala #151

oswaldo started this conversation in Ideas & features
Discussion options

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

You must be logged in to vote

Replies: 3 comments

Comment options

I move your request here for discussions. Your description and code pattern are very good example.

You must be logged in to vote
0 replies
Comment options

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.

You must be logged in to vote
0 replies
Comment options

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.

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Converted from issue

This discussion was converted from issue #150 on March 03, 2023 03:52.

AltStyle によって変換されたページ (->オリジナル) /