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: identifies arbitrary dotted text in strings as links #70033

Open
marc-ostrow opened this issue Oct 2, 2024 · 2 comments
Open
Labels
gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository. upstream-tools
Milestone

Comments

@marc-ostrow
Copy link

marc-ostrow commented Oct 2, 2024

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

Version Information
  • Run go version to get version of Go from the VS Code integrated terminal.
% go version
go version go1.23.1 darwin/amd64
  • Run gopls -v version to get version of Gopls from the VS Code integrated terminal.
% $(go env GOPATH)/bin/gopls -v version
Build info
----------
golang.org/x/tools/gopls v0.16.2
    golang.org/x/tools/gopls@v0.16.2 h1:K1z03MlikHfaMTtG01cUeL5FAOTJnITuNe0TWOcg8tM=
    github.com/BurntSushi/toml@v1.2.1 h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak=
    github.com/google/go-cmp@v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
    golang.org/x/exp/typeparams@v0.0.0-20221212164502-fae10dda9338 h1:2O2DON6y3XMJiQRAS1UWU+54aec2uopH3x7MAiqGW6Y=
    golang.org/x/mod@v0.20.0 h1:utOm6MM3R3dnawAiJgn0y+xvuYRsm1RKM/4giyfDgV0=
    golang.org/x/sync@v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
    golang.org/x/telemetry@v0.0.0-20240829154258-f29ab539cc98 h1:Wm3cG5X6sZ0RSVRc/H1/sciC4AT6HAKgLCSH2lbpR/c=
    golang.org/x/text@v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
    golang.org/x/tools@v0.22.1-0.20240829175637-39126e24d653 h1:6bJEg2w2kUHWlfdJaESYsmNfI1LKAZQi6zCa7LUn7eI=
    golang.org/x/vuln@v1.0.4 h1:SP0mPeg2PmGCu03V+61EcQiOjmpri2XijexKdzv8Z1I=
    honnef.co/go/tools@v0.4.7 h1:9MDAWxMoSnB6QoSqiVr7P5mtkT9pOc1kSxchzPCnqJs=
    mvdan.cc/gofumpt@v0.6.0 h1:G3QvahNDmpD+Aek/bNOLrFR2XC6ZAdo62dZu65gmwGo=
    mvdan.cc/xurls/v2@v2.5.0 h1:lyBNOm8Wo71UknhUs4QTFUNNMyxy2JEIaKKo0RWOh+8=
go: go1.23.1
  • Run code -v or code-insiders -v to get version of VS Code or VS Code Insiders.
 % code -v
[1002/194224.823600:ERROR:codesign_util.cc(109)] SecCodeCheckValidity: Error Domain=NSOSStatusErrorDomain Code=-67062 "(null)" (-67062)
1.93.1
38c31bc77e0dd6ae88a4e9cc93428cc27a56ba40
x64
  • Check your installed extensions to get the version of the VS Code Go extension

v0.42.1

  • Run Ctrl+Shift+P (Cmd+Shift+P on Mac OS) > Go: Locate Configured Go Tools command.
# Tools Configuration


## Environment

GOBIN: undefined
toolsGopath: 
gopath: /Users/marc/.asdf/installs/golang/1.23.1/packages
GOROOT: /Users/marc/.asdf/installs/golang/1.23.1/go
PATH: /usr/local/anaconda3/condabin:/Users/marc/.asdf/shims:/usr/local/opt/asdf/libexec/bin:/Users/marc/.cargo/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/opt/X11/bin:/Library/Apple/usr/bin:/usr/local/MacGPG2/bin:/Library/TeX/texbin:/Applications/Wireshark.app/Contents/MacOS:/Applications/iTerm.app/Contents/Resources/utilities

