Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
8140cd91
Commit
8140cd91
authored
Jun 13, 2012
by
Robert Griesemer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
godoc: show comments in various filtered views
Fixes #3454. R=rsc CC=golang-dev
https://golang.org/cl/6305069
parent
f5f23e07
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
4 deletions
+22
-4
src/cmd/godoc/godoc.go
src/cmd/godoc/godoc.go
+15
-2
src/cmd/godoc/main.go
src/cmd/godoc/main.go
+7
-2
No files found.
src/cmd/godoc/godoc.go
View file @
8140cd91
...
...
@@ -866,6 +866,19 @@ func inList(name string, list []string) bool {
return
false
}
// packageExports is a local implementation of ast.PackageExports
// which correctly updates each package file's comment list.
// (The ast.PackageExports signature is frozen, hence the local
// implementation).
//
func
packageExports
(
fset
*
token
.
FileSet
,
pkg
*
ast
.
Package
)
{
for
_
,
src
:=
range
pkg
.
Files
{
cmap
:=
ast
.
NewCommentMap
(
fset
,
src
)
ast
.
FileExports
(
src
)
src
.
Comments
=
cmap
.
Filter
(
src
)
.
Comments
()
}
}
// getPageInfo returns the PageInfo for a package directory abspath. If the
// parameter genAST is set, an AST containing only the package exports is
// computed (PageInfo.PAst), otherwise package documentation (PageInfo.Doc)
...
...
@@ -1012,9 +1025,9 @@ func (h *docServer) getPageInfo(abspath, relpath, pkgname string, mode PageInfoM
// TODO(gri) Consider eliminating export filtering in this mode,
// or perhaps eliminating the mode altogether.
if
mode
&
noFiltering
==
0
{
ast
.
PackageExports
(
pkg
)
packageExports
(
fset
,
pkg
)
}
past
=
ast
.
MergePackageFiles
(
pkg
,
ast
.
FilterUnassociatedComments
)
past
=
ast
.
MergePackageFiles
(
pkg
,
0
)
}
}
...
...
src/cmd/godoc/main.go
View file @
8140cd91
...
...
@@ -36,6 +36,7 @@ import (
"fmt"
"go/ast"
"go/build"
"go/printer"
"io"
"log"
"net/http"
...
...
@@ -424,20 +425,24 @@ func main() {
filter
:=
func
(
s
string
)
bool
{
return
rx
.
MatchString
(
s
)
}
switch
{
case
info
.
PAst
!=
nil
:
cmap
:=
ast
.
NewCommentMap
(
info
.
FSet
,
info
.
PAst
)
ast
.
FilterFile
(
info
.
PAst
,
filter
)
// Special case: Don't use templates for printing
// so we only get the filtered declarations without
// package clause or extra whitespace.
for
i
,
d
:=
range
info
.
PAst
.
Decls
{
// determine the comments associated with d only
comments
:=
cmap
.
Filter
(
d
)
.
Comments
()
cn
:=
&
printer
.
CommentedNode
{
Node
:
d
,
Comments
:
comments
}
if
i
>
0
{
fmt
.
Println
()
}
if
*
html
{
var
buf
bytes
.
Buffer
writeNode
(
&
buf
,
info
.
FSet
,
d
)
writeNode
(
&
buf
,
info
.
FSet
,
cn
)
FormatText
(
os
.
Stdout
,
buf
.
Bytes
(),
-
1
,
true
,
""
,
nil
)
}
else
{
writeNode
(
os
.
Stdout
,
info
.
FSet
,
d
)
writeNode
(
os
.
Stdout
,
info
.
FSet
,
cn
)
}
fmt
.
Println
()
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment