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

tools: support VDOC_SORT=false ./v doc time

This commit is contained in:
Delyan Angelov 2023-03-30 14:33:23 +03:00
parent b9352ce834
commit 214f72ba03
3 changed files with 18 additions and 4 deletions

View File

@ -394,9 +394,13 @@ fn doc_node_html(dn doc.DocNode, link string, head bool, include_examples bool,
node_class := if dn.kind == .const_group { ' const' } else { '' }
sym_name := get_sym_name(dn)
mut deprecated_tags := dn.tags.filter(it.starts_with('deprecated'))
deprecated_tags.sort()
if doc.should_sort {
deprecated_tags.sort()
}
mut tags := dn.tags.filter(!it.starts_with('deprecated'))
tags.sort()
if doc.should_sort {
tags.sort()
}
mut node_id := get_node_id(dn)
mut hash_link := if !head { ' <a href="#${node_id}">#</a>' } else { '' }
if head && is_module_readme(dn) {

View File

@ -1,5 +1,9 @@
module doc
import os
pub const should_sort = os.getenv_opt('VDOC_SORT') or { 'true' }.bool()
pub fn (nodes []DocNode) find(symname string) !DocNode {
for node in nodes {
if node.name != symname {
@ -12,12 +16,16 @@ pub fn (nodes []DocNode) find(symname string) !DocNode {
// sort_by_name sorts the array based on the symbol names.
pub fn (mut nodes []DocNode) sort_by_name() {
nodes.sort_with_compare(compare_nodes_by_name)
if doc.should_sort {
nodes.sort_with_compare(compare_nodes_by_name)
}
}
// sort_by_kind sorts the array based on the symbol kind.
pub fn (mut nodes []DocNode) sort_by_kind() {
nodes.sort_with_compare(compare_nodes_by_kind)
if doc.should_sort {
nodes.sort_with_compare(compare_nodes_by_kind)
}
}
fn compare_nodes_by_kind(a &DocNode, b &DocNode) int {

View File

@ -39,3 +39,5 @@ For HTML mode:
For plain text mode:
-l Shows the locations of the generated signatures.
-comments Includes comments in the output.
Note: set the environment variable `VDOC_SORT` to `false`, to avoid sorting the output.