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: use conventional variable names when filling function signatures #48260

Closed
seankhliao opened this issue Sep 8, 2021 · 6 comments
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. help wanted NeedsFix The path to resolution is known, but the work has not been done. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@seankhliao
Copy link
Member

Given the following example

package main

import "context"

type Foo struct {
	F func(context.Context, error)
}

func main() {
	foo := Foo{
		F: <cursor here>,
	}
	_ = foo
}

gopls will offer to generate the function signature

	foo := Foo{
		F: func(c context.Context, e error) {
                },
	}

It would be nice to have it use the more conventional variable names of ctx and err for the 2 types

@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 Sep 8, 2021
@gopherbot gopherbot added this to the Unreleased milestone Sep 8, 2021
@stamblerre stamblerre modified the milestones: Unreleased, gopls/unplanned Sep 9, 2021
@stamblerre stamblerre added help wanted FeatureRequest NeedsFix The path to resolution is known, but the work has not been done. and removed FeatureRequest labels Sep 9, 2021
@muirdm
Copy link

muirdm commented Sep 13, 2021

Another notable instance of this problem is http.HandleFunc where you get a ResponseWriter named "rw" instead of "w".

A workaround for now is to give the parameters names in the type signature (e.g. F func(ctx context.Context, err error)).

@ShoshinNikita
Copy link

The fix is pretty simple. But I think it would be better to add more common acronyms. I could come up with the following list:

Type Current Common
context.Context c ctx
error e err
sql.Tx, sqlx.Tx and etc. t tx
http.ResponseWriter rw w

Did I forget something?

@gopherbot
Copy link

Change https://golang.org/cl/350750 mentions this issue: internal/lsp: hardcode some parameter names for literal completions

@gopherbot
Copy link

Change https://golang.org/cl/353971 mentions this issue: internal/lsp: Added parameter names for Context and error literal completion.

@gopherbot
Copy link

Change https://golang.org/cl/357755 mentions this issue: internal/lsp: use idiomatic parameter names for ctx, err in literal completions.

@gopherbot
Copy link

Change https://golang.org/cl/381969 mentions this issue: internal/lsp/source/completion: add conventional acronyms for type names

@golang golang locked and limited conversation to collaborators Aug 14, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. help wanted NeedsFix The path to resolution is known, but the work has not been done. 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.

6 participants