Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gopls/internal/golang: fix folding range for function calls #546

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion gopls/internal/golang/folding_range.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
70 changes: 69 additions & 1 deletion gopls/internal/test/marker/testdata/foldingrange/a_lineonly.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package folding //@foldingrange(raw)
import (
"fmt"
_ "log"
"sort"
)

import _ "os"
Expand Down Expand Up @@ -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"</0>
_ "log"
"sort"</0>
)

import _ "os"
Expand Down Expand Up @@ -161,3 +196,36 @@ func bar() string {<2 kind="">
this string
is not indented`</2></22>
}

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</24>
})

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]</26>
}</25>,
)

fmt.Println(<27 kind="">
1, 2, 3,
4</27>,
)

fmt.Println(1, 2, 3,
4, 5, 6,
7, 8, 9,
10)</23>
}

func _(<28 kind="">
a int, b int,
c int</28>,
) {
}