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 <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
This commit is contained in:
Alan Donovan 2024-06-26 17:55:18 -04:00 коммит произвёл Gopher Robot
Родитель 5cc2d0b12c
Коммит c0ae6bbd24
3 изменённых файлов: 17 добавлений и 22 удалений

Просмотреть файл

@ -167,26 +167,21 @@ func findSplitJoinTarget(fset *token.FileSet, file *ast.File, src []byte, start,
for _, node := range path { for _, node := range path {
switch node := node.(type) { switch node := node.(type) {
case *ast.FuncType: case *ast.FuncType:
// target function signature parameters and results. // params or results of func signature
// type someFunc func (a int, b int, c int) (d int, e int) // Note:
params := node.Params // - each ast.Field (e.g. "x, y, z int") is considered a single item.
if isCursorInside(params.Opening, params.Closing) { // - splitting Params and Results lists is not usually good style.
return "parameters", params, params.Opening, params.Closing if p := node.Params; isCursorInside(p.Opening, p.Closing) {
return "parameters", p, p.Opening, p.Closing
} }
if r := node.Results; r != nil && isCursorInside(r.Opening, r.Closing) {
results := node.Results return "results", r, r.Opening, r.Closing
if results != nil && isCursorInside(results.Opening, results.Closing) {
return "results", results, results.Opening, results.Closing
} }
case *ast.CallExpr: case *ast.CallExpr: // f(a, b, c)
// target function calls.
// someFunction(a, b, c)
if isCursorInside(node.Lparen, node.Rparen) { if isCursorInside(node.Lparen, node.Rparen) {
return "parameters", node, node.Lparen, node.Rparen return "arguments", node, node.Lparen, node.Rparen
} }
case *ast.CompositeLit: case *ast.CompositeLit: // T{a, b, c}
// target composite lit instantiation (structs, maps, arrays).
// A{b: 1, c: 2, d: 3}
if isCursorInside(node.Lbrace, node.Rbrace) { if isCursorInside(node.Lbrace, node.Rbrace) {
return "elements", node, node.Lbrace, node.Rbrace return "elements", node, node.Lbrace, node.Rbrace
} }

Просмотреть файл

@ -108,7 +108,7 @@ func a() {
2, 2,
3, 3,
fmt.Sprintf( fmt.Sprintf(
"hello %d" /*@codeaction("hello", "hello", "refactor.rewrite", indent, "Join parameters into one line")*/, "hello %d" /*@codeaction("hello", "hello", "refactor.rewrite", indent, "Join arguments into one line")*/,
4, 4,
)) ))
} }
@ -123,7 +123,7 @@ func a() {
1, 1,
2, 2,
3, 3,
fmt.Sprintf("hello %d" /*@codeaction("hello", "hello", "refactor.rewrite", indent, "Join parameters into one line")*/, 4)) fmt.Sprintf("hello %d" /*@codeaction("hello", "hello", "refactor.rewrite", indent, "Join arguments into one line")*/, 4))
} }
-- structelts/structelts.go -- -- structelts/structelts.go --

Просмотреть файл

@ -103,7 +103,7 @@ package indent
import "fmt" import "fmt"
func a() { func a() {
fmt.Println(1, 2, 3, fmt.Sprintf("hello %d", 4)) //@codeaction("hello", "hello", "refactor.rewrite", indent, "Split parameters into separate lines") fmt.Println(1, 2, 3, fmt.Sprintf("hello %d", 4)) //@codeaction("hello", "hello", "refactor.rewrite", indent, "Split arguments into separate lines")
} }
-- @indent/indent/indent.go -- -- @indent/indent/indent.go --
@ -115,7 +115,7 @@ func a() {
fmt.Println(1, 2, 3, fmt.Sprintf( fmt.Println(1, 2, 3, fmt.Sprintf(
"hello %d", "hello %d",
4, 4,
)) //@codeaction("hello", "hello", "refactor.rewrite", indent, "Split parameters into separate lines") )) //@codeaction("hello", "hello", "refactor.rewrite", indent, "Split arguments into separate lines")
} }
-- indent2/indent2.go -- -- indent2/indent2.go --
@ -125,7 +125,7 @@ import "fmt"
func a() { func a() {
fmt. fmt.
Println(1, 2, 3, fmt.Sprintf("hello %d", 4)) //@codeaction("1", "1", "refactor.rewrite", indent2, "Split parameters into separate lines") Println(1, 2, 3, fmt.Sprintf("hello %d", 4)) //@codeaction("1", "1", "refactor.rewrite", indent2, "Split arguments into separate lines")
} }
-- @indent2/indent2/indent2.go -- -- @indent2/indent2/indent2.go --
@ -140,7 +140,7 @@ func a() {
2, 2,
3, 3,
fmt.Sprintf("hello %d", 4), fmt.Sprintf("hello %d", 4),
) //@codeaction("1", "1", "refactor.rewrite", indent2, "Split parameters into separate lines") ) //@codeaction("1", "1", "refactor.rewrite", indent2, "Split arguments into separate lines")
} }
-- structelts/structelts.go -- -- structelts/structelts.go --