Skip to content

Commit fc2e3fa

Browse files
committed
do nothing if we got comments inside
1 parent 8dcb013 commit fc2e3fa

File tree

1 file changed

+9
-16
lines changed

1 file changed

+9
-16
lines changed

gopls/internal/lsp/source/lines.go

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,7 @@ import (
1313
"golang.org/x/tools/gopls/internal/util/safetoken"
1414
)
1515

16-
func CanSplitLines(
17-
file *ast.File,
18-
fset *token.FileSet,
19-
start, end token.Pos,
20-
) (string, bool, error) {
16+
func CanSplitLines(file *ast.File, fset *token.FileSet, start, end token.Pos) (string, bool, error) {
2117
msg, lines, numElts, target := findSplitGroupTarget(file, fset, start, end)
2218
if target == nil {
2319
return "", false, nil
@@ -79,9 +75,12 @@ func groupLines(
7975
return fset, processLines(fset, target, src, file, ", ", "", "", ""), nil
8076
}
8177

82-
func processLines(fset *token.FileSet, target ast.Node, src []byte, file *ast.File, sep,
83-
prefix,
84-
suffix, indent string,
78+
func processLines(
79+
fset *token.FileSet,
80+
target ast.Node,
81+
src []byte,
82+
file *ast.File,
83+
sep, prefix, suffix, indent string,
8584
) *analysis.SuggestedFix {
8685
var replPos, replEnd token.Pos
8786
var lines []string
@@ -131,9 +130,7 @@ func findSplitGroupTarget(
131130
// current cursor is inside the parens/bracket
132131
isInside := opening < start && end < closing
133132

134-
// todo: retain /*-style comments.
135-
// it doesnt have //-style comment in between
136-
// we prefer not to do anything here because it will break the code once it got grouped.
133+
// todo: retain /*-style comments instead of rejecting them.
137134
for _, comment := range file.Comments {
138135
if comment.End() < start {
139136
continue
@@ -143,11 +140,7 @@ func findSplitGroupTarget(
143140
break
144141
}
145142

146-
for _, c := range comment.List {
147-
if strings.HasPrefix(c.Text, "//") {
148-
return false
149-
}
150-
}
143+
return false
151144
}
152145

153146
// and it has more than 1 element

0 commit comments

Comments
 (0)