Skip to content

Commit 1ef3e9f

Browse files
Copilotjakebailey
andcommitted
Refactor: Extract ensureMinimumSpanSize helper function
Extracted the logic for ensuring minimum span size into a helper function to reduce code duplication and improve maintainability. Addressed code review feedback. Co-authored-by: jakebailey <[email protected]>
1 parent 31ce9d1 commit 1ef3e9f

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

internal/ls/signaturehelp.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,23 +1070,29 @@ func getApplicableSpanForArguments(argumentList *ast.NodeList, node *ast.Node, s
10701070
spanStart := node.End()
10711071
spanEnd := scanner.SkipTrivia(sourceFile.Text(), node.End())
10721072
// Ensure the span includes at least the position right after the opening paren
1073-
if spanEnd <= spanStart {
1074-
spanEnd = spanStart + 1
1075-
}
1073+
spanEnd = ensureMinimumSpanSize(spanStart, spanEnd)
10761074
return core.NewTextRange(spanStart, spanEnd)
10771075
}
10781076
applicableSpanStart := argumentList.Pos()
10791077
applicableSpanEnd := scanner.SkipTrivia(sourceFile.Text(), argumentList.End())
10801078

10811079
// If the argument list is empty (Pos == End), extend the span to include at least
10821080
// one position. This handles foo(|) where the cursor is right after the opening paren.
1083-
if applicableSpanEnd <= applicableSpanStart {
1084-
applicableSpanEnd = applicableSpanStart + 1
1085-
}
1081+
applicableSpanEnd = ensureMinimumSpanSize(applicableSpanStart, applicableSpanEnd)
10861082

10871083
return core.NewTextRange(applicableSpanStart, applicableSpanEnd)
10881084
}
10891085

1086+
// ensureMinimumSpanSize ensures that a span includes at least one position.
1087+
// This is necessary for empty argument lists where start == end would create
1088+
// a span that doesn't contain any position.
1089+
func ensureMinimumSpanSize(start, end int) int {
1090+
if end <= start {
1091+
return start + 1
1092+
}
1093+
return end
1094+
}
1095+
10901096
type argumentOrParameterListAndIndex struct {
10911097
list *ast.NodeList
10921098
argumentIndex int

0 commit comments

Comments
 (0)