Skip to content

Commit

Permalink
gopls/internal/golang: splitlines: s/parameter/arguments/ in CallExpr
Browse files Browse the repository at this point in the history
(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>
  • Loading branch information
adonovan authored and gopherbot committed Jun 27, 2024
1 parent 5cc2d0b commit c0ae6bb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 22 deletions.
27 changes: 11 additions & 16 deletions gopls/internal/golang/lines.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,26 +167,21 @@ func findSplitJoinTarget(fset *token.FileSet, file *ast.File, src []byte, start,
for _, node := range path {
switch node := node.(type) {
case *ast.FuncType:
// target function signature parameters and results.
// type someFunc func (a int, b int, c int) (d int, e int)
params := node.Params
if isCursorInside(params.Opening, params.Closing) {
return "parameters", params, params.Opening, params.Closing
// params or results of func signature
// Note:
// - each ast.Field (e.g. "x, y, z int") is considered a single item.
// - splitting Params and Results lists is not usually good style.
if p := node.Params; isCursorInside(p.Opening, p.Closing) {
return "parameters", p, p.Opening, p.Closing
}

results := node.Results
if results != nil && isCursorInside(results.Opening, results.Closing) {
return "results", results, results.Opening, results.Closing
if r := node.Results; r != nil && isCursorInside(r.Opening, r.Closing) {
return "results", r, r.Opening, r.Closing
}
case *ast.CallExpr:
// target function calls.
// someFunction(a, b, c)
case *ast.CallExpr: // f(a, b, c)
if isCursorInside(node.Lparen, node.Rparen) {
return "parameters", node, node.Lparen, node.Rparen
return "arguments", node, node.Lparen, node.Rparen
}
case *ast.CompositeLit:
// target composite lit instantiation (structs, maps, arrays).
// A{b: 1, c: 2, d: 3}
case *ast.CompositeLit: // T{a, b, c}
if isCursorInside(node.Lbrace, node.Rbrace) {
return "elements", node, node.Lbrace, node.Rbrace
}
Expand Down
4 changes: 2 additions & 2 deletions gopls/internal/test/marker/testdata/codeaction/grouplines.txt
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func a() {
2,
3,
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,
))
}
Expand All @@ -123,7 +123,7 @@ func a() {
1,
2,
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 --
Expand Down
8 changes: 4 additions & 4 deletions gopls/internal/test/marker/testdata/codeaction/splitlines.txt
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ package indent
import "fmt"

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 --
Expand All @@ -115,7 +115,7 @@ func a() {
fmt.Println(1, 2, 3, fmt.Sprintf(
"hello %d",
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 --
Expand All @@ -125,7 +125,7 @@ import "fmt"

func a() {
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 --
Expand All @@ -140,7 +140,7 @@ func a() {
2,
3,
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 --
Expand Down

0 comments on commit c0ae6bb

Please sign in to comment.