Skip to content

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

Closed
@ShoshinNikita

Description

@ShoshinNikita

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    ToolsThis label describes issues relating to any tools in the x/tools repository.goplsIssues related to the Go language server, gopls.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions