Skip to content

Commit 3d51660

Browse files
Copilotjakebailey
andcommitted
WIP: Attempt to fix TestSignatureHelpWithTriggers02 - still failing
The logic now returns the first call found if any call contains the position, falling back to the innermost call. However, TestSignatureHelpWithTriggers02 still fails because the applicable span for bar() with empty arguments doesn't include the position right after inserting '('. The issue appears to be in getApplicableSpanForArguments when argumentList is nil - the span calculation may not correctly include positions inside empty parentheses. Co-authored-by: jakebailey <[email protected]>
1 parent bed1740 commit 3d51660

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

internal/ls/signaturehelp.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,7 @@ func containsPrecedingToken(startingToken *ast.Node, sourceFile *ast.SourceFile,
750750
}
751751

752752
func getContainingArgumentInfo(node *ast.Node, sourceFile *ast.SourceFile, checker *checker.Checker, isManuallyInvoked bool, position int) *argumentListInfo {
753-
var lastArgumentInfo *argumentListInfo
753+
var firstArgumentInfo *argumentListInfo
754754
for n := node; !ast.IsSourceFile(n) && (isManuallyInvoked || !ast.IsBlock(n)); n = n.Parent {
755755
// If the node is not a subspan of its parent, this is a big problem.
756756
// There have been crashes that might be caused by this violation.
@@ -765,22 +765,23 @@ func getContainingArgumentInfo(node *ast.Node, sourceFile *ast.SourceFile, check
765765
return argumentInfo
766766
}
767767

768-
// For regular call expressions, check if the position is actually within the applicable span.
769-
// This ensures that for nested calls, the outer call takes precedence
770-
// when the position is outside the inner call's argument list.
768+
// Remember the first (innermost) argument info we find
769+
if firstArgumentInfo == nil {
770+
firstArgumentInfo = argumentInfo
771+
}
772+
773+
// If any call's span contains the position, return it.
774+
// We walk from inner to outer, so this naturally prefers the innermost call
775+
// when multiple calls contain the position.
771776
if argumentInfo.argumentsSpan.Contains(position) {
772777
return argumentInfo
773778
}
774-
// Remember this argument info in case we don't find an outer call
775-
if lastArgumentInfo == nil {
776-
lastArgumentInfo = argumentInfo
777-
}
778-
// Continue looking for an outer call if position is outside this call's applicable span
779779
}
780780
}
781-
// If we didn't find a call that contains the position, return the last call we found.
782-
// This handles cases where the cursor is at the edge of a call (e.g., right after a parameter).
783-
return lastArgumentInfo
781+
782+
// No call's span contains the position. Return the innermost call as fallback.
783+
// This handles cases like foo(bar(|)) where bar's span might be empty.
784+
return firstArgumentInfo
784785
}
785786

786787
func getImmediatelyContainingArgumentOrContextualParameterInfo(node *ast.Node, position int, sourceFile *ast.SourceFile, checker *checker.Checker) *argumentListInfo {

0 commit comments

Comments
 (0)