golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
124.21k stars 17.7k forks source link

x/tools/gopls: fix folding range for function calls #70467

Open ShoshinNikita opened 1 day ago

ShoshinNikita commented 1 day ago

gopls version: gopls@e751756 (master branch)

Fold calls to sort.Slice and fmt.Println in VSCode (or, likely, any other editor with LineFoldingOnly set to true):

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

    fmt.Println(
        1, 2, 3,
        4,
    )
}

Not only the arguments but also the closing parentheses are being folded. There are several issues with this behavior:

  1. Lack of the closing parenthesis makes code editing more difficult. For example, users have to unfold fmt.Println to add more code. This behavior is particularly frustrating when working with calls like t.Run.
  2. It is inconsistent with the folding of function bodies and composite literals - } is always visible.
Current behavior Expected behavior
1 2
gabyhelp commented 1 day ago

Related Issues

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

gopherbot commented 1 day ago

Change https://go.dev/cl/630056 mentions this issue: gopls/internal/golang: fix folding range for function calls