Skip to content

Commit

Permalink
internal/godoc/dochtml: remove deprecated split
Browse files Browse the repository at this point in the history
Remove the code that split out deprecated symbols.

For golang/go#40850

Change-Id: Ibf3cc5bf57a0e450853f9130c489e3f1d78900b6
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/314089
Trust: Jonathan Amsterdam <jba@google.com>
Run-TryBot: Jonathan Amsterdam <jba@google.com>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Jamal Carvalho <jamal@golang.org>
  • Loading branch information
jba committed Apr 27, 2021
1 parent ef62493 commit bd1d5f7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 103 deletions.
39 changes: 17 additions & 22 deletions content/static/html/doc/body.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -57,28 +57,6 @@
</section>
{{- end -}}

{{template "decls" .}}

{{- end -}}

{{- if .Notes -}}
<h3 tabindex="-1" id="pkg-notes" class="Documentation-notesHeader">Notes <a href="#pkg-notes">¶</a></h3>{{"\n"}}
<section class="Documentation-notes">
{{- range $marker, $content := .Notes -}}
<div class="Documentation-note">
<h3 tabindex="-1" id="{{(index $.NoteHeaders $marker).SafeIdentifier}}" class="Documentation-noteHeader">{{(index $.NoteHeaders $marker).Label}}s <a href="#pkg-note-{{$marker}}">¶</a></h3>
<ul class="Documentation-noteList" style="padding-left: 20px; list-style: initial;">{{"\n" -}}
{{- range $v := $content -}}
<li style="margin: 6px 0 6px 0;">{{render_doc $v.Body}}</li>
{{- end -}}
</ul>{{"\n" -}}
</div>
{{- end -}}
</section>
{{- end -}}
</div> {{/* End documentation content container */}}

{{- define "decls" -}}
<h3 tabindex="-1" id="pkg-constants" class="Documentation-constantsHeader">Constants <a href="#pkg-constants">¶</a></h3>{{"\n"}}
<section class="Documentation-constants">
{{- if .Consts -}}
Expand Down Expand Up @@ -177,3 +155,20 @@
{{- end -}}
</section>
{{- end -}}

{{- if .Notes -}}
<h3 tabindex="-1" id="pkg-notes" class="Documentation-notesHeader">Notes <a href="#pkg-notes">¶</a></h3>{{"\n"}}
<section class="Documentation-notes">
{{- range $marker, $content := .Notes -}}
<div class="Documentation-note">
<h3 tabindex="-1" id="{{(index $.NoteHeaders $marker).SafeIdentifier}}" class="Documentation-noteHeader">{{(index $.NoteHeaders $marker).Label}}s <a href="#pkg-note-{{$marker}}">¶</a></h3>
<ul class="Documentation-noteList" style="padding-left: 20px; list-style: initial;">{{"\n" -}}
{{- range $v := $content -}}
<li style="margin: 6px 0 6px 0;">{{render_doc $v.Body}}</li>
{{- end -}}
</ul>{{"\n" -}}
</div>
{{- end -}}
</section>
{{- end -}}
</div> {{/* End documentation content container */}}
81 changes: 0 additions & 81 deletions internal/godoc/dochtml/dochtml.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ import (
"github.com/google/safehtml/legacyconversions"
"github.com/google/safehtml/template"
"github.com/google/safehtml/uncheckedconversions"
"golang.org/x/pkgsite/internal"
"golang.org/x/pkgsite/internal/derrors"
"golang.org/x/pkgsite/internal/experiment"
"golang.org/x/pkgsite/internal/godoc/dochtml/internal/render"
"golang.org/x/pkgsite/internal/godoc/internal/doc"
)
Expand Down Expand Up @@ -70,8 +68,6 @@ type templateData struct {
*doc.Package
Examples *examples
NoteHeaders map[string]noteHeader
Deprecated *deprecated // extracted from doc.Package; do not appear in outline
Suffix string // suffix for links; always empty (see type deprecated)
}

