Skip to content

Commit

Permalink
Merge pull request #1746 from visualfc/comment
Browse files Browse the repository at this point in the history
cl: commentFunc set //line before doc
  • Loading branch information
xushiwei committed Feb 15, 2024
2 parents c84d8bd + 09ed4f9 commit 8fcb42b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 2 additions & 4 deletions cl/compile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4141,9 +4141,8 @@ func (pt *Point) Test() {
//line /foo/bar.gop:8:1
fmt.Println(pt.x, pt.y)
}
//line /foo/bar.gop:11:1
// testPoint is test point
//
//line /foo/bar.gop:12:1
func testPoint() {
//line /foo/bar.gop:13:1
var pt Point
Expand Down Expand Up @@ -4196,9 +4195,8 @@ func (pt *Point) Test() {
//line ../bar.gop:8:1
fmt.Println(pt.x, pt.y)
}
//line ../bar.gop:11:1
// testPoint is test point
//
//line ../bar.gop:12:1
func testPoint() {
//line ../bar.gop:13:1
var pt Point
Expand Down
6 changes: 4 additions & 2 deletions cl/stmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ func commentStmtEx(cb *gox.CodeBuilder, ctx *pkgCtx, stmt ast.Stmt) {
func commentFunc(ctx *blockCtx, fn *gox.Func, decl *ast.FuncDecl) {
start := decl.Name.Pos()
if ctx.fileLine && start != token.NoPos {
if decl.Doc != nil {
start = decl.Doc.Pos()
}
pos := ctx.fset.Position(start)
if ctx.relBaseDir != "" {
pos.Filename = fileLineFile(ctx.relBaseDir, pos.Filename)
Expand All @@ -78,11 +81,10 @@ func commentFunc(ctx *blockCtx, fn *gox.Func, decl *ast.FuncDecl) {
line = fmt.Sprintf("//line %s:%d:1", pos.Filename, pos.Line)
}
doc := &goast.CommentGroup{}
doc.List = append(doc.List, &goast.Comment{Text: line})
if decl.Doc != nil {
doc.List = append(doc.List, decl.Doc.List...)
doc.List = append(doc.List, &goast.Comment{Text: "//"})
}
doc.List = append(doc.List, &goast.Comment{Text: line})
fn.SetComments(ctx.pkg, doc)
} else if decl.Doc != nil {
fn.SetComments(ctx.pkg, decl.Doc)
Expand Down

0 comments on commit 8fcb42b

Please sign in to comment.