gopls idea: show documentation for function literal whose type is documented

182 views
Skip to first unread message

Qingwei Li

unread,
Nov 4, 2025, 8:06:54 AM (7 days ago) Nov 4
to golang-nuts
Hello. I'm here to propose an idea for gopls. The idea is that when we hover over `func` token of a function literal whose type is documented, the documentation of the type can be shown.

The motivating example is as follows:

filepath.WalkDir(dir, func(path string, d os.DirEntry, err error) error {
    ...
}

When I am coding filepath.WalkDir, whose signature is `func filepath.WalkDir(root string, fn fs.WalkDirFunc) error`, I don't know what's the meaning of the third parameter `err` of `fs.WalkDirFunc`. I have to go to the browser to see documentation or ask LLM.

If we can decide the type of function literal is `fs.WalkDirFunc` and if `fs.WalkDirFunc` is documented, can we show documentation when hovering over `func` token? This is a similar behavior like hovering over function name of a call statement I think.


Jason E. Aten

unread,
Nov 4, 2025, 11:29:15 PM (7 days ago) Nov 4
to golang-nuts
Hi Qingwei Li,

The gopls server can already answer such queries. However it is up to your editor 
(the client of the language server) to make the query in the first place. 

the role of the client and the role of the server.

You probably need to add a new gopls query to your editor, or 
ask its authors for such a feature if it is not open source.

Kind regards,
Jason


~/go/pkg/mod/github.com/glycerine/parall...@v0.3.1 $ gopls definition walk.go:154:31

~/go/pkg/mod/github.com/glycerine/parall...@v0.3.1/walk.go:37:6-14: defined here as type WalkFunc func(path string, info os.FileInfo, hasSubDir bool, err error) error

WalkFunc is the type of the function called for each file or directory
visited by Walk. The path argument contains the argument to Walk as a
prefix; that is, if Walk is called with "dir", which is a directory
containing the file "a", the walk function will be called with argument
"dir/a". The info argument is the os.FileInfo for the named path.

If there was a problem walking to the file or directory named by path, the
incoming error will describe the problem and the function can decide how
to handle that error (and Walk will not descend into that directory). If
an error is returned, processing stops. The sole exception is that if path
is a directory and the function returns the special value SkipDir, the
contents of the directory are skipped and processing continues as usual on
the next file.
$

Qingwei Li

unread,
Nov 5, 2025, 4:29:11 AM (6 days ago) Nov 5
to golang-nuts
Thanks for your detailed explanation. I'm using vscode-go. So the better title of the conversation would be "vscode-go idea: ...". Sorry for wrong reference to gopls.

Besides, it seems that I can't modify the title of the conversation.

Jason E. Aten

unread,
Nov 5, 2025, 11:18:19 AM (6 days ago) Nov 5
to golang-nuts
Hi Qingwei Li,

You need to talk to the Microsoft
Visual Studio Code folks. Nobody minds helping
beginners to understand such easy to make mistakes, 
but it seems a tragedy not to get you to the right place,
or to leave you with the impression that continuing
this thread will produce any progress towards your goal.

In short, this is forum of Go Users, not Visual Studio Code 
developers. If you actually want a better VSCode 
experience you need to post an issue to 
or even better, implement the feature and
submit a pull request. VSCode is open source and
under an MIT license. You'll want to review 
if you wish to get your feature upstreamed.

Kind regards,
Jason

robert engels

unread,
Nov 5, 2025, 11:23:41 AM (6 days ago) Nov 5
to Jason E. Aten, golang-nuts
That isn’t true. The Go extension for VSCode is developed by the Go Team at Google.

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/golang-nuts/cd49a189-cc62-42a3-8f10-37562b312738n%40googlegroups.com.

Jason E. Aten

unread,
Nov 5, 2025, 11:28:53 AM (6 days ago) Nov 5
to golang-nuts
Oh. Interesting. Thanks for correcting me.

Qingwei Li, this may be the appropriate place:
On Wednesday, November 5, 2025 at 4:23:41 PM UTC robert engels wrote:
That isn’t true. The Go extension for VSCode is developed by the Go Team at Google.

Qingwei Li

unread,
Nov 6, 2025, 9:53:23 AM (5 days ago) Nov 6
to golang-nuts
Thanks. I created an issue last day in vscode-go and the issue is moved to golang/go now.  x/tools/gopls: Hover: for func literal implicitly converted to named func type, show doc for that type · Issue #76191 · golang/go

It's a gopls issue. I also tried command `gopls definition ...` in the location of `func` token and nothing was returned.

Reply all
Reply to author
Forward
0 new messages