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

Open
seankhliao opened this issue Sep 8, 2021 · 5 comments

Comments

@seankhliao
Copy link
Contributor

@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

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

@ShoshinNikita
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?

@gopherbot
Copy link

@gopherbot gopherbot commented Sep 17, 2021

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

@gopherbot
Copy link

@gopherbot gopherbot commented Oct 5, 2021

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

@gopherbot
Copy link

@gopherbot gopherbot commented Oct 21, 2021

Change https://golang.org/cl/357755 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
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants