diff --git a/gopls/internal/golang/folding_range.go b/gopls/internal/golang/folding_range.go index 85faea5e31a..459e53980ff 100644 --- a/gopls/internal/golang/folding_range.go +++ b/gopls/internal/golang/folding_range.go @@ -89,8 +89,13 @@ func foldingRangeFunc(pgf *parsego.File, n ast.Node, lineFoldingOnly bool) *Fold // Fold from position of ":" to end. start, end = n.Colon+1, n.End() case *ast.CallExpr: - // Fold from position of "(" to position of ")". + // Fold between positions of or lines between "(" and ")". start, end = n.Lparen+1, n.Rparen + if len(n.Args) > 0 { + argsStart := n.Args[0].End() + argsEnd := n.Args[len(n.Args)-1].End() + start, end = validLineFoldingRange(pgf.Tok, n.Lparen, n.Rparen, argsStart, argsEnd, lineFoldingOnly) + } case *ast.FieldList: // Fold between positions of or lines between opening parenthesis/brace and closing parenthesis/brace. var startList, endList token.Pos diff --git a/gopls/internal/test/marker/testdata/foldingrange/a_lineonly.txt b/gopls/internal/test/marker/testdata/foldingrange/a_lineonly.txt index 0c532e760f1..4c3725460a8 100644 --- a/gopls/internal/test/marker/testdata/foldingrange/a_lineonly.txt +++ b/gopls/internal/test/marker/testdata/foldingrange/a_lineonly.txt @@ -15,6 +15,7 @@ package folding //@foldingrange(raw) import ( "fmt" _ "log" + "sort" ) import _ "os" @@ -85,12 +86,46 @@ func bar() string { this string is not indented` } + +func _() { + slice := []int{1, 2, 3} + sort.Slice(slice, func(i, j int) bool { + a, b := slice[i], slice[j] + return a < b + }) + + sort.Slice(slice, func(i, j int) bool { return slice[i] < slice[j] }) + + sort.Slice( + slice, + func(i, j int) bool { + return slice[i] < slice[j] + }, + ) + + fmt.Println( + 1, 2, 3, + 4, + ) + + fmt.Println(1, 2, 3, + 4, 5, 6, + 7, 8, 9, + 10) +} + +func _( + a int, b int, + c int, +) { +} -- @raw -- package folding //@foldingrange(raw) import (<0 kind="imports"> "fmt" - _ "log" + _ "log" + "sort" ) import _ "os" @@ -161,3 +196,36 @@ func bar() string {<2 kind=""> this string is not indented` } + +func _() {<23 kind=""> + slice := []int{1, 2, 3} + sort.Slice(slice, func(i, j int) bool {<24 kind=""> + a, b := slice[i], slice[j] + return a < b + }) + + sort.Slice(slice, func(i, j int) bool { return slice[i] < slice[j] }) + + sort.Slice(<25 kind=""> + slice, + func(i, j int) bool {<26 kind=""> + return slice[i] < slice[j] + }, + ) + + fmt.Println(<27 kind=""> + 1, 2, 3, + 4, + ) + + fmt.Println(1, 2, 3, + 4, 5, 6, + 7, 8, 9, + 10) +} + +func _(<28 kind=""> + a int, b int, + c int, +) { +}