Skip to content

Commit 9a14c39

Browse files
Merge branch 'golang:master' into fix/wrong-internal-code-comment
2 parents 63b4523 + 0e7ccc0 commit 9a14c39

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

gopls/internal/golang/pkgdoc.go

+23-6
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import (
5151
"golang.org/x/tools/gopls/internal/util/safetoken"
5252
"golang.org/x/tools/gopls/internal/util/slices"
5353
"golang.org/x/tools/gopls/internal/util/typesutil"
54+
"golang.org/x/tools/internal/stdlib"
5455
"golang.org/x/tools/internal/typesinternal"
5556
)
5657

@@ -415,6 +416,12 @@ header {
415416
padding: 0.3em;
416417
}
417418
419+
.Documentation-sinceVersion {
420+
font-weight: normal;
421+
color: #808080;
422+
float: right;
423+
}
424+
418425
#pkgsite { height: 1.5em; }
419426
420427
#hdr-Selector {
@@ -782,15 +789,25 @@ window.addEventListener('load', function() {
782789
values(docpkg.Vars)
783790
}
784791

792+
// addedInHTML returns an HTML division containing the Go release version at
793+
// which this obj became available.
794+
addedInHTML := func(obj types.Object) string {
795+
if sym := StdSymbolOf(obj); sym != nil && sym.Version != stdlib.Version(0) {
796+
return fmt.Sprintf("<span class='Documentation-sinceVersion'>added in %v</span>", sym.Version)
797+
}
798+
return ""
799+
}
800+
785801
// package-level functions
786802
fmt.Fprintf(&buf, "<h2 id='hdr-Functions'>Functions</h2>\n")
787803
// funcs emits a list of package-level functions,
788804
// possibly organized beneath the type they construct.
789805
funcs := func(funcs []*doc.Func) {
790806
for _, docfn := range funcs {
791807
obj := scope.Lookup(docfn.Name).(*types.Func)
792-
fmt.Fprintf(&buf, "<h3 id='%s'>func %s</h3>\n",
793-
docfn.Name, objHTML(pkg.FileSet(), web, obj))
808+
809+
fmt.Fprintf(&buf, "<h3 id='%s'>func %s %s</h3>\n",
810+
docfn.Name, objHTML(pkg.FileSet(), web, obj), addedInHTML(obj))
794811

795812
// decl: func F(params) results
796813
fmt.Fprintf(&buf, "<pre class='code'>%s</pre>\n",
@@ -808,8 +825,8 @@ window.addEventListener('load', function() {
808825
tname := scope.Lookup(doctype.Name).(*types.TypeName)
809826

810827
// title and source link
811-
fmt.Fprintf(&buf, "<h3 id='%s'>type %s</a></h3>\n",
812-
doctype.Name, objHTML(pkg.FileSet(), web, tname))
828+
fmt.Fprintf(&buf, "<h3 id='%s'>type %s %s</h3>\n",
829+
doctype.Name, objHTML(pkg.FileSet(), web, tname), addedInHTML(tname))
813830

814831
// declaration
815832
// TODO(adonovan): excise non-exported struct fields somehow.
@@ -828,10 +845,10 @@ window.addEventListener('load', function() {
828845
// methods on T
829846
for _, docmethod := range doctype.Methods {
830847
method, _, _ := types.LookupFieldOrMethod(tname.Type(), true, tname.Pkg(), docmethod.Name)
831-
fmt.Fprintf(&buf, "<h4 id='%s.%s'>func (%s) %s</h4>\n",
848+
fmt.Fprintf(&buf, "<h4 id='%s.%s'>func (%s) %s %s</h4>\n",
832849
doctype.Name, docmethod.Name,
833850
docmethod.Orig, // T or *T
834-
objHTML(pkg.FileSet(), web, method))
851+
objHTML(pkg.FileSet(), web, method), addedInHTML(method))
835852

836853
// decl: func (x T) M(params) results
837854
fmt.Fprintf(&buf, "<pre class='code'>%s</pre>\n",

0 commit comments

Comments
 (0)