Skip to main content

Module graph_builder

Module graph_builder 

Source
Expand description

Graph construction and caching logic for the server.

§Overview

This module is responsible for turning raw parser facts into a fully resolved CodePropertyGraph. It supports three distinct workflows:

  • build – parse a project or a single file and construct the graph from scratch.
  • cache – serialise the graph to a compressed binary format using icb_graph::cache so that subsequent runs can skip parsing entirely.
  • load – restore a previously cached graph, automatically cleaning up node names.

§Incremental fact caching

When a cache directory is provided (or the default .icb_cache is used), the module stores extracted facts for every source file together with a SHA‑256 hash of the file content. On subsequent runs, files that have not changed are loaded directly from the cache, skipping the parser entirely. This can reduce the analysis time for large projects from seconds to milliseconds.

The incremental cache is transparently used by both the Clang and tree‑sitter backends – you get fast reloads regardless of the chosen parser.

§C/C++: Clang preferred, tree‑sitter fallback

For C and C++ projects the module prefers the Clang parser when the icb-clang crate is available. Clang provides exact semantic analysis and never mistakes documentation, HTML, or embedded JavaScript for C++ code. If Clang cannot be loaded (e.g. LLVM not installed), the pipeline automatically falls back to tree‑sitter‑cpp.

§Strict file extension filtering & multi‑language support

For every known language, only a curated list of file extensions is accepted. This eliminates noise from documentation, build artefacts, and web assets. When build_or_load_graph_multi is called with a specific list of languages, only those extensions are scanned.

§Auto‑detection of language

When language is "auto", the module scans the project directory and picks the dominant language based on file extensions. Unknown extensions fall back to the universal heuristic parser.

Structs§

PipelineConfig 🔒

Functions§

build_or_load_graph
Entry point: single-language
build_or_load_graph_multi
Entry point: multi-language
detect_language_from_extension 🔒
detect_language_from_project 🔒
extensions_for_language 🔒
is_javascript_noise 🔒
is_type_keyword 🔒
is_valid_identifier 🔒
parse_language 🔒
resolve_language 🔒
run_pipeline 🔒
Core pipeline executor
strip_comments 🔒
try_clang_pipeline 🔒