-
Notifications
You must be signed in to change notification settings - Fork 324
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
Add convertToNamedParameters support for Scala 3 #4131
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for working on this @jkciesluk !
This implementation converts all Apply to named arguments instead of selected Apply, we have to convert only the selected one (in the following case, we should convert only the arguments of foo
method).
We should add unit test that has multiple Apply
Also, we would need to copy some test suite from https://github.com/scalameta/metals/blob/ec89eac187c5c9e1358a8229ebac85b64a71a8a9/tests/unit/src/test/scala/tests/codeactions/ConvertToNamedArgumentsLspSuite.scala to https://github.com/scalameta/metals/blob/ec89eac187c5c9e1358a8229ebac85b64a71a8a9/tests/slow/src/test/scala/tests/feature/Scala3CodeActionLspSuite.scala (I'm wondering we can cross run those LSP test 🤔 but not this time)
.map(ScalaVersions.isScala3Version) | ||
.getOrElse(false) | ||
if (isScala3) Future.successful(Nil) | ||
else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
.foreach(result.addOne(_)) | ||
case t => | ||
traverseChildren(t) | ||
traverser.traverse(tree)(using newctx) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of traversing the whole tree, it would be useful to check the enclosing tree (of the given position (via param)) using Interactive.pathTo
or Interactive.enclosingTree
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, thank you for help!
Using pathTo
works. I've also copied tests to https://github.com/scalameta/metals/blob/ec89eac187c5c9e1358a8229ebac85b64a71a8a9/tests/slow/src/test/scala/tests/feature/Scala3CodeActionLspSuite.scala and extended them by testing multiple Apply.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
You may have to rebase on |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Just very minor remarks about the tests
@@ -328,6 +338,264 @@ class Scala3CodeActionLspSuite | |||
expectNoDiagnostics = false, | |||
) | |||
|
|||
check( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can really just add one test (first one looks good), since we only want to test the branch when we have Scala 3 dialect. All the other cases are already handled in the ConvertToNamedArgumentsLspSuite.
Anything specific to Scala 3 we can test in cross suite.
The reason is for this comment is that these tests each can last up to a couple of seconds and it's harsh on out CI.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, right.
All the other cases are already handled in the ConvertToNamedArgumentsLspSuite.
ConvertToNamedArgumentsLspSuite
test against Scala 2.13, it doesn't verify anything against Scala 3.
Actually, those tests that verify the behavior (rather than the first one) should be in PC tests instead of xxxLSPSuite
.
Sorry, we should did this in #3971
For example, Implementing all abstract member code action
have two (three?) test suite
- cross test in pc (presentation compiler)
metals/tests/cross/src/test/scala/tests/pc/AutoImplementAbstractMembersSuite.scala
Line 14 in 53249aa
class AutoImplementAbstractMembersSuite extends BaseCodeActionSuite { - These tests verify the behavior of code action, but it doesn't check the code action is available or not. Those test anyway invoke the code action even if the user won't see it's available.
- These tests run against all Scala versions
- You can run those tests with the specific version by
++3.1.3 cross/testOnly tests.pc.AutoImplementAbstractMemberSuite
.
- ImplementAbstractMemberLspSuite
metals/tests/unit/src/test/scala/tests/codeactions/ImplementAbstractMembersLspSuite.scala
Lines 5 to 6 in 53249aa
class ImplementAbstractMembersLspSuite extends BaseCodeActionLspSuite("implementAbstractMembers") { - These test verify the code actions are available for users when we have a certain error (missing implementation error)
- This test runs against only Scala 2.13
- Scala3CodeActionLspSuite
metals/tests/slow/src/test/scala/tests/feature/Scala3CodeActionLspSuite.scala
Lines 332 to 358 in 53249aa
check( "given-object-creation", """|package a | |trait Foo: | def foo(x: Int): Int | def bar(x: String): String | |given <<Foo>> with {} |""".stripMargin, s"""|${ImplementAbstractMembers.title} |""".stripMargin, """|package a | |trait Foo: | def foo(x: Int): Int | def bar(x: String): String | |given Foo with { | | override def foo(x: Int): Int = ??? | | override def bar(x: String): String = ??? | |} |""".stripMargin, ) - This test check the code action is available in Scala3. We test this because if the Scala3 compiler has different error message than Scala2, we might need to change the regex to capture the error message for missing implementation error.
- This test runs against only Scala3.
So, we should migrate most of ConvertToNamedArgumentsLspSuite
into pc suite (that we haven't yet implemented). but it can be done in another PR :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So what is the difference between:
- cross test in pc (presentation compiler) which have
ignoreScala2
tag - slow/Scala3CodeActionLspSuite
I think I still don't get it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Scala3CodeActionLspSuite will run the entire server, while cross tests will only invoke the compiler, which should be much faster.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's probably fine to test if the workflow works for Scala 3, which confirms one new path for testing, while we can test anything specific to Scala 3 compiler in the cross tests.
import tests.codeactions.BaseCodeActionLspSuite | ||
|
||
class Scala3CodeActionLspSuite | ||
extends BaseCodeActionLspSuite("cross-code-actions") { | ||
|
||
override protected val scalaVersion: String = BuildInfo.scala3 | ||
val filterAction: CodeAction => Boolean = { act: CodeAction => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this needed? I see that we anyway ConvertToNamedArguments
action showing up below?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Closes #4059
Add Scala 3 support for #3971