## Tools

	go:	/Users/marc/.asdf/shims/go: go version go1.23.1 darwin/amd64

	gopls:	/Users/marc/.asdf/installs/golang/1.23.1/packages/bin/gopls	(version: v0.16.2 built with go: go1.23.1)
	gotests:	/Users/marc/.asdf/installs/golang/1.23.1/packages/bin/gotests	(version: v1.6.0 built with go: go1.23.1)
	gomodifytags:	/Users/marc/.asdf/installs/golang/1.23.1/packages/bin/gomodifytags	(version: v1.17.0 built with go: go1.23.1)
	impl:	/Users/marc/.asdf/installs/golang/1.23.1/packages/bin/impl	(version: v1.4.0 built with go: go1.23.1)
	goplay:	/Users/marc/.asdf/installs/golang/1.23.1/packages/bin/goplay	(version: v1.0.0 built with go: go1.23.1)
	dlv:	/Users/marc/.asdf/installs/golang/1.23.1/packages/bin/dlv	(version: v1.23.1 built with go: go1.23.1)
	staticcheck:	/Users/marc/.asdf/installs/golang/1.23.1/packages/bin/staticcheck	(version: v0.5.1 built with go: go1.23.1)

## Go env

Workspace Folder (bugreport): /Users/marc/Projects/go/bugreport

	GO111MODULE=''
	GOARCH='amd64'
	GOBIN=''
	GOCACHE='/Users/marc/Library/Caches/go-build'
	GOENV='/Users/marc/Library/Application Support/go/env'
	GOEXE=''
	GOEXPERIMENT=''
	GOFLAGS=''
	GOHOSTARCH='amd64'
	GOHOSTOS='darwin'
	GOINSECURE=''
	GOMODCACHE='/Users/marc/.asdf/installs/golang/1.23.1/packages/pkg/mod'
	GONOPROXY='gitlab.com/nielsen-media/*'
	GONOSUMDB='gitlab.com/nielsen-media/*'
	GOOS='darwin'
	GOPATH='/Users/marc/.asdf/installs/golang/1.23.1/packages'
	GOPRIVATE='gitlab.com/nielsen-media/*'
	GOPROXY='https://proxy.golang.org,direct'
	GOROOT='/Users/marc/.asdf/installs/golang/1.23.1/go'
	GOSUMDB='sum.golang.org'
	GOTMPDIR=''
	GOTOOLCHAIN='auto'
	GOTOOLDIR='/Users/marc/.asdf/installs/golang/1.23.1/go/pkg/tool/darwin_amd64'
	GOVCS=''
	GOVERSION='go1.23.1'
	GODEBUG=''
	GOTELEMETRY='local'
	GOTELEMETRYDIR='/Users/marc/Library/Application Support/go/telemetry'
	GCCGO='gccgo'
	GOAMD64='v1'
	AR='ar'
	CC='clang'
	CXX='clang++'
	CGO_ENABLED='1'
	GOMOD='/Users/marc/Projects/go/bugreport/go.mod'
	GOWORK=''
	CGO_CFLAGS='-O2 -g'
	CGO_CPPFLAGS=''
	CGO_CXXFLAGS='-O2 -g'
	CGO_FFLAGS='-O2 -g'
	CGO_LDFLAGS='-O2 -g'
	PKG_CONFIG='pkg-config'
	GOGCCFLAGS='-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/0d/8r9jqxd54rx2l7n0vqv2f0qm0000gn/T/go-build2339330694=/tmp/go-build -gno-record-gcc-switches -fno-common'

Share the Go related settings you have added/edited

Run Preferences: Open Settings (JSON) command to open your settings.json file.
Share all the settings with the go. or ["go"] or gopls prefixes.

{
    "go.coverOnSingleTest": true,
    "go.coverOnSingleTestFile": true,
    "go.enableCodeLens": {},
    "go.formatTool": "goimports",
    "go.testFlags": [
        "-count=1",
        "-v",
        "-args",
        "-test.v"
    ],
    "go.testTimeout": "0",
    "go.toolsManagement.autoUpdate": false,
    "gopls": {
        "ui.semanticTokens": true,
    },
}

Describe the bug

A clear and concise description of what the bug.

Arbitrary dotted text in strings is being identified as links and is underlined when "editor.links" is enabled (set to true). When this extension, golang.go, is enabled, this happens. When this extension is disabled, it does not.

