Skip to main content

Crate components_rs

Crate components_rs 

Source
Expand description

Static analysis library for Components.js projects.

Components.js is a semantic dependency injection framework for TypeScript/JavaScript that describes classes and their constructor parameters in JSON-LD files (components.jsonld) and wires concrete instances together in configuration files (config/*.jsonld).

This crate reads those files and produces typed Rust structs that a language server can use to implement:

  • Autocompletion of @type values and parameter keys in config files
  • Hover documentation from rdfs:comment strings
  • Goto-definition via byte-range spans (iri_span) stored on every extracted type
  • Diagnostics for missing required parameters or unknown component IRIs

§Typical usage (in an LSP)

use components_rs::{fs::OsFs, module_state::ModuleState,
                    components::registry::ComponentRegistry,
                    config::registry::ConfigRegistry};

let fs = OsFs;
let state = ModuleState::build(&fs, &project_root).await?;

let mut comp_reg = ComponentRegistry::new();
comp_reg.register_available_modules(&fs, &state).await?;
comp_reg.finalize(); // resolves inherited parameters

let mut cfg_reg = ConfigRegistry::new();
cfg_reg.discover_configs(&fs, &state).await?;

§Module map

ModulePurpose
module_stateEntry point — discovers all packages and builds the shared lookup tables
componentsExtracted component classes, parameters, and modules
configExtracted configuration instances (concrete wirings)
contextJSON-LD context resolution and IRI expansion/compaction
discoveryLow-level node_modules traversal and package.json parsing
fsAbstract filesystem trait (swap in-memory impl for WASM/tests)
errorShared error type

Modules§

components
Component extraction — the classes and parameters defined in components.jsonld files.
config
Configuration instance extraction — the concrete wirings in config/*.jsonld files.
context
JSON-LD context resolution: expanding compact IRIs to full IRIs and back.
discovery
Low-level discovery of npm packages and their Components.js metadata.
error
Shared error type for all fallible operations in this crate.
fs
Abstract filesystem trait and the default OS-backed implementation.
module_state
Project-wide state: the shared lookup tables built from all discovered packages.