vdoc: fix 'module, comment, import' sequence bug
parent
11b7b97311
commit
0058b8253d
|
@ -403,6 +403,9 @@ fn (cfg DocConfig) gen_plaintext(idx int) string {
|
|||
dcs := cfg.docs[idx]
|
||||
mut pw := strings.new_builder(200)
|
||||
pw.writeln('${dcs.head.content}\n')
|
||||
if dcs.head.comment.len > 0 {
|
||||
pw.writeln('// ' + dcs.head.comment.replace('\n', '\n// ') + '\n')
|
||||
}
|
||||
for cn in dcs.contents {
|
||||
pw.writeln(cn.content)
|
||||
if cn.comment.len > 0 {
|
||||
|
@ -553,8 +556,12 @@ fn (mut cfg DocConfig) generate_docs_from_file() {
|
|||
cfg.vprintln('Rendering docs...')
|
||||
if cfg.output_path.len == 0 {
|
||||
outputs := cfg.render()
|
||||
first := outputs.keys()[0]
|
||||
println(outputs[first])
|
||||
if outputs.size == 0 {
|
||||
println('No documentation for $dirs')
|
||||
} else {
|
||||
first := outputs.keys()[0]
|
||||
println(outputs[first])
|
||||
}
|
||||
} else {
|
||||
if !os.is_dir(cfg.output_path) {
|
||||
cfg.output_path = os.real_path('.')
|
||||
|
|
|
@ -40,6 +40,17 @@ pub mut:
|
|||
parent_type string = ''
|
||||
}
|
||||
|
||||
pub fn merge_comments(stmts []ast.Stmt) string {
|
||||
mut res := []string{}
|
||||
for s in stmts {
|
||||
if s is ast.Comment {
|
||||
c := s as ast.Comment
|
||||
res << c.text.trim_left('|')
|
||||
}
|
||||
}
|
||||
return res.join('\n')
|
||||
}
|
||||
|
||||
pub fn get_comment_block_right_before(stmts []ast.Stmt) string {
|
||||
if stmts.len == 0 {
|
||||
return ''
|
||||
|
@ -263,9 +274,17 @@ pub fn (mut d Doc) generate() ?bool {
|
|||
} else if file_ast.mod.name != orig_mod_name {
|
||||
continue
|
||||
}
|
||||
mut prev_comments := []ast.Stmt{}
|
||||
stmts := file_ast.stmts
|
||||
for o, stmt in stmts {
|
||||
//
|
||||
mut last_import_stmt_idx := 0
|
||||
for sidx, stmt in stmts {
|
||||
if stmt is ast.Import {
|
||||
last_import_stmt_idx = sidx
|
||||
}
|
||||
}
|
||||
mut prev_comments := []ast.Stmt{}
|
||||
mut imports_section := true
|
||||
for sidx, stmt in stmts {
|
||||
//eprintln('stmt typeof: ' + typeof(stmt))
|
||||
if stmt is ast.Comment {
|
||||
prev_comments << stmt
|
||||
|
@ -287,6 +306,20 @@ pub fn (mut d Doc) generate() ?bool {
|
|||
d.head.comment += module_comment
|
||||
continue
|
||||
}
|
||||
if last_import_stmt_idx > 0 && sidx == last_import_stmt_idx {
|
||||
// the accumulated comments were interspersed before/between the imports;
|
||||
// just add them all to the module comment:
|
||||
import_comments := merge_comments(prev_comments)
|
||||
if d.head.comment != '' {
|
||||
d.head.comment += '\n'
|
||||
}
|
||||
d.head.comment += import_comments
|
||||
prev_comments = []
|
||||
imports_section = false
|
||||
}
|
||||
if stmt is ast.Import {
|
||||
continue
|
||||
}
|
||||
signature := d.get_signature(stmt)
|
||||
pos := d.get_pos(stmt)
|
||||
mut name := d.get_name(stmt)
|
||||
|
@ -316,7 +349,7 @@ pub fn (mut d Doc) generate() ?bool {
|
|||
}
|
||||
if stmt is ast.ConstDecl {
|
||||
if const_idx == -1 {
|
||||
const_idx = o
|
||||
const_idx = sidx
|
||||
} else {
|
||||
node.parent_type = 'Constants'
|
||||
}
|
||||
|
|
|
@ -129,8 +129,16 @@ fn (mut p Parser) parse() ast.File {
|
|||
module_decl := p.module_decl()
|
||||
stmts << module_decl
|
||||
// imports
|
||||
for p.tok.kind == .key_import {
|
||||
stmts << p.import_stmt()
|
||||
for {
|
||||
if p.tok.kind == .key_import {
|
||||
stmts << p.import_stmt()
|
||||
continue
|
||||
}
|
||||
if p.tok.kind == .comment {
|
||||
stmts << p.comment()
|
||||
continue
|
||||
}
|
||||
break
|
||||
}
|
||||
for {
|
||||
if p.tok.kind == .eof {
|
||||
|
|
Loading…
Reference in New Issue