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: support detecting URLs in comments and string literals for documentLink #32339

Closed
litleleprikon opened this issue May 30, 2019 · 9 comments
Labels
Documentation FrozenDueToAge gopls Issues related to the Go language server, gopls. Suggested Issues that may be good for new contributors looking for work to do.
Milestone

Comments

@litleleprikon
Copy link

What version of Go are you using (go version)?

$ go version
go version go1.12.5 darwin/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/esharifu/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/esharifu/projects/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/Cellar/go/1.12.5/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.12.5/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/sh/vcq1w7n1547584p7d_kh_vf00000gn/T/go-build793298206=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Opened .go file in VSCode

What did you expect to see?

Expect to see URLs detected in comments, docstrings and string literals

What did you see instead?

URLs only detected in imports

@gopherbot gopherbot added this to the Unreleased milestone May 30, 2019
@gopherbot gopherbot added Documentation gopls Issues related to the Go language server, gopls. labels May 30, 2019
@litleleprikon
Copy link
Author

If development team find this valuable I can work on it

@stamblerre stamblerre added the Suggested Issues that may be good for new contributors looking for work to do. label Jun 3, 2019
@stamblerre
Copy link
Contributor

@litleleprikon: Absolutely, feel free to send us a contribution!

@litleleprikon
Copy link
Author

@stamblerre: Probably label "Documentation" should be removed from this issue.

Also internal/lsp/testdata/links/links.go contains tests for correct link detection and after I add the ability to locate links in comments this test starts to fail because it detects multiple links at line.

For example:

// Foo check example.com/foo @link(re`".*"`,"example.com/foo")

Fails with following error:

lsp_test.go:579: unexpected link /var/folders/sh/vcq1w7n1547584p7d_kh_vf00000gn/T/TestLSP_GOPATH214019797/lsp/src/golang.org/x/tools/internal/lsp/links/links.go:14:11-26:example.com/foo
lsp_test.go:579: unexpected link /var/folders/sh/vcq1w7n1547584p7d_kh_vf00000gn/T/TestLSP_GOPATH214019797/lsp/src/golang.org/x/tools/internal/lsp/links/links.go:14:43-58:example.com/foo

Can you suggest how to make @link call to not to count links in it's arguments?

@stamblerre stamblerre changed the title x/tools/cmd/gopls: basic support of detecting URLs in comments and string literals for textDocument/documentLink x/tools/cmd/gopls: support detecting URLs in comments and string literals for textDocument/documentLink Jun 5, 2019
@stamblerre
Copy link
Contributor

Unfortunately gopherbot adds the "Documentation" label to any issue containing the word "document".

The regular expression matcher in your example case is looking for double quotes (as in the import lines in the other test cases). You may want to try changing that to @link("example.com", "example.com").

@litleleprikon
Copy link
Author

Hi @stamblerre! Thank you for your advice but unfortunately it seems that I am doing something wrong. I stuck with adopting tests for the new functionality of searching links in comments. As I have test file with following content

package links

import (
	"fmt" //@link(re`".*"`,`https://godoc.org/fmt`)

	"golang.org/x/tools/internal/lsp/foo" //@link(re`".*"`,`https://godoc.org/golang.org/x/tools/internal/lsp/foo`)
)

var (
	_ fmt.Formatter
	_ foo.StructFoo
)

// Foo check https://example.com/comment //@link("https://example.com/comment", "http://example.com/comment")
func Foo() string {
	url := "https://example.com/string_literal" //@link(re`".*"`,`https://example.com/string_literal`)
	return url
}

