How chanhx/crabviz works
Project Type and Purpose
• Crabviz is a tool that leverages the Language Server Protocol (LSP) to generate interactive call graphs. It’s designed for visual code exploration and is most effective as an IDE/editor extension.
• The project is implemented primarily in Rust (indicated by Cargo.toml, Cargo.lock, and src/) with an additional editor integration component found under editors/code (which contains VS Code extension files and configurations).
Main Components
• Core Call Graph Generation Engine (Rust Core):
• Represented by the src/ directory with key modules:
▪ Generator: Files in src/generator (generator.rs, tests.rs, types.rs, wasm.rs) which handle the logic for generating call graphs.
▪ Graph: The src/graph directory (graph.rs, dot.rs) dealing with the construction and representation of call graphs.
▪ Language-specific Parsers/Adapters: In src/lang (and its submodules like go.rs and rust.rs) which tailor graph generation to different languages.
▪ Additional utilities like src/lsp_types.rs and src/lib.rs that help interface with the Language Server Protocol.
• Editor/Extension Integration:
• Found under editors/code/ which contains:
▪ VS Code extension-specific files (extension.ts, command-manager.ts, webview.ts) for interfacing with the editor.
▪ Configuration files (.eslintrc.json, package.json, webpack.config.js) that define the extension’s setup.
▪ UI assets (media folder with CSS, JS files) for rendering the interactive graphs.
Relationships and Interactions
• The VS Code Extension (editors/code) communicates with the Rust core via the language server protocol.
• User actions in the editor (e.g., file selection, function highlight) trigger commands (via command-manager.ts) that call into the Rust backend for processing.
• The Rust core processes source code, generates the call graph data (using the generator, graph, and language modules), and provides output that the extension then transforms into interactive UI elements (such as SVG exports and clickable nodes).
• There is also a separation between UI rendering (front end) and core business logic (back end), with data flowing from the core calculation modules to the user interface components.
Architectural Patterns and Design Principles
• Modular Architecture: The project splits its responsibilities clearly between core processing (Rust modules) and UI/editor integration (VS Code extension code).
• Separation of Concerns: Distinct boundaries exist where LSP functionalities, graph algorithm implementations, and visual presentation are isolated into separate directories/components.
• Extensibility: The use of modular language-specific adapters (in src/lang) indicates the design supports multiple programming languages.
• Clear command flow: The “command-manager.ts” and associated helper utilities in the editors section hint at a command-driven pattern coordinating interactions triggered by editor events.
Technologies and Frameworks
• Programming Languages: Rust for the core functionality and TypeScript/JavaScript for the VS Code extension.
• LSP (Language Server Protocol): Used by the core engine to interact with languages and communicate with the editor.
• VS Code Extension API: Used in the editors/code components for integration.
• Webpack and other build tools: Employed for bundling the extension’s web assets.
• Testing: The presence of test files (e.g., src/generator/tests.rs, extension.test.ts) demonstrates that testing is an integral part of the system, so include test components as secondary nodes if needed.
Emphasizing Essential Architectural Elements
• Recognize that while the project only currently supports VS Code, the design is modular enough to integrate with other editors – include an architectural note about potential extension points.