Skip to content

Commit

Permalink
catch NullPointerException in typedTreeAt in signature help
Browse files Browse the repository at this point in the history
  • Loading branch information
kasiaMarek committed Dec 18, 2024
1 parent 22f0c44 commit 61144f7
Showing 1 changed file with 15 additions and 7 deletions.
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

0 comments on commit 61144f7

Please sign in to comment.