mirror of
https://github.com/golang/go
synced 2024-11-05 17:06:13 -07:00
godoc: Strip "/src/pkg/" prefix from identifier keys, so that it's keyed identically to import count.
Intern the documentation strings. LGTM=sameer R=sameer, bradfitz CC=golang-codereviews https://golang.org/cl/107250043
This commit is contained in:
parent
969a226d69
commit
936715c71c
@ -303,11 +303,12 @@ func (info *PageInfo) IsEmpty() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func pkgLinkFunc(path string) string {
|
func pkgLinkFunc(path string) string {
|
||||||
relpath := path[1:]
|
|
||||||
// because of the irregular mapping under goroot
|
// because of the irregular mapping under goroot
|
||||||
// we need to correct certain relative paths
|
// we need to correct certain relative paths
|
||||||
relpath = strings.TrimPrefix(relpath, "src/pkg/")
|
path = strings.TrimPrefix(path, "/")
|
||||||
return "pkg/" + relpath // remove trailing '/' for relative URL
|
path = strings.TrimPrefix(path, "src/")
|
||||||
|
path = strings.TrimPrefix(path, "pkg/")
|
||||||
|
return "pkg/" + path
|
||||||
}
|
}
|
||||||
|
|
||||||
func newPosLink_urlFunc(srcPosLinkFunc func(s string, line, low, high int) string) func(info *PageInfo, n interface{}) string {
|
func newPosLink_urlFunc(srcPosLinkFunc func(s string, line, low, high int) string) func(info *PageInfo, n interface{}) string {
|
||||||
@ -368,6 +369,7 @@ func srcPosLinkFunc(s string, line, low, high int) string {
|
|||||||
|
|
||||||
func srcLinkFunc(s string) string {
|
func srcLinkFunc(s string) string {
|
||||||
s = pathpkg.Clean("/" + s)
|
s = pathpkg.Clean("/" + s)
|
||||||
|
// TODO(bgarcia): Once the /src/pkg -> /src transition occurs, update this function.
|
||||||
if !strings.HasPrefix(s, "/src/pkg/") {
|
if !strings.HasPrefix(s, "/src/pkg/") {
|
||||||
s = "/src/pkg" + s
|
s = "/src/pkg" + s
|
||||||
}
|
}
|
||||||
@ -388,8 +390,7 @@ func queryLinkFunc(s, query string, line int) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func docLinkFunc(s string, ident string) string {
|
func docLinkFunc(s string, ident string) string {
|
||||||
s = strings.TrimPrefix(s, "/src")
|
return pathpkg.Clean("/pkg/"+s) + "/#" + ident
|
||||||
return pathpkg.Clean("/"+s) + "/#" + ident
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Presentation) example_textFunc(info *PageInfo, funcName, indent string) string {
|
func (p *Presentation) example_textFunc(info *PageInfo, funcName, indent string) string {
|
||||||
|
@ -14,7 +14,9 @@ func TestPkgLinkFunc(t *testing.T) {
|
|||||||
want string
|
want string
|
||||||
}{
|
}{
|
||||||
{"/src/pkg/fmt", "pkg/fmt"},
|
{"/src/pkg/fmt", "pkg/fmt"},
|
||||||
|
{"src/pkg/fmt", "pkg/fmt"},
|
||||||
{"/fmt", "pkg/fmt"},
|
{"/fmt", "pkg/fmt"},
|
||||||
|
{"fmt", "pkg/fmt"},
|
||||||
} {
|
} {
|
||||||
if got := pkgLinkFunc(tc.path); got != tc.want {
|
if got := pkgLinkFunc(tc.path); got != tc.want {
|
||||||
t.Errorf("pkgLinkFunc(%v) = %v; want %v", tc.path, got, tc.want)
|
t.Errorf("pkgLinkFunc(%v) = %v; want %v", tc.path, got, tc.want)
|
||||||
@ -84,8 +86,8 @@ func TestDocLinkFunc(t *testing.T) {
|
|||||||
ident string
|
ident string
|
||||||
want string
|
want string
|
||||||
}{
|
}{
|
||||||
{"/src/pkg/fmt", "Sprintf", "/pkg/fmt/#Sprintf"},
|
{"fmt", "Sprintf", "/pkg/fmt/#Sprintf"},
|
||||||
{"/src/pkg/fmt", "EOF", "/pkg/fmt/#EOF"},
|
{"fmt", "EOF", "/pkg/fmt/#EOF"},
|
||||||
} {
|
} {
|
||||||
if got := docLinkFunc(tc.src, tc.ident); got != tc.want {
|
if got := docLinkFunc(tc.src, tc.ident); got != tc.want {
|
||||||
t.Errorf("docLinkFunc(%v, %v) = %v; want %v", tc.src, tc.ident, got, tc.want)
|
t.Errorf("docLinkFunc(%v, %v) = %v; want %v", tc.src, tc.ident, got, tc.want)
|
||||||
|
@ -694,11 +694,11 @@ func isWhitelisted(filename string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (x *Indexer) indexDocs(dirname string, filename string, astFile *ast.File) {
|
func (x *Indexer) indexDocs(dirname string, filename string, astFile *ast.File) {
|
||||||
pkgName := astFile.Name.Name
|
pkgName := x.intern(astFile.Name.Name)
|
||||||
if pkgName == "main" {
|
if pkgName == "main" {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
dirname = pathpkg.Clean(dirname)
|
pkgPath := x.intern(strings.TrimPrefix(strings.TrimPrefix(dirname, "/src/"), "pkg/"))
|
||||||
astPkg := ast.Package{
|
astPkg := ast.Package{
|
||||||
Name: pkgName,
|
Name: pkgName,
|
||||||
Files: map[string]*ast.File{
|
Files: map[string]*ast.File{
|
||||||
@ -711,8 +711,9 @@ func (x *Indexer) indexDocs(dirname string, filename string, astFile *ast.File)
|
|||||||
if x.idents[sk] == nil {
|
if x.idents[sk] == nil {
|
||||||
x.idents[sk] = make(map[string][]Ident)
|
x.idents[sk] = make(map[string][]Ident)
|
||||||
}
|
}
|
||||||
|
name = x.intern(name)
|
||||||
x.idents[sk][name] = append(x.idents[sk][name], Ident{
|
x.idents[sk][name] = append(x.idents[sk][name], Ident{
|
||||||
Path: dirname,
|
Path: pkgPath,
|
||||||
Package: pkgName,
|
Package: pkgName,
|
||||||
Name: name,
|
Name: name,
|
||||||
Doc: doc.Synopsis(docstr),
|
Doc: doc.Synopsis(docstr),
|
||||||
@ -722,7 +723,7 @@ func (x *Indexer) indexDocs(dirname string, filename string, astFile *ast.File)
|
|||||||
if x.idents[PackageClause] != nil {
|
if x.idents[PackageClause] != nil {
|
||||||
pkgs := x.idents[PackageClause][docPkg.Name]
|
pkgs := x.idents[PackageClause][docPkg.Name]
|
||||||
for i, p := range pkgs {
|
for i, p := range pkgs {
|
||||||
if p.Path == dirname {
|
if p.Path == pkgPath {
|
||||||
foundPkg = true
|
foundPkg = true
|
||||||
if docPkg.Doc != "" {
|
if docPkg.Doc != "" {
|
||||||
p.Doc = doc.Synopsis(docPkg.Doc)
|
p.Doc = doc.Synopsis(docPkg.Doc)
|
||||||
@ -760,7 +761,7 @@ func (x *Indexer) indexDocs(dirname string, filename string, astFile *ast.File)
|
|||||||
// Change the name of methods to be "<typename>.<methodname>".
|
// Change the name of methods to be "<typename>.<methodname>".
|
||||||
// They will still be indexed as <methodname>.
|
// They will still be indexed as <methodname>.
|
||||||
idents := x.idents[MethodDecl][f.Name]
|
idents := x.idents[MethodDecl][f.Name]
|
||||||
idents[len(idents)-1].Name = t.Name + "." + f.Name
|
idents[len(idents)-1].Name = x.intern(t.Name + "." + f.Name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, v := range docPkg.Vars {
|
for _, v := range docPkg.Vars {
|
||||||
@ -797,7 +798,7 @@ func (x *Indexer) indexGoFile(dirname string, filename string, file *token.File,
|
|||||||
if _, ok := x.packagePath[ppKey]; !ok {
|
if _, ok := x.packagePath[ppKey]; !ok {
|
||||||
x.packagePath[ppKey] = make(map[string]bool)
|
x.packagePath[ppKey] = make(map[string]bool)
|
||||||
}
|
}
|
||||||
pkgPath := x.intern(strings.TrimPrefix(dirname, "/src/pkg/"))
|
pkgPath := x.intern(strings.TrimPrefix(strings.TrimPrefix(dirname, "/src/"), "pkg/"))
|
||||||
x.packagePath[ppKey][pkgPath] = true
|
x.packagePath[ppKey][pkgPath] = true
|
||||||
|
|
||||||
// Merge in exported symbols found walking this file into
|
// Merge in exported symbols found walking this file into
|
||||||
|
@ -231,23 +231,23 @@ func checkIdents(t *testing.T, c *Corpus, ix *Index) {
|
|||||||
want = map[SpotKind]map[string][]Ident{
|
want = map[SpotKind]map[string][]Ident{
|
||||||
PackageClause: map[string][]Ident{
|
PackageClause: map[string][]Ident{
|
||||||
"bar": []Ident{
|
"bar": []Ident{
|
||||||
{"/src/pkg/bar", "bar", "bar", "Package bar is another example to test races."},
|
{"bar", "bar", "bar", "Package bar is another example to test races."},
|
||||||
{"/src/pkg/other/bar", "bar", "bar", "Package bar is another bar package."},
|
{"other/bar", "bar", "bar", "Package bar is another bar package."},
|
||||||
},
|
},
|
||||||
"foo": []Ident{{"/src/pkg/foo", "foo", "foo", "Package foo is an example."}},
|
"foo": []Ident{{"foo", "foo", "foo", "Package foo is an example."}},
|
||||||
},
|
},
|
||||||
ConstDecl: map[string][]Ident{
|
ConstDecl: map[string][]Ident{
|
||||||
"Pi": []Ident{{"/src/pkg/foo", "foo", "Pi", ""}},
|
"Pi": []Ident{{"foo", "foo", "Pi", ""}},
|
||||||
},
|
},
|
||||||
VarDecl: map[string][]Ident{
|
VarDecl: map[string][]Ident{
|
||||||
"Foos": []Ident{{"/src/pkg/foo", "foo", "Foos", ""}},
|
"Foos": []Ident{{"foo", "foo", "Foos", ""}},
|
||||||
},
|
},
|
||||||
TypeDecl: map[string][]Ident{
|
TypeDecl: map[string][]Ident{
|
||||||
"Foo": []Ident{{"/src/pkg/foo", "foo", "Foo", "Foo is stuff."}},
|
"Foo": []Ident{{"foo", "foo", "Foo", "Foo is stuff."}},
|
||||||
},
|
},
|
||||||
FuncDecl: map[string][]Ident{
|
FuncDecl: map[string][]Ident{
|
||||||
"New": []Ident{{"/src/pkg/foo", "foo", "New", ""}},
|
"New": []Ident{{"foo", "foo", "New", ""}},
|
||||||
"X": []Ident{{"/src/pkg/other/bar", "bar", "X", ""}},
|
"X": []Ident{{"other/bar", "bar", "X", ""}},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user