Skip to content

Commit b7a391a

Browse files
committed
simplify existing code
1 parent 4f90466 commit b7a391a

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

compiler/src/dotty/tools/dotc/util/Signatures.scala

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,16 @@ object Signatures {
4242
/**
4343
* Extract (current parameter index, function index, functions) out of a method call.
4444
*
45-
* @param path The path to the function starting with closest one to `span`
45+
* @param enclosingApply Enclosing function application
4646
* @param span The position of the cursor
4747
* @return A triple containing the index of the parameter being edited, the index of the function
4848
* being called, the list of overloads of this function).
4949
*/
50-
def callInfo(path: List[tpd.Tree], span: Span)(using Context): (Int, Int, List[SingleDenotation]) =
51-
path match {
52-
case UnApply(fun, _, patterns) :: _ => callInfo(span, patterns, fun, Signatures.countParams(fun))
53-
case Apply(fun, params) :: _ => callInfo(span, params, fun, Signatures.countParams(fun))
54-
case _ =>
55-
(0, 0, Nil)
56-
}
50+
def callInfo(enclosingApply: Option[tpd.Tree], span: Span)(using Context): (Int, Int, List[SingleDenotation]) =
51+
enclosingApply.map {
52+
case UnApply(fun, _, patterns) => callInfo(span, patterns, fun, Signatures.countParams(fun))
53+
case Apply(fun, params) => callInfo(span, params, fun, Signatures.countParams(fun))
54+
}.getOrElse((0, 0, Nil))
5755

5856
def callInfo(
5957
span: Span,

language-server/src/dotty/tools/languageserver/DottyLanguageServer.scala

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -556,12 +556,13 @@ class DottyLanguageServer extends LanguageServer
556556

557557
val pos = sourcePosition(driver, uri, params.getPosition)
558558
val trees = driver.openedTrees(uri)
559-
val path = Interactive.pathTo(trees, pos).span {
560-
case Apply(fun, _) => fun.span.contains(pos.span)
561-
case UnApply(fun, _, _) => fun.span.contains(pos.span)
562-
case _ => true
559+
val path = Interactive.pathTo(trees, pos).find {
560+
case Apply(fun, _) => !fun.span.contains(pos.span)
561+
case UnApply(fun, _, _) => !fun.span.contains(pos.span)
562+
case _ => false
563563
}
564-
val (paramN, callableN, alternatives) = Signatures.callInfo(path._2, pos.span)
564+
565+
val (paramN, callableN, alternatives) = Signatures.callInfo(path, pos.span)
565566
val signatureInfos = alternatives.flatMap(Signatures.toSignature)
566567

567568
new SignatureHelp(signatureInfos.map(signatureToSignatureInformation).asJava, callableN, paramN)

0 commit comments

Comments
 (0)