mirror of
https://github.com/golang/go
synced 2024-11-26 14:46:47 -07:00
A couple of godoc improvements:
- sort directories before printing - apply filtering to factory functions and methods - remove a couple of unused files R=r DELTA=84 (34 added, 40 deleted, 10 changed) OCL=28657 CL=28657
This commit is contained in:
parent
3619f1ea6a
commit
c6da3e5a69
@ -523,11 +523,11 @@ func filterValueDocs(a []*ValueDoc, names []string) []*ValueDoc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func filterTypeDocs(a []*TypeDoc, names []string) []*TypeDoc {
|
func filterFuncDocs(a []*FuncDoc, names []string) []*FuncDoc {
|
||||||
w := 0;
|
w := 0;
|
||||||
for i, td := range a {
|
for i, fd := range a {
|
||||||
if matchDecl(td.Decl, names) {
|
if match(fd.Name, names) {
|
||||||
a[w] = td;
|
a[w] = fd;
|
||||||
w++;
|
w++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -535,11 +535,20 @@ func filterTypeDocs(a []*TypeDoc, names []string) []*TypeDoc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func filterFuncDocs(a []*FuncDoc, names []string) []*FuncDoc {
|
func filterTypeDocs(a []*TypeDoc, names []string) []*TypeDoc {
|
||||||
w := 0;
|
w := 0;
|
||||||
for i, fd := range a {
|
for i, td := range a {
|
||||||
if match(fd.Name, names) {
|
match := false;
|
||||||
a[w] = fd;
|
if matchDecl(td.Decl, names) {
|
||||||
|
match = true;
|
||||||
|
} else {
|
||||||
|
// type name doesn't match, but we may have matching factories or methods
|
||||||
|
td.Factories = filterFuncDocs(td.Factories, names);
|
||||||
|
td.Methods = filterFuncDocs(td.Methods, names);
|
||||||
|
match = len(td.Factories) > 0 || len(td.Methods) > 0;
|
||||||
|
}
|
||||||
|
if match {
|
||||||
|
a[w] = td;
|
||||||
w++;
|
w++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -424,6 +424,14 @@ type pakDesc struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// TODO if we don't plan to use the directory information, simplify to []string
|
||||||
|
type dirList []*os.Dir
|
||||||
|
|
||||||
|
func (d dirList) Len() int { return len(d) }
|
||||||
|
func (d dirList) Less(i, j int) bool { return d[i].Name < d[j].Name }
|
||||||
|
func (d dirList) Swap(i, j int) { d[i], d[j] = d[j], d[i] }
|
||||||
|
|
||||||
|
|
||||||
func isPackageFile(dirname, filename, pakname string) bool {
|
func isPackageFile(dirname, filename, pakname string) bool {
|
||||||
// ignore test files
|
// ignore test files
|
||||||
if strings.HasSuffix(filename, "_test.go") {
|
if strings.HasSuffix(filename, "_test.go") {
|
||||||
@ -444,7 +452,7 @@ func isPackageFile(dirname, filename, pakname string) bool {
|
|||||||
// sub-directories in the corresponding package directory.
|
// sub-directories in the corresponding package directory.
|
||||||
// If there is no such package, the first result is nil. If
|
// If there is no such package, the first result is nil. If
|
||||||
// there are no sub-directories, that list is nil.
|
// there are no sub-directories, that list is nil.
|
||||||
func findPackage(importpath string) (*pakDesc, []os.Dir) {
|
func findPackage(importpath string) (*pakDesc, dirList) {
|
||||||
// get directory contents, if possible
|
// get directory contents, if possible
|
||||||
dirname := pathutil.Join(*pkgroot, importpath);
|
dirname := pathutil.Join(*pkgroot, importpath);
|
||||||
if !isDir(dirname) {
|
if !isDir(dirname) {
|
||||||
@ -475,7 +483,7 @@ func findPackage(importpath string) (*pakDesc, []os.Dir) {
|
|||||||
case isGoFile(&entry) && isPackageFile(dirname, entry.Name, pakname):
|
case isGoFile(&entry) && isPackageFile(dirname, entry.Name, pakname):
|
||||||
// add file to package desc
|
// add file to package desc
|
||||||
if tmp, found := filenames[entry.Name]; found {
|
if tmp, found := filenames[entry.Name]; found {
|
||||||
panic("internal error: same file added more then once: " + entry.Name);
|
panic("internal error: same file added more than once: " + entry.Name);
|
||||||
}
|
}
|
||||||
filenames[entry.Name] = true;
|
filenames[entry.Name] = true;
|
||||||
case entry.IsDirectory():
|
case entry.IsDirectory():
|
||||||
@ -484,16 +492,21 @@ func findPackage(importpath string) (*pakDesc, []os.Dir) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// make the list of sub-directories, if any
|
// make the list of sub-directories, if any
|
||||||
var subdirs []os.Dir;
|
var subdirs dirList;
|
||||||
if nsub > 0 {
|
if nsub > 0 {
|
||||||
subdirs = make([]os.Dir, nsub);
|
subdirs = make(dirList, nsub);
|
||||||
nsub = 0;
|
nsub = 0;
|
||||||
for i, entry := range list {
|
for i, entry := range list {
|
||||||
if entry.IsDirectory() {
|
if entry.IsDirectory() {
|
||||||
subdirs[nsub] = entry;
|
// make a copy here so sorting (and other code) doesn't
|
||||||
|
// have to make one every time an entry is moved
|
||||||
|
copy := new(os.Dir);
|
||||||
|
*copy = entry;
|
||||||
|
subdirs[nsub] = copy;
|
||||||
nsub++;
|
nsub++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
sort.Sort(subdirs);
|
||||||
}
|
}
|
||||||
|
|
||||||
// if there are no package files, then there is no package
|
// if there are no package files, then there is no package
|
||||||
@ -549,16 +562,13 @@ func servePackage(c *http.Conn, desc *pakDesc) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// TODO like to use []*os.Dir instead of []os.Dir - template.go doesn't
|
|
||||||
// automatically indirect pointers it seems, so this would require
|
|
||||||
// custom formatters at the moment
|
|
||||||
type Dirs struct {
|
type Dirs struct {
|
||||||
Path string;
|
Path string;
|
||||||
Dirs []os.Dir;
|
Dirs dirList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func serveDirList(c *http.Conn, path string, dirs []os.Dir) {
|
func serveDirList(c *http.Conn, path string, dirs dirList) {
|
||||||
var buf io.ByteBuffer;
|
var buf io.ByteBuffer;
|
||||||
err := dirlistHtml.Execute(Dirs{path, dirs}, &buf);
|
err := dirlistHtml.Execute(Dirs{path, dirs}, &buf);
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -1,15 +0,0 @@
|
|||||||
{.section Packages}
|
|
||||||
<b>Packages</b><br />
|
|
||||||
{.repeated section @}
|
|
||||||
<a href="{pakname|html}">{importpath|html}</a><br />
|
|
||||||
{.end}
|
|
||||||
{.or}
|
|
||||||
No such package {Path|html}<br />
|
|
||||||
{.end}
|
|
||||||
{.section Subdirs}
|
|
||||||
<br />
|
|
||||||
<b>Directories</b><br />
|
|
||||||
{.repeated section @}
|
|
||||||
<a href="{Name|html}/">{Path|html}{Name|html}/</a><br />
|
|
||||||
{.end}
|
|
||||||
{.end}
|
|
@ -1,10 +0,0 @@
|
|||||||
{.repeated section Packages}
|
|
||||||
godoc {pakname}
|
|
||||||
{.or}
|
|
||||||
godoc: package not found: {Path}
|
|
||||||
{.end}
|
|
||||||
{.section Packages}
|
|
||||||
{.repeated section Subdirs}
|
|
||||||
godoc {Path}/{Name}/
|
|
||||||
{.end}
|
|
||||||
{.end}
|
|
Loading…
Reference in New Issue
Block a user