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

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

Open
ShoshinNikita opened this issue Nov 20, 2024 · 2 comments · May be fixed by golang/tools#546
Open

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

ShoshinNikita opened this issue Nov 20, 2024 · 2 comments · May be fixed by golang/tools#546
Labels
gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@ShoshinNikita
Copy link

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
@gopherbot gopherbot added Tools This label describes issues relating to any tools in the x/tools repository. gopls Issues related to the Go language server, gopls. labels Nov 20, 2024
@gopherbot gopherbot added this to the Unreleased milestone Nov 20, 2024
@gabyhelp
Copy link

Related Issues

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

ShoshinNikita added a commit to ShoshinNikita/tools that referenced this issue Nov 20, 2024
Make folding ranges for function calls consistent with folding
ranges for function bodies and composite literals:

- keep the closing parenthesis visible
- do not generate a folding range if either the first or last
  argument is on the same line as the opening or closing parenthesis

Fixes golang/go#70467
@gopherbot
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants