Skip to content

feat(markdown): add Labeled blocks, programmatic Document builder, and spatial paint index - #70

Merged
Mucheen merged 3 commits into
mainfrom
feat/doc-comment-markdown
Nov 28, 2026
Merged

Mucheen merged 3 commits into
mainfrom
feat/doc-comment-markdown

Conversation

@Mucheen

@Mucheen Mucheen commented Nov 27, 2026

Copy link
Copy Markdown

What this changes

  • markdown/markdown.go & markdown/builder.go:
    • Add a generic borderless two-column Labeled block kind (labelLo/labelHi, Document.LabelSpans) for aligned key/value or metadata sections without hardcoding any domain-specific tag semantics.
    • Add a programmatic builder API on markdown.Document (Reset, AppendParagraph, AppendHeading, AppendItem, AppendCode, AppendRule, AppendLabeled, AppendTable, and AllocatedBytes) so host applications with pre-parsed structured IR can populate markdown.Document directly without re-serializing to Markdown text.
  • components/markdown.go, components/markdown_index.go, components/markdown_index_test.go, components/doc_test.go:
    • Render markdown.Labeled blocks with a shared aligned label column width measured across consecutive labeled blocks.
    • Build a four-level vertical spatial index (blockSpans → tableRows → cellSpans → rowSpans), depth-bucketed disjoint quote-bar index (quoteBarIdx[8]), and an independent plainPieces binary-search index for CaretAt, while preserving original reading order across pieces, plain, boxes, links, and images.
    • Expose MarkdownView.AllocatedBytes() and MarkdownView.BlockAnchorTop(blockIndex) for cache-budget accounting and local section anchor navigation.
    • Register markdown_index.go in docPrimaryEntries (components/doc_test.go).

Why

Applications embedding native rich-text documentation (such as rendered documentation comments and quick-doc popups with large tables, long blockquotes, and aligned metadata rows like Since: / See also: / Author: / Type parameters:) need:

  1. Direct IR-to-markdown.Document population without round-tripping through Markdown syntax.
  2. Borderless two-column aligned rows as a generic document layout primitive.
  3. Allocation-free, sub-linear clipped Paint and CaretAt lookups even for tall table cells or multi-hundred-paragraph quote blocks, plus deterministic memory accounting and top-level block anchor coordinates.

How it was verified

  • gofmt -l over modified/added Go files (clean)
  • go vet ./... (passed)
  • go test ./markdown/... ./components/... -count=1 (passed, including TestDocCatalogCoversEveryComponent, Labeled alignment, opaque links, 1-row 1,100-line tall table cell, and 600-paragraph quote bar tests)
  • GOOS=windows GOARCH=amd64 go build ./... and GOOS=windows GOARCH=arm64 go build ./... (passed)
  • Benchmark (components/markdown_index_test.go, Apple M5, go test -run '^$' -bench '^BenchmarkMarkdownViewClippedPaintSteady' -benchmem -count 3 -benchtime 200ms ./components):
    • BenchmarkMarkdownViewClippedPaintSteady: ~1.77 µs/op (1596–2104 ns/op), 0 B/op, 0 allocs/op over a clipped viewport in a large mixed document with tall tables and blockquotes.
  • platform vet (backends untouched)
  • stripped binary size (no new external dependencies)
  • real window verification (verified via Lithe desktop headless renders in Light/Dark × zh-CN/en-US; interactive native window QA pending)

Visual evidence

  • Changed: MarkdownView layout for markdown.Labeled aligned two-column rows and clipped painting of large documents.
  • Reach it by: populating a markdown.Document via AppendLabeled / AppendParagraph / AppendCode / AppendTable and painting via components.MarkdownView.
  • Protected by: TestMarkdownViewLabeledAlignment, TestMarkdownViewTallTableCellFourLevelIndex, TestMarkdownViewDeepQuoteBarSpatialIndex, TestMarkdownViewBlockAnchorTop, and BenchmarkMarkdownViewClippedPaintSteady in components/markdown_index_test.go.

Where the boundary sits

Generic document primitives (Labeled two-column blocks, programmatic markdown.Document builder, clipped spatial indexing, AllocatedBytes, and BlockAnchorTop) belong in Viva's reusable markdown and components packages. All HTML/Javadoc/Markdown parsing, language-specific tag localization, and editor projection stay in the host application and Rust Core.

Cost

Programs that do not construct Labeled blocks or call Append*/BlockAnchorTop pay zero extra per-frame cost; steady-state clipped Paint stays 0 B/op, 0 allocs/op. The spatial index stores compact integer span slices built once during Layout and accounted for in AllocatedBytes().

@Mucheen

Mucheen commented Nov 27, 2026

Copy link
Copy Markdown
Author

Upstream PR: vivaui#489

@Mucheen
Mucheen marked this pull request as ready for review November 27, 2026 22:58
@Mucheen
Mucheen merged commit 5c6220c into main Nov 28, 2026
32 of 35 checks passed
Mucheen added a commit to Mucheen/Lithe-IDEA that referenced this pull request Nov 28, 2026
Includes Lithe-IDEA/Lithe-viva#70 and 1lck#73 (empty code line hit-test fix
in MarkdownView offsetAtIndexed and dense-grid linear equivalence tests).
Mucheen added a commit to 1lck/Lithe-IDEA that referenced this pull request Nov 28, 2026
* feat(editor): render HTML, Javadoc, and Markdown doc comments natively (#2475)

* fix(editor): address code review findings and update Core/Viva pins

* fix(editor): address Devin Review edge cases for selection, anchors, PageUp, long-line scan, and bulk toggles

* fix(editor): keep Render All enabled after FoldAll and harden doc block drag selection boundary

* fix(editor): keep word and line drags from overshooting past rendered doc blocks

* chore(desktop): bump pinned Lithe-viva to main commit 6b89cf2a33b1

Includes Lithe-IDEA/Lithe-viva#70 and #73 (empty code line hit-test fix
in MarkdownView offsetAtIndexed and dense-grid linear equivalence tests).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant