1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

vdoc: add -comments and new comment merger (#11221)

This commit is contained in:
Leo Developer
2021-08-19 09:20:43 +02:00
committed by GitHub
parent 337c325109
commit 7bffabbce2
15 changed files with 208 additions and 53 deletions

View File

@@ -0,0 +1,7 @@
module main
const (
source_root = 'temp'
)
fn funky()
funky - comment for function below

View File

@@ -0,0 +1,6 @@
module main
const (
source_root = 'temp'
)
fn funky()

View File

@@ -1,8 +1,8 @@
const (
pub const (
source_root = 'temp'
)
// funky - comment for function below
fn funky() {
pub fn funky() {
println('hi')
}

View File

@@ -0,0 +1,9 @@
module main
fn a1()
normal comment
fn a2()
this should be merged into the same line
fn a3()
This should be its own parapgraph, because it ends with a dot.
This should be another paragraph.

View File

@@ -0,0 +1,5 @@
module main
fn a1()
fn a2()
fn a3()

View File

@@ -0,0 +1,16 @@
// normal comment
pub fn a1() {
println('hi')
}
// this should be merged
// into the same line
pub fn a2() {
println('hi')
}
// This should be its own parapgraph, because it ends with a dot.
// This should be another paragraph.
pub fn a3() {
println('hi')
}

View File

@@ -0,0 +1,22 @@
module main
fn funky()
hello
empty line
newline using a full stop.
```v
code
```
test
====
- foo
- bar
# test
########### deep test
#a shouldnt have a newline test
| foo bar | yes |
|-----------|--------|
| working | yup |

View File

@@ -0,0 +1,3 @@
module main
fn funky()

View File

@@ -0,0 +1,23 @@
// hello
//
// empty line
// newline using a full stop.
// ```v
// code
// ```
//
// test
// ====
// - foo
// - bar
// # test
// ########### deep test
// #a shouldnt have a newline
// test
//
// | foo bar | yes |
// |-----------|--------|
// | working | yup |
pub fn funky() {
println('hi')
}

View File

@@ -1 +0,0 @@
vdoc: No documentation found for /v/vmaster/cmd/tools/vdoc/tests/testdata/project1/main.v

View File

@@ -43,25 +43,45 @@ fn check_path(vexe string, dir string, tests []string) int {
expected = clean_line_endings(expected)
found := clean_line_endings(res.output)
if expected != found {
println(term.red('FAIL'))
println('============')
println('expected:')
println(expected)
println('============')
println('found:')
println(found)
println('============\n')
println('diff:')
println(diff.color_compare_strings(diff_cmd, rand.ulid(), found, expected))
println('============\n')
nb_fail++
} else {
print_compare(expected, found)
}
res_comments := os.execute('$vexe doc -comments $program')
if res_comments.exit_code < 0 {
panic(res_comments.output)
}
mut expected_comments := os.read_file(program.replace('main.v', 'main.comments.out')) or {
panic(err)
}
expected_comments = clean_line_endings(expected_comments)
found_comments := clean_line_endings(res_comments.output)
if expected_comments != found_comments {
print_compare(expected_comments, found_comments)
}
if expected == found && expected_comments == found_comments {
println(term.green('OK'))
} else {
nb_fail++
}
}
return nb_fail
}
fn print_compare(expected string, found string) {
println(term.red('FAIL'))
println('============')
println('expected:')
println(expected)
println('============')
println('found:')
println(found)
println('============\n')
println('diff:')
println(diff.color_compare_strings(diff_cmd, rand.ulid(), found, expected))
println('============\n')
}
fn clean_line_endings(s string) string {
mut res := s.trim_space()
res = res.replace(' \n', '\n')

View File

@@ -51,6 +51,7 @@ mut:
is_verbose bool
include_readme bool
include_examples bool = true
include_comments bool // for plaintext
inline_assets bool
no_timestamp bool
output_path string
@@ -95,13 +96,15 @@ fn (vd VDoc) gen_plaintext(d doc.Doc) string {
} else {
pw.writeln('$d.head.content\n')
}
comments := if cfg.include_examples {
d.head.merge_comments()
} else {
d.head.merge_comments_without_examples()
}
if comments.trim_space().len > 0 && !cfg.pub_only {
pw.writeln(comments.split_into_lines().map(' ' + it).join('\n'))
if cfg.include_comments {
comments := if cfg.include_examples {
d.head.merge_comments()
} else {
d.head.merge_comments_without_examples()
}
if comments.trim_space().len > 0 {
pw.writeln(comments.split_into_lines().map(' ' + it).join('\n'))
}
}
vd.write_plaintext_content(d.contents.arr(), mut pw)
return pw.str()
@@ -116,7 +119,7 @@ fn (vd VDoc) write_plaintext_content(contents []doc.DocNode, mut pw strings.Buil
} else {
pw.writeln(cn.content)
}
if cn.comments.len > 0 && !cfg.pub_only {
if cn.comments.len > 0 && cfg.include_comments {
comments := if cfg.include_examples {
cn.merge_comments()
} else {
@@ -414,6 +417,9 @@ fn parse_arguments(args []string) Config {
'-l' {
cfg.show_loc = true
}
'-comments' {
cfg.include_comments = true
}
'-m' {
cfg.is_multi = true
}

View File

@@ -21,8 +21,8 @@ Options:
-o Specifies the output file/folder path where to store the generated docs.
Set it to "stdout" to print the output instead of saving the contents
to a file.
-color Force stdout colorize output.
-no-color Force plain text output, without ANSI colors.
-color Forces stdout colorize output.
-no-color Forces plain text output, without ANSI colors.
-readme Include README.md to docs if present.
-v Enables verbose logging. For debugging purposes.
-no-timestamp Omits the timestamp in the output file.
@@ -31,4 +31,5 @@ For HTML mode:
-inline-assets Embeds the contents of the CSS and JS assets into the webpage directly.
For plain text mode:
-l Show the locations of the generated signatures.
-l Shows the locations of the generated signatures.
-comments Includes comments in the output.