A clear and concise description of what you expected to happen.

I'd expect URLs having schema to be underscored as links when "editor.links" is enabled. Maybe "real" FQDNs not having a schema, can be detected and underscored as links, but would require name lookups, to verify dotted text as links, which would slow things down quite a bit.

Steps to reproduce the behavior:

  • Create a simple Go program
    • mkdir bugreport; cd bugreport
    • go mod init bugreport
    • create file main.go and paste the following content into main.go
package main

import (
	"log"
	"time"
)

type person struct {
	name string
	age  int
}

func main() {
	announcement := time.Date(2009, 11, 10, 0, 0, 0, 0, time.UTC)
	years := int(time.Since(announcement).Hours() / 24 / 365)
	p := person{name: "gopher", age: years}
	log.Printf("p.name is %q, p.age is %d", p.name, p.age)
	log.Printf("go.dev is my favorite site!")
	log.Printf("https://p.name is not a real site!")
}

With "editor.links" enabled (set to true), and the golang.go extension enabled, the following dotted text in the log.Printf format strings is underlined as links in main()

With "editor.links" enabled (set to true), and the golang.go extension disabled, the following dotted text in the log.Printf format strings is underlined as links in main()

With "editor.links" disabled (set to false), none of the dotted text is underlined as links.

Screenshots or recordings

If applicable, add screenshots or recordings to help explain your problem.

"editor.links" enabled && golang.go extension enabled

editor links-n-golang go

"editor.links" enabled && golang.go extension disabled

editor links-n-not-golang go

"editor.links" disabled && golang.go extension enabled

not-editor links-n-golang go

@marc-ostrow marc-ostrow changed the title golang.go extension causes golang.go extension identifying arbitrary dotted text as links to the editor Oct 2, 2024
@marc-ostrow marc-ostrow changed the title golang.go extension identifying arbitrary dotted text as links to the editor golang.go extension identifying arbitrary dotted text in strings as links to the editor Oct 2, 2024
@hyangah
Copy link
Contributor

hyangah commented Oct 3, 2024

Thanks for the detailed repro instruction.

I thought this was fixed in #43990
but I can still reproduce this issue (gopls provides documentLink for them).

cc @findleyr

[Trace - 8:25:38 AM] Received response 'textDocument/documentLink - (7)' in 422ms.
Result: [
    {
        "range": {
            "start": {
                "line": 3,
                "character": 2
            },
            "end": {
                "line": 3,
                "character": 5
            }
        },
        "target": "https://pkg.go.dev/log"
    },
    {
        "range": {
            "start": {
                "line": 4,
                "character": 2
            },
            "end": {
                "line": 4,
                "character": 6
            }
        },
        "target": "https://pkg.go.dev/time"
    },
    {
        "range": {
            "start": {
                "line": 16,
                "character": 13
            },
            "end": {
                "line": 16,
                "character": 19
            }
        },
        "target": "https://p.name"
    },
    {
        "range": {
            "start": {
                "line": 17,
                "character": 13
            },
            "end": {
                "line": 17,
                "character": 19
            }
        },
        "target": "https://go.dev"
    },
    {
        "range": {
            "start": {
                "line": 18,
                "character": 13
            },
            "end": {
                "line": 18,
                "character": 27
            }
        },
        "target": "https://p.name"
    }
]

@hyangah hyangah added upstream-tools gopls Issues related to the Go language server, gopls. labels Oct 3, 2024
@findleyr
Copy link
Member

This is a gopls issue. Transferring to the gopls issue tracker.

@findleyr findleyr changed the title golang.go extension identifying arbitrary dotted text in strings as links to the editor x/tools/gopls: identifies arbitrary dotted text in strings as links Oct 24, 2024
@findleyr findleyr transferred this issue from golang/vscode-go Oct 24, 2024
@findleyr findleyr added this to the gopls/v0.18.0 milestone Oct 24, 2024
@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label Oct 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository. upstream-tools
Projects
None yet
Development

No branches or pull requests

4 participants