Skip to content

Commit c0ae6bb

Browse files
adonovangopherbot
authored andcommitted
gopls/internal/golang: splitlines: s/parameter/arguments/ in CallExpr
(Another terminological nitpick that I missed until reading the docs.) Also, commentary. Change-Id: I8d985234637224be7b921bdaa8113baa9c54be66 Reviewed-on: https://go-review.googlesource.com/c/tools/+/595118 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Robert Findley <[email protected]> Auto-Submit: Alan Donovan <[email protected]>
1 parent 5cc2d0b commit c0ae6bb

File tree

3 files changed

+17
-22
lines changed

3 files changed

+17
-22
lines changed

gopls/internal/golang/lines.go

+11-16
Original file line numberDiff line numberDiff line change
@@ -167,26 +167,21 @@ func findSplitJoinTarget(fset *token.FileSet, file *ast.File, src []byte, start,
167167
for _, node := range path {
168168
switch node := node.(type) {
169169
case *ast.FuncType:
170-
// target function signature parameters and results.
171-
// type someFunc func (a int, b int, c int) (d int, e int)
172-
params := node.Params
173-
if isCursorInside(params.Opening, params.Closing) {
174-
return "parameters", params, params.Opening, params.Closing
170+
// params or results of func signature
171+
// Note:
172+
// - each ast.Field (e.g. "x, y, z int") is considered a single item.
173+
// - splitting Params and Results lists is not usually good style.
174+
if p := node.Params; isCursorInside(p.Opening, p.Closing) {
175+
return "parameters", p, p.Opening, p.Closing
175176
}
176-
177-
results := node.Results
178-
if results != nil && isCursorInside(results.Opening, results.Closing) {
179-
return "results", results, results.Opening, results.Closing
177+
if r := node.Results; r != nil && isCursorInside(r.Opening, r.Closing) {
178+
return "results", r, r.Opening, r.Closing
180179
}
181-
case *ast.CallExpr:
182-
// target function calls.
183-
// someFunction(a, b, c)
180+
case *ast.CallExpr: // f(a, b, c)
184181
if isCursorInside(node.Lparen, node.Rparen) {
185-
return "parameters", node, node.Lparen, node.Rparen
182+
return "arguments", node, node.Lparen, node.Rparen
186183
}
187-
case *ast.CompositeLit:
188-
// target composite lit instantiation (structs, maps, arrays).
189-
// A{b: 1, c: 2, d: 3}
184+
case *ast.CompositeLit: // T{a, b, c}
190185
if isCursorInside(node.Lbrace, node.Rbrace) {
191186
return "elements", node, node.Lbrace, node.Rbrace
192187
}

gopls/internal/test/marker/testdata/codeaction/grouplines.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func a() {
108108
2,
109109
3,
110110
fmt.Sprintf(
111-
"hello %d" /*@codeaction("hello", "hello", "refactor.rewrite", indent, "Join parameters into one line")*/,
111+
"hello %d" /*@codeaction("hello", "hello", "refactor.rewrite", indent, "Join arguments into one line")*/,
112112
4,
113113
))
114114
}
@@ -123,7 +123,7 @@ func a() {
123123
1,
124124
2,
125125
3,
126-
fmt.Sprintf("hello %d" /*@codeaction("hello", "hello", "refactor.rewrite", indent, "Join parameters into one line")*/, 4))
126+
fmt.Sprintf("hello %d" /*@codeaction("hello", "hello", "refactor.rewrite", indent, "Join arguments into one line")*/, 4))
127127
}
128128

129129
-- structelts/structelts.go --

gopls/internal/test/marker/testdata/codeaction/splitlines.txt

+4-4
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ package indent
103103
import "fmt"
104104

105105
func a() {
106-
fmt.Println(1, 2, 3, fmt.Sprintf("hello %d", 4)) //@codeaction("hello", "hello", "refactor.rewrite", indent, "Split parameters into separate lines")
106+
fmt.Println(1, 2, 3, fmt.Sprintf("hello %d", 4)) //@codeaction("hello", "hello", "refactor.rewrite", indent, "Split arguments into separate lines")
107107
}
108108

109109
-- @indent/indent/indent.go --
@@ -115,7 +115,7 @@ func a() {
115115
fmt.Println(1, 2, 3, fmt.Sprintf(
116116
"hello %d",
117117
4,
118-
)) //@codeaction("hello", "hello", "refactor.rewrite", indent, "Split parameters into separate lines")
118+
)) //@codeaction("hello", "hello", "refactor.rewrite", indent, "Split arguments into separate lines")
119119
}
120120

121121
-- indent2/indent2.go --
@@ -125,7 +125,7 @@ import "fmt"
125125

126126
func a() {
127127
fmt.
128-
Println(1, 2, 3, fmt.Sprintf("hello %d", 4)) //@codeaction("1", "1", "refactor.rewrite", indent2, "Split parameters into separate lines")
128+
Println(1, 2, 3, fmt.Sprintf("hello %d", 4)) //@codeaction("1", "1", "refactor.rewrite", indent2, "Split arguments into separate lines")
129129
}
130130

131131
-- @indent2/indent2/indent2.go --
@@ -140,7 +140,7 @@ func a() {
140140
2,
141141
3,
142142
fmt.Sprintf("hello %d", 4),
143-
) //@codeaction("1", "1", "refactor.rewrite", indent2, "Split parameters into separate lines")
143+
) //@codeaction("1", "1", "refactor.rewrite", indent2, "Split arguments into separate lines")
144144
}
145145

146146
-- structelts/structelts.go --

0 commit comments

Comments
 (0)