vdoc: plaintext fixes

pull/5095/head
Ned Palacios 2020-06-10 17:14:03 +08:00 committed by GitHub
parent e3c40f1df8
commit 8f9f426479
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 13 deletions

View File

@ -441,13 +441,13 @@ fn (cfg DocConfig) gen_plaintext(idx int) string {
dcs := cfg.docs[idx] dcs := cfg.docs[idx]
mut pw := strings.new_builder(200) mut pw := strings.new_builder(200)
pw.writeln('${dcs.head.content}\n') pw.writeln('${dcs.head.content}\n')
if dcs.head.comment.len > 0 { if dcs.head.comment.trim_space().len > 0 {
pw.writeln('// ' + dcs.head.comment.replace('\n', '\n// ') + '\n') pw.writeln('// ' + dcs.head.comment.replace('\n', '\n// ') + '\n')
} }
for cn in dcs.contents { for cn in dcs.contents {
pw.writeln(cn.content) pw.writeln(cn.content)
if cn.comment.len > 0 { if cn.comment.len > 0 {
pw.writeln('\n' + '\/\/ ' + cn.comment.trim_space()) pw.writeln('\/\/ ' + cn.comment.trim_space() + '\n')
} }
if cfg.show_loc { if cfg.show_loc {
pw.writeln('Location: ${cn.file_path}:${cn.pos.line}:${cn.pos.col}\n\n') pw.writeln('Location: ${cn.file_path}:${cn.pos.line}:${cn.pos.col}\n\n')

View File

@ -119,7 +119,6 @@ pub fn (mut a array) sort_with_compare(compare voidptr) {
// In the current state only that would work: // In the current state only that would work:
// i := 3 // i := 3
// a.insert(0, &i) // a.insert(0, &i)
// ----------------------------
pub fn (mut a array) insert(i int, val voidptr) { pub fn (mut a array) insert(i int, val voidptr) {
$if !no_bounds_checking? { $if !no_bounds_checking? {
if i < 0 || i > a.len { if i < 0 || i > a.len {
@ -135,7 +134,6 @@ pub fn (mut a array) insert(i int, val voidptr) {
// TODO array.prepend is broken // TODO array.prepend is broken
// It depends on array.insert // It depends on array.insert
// -----------------------------
pub fn (mut a array) prepend(val voidptr) { pub fn (mut a array) prepend(val voidptr) {
a.insert(0, val) a.insert(0, val)
} }

View File

@ -298,20 +298,23 @@ pub fn (mut d Doc) generate() ?bool {
prev_comments << stmt prev_comments << stmt
continue continue
} }
// TODO: Fetch head comment once
if stmt is ast.Module { if stmt is ast.Module {
// the previous comments were probably a copyright/license one // the previous comments were probably a copyright/license one
module_comment := get_comment_block_right_before(prev_comments) module_comment := get_comment_block_right_before(prev_comments)
prev_comments = [] prev_comments = []
if module_comment == '' { if 'vlib' !in base_path && !module_comment.starts_with('Copyright (c)') {
continue if module_comment == '' {
continue
}
if module_comment == d.head.comment {
continue
}
if d.head.comment != '' {
d.head.comment += '\n'
}
d.head.comment += module_comment
} }
if module_comment == d.head.comment {
continue
}
if d.head.comment != '' {
d.head.comment += '\n'
}
d.head.comment += module_comment
continue continue
} }
if last_import_stmt_idx > 0 && sidx == last_import_stmt_idx { if last_import_stmt_idx > 0 && sidx == last_import_stmt_idx {