MCPcopy Create free account
hub / github.com/Effect-TS/tsgo / parseRefactorComment

Function parseRefactorComment

internal/effecttest/refactor_runner.go:64–110  ·  view source on GitHub ↗

parseRefactorComment scans the test file content for a first-line "// refactor: L:C-L:C,L:C-L:C,..." comment (1-based lines and columns). Multiple ranges are separated by commas. A single "L:C" denotes a point selection (zero-width range where start == end). The comment is NOT stripped from the sour

(content string)

Source from the content-addressed store, hash-verified

62// selection (zero-width range where start == end). The comment is NOT stripped
63// from the source content.
64func parseRefactorComment(content string) refactorCommentResult {
65 lines := strings.SplitN(content, "\n", 2)
66 firstLine := strings.TrimSpace(lines[0])
67
68 if !refactorCommentPrefix.MatchString(firstLine) {
69 return refactorCommentResult{found: false}
70 }
71
72 // Strip the "// refactor:" prefix to get the ranges portion
73 payload := refactorCommentPrefix.ReplaceAllString(firstLine, "")
74
75 // Split on "," to get individual range/point tokens
76 parts := strings.Split(payload, ",")
77 var ranges []lsproto.Range
78 for _, part := range parts {
79 part = strings.TrimSpace(part)
80 if part == "" {
81 continue
82 }
83 if m := rangeRegex.FindStringSubmatch(part); m != nil {
84 startLine, _ := strconv.Atoi(m[1])
85 startCol, _ := strconv.Atoi(m[2])
86 endLine, _ := strconv.Atoi(m[3])
87 endCol, _ := strconv.Atoi(m[4])
88
89 ranges = append(ranges, lsproto.Range{
90 Start: lsproto.Position{Line: uint32(startLine - 1), Character: uint32(startCol - 1)},
91 End: lsproto.Position{Line: uint32(endLine - 1), Character: uint32(endCol - 1)},
92 })
93 } else if m := pointRegex.FindStringSubmatch(part); m != nil {
94 line, _ := strconv.Atoi(m[1])
95 col, _ := strconv.Atoi(m[2])
96
97 pos := lsproto.Position{Line: uint32(line - 1), Character: uint32(col - 1)}
98 ranges = append(ranges, lsproto.Range{
99 Start: pos,
100 End: pos,
101 })
102 }
103 }
104
105 if len(ranges) == 0 {
106 return refactorCommentResult{found: false}
107 }
108
109 return refactorCommentResult{found: true, ranges: ranges}
110}
111
112// RunEffectRefactorTest executes a single Effect refactor baseline test case.
113// It creates a fourslash test instance, collects refactor inventory and application

Callers 1

RunEffectRefactorTestFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected