diff --git a/mtags/src/main/scala-2/scala/meta/internal/pc/InferredTypeProvider.scala b/mtags/src/main/scala-2/scala/meta/internal/pc/InferredTypeProvider.scala index ecbd687fcfb..15a94337fc0 100644 --- a/mtags/src/main/scala-2/scala/meta/internal/pc/InferredTypeProvider.scala +++ b/mtags/src/main/scala-2/scala/meta/internal/pc/InferredTypeProvider.scala @@ -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)) @@ -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 diff --git a/mtags/src/main/scala-2/scala/meta/internal/pc/SignatureHelpProvider.scala b/mtags/src/main/scala-2/scala/meta/internal/pc/SignatureHelpProvider.scala index 8f2df9c7667..a63dc555de2 100644 --- a/mtags/src/main/scala-2/scala/meta/internal/pc/SignatureHelpProvider.scala +++ b/mtags/src/main/scala-2/scala/meta/internal/pc/SignatureHelpProvider.scala @@ -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 = { @@ -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(