Keyboard Shortcuts

File
u :up to issue
m :publish + mail comments
M :edit review message
j / k :jump to file after / before current file
J / K :jump to next file with a comment after / before current file
Side-by-side diff
i :toggle intra-line diffs
e :expand all comments
c :collapse all comments
s :toggle showing all comments
n / p :next / previous diff chunk or comment
N / P :next / previous comment
<Up> / <Down> :next / previous line
<Enter> :respond to / edit current comment
d :mark current comment as done
Issue
u :up to list of issues
m :publish + mail comments
j / k :jump to patch after / before current patch
o / <Enter> :open current patch in side-by-side view
i :open current patch in unified diff view
Issue List
j / k :jump to issue after / before current issue
o / <Enter> :open current issue
# : close issue
Comment/message editing
<Ctrl> + s or <Ctrl> + Enter :save comment
<Esc> :cancel edit
Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(316)
Issues Repositories Search
Open Issues | Closed Issues | All Issues | Sign in with your Google Account to create issues and add comments

Issue 6970051: code review 6970051: cmd/godoc: ignore misnamed examples and print a warning

Can't Edit
Can't Publish+Mail
Start Review
Created:
13 years ago by kisielk
Modified:
13 years ago
Reviewers:
adg
CC:
golang-dev, adg
Visibility:
Public.
cmd/godoc: ignore misnamed examples and print a warning Fixes issue 4211.

Patch Set 1 #

Patch Set 2 : diff -r 5acb449b2a67 https://code.google.com/p/go #

Patch Set 3 : diff -r 5acb449b2a67 https://code.google.com/p/go #

Total comments: 3

Patch Set 4 : diff -r 5acb449b2a67 https://code.google.com/p/go #

Total comments: 5

Patch Set 5 : diff -r 5acb449b2a67 https://code.google.com/p/go #

Total comments: 2

Patch Set 6 : diff -r 5acb449b2a67 https://code.google.com/p/go #

Total comments: 8

Patch Set 7 : diff -r 5acb449b2a67 https://code.google.com/p/go #

Created: 13 years ago
Download [raw] [tar.bz2]
Unified diffs Side-by-side diffs Delta from patch set Stats (+91 lines, -24 lines) Patch
M src/cmd/godoc/godoc.go View 1 2 3 4 5 6 3 chunks +91 lines, -24 lines 0 comments Download
Total messages: 12
|
kisielk
Hello golang-dev@googlegroups.com, I'd like you to review this change to https://code.google.com/p/go
13 years ago (2012年12月20日 04:27:35 UTC) #1
Hello golang-dev@googlegroups.com,
I'd like you to review this change to
https://code.google.com/p/go 
Sign in to reply to this message.
adg
https://codereview.appspot.com/6970051/diff/3001/src/cmd/godoc/godoc.go File src/cmd/godoc/godoc.go (right): https://codereview.appspot.com/6970051/diff/3001/src/cmd/godoc/godoc.go#newcode895 src/cmd/godoc/godoc.go:895: func declInPackages(p map[string]*ast.Package, name string) bool { split this ...
13 years ago (2012年12月20日 04:59:22 UTC) #2
https://codereview.appspot.com/6970051/diff/3001/src/cmd/godoc/godoc.go
File src/cmd/godoc/godoc.go (right):
https://codereview.appspot.com/6970051/diff/3001/src/cmd/godoc/godoc.go#newco...
src/cmd/godoc/godoc.go:895: func declInPackages(p map[string]*ast.Package, name
string) bool {
split this into two functions
func hasGlobalName(p map[string]*ast.Package, name string) bool
func hasName(decl ast.Decl, name string) bool
so that the former is just the three for loops, and the latter is the switch
statement.
https://codereview.appspot.com/6970051/diff/3001/src/cmd/godoc/godoc.go#newco...
src/cmd/godoc/godoc.go:1001: filter = func(d os.FileInfo) bool {
this is getting big, please move lines 1000 through 1019 to a function, so that
it becomes:
examples, err := parseExamples(fset, path)
if err != nil {
 log.Println("parsing examples:", err)
}
https://codereview.appspot.com/6970051/diff/3001/src/cmd/godoc/godoc.go#newco...
src/cmd/godoc/godoc.go:1017: log.Println("skipping example Example" + e.Name +
": refers to unknown function or type")
log.Printf("ignoring Example%s: refers to unknown declaration", e.Name)
Sign in to reply to this message.
kisielk
Hello golang-dev@googlegroups.com, adg@golang.org (cc: golang-dev@googlegroups.com), Please take another look.
13 years ago (2012年12月20日 05:43:04 UTC) #3
Hello golang-dev@googlegroups.com, adg@golang.org (cc:
golang-dev@googlegroups.com),
Please take another look.
Sign in to reply to this message.
adg
https://codereview.appspot.com/6970051/diff/6003/src/cmd/godoc/godoc.go File src/cmd/godoc/godoc.go (right): https://codereview.appspot.com/6970051/diff/6003/src/cmd/godoc/godoc.go#newcode894 src/cmd/godoc/godoc.go:894: // with a matching name period. https://codereview.appspot.com/6970051/diff/6003/src/cmd/godoc/godoc.go#newcode908 src/cmd/godoc/godoc.go:908: // ...
13 years ago (2012年12月20日 05:49:33 UTC) #4
https://codereview.appspot.com/6970051/diff/6003/src/cmd/godoc/godoc.go
File src/cmd/godoc/godoc.go (right):
https://codereview.appspot.com/6970051/diff/6003/src/cmd/godoc/godoc.go#newco...
src/cmd/godoc/godoc.go:894: // with a matching name
period.
https://codereview.appspot.com/6970051/diff/6003/src/cmd/godoc/godoc.go#newco...
src/cmd/godoc/godoc.go:908: // hasName returns true if decl has a matching name
period.
https://codereview.appspot.com/6970051/diff/6003/src/cmd/godoc/godoc.go#newco...
src/cmd/godoc/godoc.go:934: // parseExamples gets examples for packages in pkgs
from *_test.go files in abspath
s/gets/reads/
s/abspath/dir/
period.
https://codereview.appspot.com/6970051/diff/6003/src/cmd/godoc/godoc.go#newco...
src/cmd/godoc/godoc.go:935: func parseExamples(fset *token.FileSet, pkgs
map[string]*ast.Package, abspath string) ([]*doc.Example, error) {
s/abspath/dir/
https://codereview.appspot.com/6970051/diff/6003/src/cmd/godoc/godoc.go#newco...
src/cmd/godoc/godoc.go:942: } else {
no else needed after return
Sign in to reply to this message.
kisielk
Hello golang-dev@googlegroups.com, adg@golang.org (cc: golang-dev@googlegroups.com), Please take another look.
13 years ago (2012年12月20日 06:03:58 UTC) #5
Sign in to reply to this message.
adg
https://codereview.appspot.com/6970051/diff/2002/src/cmd/godoc/godoc.go File src/cmd/godoc/godoc.go (right): https://codereview.appspot.com/6970051/diff/2002/src/cmd/godoc/godoc.go#newcode951 src/cmd/godoc/godoc.go:951: if name == "" || hasGlobalName(pkgs, name) { I ...
13 years ago (2012年12月20日 06:14:03 UTC) #6
https://codereview.appspot.com/6970051/diff/2002/src/cmd/godoc/godoc.go
File src/cmd/godoc/godoc.go (right):
https://codereview.appspot.com/6970051/diff/2002/src/cmd/godoc/godoc.go#newco...
src/cmd/godoc/godoc.go:951: if name == "" || hasGlobalName(pkgs, name) {
I just realized: this hasGlobalName function is pretty expensive, and we're
doing it for each example in the package.
It might be better to write a function:
function globalNames(pkgs map[string]*ast.Package) map[string]bool
that returns all names in those packages. Call that function once, outside of
these loops. Here, you'd just check for the presence of the name in the map;
cheap.
Furthermore, I don't think this code works with methods. The globalNames
function should, for each method declaration, return the name in the form
Receiver_Method; the same form we use for the example functions.
Sign in to reply to this message.
kisielk
Hello golang-dev@googlegroups.com, adg@golang.org (cc: golang-dev@googlegroups.com), Please take another look.
13 years ago (2012年12月20日 07:35:41 UTC) #7
Sign in to reply to this message.
kisielk
https://codereview.appspot.com/6970051/diff/2002/src/cmd/godoc/godoc.go File src/cmd/godoc/godoc.go (right): https://codereview.appspot.com/6970051/diff/2002/src/cmd/godoc/godoc.go#newcode951 src/cmd/godoc/godoc.go:951: if name == "" || hasGlobalName(pkgs, name) { On ...
13 years ago (2012年12月20日 07:38:19 UTC) #8
https://codereview.appspot.com/6970051/diff/2002/src/cmd/godoc/godoc.go
File src/cmd/godoc/godoc.go (right):
https://codereview.appspot.com/6970051/diff/2002/src/cmd/godoc/godoc.go#newco...
src/cmd/godoc/godoc.go:951: if name == "" || hasGlobalName(pkgs, name) {
On 2012年12月20日 06:14:03, adg wrote:
> I just realized: this hasGlobalName function is pretty expensive, and we're
> doing it for each example in the package.
> 
> It might be better to&nbsp;write a function:
> 
> function globalNames(pkgs map[string]*ast.Package) map[string]bool
> 
> that returns all names in those packages. Call that function once, outside of
> these loops. Here, you'd just check for the presence of the name in the map;
> cheap.
> 
> Furthermore, I don't think this code works with methods. The globalNames
> function should, for each method declaration, return the name in the form
> Receiver_Method; the same form we use for the example functions.
Right on both counts. I was just testing with the errors package which didn't
have any methods. The updated version I just posted I tested with both errors
and regexp and it seems to work correctly in both cases.
I'm a little iffy about the type conversions used when dealing with the AST in
the new changeset...
Sign in to reply to this message.
adg
Way better! https://codereview.appspot.com/6970051/diff/7002/src/cmd/godoc/godoc.go File src/cmd/godoc/godoc.go (right): https://codereview.appspot.com/6970051/diff/7002/src/cmd/godoc/godoc.go#newcode895 src/cmd/godoc/godoc.go:895: func declName(decl ast.Decl) []string { func declNames(decl ...
13 years ago (2012年12月20日 20:21:48 UTC) #9
Way better!
https://codereview.appspot.com/6970051/diff/7002/src/cmd/godoc/godoc.go
File src/cmd/godoc/godoc.go (right):
https://codereview.appspot.com/6970051/diff/7002/src/cmd/godoc/godoc.go#newco...
src/cmd/godoc/godoc.go:895: func declName(decl ast.Decl) []string {
func declNames(decl ast.Decl) (names []string)
https://codereview.appspot.com/6970051/diff/7002/src/cmd/godoc/godoc.go#newco...
src/cmd/godoc/godoc.go:896: var names []string
delete
https://codereview.appspot.com/6970051/diff/7002/src/cmd/godoc/godoc.go#newco...
src/cmd/godoc/godoc.go:915: names = []string{s.Name.Name}
names = append(names, s.Name.Name)
there can be more than one spec
https://codereview.appspot.com/6970051/diff/7002/src/cmd/godoc/godoc.go#newco...
src/cmd/godoc/godoc.go:923: fmt.Println(names)
delete
https://codereview.appspot.com/6970051/diff/7002/src/cmd/godoc/godoc.go#newco...
src/cmd/godoc/godoc.go:924: return names
return
https://codereview.appspot.com/6970051/diff/7002/src/cmd/godoc/godoc.go#newco...
src/cmd/godoc/godoc.go:927: // globalNames returns a map with the values of keys
corresponding to global names in pks set to true.
// globalNames finds all top-level declarations in pkgs and returns a map
// with the identifier names as keys.
https://codereview.appspot.com/6970051/diff/7002/src/cmd/godoc/godoc.go#newco...
src/cmd/godoc/godoc.go:960: _, hasName := globals[name]
delete
can use the bool value instead, it defaults to false if key not present
https://codereview.appspot.com/6970051/diff/7002/src/cmd/godoc/godoc.go#newco...
src/cmd/godoc/godoc.go:961: if name == "" || hasName {
if name == "" || globals[name] {
Sign in to reply to this message.
kisielk
Hello golang-dev@googlegroups.com, adg@golang.org (cc: golang-dev@googlegroups.com), Please take another look.
13 years ago (2012年12月21日 06:08:24 UTC) #10
Sign in to reply to this message.
adg
LGTM
13 years ago (2013年01月02日 04:11:53 UTC) #11
LGTM
Sign in to reply to this message.
adg
*** Submitted as https://code.google.com/p/go/source/detail?r=0dfd8fcdbca5 *** cmd/godoc: ignore misnamed examples and print a warning Fixes issue ...
13 years ago (2013年01月02日 05:00:58 UTC) #12
*** Submitted as https://code.google.com/p/go/source/detail?r=0dfd8fcdbca5 ***
cmd/godoc: ignore misnamed examples and print a warning
Fixes issue 4211.
R=golang-dev, adg
CC=golang-dev
https://codereview.appspot.com/6970051
Committer: Andrew Gerrand <adg@golang.org>
Sign in to reply to this message.
|
This is Rietveld f62528b

AltStyle によって変換されたページ (->オリジナル) /