I have the tests failing with following errors(pasting log only for GOPATH, for modules errors are similar)

        --- FAIL: TestLSP/GOPATH/Link (0.18s)
            /Users/esharifu/projects/go/src/golang.org/x/tools/internal/lsp/lsp_test.go:57: got 3 links expected 2
            /Users/esharifu/projects/go/src/golang.org/x/tools/internal/lsp/lsp_test.go:658: unexpected link /var/folders/sh/vcq1w7n1547584p7d_kh_vf00000gn/T/TestLSP_GOPATH004942013/lsp/src/golang.org/x/tools/internal/lsp/links/links.go:4:26-47:https://godoc.org/fmt
            /Users/esharifu/projects/go/src/golang.org/x/tools/internal/lsp/lsp_test.go:658: unexpected link /var/folders/sh/vcq1w7n1547584p7d_kh_vf00000gn/T/TestLSP_GOPATH004942013/lsp/src/golang.org/x/tools/internal/lsp/links/links.go:6:58-111:https://godoc.org/golang.org/x/tools/internal/lsp/foo
            /Users/esharifu/projects/go/src/golang.org/x/tools/internal/lsp/lsp_test.go:658: unexpected link /var/folders/sh/vcq1w7n1547584p7d_kh_vf00000gn/T/TestLSP_GOPATH004942013/lsp/src/golang.org/x/tools/internal/lsp/links/links.go:14:14-41:https://example.com/comment
            /Users/esharifu/projects/go/src/golang.org/x/tools/internal/lsp/lsp_test.go:658: unexpected link /var/folders/sh/vcq1w7n1547584p7d_kh_vf00000gn/T/TestLSP_GOPATH004942013/lsp/src/golang.org/x/tools/internal/lsp/links/links.go:14:51-78:https://example.com/comment
            /Users/esharifu/projects/go/src/golang.org/x/tools/internal/lsp/lsp_test.go:658: unexpected link /var/folders/sh/vcq1w7n1547584p7d_kh_vf00000gn/T/TestLSP_GOPATH004942013/lsp/src/golang.org/x/tools/internal/lsp/links/links.go:14:82-108:http://example.com/comment
            /Users/esharifu/projects/go/src/golang.org/x/tools/internal/lsp/lsp_test.go:658: unexpected link /var/folders/sh/vcq1w7n1547584p7d_kh_vf00000gn/T/TestLSP_GOPATH004942013/lsp/src/golang.org/x/tools/internal/lsp/links/links.go:16:64-98:https://example.com/string_literal
            /Users/esharifu/projects/go/src/golang.org/x/tools/internal/lsp/lsp_test.go:662: missing link /var/folders/sh/vcq1w7n1547584p7d_kh_vf00000gn/T/TestLSP_GOPATH004942013/lsp/src/golang.org/x/tools/internal/lsp/links/links.go:16:9-45:https://example.com/string_literal

Can you please point me where I can check how @link exactly works because I was unable to find it by myself. Or can you propose how to fix regular expression? I was experimenting with different regexes but it was not successful. Thank you!

@litleleprikon
Copy link
Author

Hi @stamblerre @ianthehat ! Can you please advice me how can I fix the issues I described in previous comment?

@stamblerre
Copy link
Contributor

@link is defined here, but the error you are seeing is actually coming from this check.
When you add tests, you will have to increase the values set here. We use them to confirm that the expected number of tests have run.

@litleleprikon
Copy link
Author

Thank you @stamblerre your comment is very helpful for me!

@stamblerre stamblerre changed the title x/tools/cmd/gopls: support detecting URLs in comments and string literals for textDocument/documentLink x/tools/gopls: support detecting URLs in comments and string literals for textDocument/documentLink Jul 2, 2019
@gopherbot
Copy link

Change https://golang.org/cl/185219 mentions this issue: internal/lsp: Add links search in comments and string literals

@stamblerre stamblerre changed the title x/tools/gopls: support detecting URLs in comments and string literals for textDocument/documentLink x/tools/gopls: support detecting URLs in comments and string literals for documentLink Jul 8, 2019
@golang golang locked and limited conversation to collaborators Jul 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Documentation FrozenDueToAge gopls Issues related to the Go language server, gopls. Suggested Issues that may be good for new contributors looking for work to do.
Projects
None yet
Development

No branches or pull requests

3 participants