1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//! docs-symbols: symbol-anchored source extraction for docs sites
//! (docs-core extension program, `SPEC.md` REQ-S).
//!
//! A docs compiler resolves ```include-symbol fences against real source
//! files: this crate parses the file with tree-sitter, walks the AST by
//! ordered name matching (modules, items, impls keyed on type name), and
//! returns the symbol's exact byte span plus a position-independent
//! anchor ID derived from the symbol path itself (REQ-S1/S3). Unknown
//! paths fail with typed errors naming the offending segment (REQ-S2).
//!
//! ```
//! use docs_symbols::{extract, Language};
//!
//! let source = "mod engine {\n fn process_order() -> u32 { 7 }\n}\n";
//! let span = extract(source, Language::Rust, "engine::process_order").unwrap();
//! assert_eq!(span.start_line, 2);
//! assert!(span.code.contains("fn process_order"));
//! assert!(span.anchor_id.starts_with("dsym-rust-"));
//! ```
//!
//! # Scope (0.1, honest)
//!
//! In: Rust only (`Language::Rust`); item kinds function/struct/enum/
//! trait/type/const/static/mod/macro; impl methods keyed on the impl's
//! type name (inherent and trait impls alike); document order as the
//! deterministic first-match tiebreak; strict parsing (any ERROR or
//! MISSING node rejects the source).
//! Out: other languages (grammars are added per language, each gated by
//! its own tests), generic-parameter-qualified paths (`Vec::<u8>::new`),
//! trait-name segments on trait impls, associated consts via type paths,
//! and doc-comment inclusion in spans (the span is the item node). Each
//! absence is a later increment, not silent.
//!
//! # Layer
//!
//! L0 - leaf. Zero estate-internal dependencies; the external floor is
//! `tree-sitter` and `tree-sitter-rust`.
pub use SymbolError;
pub use extract;
pub use Span;
/// Languages with a grammar compiled into this crate.
/// The crate's version, for callers that report it.
pub const VERSION: &str = env!;