// Parts contains HTML for each part of the documentation.
Expand Down Expand Up @@ -195,16 +191,11 @@ func renderInfo(ctx context.Context, fset *token.FileSet, p *doc.Package, opt Re
"source_link": sourceLink,
"since_version": sinceVersion,
}
var dep *deprecated
if experiment.IsActive(ctx, internal.ExperimentDeprecatedDoc) {
dep = extractDeprecated(p)
}
data := templateData{
RootURL: "/pkg",
Package: p,
Examples: collectExamples(p),
NoteHeaders: buildNoteHeaders(p.Notes),
Deprecated: dep,
}
return funcs, data, r.Links
}
Expand Down Expand Up @@ -250,15 +241,6 @@ type example struct {
Suffix string // optional suffix name in title case
}

// deprecated holds parts of a doc.Package that are deprecated.
type deprecated struct {
Consts []*doc.Value
Types []*doc.Type
Vars []*doc.Value
Funcs []*doc.Func
Examples []*doc.Example
}

// Code returns an printer.CommentedNode if ex.Comments is non-nil,
// otherwise it returns ex.Code as is.
func (ex *example) Code() interface{} {
Expand Down Expand Up @@ -374,66 +356,3 @@ func versionedPkgPath(pkgPath string, modInfo *ModuleInfo) string {
innerPkgPath := pkgPath[len(modInfo.ModulePath):]
return fmt.Sprintf("%s@%s%s", modInfo.ModulePath, modInfo.ResolvedVersion, innerPkgPath)
}

// extractDeprecated removes and returns all deprecated decls in p.
// It doesn't deal with examples; that is handled elsewhere.
func extractDeprecated(p *doc.Package) *deprecated {
d := &deprecated{}
p.Consts, d.Consts = splitDeprecatedValues(p.Consts)
p.Vars, d.Vars = splitDeprecatedValues(p.Vars)
p.Funcs, d.Funcs = splitDeprecatedFuncs(p.Funcs)
var dfs []*doc.Func
p.Types, d.Types, dfs = splitDeprecatedTypes(p.Types)
// Tack all the deprecated functions and methods from non-deprecated types
// onto the end of the top-level deprecated functions.
d.Funcs = append(d.Funcs, dfs...)
return d
}

// splitDeprecatedValues splits the given values into two lists: non-deprecated
// and deprecated.
func splitDeprecatedValues(xs []*doc.Value) (n, d []*doc.Value) {
for _, x := range xs {
if x.IsDeprecated {
d = append(d, x)
} else {
n = append(n, x)
}
}
return n, d
}

// splitDeprecatedFuncs splits the given funcs into two lists: non-deprecated
// and deprecated.
func splitDeprecatedFuncs(xs []*doc.Func) (n, d []*doc.Func) {
for _, x := range xs {
if x.IsDeprecated {
d = append(d, x)
} else {
n = append(n, x)
}
}
return n, d
}

// splitDeprecatedTypes splits the given types into two lists: non-deprecated
// and deprecated.
// It also returns a list of deprecated functions and methods from
// non-deprecated types.
func splitDeprecatedTypes(xs []*doc.Type) (n, d []*doc.Type, df []*doc.Func) {
for _, x := range xs {
if x.IsDeprecated {
d = append(d, x)
} else {
n = append(n, x)
// Even if a type isn't deprecated, its child decls might be.
// We only care about functions and methods.
var f, m []*doc.Func
x.Funcs, f = splitDeprecatedFuncs(x.Funcs)
df = append(df, f...)
x.Methods, m = splitDeprecatedFuncs(x.Methods)
df = append(df, m...)
}
}
return n, d, df
}
1 change: 1 addition & 0 deletions internal/godoc/dochtml/testdata/everydecl.golden
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ BUG(uid): this verifies that notes are rendered
</div><p>this verifies that notes are rendered
</p></li></ul>
</div></section></div>

----

<ul role="group" id="doc-outline">
Expand Down

0 comments on commit bd1d5f7

Please sign in to comment.