-
Notifications
You must be signed in to change notification settings - Fork 337
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
bugfix: Named args completions with default values #5657
Conversation
9783cde
to
7760bd6
Compare
@@ -237,15 +237,22 @@ object NamedArgCompletions: | |||
.getOrElse(baseArgs) | |||
.filterNot(isUselessLiteral) | |||
|
|||
def isDefaultParam(t: Tree): Boolean = t match |
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.
Could be wrong, but looking at the implementation maybe this could be marked as a @tailrec
function? 🙂
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.
You're right, thanks!
) | ||
|
||
check( | ||
"default-args5", |
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.
Before 3.3.1
, the path in this case looks way different -
After 3.3.1
:
Ident(name = CURSOR),
Apply(
fun = Apply(fun = Ident(name = deployment), args = List(Literal(const = ( = "str")))),
args = List(Ident(name = CURSOR))
),
ValDef(
name = abc,
tpt = TypeTree[dotty.tools.dotc.core.Types$UnspecifiedErrorType$@2de07d9c],
preRhs = Apply(
fun = Apply(fun = Ident(name = deployment), args = List(Literal(const = ( = "str")))),
args = List(Ident(name = CURSOR))
)
)
Before:
Ident(name = CURSOR),
ValDef(
name = DerivedName(underlying = opt, info = NumberedInfo(num = 1)),
tpt = TypeTree[dotty.tools.dotc.core.Types$PreviousErrorType@44aa396b],
preRhs = Ident(name = CURSOR)
),
Block(
stats = List(
ValDef(
name = DerivedName(underlying = opt, info = NumberedInfo(num = 1)),
tpt = TypeTree[dotty.tools.dotc.core.Types$PreviousErrorType@44aa396b],
preRhs = Ident(name = CURSOR)
)
),
expr = Block(
stats = List(
DefDef(
name = $anonfun,
paramss = List(
List(
ValDef(
name = fst,
tpt = TypeTree[TypeRef(TermRef(ThisType(TypeRef(NoPrefix,module class scala)),object Predef),type String)],
preRhs = Thicket(trees = List())
),
ValDef(
name = snd,
tpt = TypeTree[TypeRef(TermRef(ThisType(TypeRef(NoPrefix,module class <root>)),object scala),class Int)],
preRhs = Thicket(trees = List())
)
)
),
tpt = TypeTree[AppliedType(TypeRef(TermRef(ThisType(TypeRef(NoPrefix,module class <root>)),object scala),class Option),List(TypeRef(TermRef(ThisType(TypeRef(NoPrefix,module class <root>)),object scala),class Int)))],
preRhs = Apply(
fun = Apply(
fun = Apply(fun = Ident(name = deployment), args = List(Literal(const = ( = "str")))),
args = List(Ident(name = DerivedName(underlying = opt, info = NumberedInfo(num = 1))))
),
args = List(Ident(name = fst), Ident(name = snd))
)
)
),
expr = Closure(env = List(), meth = Ident(name = $anonfun), tpt = Thicket(trees = List()))
)
)
I will investigate further what can be done for older version
7760bd6
to
c7ad8f2
Compare
@@ -19,7 +19,12 @@ trait ArgCompletions { this: MetalsGlobal => | |||
val editRange: l.Range = | |||
pos.withStart(ident.pos.start).withEnd(pos.start).toLsp | |||
val funPos = apply.fun.pos | |||
val method: Tree = typedTreeAt(funPos) | |||
val method: Tree = typedTreeAt(funPos) match { | |||
case Apply(Block(defParams, app: 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.
Nit: from my perspective a small comment explaining this case would be really welcome (like the very nice remarks in the isDefaultArg
function). 🙂
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, could you also take a look if the signature help in those cases work correctly?
I've fixed it for Scala 2, for Scala 3 it worked fine. |
Ok, let's rebase then. I broke the CI before 😓 |
8803f49
to
2239151
Compare
@@ -925,4 +925,144 @@ class SignatureHelpSuite extends BaseSignatureHelpSuite { | |||
|""".stripMargin, | |||
) | |||
|
|||
// NOTE: | |||
// Unignore after merging https://github.com/lampepfl/dotty/pull/18594 |
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.
This has been already merged a while ago, so maybe the test could be enabled now. 🙂
2239151
to
6d17650
Compare
No description provided.