Repository navigation
✨ sphinx-codelinks: VHDL comment type - #2077
lennard-ub wants to merge 1 commit into
Conversation
Documentation build overview
54 files changed ·
|
ubmarco
left a comment
There was a problem hiding this comment.
Reviewed together with its ubCode counterpart, useblocks/ubcode#3875. The extraction itself is careful. Master has gained more than 100 commits since 6434aef0, including the scope snapshots (#2128), physical columns (#2129), multi-line needs (#2152) and TypeScript (#2166). So the rebase re-plugs VHDL into those seams. Two behaviour decisions come first; they apply to both repositories.
1. Scope association: a VHDL rule instead of the generic walk
find_next_scope binds a marker to the next scope-kind sibling anywhere further down. VHDL code is mostly declarations and concurrent statements, so that puts markers on the wrong construct. Measured with a standalone probe on 72 VHDL samples (82 markers); tree-sitter-vhdl 1.4.0 and 2.0.3 agree on every one.
| Marker | binds with this PR's tables | should bind |
|---|---|---|
above u_fifo : entity work.fifo … |
the next process | the instantiation |
above or trailing led_o <= …; |
the next process | the assignment |
above or trailing a signal or constant |
a later function, or the architecture | the declaration |
trailing a port (clk : in std_logic; --! …) |
the entity | the port |
above a process inside for … generate |
the generate | the process |
| above the first procedure of a process | the process | the procedure |
above a function in a block's declarations |
the block | the function |
The rule, as a VHDL branch of find_associated_scope (YAML and JSONC have their own):
- Trailing comment (a preceding non-comment sibling ends on the comment's row): the innermost design element ending on that row, which reaches a port inside
interface_list. If there is none, the nearest enclosing design element. Comment siblings are skipped when looking back, because a VHDLline_commentholds its newline, so the comment on the row above "ends" on this row. - Leading comment: the next non-comment sibling, if it is a design element.
- If that sibling is a wrapper (
design_unit,process_head,block_head,generate_head,generate_block,interface_list), its first non-comment item instead. In adesign_unit, that is the first item after thelibrary,useand context clauses. - The walk never passes a sibling. This is the first fix candidate of #2151, so VHDL starts where the other languages are heading.
- If that sibling is a wrapper (
- Otherwise the nearest enclosing design element, or none at file level.
Design elements, for SCOPE_NODE_TYPES[CommentType.vhdl], are 37 kinds:
- Design units:
entity_declaration,architecture_definition,package_declaration,package_definition,package_instantiation_declaration,configuration_declaration,context_declaration. - Subprograms:
subprogram_declaration,subprogram_definition,subprogram_instantiation_declaration. - Declarations:
type_declaration,subtype_declaration,component_declaration,constant_declaration,signal_declaration,variable_declaration,file_declaration,alias_declaration. - Generics, ports and parameters:
interface_declarationand the seveninterface_*_declarationkinds. - Concurrent statements:
process_statement,block_statement, the three*_generate_statementkinds,component_instantiation_statement, the threeconcurrent_*_signal_assignmentkinds,concurrent_assertion_statement,concurrent_procedure_call_statement.
Sequential statements are not design elements: a marker among them documents its process or subprogram. Each of the six wrappers is needed by at least one probe marker. Under this rule, 36 of the 82 markers bind differently than with this PR's tables. The hard-coded {"block", "design_unit"} in the shared find_next_scope goes. FE_VHDL's "Accurate scope detection for nested structures" then holds; today a process inside a generate binds to the generate.
2. Doxygen --! lines become needs with garbage ids
--! is Doxygen's VHDL comment. Through the shared one-line parser, sphinx-codelinks 2.0.0 turns these lines into needs, with no warning:
--! @brief Counter with enable, reset and loadbecomes a need with the idreset and load.--! @param clk Clock input, rising edge activebecomes a need with the idrising edge active.- The tag lines without a comma are dropped silently.
This is #2171 for VHDL, whose scope (/**, /*!, ///) misses --!. Implement doxygen_tag here for --! lines and write the shared corpus file's header, with the command list and the rule text, as jsdoc.yaml has. #2171 then only adds its three comment forms.
3. Rebase
LINE_DELIMITERSinanalyse/multiline_parser.pylacks--._classifytherefore returns"unknown"for-- @need …: no run forms, the lines are read unstripped, andopen_restnever sees the open word.- The
analyse.pyhunk goes: that code is gone._row_countand_line_comment_linealready handle a comment node that ends in its newline. Rust's///node does too, contrary to the description. VHDL_QUERYis word-for-wordRUST_QUERY; reuse it.COMMENT_MARKERSinconfig.pyhas no readers on master.- The extraction snapshot is in the pre-#2128 format and gets regenerated.
- In
uv.lock, keep only the semantic hunk; most of the diff is fork-marker churn. - The description's "
@rstblocks work" is obsolete since #2152.
4. Declarative fixtures
The 9 scope cases in test_analyse_utils.py assert result in text, which also passes on the enclosing node. Three of them would still pass if process_statement or subprogram_definition were missing from the table. The corpus's tagged_scope_type exists for exactly this, so the VHDL cases belong there:
scope.yaml: one case per row of the table in point 1.positions.yaml: the newline-inclusive node's end column, no newline at EOF, and a trailing comment after code.line_endings.yaml: with CRLF the node keeps\rand drops\n; with LF it keeps\n.multiline_needs.yaml,need_refs.yamland thedoxygen_tagcases.
5. Grammar floor
The floor is >=1.5.0 and the lock resolves 2.0.3, but the grammar's crates.io binding stops at 1.4.0. 1.4.0 and 2.0.3 agreed on every probe marker. Unless 1.5.0 is needed for something specific, >=1.4.0 keeps a Rust consumer of the same corpus inside the supported range.
4513c5b to
9ecafa2
Compare
9ecafa2 to
12ad472
Compare
`comment_type = "vhdl"` analyses `.vhd` and `.vhdl` files, their `--` and VHDL-2008 `/* */` comments, with the tree-sitter-vhdl grammar. - Scope: a VHDL branch of `find_associated_scope` binds a marker to the design element next to it (37 kinds in `SCOPE_NODE_TYPES`): a trailing marker to the innermost element ending on its row, a leading one to the next sibling or a wrapper's first item, never past a sibling, and otherwise to the enclosing element. - Multi-line needs: `--` and `--!` join `LINE_DELIMITERS`. - Doxygen: a command line in a `--!` comment is a `doxygen_tag` warning, not a need, under the narrowed `jsdoc_tag` rule. The command list and the rule live in the new shared corpus file `doxygen.yaml`. - Corpus: VHDL cases in scope, positions, line_endings, multiline_needs, need_refs and extra_languages.
12ad472 to
ee8e051
Compare
How the review findings were addressedEverything since your review (2026-10-19) is in 1. Scope: a VHDL rule instead of the generic walk
2. Doxygen
|
| File | Cases |
|---|---|
scope |
10 |
positions |
vhdl_line_comment_end (own line and after code), vhdl_no_newline_at_eof |
line_endings |
vhdl_crlf |
multiline_needs |
vhdl_dash_run, vhdl_doxygen_run |
need_refs |
vhdl_marker: -- and VHDL-2008 /* */ |
doxygen |
6 |
extra_languages |
default_oneliner_vhdl |
The shared discover_fixtures.json gains a vhdl_comment_type case (.vhd / .vhdl), so discovery is pinned too.
Also dropped from the first version: doc_test/vhdl_basic, tests/data/vhdl/demo.vhd and its test_analyse.py case. Bash and TypeScript have none either.
5. Grammar floor
tree-sitter-vhdl>=1.4.0. The whole suite (1103 tests, the shared corpus included) passes under 1.4.0 and under the locked 2.0.3.
Verified
uv run poe test-codelinks: 1103 passed, none skipped.poe lint,poe typecheckandpoe docs-codelinks(-nW) pass. CI: 36/36.- End to end: one project with one
ubproject.toml, built with Sphinx + sphinx-codelinks and withubc build html, gives the same one-line and multi-line needs and the samedoxygen_tagwarning on the same line. - ubCode side: useblocks/ubcode#3875 syncs this commit's snapshots. Its parity gate is green on all 242 shared cases, and goes red, naming the VHDL cases, when the Rust VHDL rule or the
--!gate is broken on purpose.
Adds VHDL as a sphinx-codelinks comment type. Rebased onto master
e29e35bc, so VHDL now uses the scope snapshots (#2128), physical columns (#2129), multi-line needs (#2152) and the TypeScript work (#2166). The ubCode counterpart is useblocks/ubcode#3875; both run the same shared corpus.What
comment_type = "vhdl"analyses.vhdand.vhdlfiles:--line comments and VHDL-2008/* */block comments. The grammar istree-sitter-vhdl>=1.4.0, and the query reusesRUST_QUERY, since VHDL names its two comment kinds the same way.find_associated_scope,find_vhdl_associated_scope, implements the rule from the review.design_unitthat is the first item after the context clauses.SCOPE_NODE_TYPES[CommentType.vhdl].find_next_scopeis unchanged.--and--!joinLINE_DELIMITERS.--!is to--what//!is to//, so a Doxygen run forms a block too.--!comment line that starts with a Doxygen command is adoxygen_tagwarning, never a need. The rule is the narrowedjsdoc_tagrule: only under the start sequence@, and only where the one-line parser would have read the line. The command end is a space, a tab,[,{or the line end, so@param[in]counts.doxygen.yaml, so A Doxygen tag line with a comma in a C/C++, C# or Go /** */ comment becomes a need with a garbage id #2171 only needs to add its/**,/*!and///forms.Review points
vhdl_*case inscope.yaml, pinned bytagged_scope_type. More cases cover thedesign_unit/interface_listwrappers, a sequential statement (binds its process) and the file level (no scope).doxygen_tag: implemented, with the shared corpus header described above.LINE_DELIMITERSgains--and--!.analyse.pyhunk is gone.RUST_QUERYis reused.COMMENT_MARKERSis left alone.uv.lockholds only the semantic hunk (+18 lines);uv lock --checkwith the hook's uv 0.12.18 passes.@rstblocks work".scope,positions(end column of the newline-inclusive node, no newline at EOF, a comment after code),line_endings(CRLF),multiline_needs(--and--!runs),need_refs,doxygenandextra_languages. The shareddiscover_fixtures.jsongains avhdl_comment_typecase. Theresult in textunit tests of the first version are not ported.>=1.4.0. The whole suite passes under 1.4.0 and under the locked 2.0.3.No
doc_testproject: Bash and TypeScript have none, and the corpus covers extraction.Checked locally
uv run poe test-codelinks: 1103 passed, none skipped. The suite passes again withtree-sitter-vhdl==1.4.0.uv run poe lint,uv run poe typecheckanduv run poe docs-codelinks(-nW) pass.ubproject.toml, built with Sphinx and with ubCode'subc build html, gives the same one-line and multi-line needs and the samedoxygen_tagwarning.