From 214f72ba034ea6927feb952e018730588838f1f4 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Thu, 30 Mar 2023 14:33:23 +0300 Subject: [PATCH] tools: support `VDOC_SORT=false ./v doc time` --- cmd/tools/vdoc/html.v | 8 ++++++-- vlib/v/doc/node.v | 12 ++++++++++-- vlib/v/help/common/doc.txt | 2 ++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/cmd/tools/vdoc/html.v b/cmd/tools/vdoc/html.v index 06b607f189..92bf83e5ee 100644 --- a/cmd/tools/vdoc/html.v +++ b/cmd/tools/vdoc/html.v @@ -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 { ' #' } else { '' } if head && is_module_readme(dn) { diff --git a/vlib/v/doc/node.v b/vlib/v/doc/node.v index 954360fb3d..a7803bff73 100644 --- a/vlib/v/doc/node.v +++ b/vlib/v/doc/node.v @@ -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 { diff --git a/vlib/v/help/common/doc.txt b/vlib/v/help/common/doc.txt index 96942f0fd3..7683f92b89 100644 --- a/vlib/v/help/common/doc.txt +++ b/vlib/v/help/common/doc.txt @@ -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.