Skip to content
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

fix: scala 2 additional checks #7039

Merged
merged 2 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ final class InferredTypeProvider(
* turns into
* `val a: Int = 1` or `var b: Int = 2`
*/
case vl @ ValDef(_, name, tpt, rhs) if !vl.symbol.isParameter =>
case vl @ ValDef(_, name, tpt, rhs)
if !vl.symbol.isParameter && tpt.pos.isDefined =>
val nameEnd = findNameEnd(tpt.pos.start, name)
val nameEndPos = tpt.pos.withEnd(nameEnd).withStart(nameEnd).toLsp
adjustOpt.foreach(adjust => nameEndPos.setEnd(adjust.adjustedEndPos))
Expand All @@ -124,7 +125,8 @@ final class InferredTypeProvider(
* turns into
* `.map((a: Int) => a + a)`
*/
case vl @ ValDef(_, name, tpt, _) if vl.symbol.isParameter =>
case vl @ ValDef(_, name, tpt, _)
if vl.symbol.isParameter && tpt.pos.isDefined =>
val nameEnd = findNameEnd(vl.pos.start, name)
val namePos = tpt.pos.withEnd(nameEnd).withStart(nameEnd).toLsp

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,23 @@ class SignatureHelpProvider(val compiler: MetalsGlobal) {
cursor = cursor(params.offset(), params.text())
)
val pos = unit.position(params.offset())
typedTreeAt(pos)
val enclosingApply = new EnclosingApply(pos).find(unit.body)
val typedEnclosing = typedTreeAt(enclosingApply.pos)
new MethodCallTraverser(unit, pos)
.fromTree(typedEnclosing)
.map(toSignatureHelp)
.getOrElse(new SignatureHelp())
(for {
_ <- safeTypedTreeAt(pos)
enclosingApply = new EnclosingApply(pos).find(unit.body)
typedEnclosing <- safeTypedTreeAt(enclosingApply.pos)
encolsingCall <- new MethodCallTraverser(unit, pos).fromTree(
typedEnclosing
)
} yield toSignatureHelp(encolsingCall)) getOrElse new SignatureHelp()
}

private def safeTypedTreeAt(pos: Position): Option[Tree] =
try {
Some(typedTreeAt(pos))
} catch {
case _: NullPointerException => None
}

class EnclosingApply(pos: Position) extends Traverser {
var last: Tree = EmptyTree
def find(tree: Tree): Tree = {
Expand Down Expand Up @@ -478,18 +486,21 @@ class SignatureHelpProvider(val compiler: MetalsGlobal) {
if (activeSignature == null) {
activeSignature = 0
}
val mainSignature = infos(activeSignature)
val deduplicated = infos
.filter { sig =>
sig != mainSignature && sig.getLabel() != mainSignature.getLabel()
}
.distinctBy(_.getLabel())
if (infos.isEmpty) new SignatureHelp()
else {
val mainSignature = infos(activeSignature)
val deduplicated = infos
.filter { sig =>
sig != mainSignature && sig.getLabel() != mainSignature.getLabel()
}
.distinctBy(_.getLabel())

new SignatureHelp(
(mainSignature :: deduplicated).asJava,
0,
activeParameter
)
new SignatureHelp(
(mainSignature :: deduplicated).asJava,
0,
activeParameter
)
}
}

def mparamss(
Expand Down
Loading