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

Comments

Projects
None yet
3 participants
@litleleprikon
Copy link

commented May 30, 2019

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

@litleleprikon

This comment has been minimized.

Copy link
Author

commented Jun 2, 2019

If development team find this valuable I can work on it

@stamblerre stamblerre added the Suggested label Jun 3, 2019

@stamblerre

This comment has been minimized.

Copy link
Contributor

commented Jun 3, 2019

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

@litleleprikon

This comment has been minimized.

Copy link
Author

commented Jun 3, 2019

@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

This comment has been minimized.

Copy link
Contributor

commented Jun 5, 2019

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

This comment has been minimized.

Copy link
Author

commented Jun 11, 2019

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

This comment has been minimized.

Copy link
Author

commented Jun 18, 2019

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

@stamblerre

This comment has been minimized.

Copy link
Contributor

commented Jun 18, 2019

@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

This comment has been minimized.

Copy link
Author

commented Jun 18, 2019

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

This comment has been minimized.

Copy link

commented Jul 7, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.