From c0ae6bbd24adc34e4b2ba9ecd75922847f718b27 Mon Sep 17 00:00:00 2001 From: Alan Donovan Date: Wed, 26 Jun 2024 17:55:18 -0400 Subject: [PATCH] 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 Reviewed-by: Robert Findley Auto-Submit: Alan Donovan --- gopls/internal/golang/lines.go | 27 ++++++++----------- .../marker/testdata/codeaction/grouplines.txt | 4 +-- .../marker/testdata/codeaction/splitlines.txt | 8 +++--- 3 files changed, 17 insertions(+), 22 deletions(-) diff --git a/gopls/internal/golang/lines.go b/gopls/internal/golang/lines.go index 736feaa12..24239941a 100644 --- a/gopls/internal/golang/lines.go +++ b/gopls/internal/golang/lines.go @@ -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 } diff --git a/gopls/internal/test/marker/testdata/codeaction/grouplines.txt b/gopls/internal/test/marker/testdata/codeaction/grouplines.txt index 8d1134c5d..0d22e6ad4 100644 --- a/gopls/internal/test/marker/testdata/codeaction/grouplines.txt +++ b/gopls/internal/test/marker/testdata/codeaction/grouplines.txt @@ -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, )) } @@ -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 -- diff --git a/gopls/internal/test/marker/testdata/codeaction/splitlines.txt b/gopls/internal/test/marker/testdata/codeaction/splitlines.txt index 4620e0bb1..76b8fb93c 100644 --- a/gopls/internal/test/marker/testdata/codeaction/splitlines.txt +++ b/gopls/internal/test/marker/testdata/codeaction/splitlines.txt @@ -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 -- @@ -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 -- @@ -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 -- @@ -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 --