Skip to main content

components_rs/
lib.rs

1//! Static analysis library for [Components.js](https://componentsjs.readthedocs.io/) projects.
2//!
3//! Components.js is a semantic dependency injection framework for TypeScript/JavaScript that
4//! describes classes and their constructor parameters in JSON-LD files (`components.jsonld`) and
5//! wires concrete instances together in configuration files (`config/*.jsonld`).
6//!
7//! This crate reads those files and produces typed Rust structs that a language server can use
8//! to implement:
9//!
10//! - **Autocompletion** of `@type` values and parameter keys in config files
11//! - **Hover documentation** from `rdfs:comment` strings
12//! - **Goto-definition** via byte-range spans (`iri_span`) stored on every extracted type
13//! - **Diagnostics** for missing required parameters or unknown component IRIs
14//!
15//! # Typical usage (in an LSP)
16//!
17//! ```ignore
18//! use components_rs::{fs::OsFs, module_state::ModuleState,
19//!                     components::registry::ComponentRegistry,
20//!                     config::registry::ConfigRegistry};
21//!
22//! let fs = OsFs;
23//! let state = ModuleState::build(&fs, &project_root).await?;
24//!
25//! let mut comp_reg = ComponentRegistry::new();
26//! comp_reg.register_available_modules(&fs, &state).await?;
27//! comp_reg.finalize(); // resolves inherited parameters
28//!
29//! let mut cfg_reg = ConfigRegistry::new();
30//! cfg_reg.discover_configs(&fs, &state).await?;
31//! ```
32//!
33//! # Module map
34//!
35//! | Module | Purpose |
36//! |--------|---------|
37//! | [`module_state`] | Entry point — discovers all packages and builds the shared lookup tables |
38//! | [`components`] | Extracted component classes, parameters, and modules |
39//! | [`config`] | Extracted configuration instances (concrete wirings) |
40//! | [`context`] | JSON-LD context resolution and IRI expansion/compaction |
41//! | [`discovery`] | Low-level `node_modules` traversal and `package.json` parsing |
42//! | [`fs`] | Abstract filesystem trait (swap in-memory impl for WASM/tests) |
43//! | [`error`] | Shared error type |
44
45pub mod components;
46pub mod config;
47pub mod context;
48pub mod discovery;
49pub mod error;
50pub mod fs;
51pub mod module_state;