Skip to content

Commit 6e064ea

Browse files
jbszczepaniakstamblerre
authored andcommitted
internal/lsp: link to the new pkg.go.dev instead of godoc.org
Updates #35563 Change-Id: I88ae3f742daf5043d4784fe8827454fb1ce1f9db Reviewed-on: https://go-review.googlesource.com/c/tools/+/209337 Reviewed-by: Rebecca Stambler <[email protected]> Run-TryBot: Rebecca Stambler <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent ecd3221 commit 6e064ea

File tree

4 files changed

+29
-5
lines changed

4 files changed

+29
-5
lines changed

gopls/doc/settings.md

+10
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,16 @@ If true, then completion responses may contain placeholders for function paramet
4646

4747
Default: `false`.
4848

49+
### **linkTarget** *string*
50+
51+
This controls where points documentation for given package in `textDocument/documentLink`.
52+
It might be one of:
53+
* `"godoc.org"`
54+
* `"pkg.go.dev"`
55+
If company chooses to use its own `godoc.org`, it's address can be used as well.
56+
57+
Default: `"pkg.go.dev"`.
58+
4959
## Experimental
5060

5161
The below settings are considered experimental. They may be deprecated or changed in the future. They are typically used to test experimental opt-in features or to disable features.

internal/lsp/link.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package lsp
66

77
import (
88
"context"
9+
"fmt"
910
"go/ast"
1011
"go/token"
1112
"regexp"
@@ -47,7 +48,7 @@ func (s *Server) documentLink(ctx context.Context, params *protocol.DocumentLink
4748
if target == "" {
4849
return false
4950
}
50-
target = "https://godoc.org/" + target
51+
target = fmt.Sprintf("https://%s/%s", view.Options().LinkTarget, target)
5152
l, err := toProtocolLink(view, m, target, n.Path.Pos()+1, n.Path.End()-1)
5253
if err != nil {
5354
log.Error(ctx, "cannot initialize DocumentLink", err, tag.Of("Path", n.Path.Value))

internal/lsp/source/options.go

+13
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ var (
6969
ComputeEdits: myers.ComputeEdits,
7070
Analyzers: defaultAnalyzers,
7171
GoDiff: true,
72+
LinkTarget: "pkg.go.dev",
7273
}
7374
)
7475

@@ -110,6 +111,8 @@ type Options struct {
110111
LocalPrefix string
111112

112113
VerboseOutput bool
114+
115+
LinkTarget string
113116
}
114117

115118
type CompletionOptions struct {
@@ -164,6 +167,8 @@ const (
164167
OptionUnexpected
165168
)
166169

170+
type LinkTarget string
171+
167172
func SetOptions(options *Options, opts interface{}) OptionResults {
168173
var results OptionResults
169174
switch opts := opts.(type) {
@@ -265,6 +270,14 @@ func (o *Options) set(name string, value interface{}) OptionResult {
265270
result.errorf("Unsupported hover kind", tag.Of("HoverKind", hoverKind))
266271
}
267272

273+
case "linkTarget":
274+
linkTarget, ok := value.(string)
275+
if !ok {
276+
result.errorf("invalid type %T for string option %q", value, name)
277+
break
278+
}
279+
o.LinkTarget = linkTarget
280+
268281
case "experimentalDisabledAnalyses":
269282
disabledAnalyses, ok := value.([]interface{})
270283
if !ok {

internal/lsp/testdata/links/links.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package links
22

33
import (
4-
"fmt" //@link(`fmt`,"https://godoc.org/fmt")
4+
"fmt" //@link(`fmt`,"https://pkg.go.dev/fmt")
55

6-
"golang.org/x/tools/internal/lsp/foo" //@link(`golang.org/x/tools/internal/lsp/foo`,`https://godoc.org/golang.org/x/tools/internal/lsp/foo`)
6+
"golang.org/x/tools/internal/lsp/foo" //@link(`golang.org/x/tools/internal/lsp/foo`,`https://pkg.go.dev/golang.org/x/tools/internal/lsp/foo`)
77

8-
_ "database/sql" //@link(`database/sql`, `https://godoc.org/database/sql`)
8+
_ "database/sql" //@link(`database/sql`, `https://pkg.go.dev/database/sql`)
99

10-
errors "golang.org/x/xerrors" //@link(`golang.org/x/xerrors`, `https://godoc.org/golang.org/x/xerrors`)
10+
errors "golang.org/x/xerrors" //@link(`golang.org/x/xerrors`, `https://pkg.go.dev/golang.org/x/xerrors`)
1111
)
1212

1313
var (

0 commit comments

Comments
 (0)