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

seankhliao opened this issue Sep 8, 2021 · 5 comments


Copy link

@seankhliao seankhliao commented Sep 8, 2021

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

Copy link

@muirdm 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)).

Copy link

@ShoshinNikita ShoshinNikita commented Sep 14, 2021

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?

Copy link

@gopherbot gopherbot commented Sep 17, 2021

Change mentions this issue: internal/lsp: hardcode some parameter names for literal completions

Copy link

@gopherbot gopherbot commented Oct 5, 2021

Change mentions this issue: internal/lsp: Added parameter names for Context and error literal completion.

Copy link

@gopherbot gopherbot commented Oct 21, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants