Commit 6706931a authored by Russ Cox's avatar Russ Cox

go/doc: restore handling of multi-paragraph BUG comments

It was lost when the generic "Notes" support went in.

Had to change the test setup, because it precluded even
being able test multi-line comments, much less multi-paragraph
comments.

Now 'godoc sync/atomic' works correctly again.

Fixes #6135.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/13427045
parent 159c2b7e
...@@ -32,6 +32,7 @@ func readTemplate(filename string) *template.Template { ...@@ -32,6 +32,7 @@ func readTemplate(filename string) *template.Template {
t.Funcs(template.FuncMap{ t.Funcs(template.FuncMap{
"node": nodeFmt, "node": nodeFmt,
"synopsis": synopsisFmt, "synopsis": synopsisFmt,
"indent": indentFmt,
}) })
return template.Must(t.ParseFiles(filepath.Join(dataDir, filename))) return template.Must(t.ParseFiles(filepath.Join(dataDir, filename)))
} }
...@@ -55,6 +56,15 @@ func synopsisFmt(s string) string { ...@@ -55,6 +56,15 @@ func synopsisFmt(s string) string {
return "// " + strings.Replace(s, "\n", " ", -1) return "// " + strings.Replace(s, "\n", " ", -1)
} }
func indentFmt(indent, s string) string {
end := ""
if strings.HasSuffix(s, "\n") {
end = "\n"
s = s[:len(s)-1]
}
return indent + strings.Replace(s, "\n", "\n"+indent, -1) + end
}
func isGoFile(fi os.FileInfo) bool { func isGoFile(fi os.FileInfo) bool {
name := fi.Name() name := fi.Name()
return !fi.IsDir() && return !fi.IsDir() &&
......
...@@ -414,7 +414,7 @@ func (r *reader) readNote(list []*ast.Comment) { ...@@ -414,7 +414,7 @@ func (r *reader) readNote(list []*ast.Comment) {
// We remove any formatting so that we don't // We remove any formatting so that we don't
// get spurious line breaks/indentation when // get spurious line breaks/indentation when
// showing the TODO body. // showing the TODO body.
body := clean(text[m[1]:]) body := clean(text[m[1]:], keepNL)
if body != "" { if body != "" {
marker := text[m[2]:m[3]] marker := text[m[2]:m[3]]
r.notes[marker] = append(r.notes[marker], &Note{ r.notes[marker] = append(r.notes[marker], &Note{
......
...@@ -27,14 +27,20 @@ func firstSentenceLen(s string) int { ...@@ -27,14 +27,20 @@ func firstSentenceLen(s string) int {
return len(s) return len(s)
} }
const (
keepNL = 1 << iota
)
// clean replaces each sequence of space, \n, \r, or \t characters // clean replaces each sequence of space, \n, \r, or \t characters
// with a single space and removes any trailing and leading spaces. // with a single space and removes any trailing and leading spaces.
func clean(s string) string { // If the keepNL flag is set, newline characters are passed through
// instead of being change to spaces.
func clean(s string, flags int) string {
var b []byte var b []byte
p := byte(' ') p := byte(' ')
for i := 0; i < len(s); i++ { for i := 0; i < len(s); i++ {
q := s[i] q := s[i]
if q == '\n' || q == '\r' || q == '\t' { if (flags&keepNL) == 0 && q == '\n' || q == '\r' || q == '\t' {
q = ' ' q = ' '
} }
if q != ' ' || p != ' ' { if q != ' ' || p != ' ' {
...@@ -57,7 +63,7 @@ func clean(s string) string { ...@@ -57,7 +63,7 @@ func clean(s string) string {
// is the empty string. // is the empty string.
// //
func Synopsis(s string) string { func Synopsis(s string) string {
s = clean(s[0:firstSentenceLen(s)]) s = clean(s[0:firstSentenceLen(s)], 0)
for _, prefix := range IllegalPrefixes { for _, prefix := range IllegalPrefixes {
if strings.HasPrefix(strings.ToLower(s), prefix) { if strings.HasPrefix(strings.ToLower(s), prefix) {
return "" return ""
......
...@@ -9,24 +9,44 @@ FILENAMES ...@@ -9,24 +9,44 @@ FILENAMES
testdata/a1.go testdata/a1.go
BUGS .Bugs is now deprecated, please use .Notes instead BUGS .Bugs is now deprecated, please use .Notes instead
// bug0 bug0
// bug1
bug1
BUGS BUGS
// bug0 (uid: uid) BUG(uid) bug0
// bug1 (uid: uid)
BUG(uid) bug1
NOTES NOTES
// 1 of 4 - this is the first line of note 1 - note 1 continues on ... (uid: foo) NOTE(uid)
// 2 of 4 (uid: foo)
// 3 of 4 (uid: bar) NOTE(foo) 1 of 4 - this is the first line of note 1
// 4 of 4 - this is the last line of note 4 (uid: bar) - note 1 continues on this 2nd line
// This note which contains a (parenthesized) subphrase must ... (uid: bam) - note 1 continues on this 3rd line
// The ':' after the marker and uid is optional. (uid: xxx)
NOTE(foo) 2 of 4
NOTE(bar) 3 of 4
NOTE(bar) 4 of 4
- this is the last line of note 4
NOTE(bam) This note which contains a (parenthesized) subphrase
must appear in its entirety.
NOTE(xxx) The ':' after the marker and uid is optional.
SECBUGS SECBUGS
// sec hole 0 need to fix asap (uid: uid) SECBUG(uid) sec hole 0
need to fix asap
TODOS TODOS
// todo0 (uid: uid) TODO(uid) todo0
// todo1 (uid: uid)
TODO(uid) todo1
...@@ -9,24 +9,44 @@ FILENAMES ...@@ -9,24 +9,44 @@ FILENAMES
testdata/a1.go testdata/a1.go
BUGS .Bugs is now deprecated, please use .Notes instead BUGS .Bugs is now deprecated, please use .Notes instead
// bug0 bug0
// bug1
bug1
BUGS BUGS
// bug0 (uid: uid) BUG(uid) bug0
// bug1 (uid: uid)
BUG(uid) bug1
NOTES NOTES
// 1 of 4 - this is the first line of note 1 - note 1 continues on ... (uid: foo) NOTE(uid)
// 2 of 4 (uid: foo)
// 3 of 4 (uid: bar) NOTE(foo) 1 of 4 - this is the first line of note 1
// 4 of 4 - this is the last line of note 4 (uid: bar) - note 1 continues on this 2nd line
// This note which contains a (parenthesized) subphrase must ... (uid: bam) - note 1 continues on this 3rd line
// The ':' after the marker and uid is optional. (uid: xxx)
NOTE(foo) 2 of 4
NOTE(bar) 3 of 4
NOTE(bar) 4 of 4
- this is the last line of note 4
NOTE(bam) This note which contains a (parenthesized) subphrase
must appear in its entirety.
NOTE(xxx) The ':' after the marker and uid is optional.
SECBUGS SECBUGS
// sec hole 0 need to fix asap (uid: uid) SECBUG(uid) sec hole 0
need to fix asap
TODOS TODOS
// todo0 (uid: uid) TODO(uid) todo0
// todo1 (uid: uid)
TODO(uid) todo1
...@@ -9,24 +9,44 @@ FILENAMES ...@@ -9,24 +9,44 @@ FILENAMES
testdata/a1.go testdata/a1.go
BUGS .Bugs is now deprecated, please use .Notes instead BUGS .Bugs is now deprecated, please use .Notes instead
// bug0 bug0
// bug1
bug1
BUGS BUGS
// bug0 (uid: uid) BUG(uid) bug0
// bug1 (uid: uid)
BUG(uid) bug1
NOTES NOTES
// 1 of 4 - this is the first line of note 1 - note 1 continues on ... (uid: foo) NOTE(uid)
// 2 of 4 (uid: foo)
// 3 of 4 (uid: bar) NOTE(foo) 1 of 4 - this is the first line of note 1
// 4 of 4 - this is the last line of note 4 (uid: bar) - note 1 continues on this 2nd line
// This note which contains a (parenthesized) subphrase must ... (uid: bam) - note 1 continues on this 3rd line
// The ':' after the marker and uid is optional. (uid: xxx)
NOTE(foo) 2 of 4
NOTE(bar) 3 of 4
NOTE(bar) 4 of 4
- this is the last line of note 4
NOTE(bam) This note which contains a (parenthesized) subphrase
must appear in its entirety.
NOTE(xxx) The ':' after the marker and uid is optional.
SECBUGS SECBUGS
// sec hole 0 need to fix asap (uid: uid) SECBUG(uid) sec hole 0
need to fix asap
TODOS TODOS
// todo0 (uid: uid) TODO(uid) todo0
// todo1 (uid: uid)
TODO(uid) todo1
//
PACKAGE bugpara
IMPORTPATH
testdata/bugpara
FILENAMES
testdata/bugpara.go
BUGS .Bugs is now deprecated, please use .Notes instead
Sometimes bugs have multiple paragraphs.
Like this one.
BUGS
BUG(rsc) Sometimes bugs have multiple paragraphs.
Like this one.
//
PACKAGE bugpara
IMPORTPATH
testdata/bugpara
FILENAMES
testdata/bugpara.go
BUGS .Bugs is now deprecated, please use .Notes instead
Sometimes bugs have multiple paragraphs.
Like this one.
BUGS
BUG(rsc) Sometimes bugs have multiple paragraphs.
Like this one.
//
PACKAGE bugpara
IMPORTPATH
testdata/bugpara
FILENAMES
testdata/bugpara.go
BUGS .Bugs is now deprecated, please use .Notes instead
Sometimes bugs have multiple paragraphs.
Like this one.
BUGS
BUG(rsc) Sometimes bugs have multiple paragraphs.
Like this one.
package bugpara
// BUG(rsc): Sometimes bugs have multiple paragraphs.
//
// Like this one.
...@@ -61,8 +61,8 @@ TYPES ...@@ -61,8 +61,8 @@ TYPES
*/}}{{with .Bugs}} */}}{{with .Bugs}}
BUGS .Bugs is now deprecated, please use .Notes instead BUGS .Bugs is now deprecated, please use .Notes instead
{{range .}} {{synopsis .}} {{range .}}{{indent "\t" .}}
{{end}}{{end}}{{with .Notes}}{{range $marker, $content := .}} {{end}}{{end}}{{with .Notes}}{{range $marker, $content := .}}
{{$marker}}S {{$marker}}S
{{range $content}} {{synopsis .Body}} (uid: {{.UID}}) {{range $content}}{{$marker}}({{.UID}}){{indent "\t" .Body}}
{{end}}{{end}}{{end}} {{end}}{{end}}{{end}}
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment