golang / vscode-go

Go extension for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=golang.Go
Other
3.8k stars 730 forks source link

gopls settings :"go.languageServerExperimentalFeatures" not recognized by vscode setting.json and set documentLink to false not work #3125

Closed DanchuoZhong closed 5 months ago

DanchuoZhong commented 6 months ago

What version of Go, VS Code & VS Code Go extension are you using?

Version Information
go :go version go1.21.5 windows/amd64 gopls: golang.org/x/tools/gopls@v0.14.2 h1:sIw6vjZiuQ9S7s0auUUkHlWgsCkKZFWDHmrge8LYsnc= vscode: 1.85.1 x64 go extension version:v0.40.1 - 21 Dec, 2023 * Run Ctrl+Shift+P (Cmd+Shift+P on Mac OS) > `Go: Locate Configured Go Tools` command. go env Workspace Folder (gopl.io@v0.0.0-20211004154805-1ae3ec64947b): d:\GoPath\pkg\mod\gopl.io@v0.0.0-20211004154805-1ae3ec64947b set GO111MODULE=auto set GOARCH=amd64 set GOBIN= set GOCACHE=C:\Users\zhong\AppData\Local\go-build set GOENV=C:\Users\zhong\AppData\Roaming\go\env set GOEXE=.exe set GOEXPERIMENT= set GOFLAGS= set GOHOSTARCH=amd64 set GOHOSTOS=windows set GOINSECURE= set GOMODCACHE=D:\GoPath\pkg\mod set GONOPROXY= set GONOSUMDB= set GOOS=windows set GOPATH=D:\GoPath set GOPRIVATE= set GOPROXY=https://goproxy.cn,direct set GOROOT=D:\Go set GOSUMDB=sum.golang.org set GOTMPDIR= set GOTOOLCHAIN=auto set GOTOOLDIR=D:\Go\pkg\tool\windows_amd64 set GOVCS= set GOVERSION=go1.21.5 set GCCGO=gccgo set GOAMD64=v1 set AR=ar set CC=gcc set CXX=g++ set CGO_ENABLED=0 set GOMOD=d:\GoPath\pkg\mod\gopl.io@v0.0.0-20211004154805-1ae3ec64947b\go.mod set GOWORK=d:\GoPath\pkg\mod\gopl.io@v0.0.0-20211004154805-1ae3ec64947b\go.work set CGO_CFLAGS=-O2 -g set CGO_CPPFLAGS= set CGO_CXXFLAGS=-O2 -g set CGO_FFLAGS=-O2 -g set CGO_LDFLAGS=-O2 -g set PKG_CONFIG=pkg-config set GOGCCFLAGS=-m64 -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=C:\Users\zhong\AppData\Local\Temp\go-build2064279383=/tmp/go-build -gno-record-gcc-switches

Share the Go related settings you have added/edited

setting.json: "go.languageServerExperimentalFeatures": { "format": true, "autoComplete": true }

Describe the bug

vscode hint for go.languageServerExperimentalFeatures : Unknown Configuration Setting image

Steps to reproduce the behavior:

  1. Go to setting.json and set a key "go.languageServerExperimentalFeatures ", will show the hint for unknown configuration

Problems

I have read the follow issues about how to disable the following link in gopls, to stop Ctrl+link on the imports will auto direct to browsers and open document, which is really annoying : https://github.com/microsoft/vscode-go/issues/2550 https://github.com/microsoft/vscode-go/issues/2614

And the documents talk about 'go.languageServerExperimentalFeatures' https://go.googlesource.com/vscode-go/+/refs/heads/dev.go2go/docs/settings.md#go.languageServerExperimentalFeatures https://go.googlesource.com/vscode-go/+/refs/heads/dev.go2go/docs/gopls.md

However,it seems like it not work for my vscode in 2024. I'm wondering

  1. if this setting is not longer support now
  2. is there any alternative choice to stop this behavior ,like this issue used to said :https://github.com/golang/go/issues/39065
hyangah commented 6 months ago

The documentation link in hover feature graduated from experiment a while ago.

Please try gopls's setting "linksInHover". https://github.com/golang/vscode-go/wiki/settings#uidocumentationlinksinhover

"gopls": {
  "ui.documentation.linksInHover": false
}

"go.languageServerExperimentalFeatures" were removed in 2023 June as well.

The dev.go2go branch in the linked source is an abandoned branch.

DanchuoZhong commented 6 months ago

The documentation link in hover feature graduated from experiment a while ago.

Please try gopls's setting "linksInHover". https://github.com/golang/vscode-go/wiki/settings#uidocumentationlinksinhover

"gopls": {
  "ui.documentation.linksInHover": false
}

"go.languageServerExperimentalFeatures" were removed in 2023 June as well.

The dev.go2go branch in the linked source is an abandoned branch.

Thanks for your reply @hyangah , I try ui.documentation.linksInHover in my setting.json but seems like it not works for me.

The Ctrl+Link will still lead to browsers and open the document , but my expecting behavior is to goto the source code.When I hover on the import statement .

image

hyangah commented 6 months ago

That is from document link providers. I am afraid currently there is no way to control it. The closest that can help you jump to the source of "fmt" package in the screenshot is to use "Go to definition" right now.

@findleyr I think the followings are bugs:

1) I thought "gopls": { "ui.documentation.linkTarget": "" } would disble it, but it just ends up producing a wrong link.

2) I thought "gopls": { "ui.navigation.importShortcut": "Definition" } would make the import statement linked to the definition, but it just makes the "Follow link" disappear and doesn't provide the shortcut to the definition.

hyangah commented 6 months ago

@DanchuoZhong I think the following setting will be what go.languageServerExperimentalFeatures's documentLink did before.

"gopls": {
   "ui.navigation.importShortcut": "Definition"
}

With the setting the gopls will stop generating the link to the pkgsite, and the "Follow link" will disappear from the tooltip. However, VS Code also triggers "Go to definition" when you cmd+click over the import statement, and gopls will provide the definition location and VS Code will open the location in the editor. One issue is a package can consist of more than one files in Go, and then Gopls returns all the files as the definition location. In such cases, VS Code opens a peek window with the list of all the returned locations, instead of opening one of the files.

Please give it a try and provide a feedback. Thanks.

DanchuoZhong commented 5 months ago

@DanchuoZhong I think the following setting will be what go.languageServerExperimentalFeatures's documentLink did before.

"gopls": {
   "ui.navigation.importShortcut": "Definition"
}

With the setting the gopls will stop generating the link to the pkgsite, and the "Follow link" will disappear from the tooltip. However, VS Code also triggers "Go to definition" when you cmd+click over the import statement, and gopls will provide the definition location and VS Code will open the location in the editor. One issue is a package can consist of more than one files in Go, and then Gopls returns all the files as the definition location. In such cases, VS Code opens a peek window with the list of all the returned locations, instead of opening one of the files.

Please give it a try and provide a feedback. Thanks.

This is exactly what I want .Sorry for my late reply and thanks for your kindly help . Wish you all good .