Skip to content

Commit fac1f55

Browse files
Copilotjakebailey
andcommitted
Fix applicable span for empty argument lists
When an argument list is empty (e.g., foo(|)), the span was [pos,pos) which doesn't include any position. Extended the span by 1 to include at least the position right after the opening paren. This fixes TestSignatureHelpWithTriggers02 which expects bar's signature at foo(bar(|)) after inserting '('. All signature help tests now pass. Co-authored-by: jakebailey <[email protected]>
1 parent 3d51660 commit fac1f55

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

internal/ls/signaturehelp.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1066,10 +1066,24 @@ func getApplicableSpanForArguments(argumentList *ast.NodeList, node *ast.Node, s
10661066
// If the user has just opened a list, and there are no arguments.
10671067
// For example, foo( )
10681068
// | |
1069-
return core.NewTextRange(node.End(), scanner.SkipTrivia(sourceFile.Text(), node.End()))
1069+
// The span should include positions inside the parentheses.
1070+
spanStart := node.End()
1071+
spanEnd := scanner.SkipTrivia(sourceFile.Text(), node.End())
1072+
// Ensure the span includes at least the position right after the opening paren
1073+
if spanEnd <= spanStart {
1074+
spanEnd = spanStart + 1
1075+
}
1076+
return core.NewTextRange(spanStart, spanEnd)
10701077
}
10711078
applicableSpanStart := argumentList.Pos()
10721079
applicableSpanEnd := scanner.SkipTrivia(sourceFile.Text(), argumentList.End())
1080+
1081+
// If the argument list is empty (Pos == End), extend the span to include at least
1082+
// one position. This handles foo(|) where the cursor is right after the opening paren.
1083+
if applicableSpanEnd <= applicableSpanStart {
1084+
applicableSpanEnd = applicableSpanStart + 1
1085+
}
1086+
10731087
return core.NewTextRange(applicableSpanStart, applicableSpanEnd)
10741088
}
10751089

0 commit comments

Comments
 (0)