# crisidev/bacon-ls architecture

> Architecture diagram of the GitHub repository crisidev/bacon-ls, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/crisidev/bacon-ls
- Repository: https://github.com/crisidev/bacon-ls

## Overview

##### Project Type and Purpose
- This project is a language server wrapper for Bacon—a diagnostic tool—and serves as a companion LSP (Language Server Protocol) that relays diagnostic information to various clients (VSCode, Neovim, etc.).
- Its primary purpose is to improve the diagnostic performance over what rust-analyzer may provide on large Rust codebases by reading Bacon’s exported diagnostic data and exposing it via LSP channels.

##### Analyzing the File Structure
- The project uses Rust for its core language server. The bulk of the server’s logic is located in the src directory (files such as main.rs, lib.rs, lsp.rs, bacon.rs, and native.rs). These files likely represent the core application initialization, the LSP protocol handling, integration with Bacon’s diagnostics, and possibly OS-specific functionality.
- There is also evidence of a TypeScript/JavaScript component (files like vscode/extension.ts, package.json, tsconfig.json, eslint.config.mjs). This indicates that the project includes a VSCode extension that integrates with the bacon-ls server.
- Other directories and files, like .github workflows and configuration files (Cargo.toml, rustfmt.toml, rust-toolchain.toml, etc.), point to a well-structured, continuous integration (CI)–driven project which includes testing, formatting, and release operations.
- Additionally, configuration files for formatting, linting, and deployment show an emphasis on maintainability and consistent development practices.

##### Components and Interactions
a. Main Components to Include:
- Core Language Server (Rust)
– This includes the initialization (main.rs), LSP handling (lsp.rs), communication modules (bacon.rs & native.rs), and shared libraries (lib.rs).
- VSCode Extension Component
– Located within the vscode folder (extension.ts) along with supporting files like package.json and tsconfig.json.
- External Bacon Diagnostic Engine
– Although not part of the codebase, Bacon runs independently and produces a diagnostics export file (.bacon-locations). This file is read by bacon-ls from its environment.
- Client Applications
– LSP Clients such as VSCode, Neovim, Helix, Coc.nvim, etc.
- CI/CD Pipeline
– Represented by GitHub workflows and configuration files that support building, testing, code coverage, and release automation.

b. Relationships and Data Flow:
- The LSP Client (VSCode, Neovim, etc.) makes LSP requests (like textDocument/diagnostic) to the bacon-ls server.
- The bacon-ls server (our Rust core) then reads diagnostic data from the Bacon-generated export file (.bacon-locations) and sends back the results via LSP responses.
- A separate VSCode extension component (built in TS) helps integrate or simplify the use of the language server on that platform.
- The CI/CD pipeline ensures that integration tests and build processes keep both the core server and its extensions in sync.

c. Architectural Patterns or Design Principles to Emphasize:
- Separation of Concerns: Different modules handle LSP protocol logic, Bacon diagnostics processing, and system-specific operations.
- Modular Design: With separate folders for core Rust components and VSCode extensions, the architecture promotes reusability and clear boundaries between the language server and its integrations.
- Integration of External Tools: Bacon (external process) plays a central role; its outputs are an integral part of how the server processes diagnostics.

d. Relevant Technologies and Frameworks:
- Rust: for the primary language server functionality.
- LSP (Language Server Protocol): as the means of communication with editors.
- TypeScript/JavaScript: for the VSCode extension.
- GitHub Actions: for CI/CD workflows.
- Cargo: as Rust’s build and package manager.
- Various configuration and dependency management tools (ESLint, Prettier, Nix flakes) add robustness to development and deployment.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% LSP Clients
    subgraph "LSP Clients"
        clients["LSP Clients (VSCode, Neovim, Helix, Coc.nvim)"]:::clients
    end

    %% Bacon-LS Core Server (Rust)
    subgraph "Bacon-LS Core Server (Rust)"
        init["Initialization (main.rs)"]:::rustComponent
        lib["Shared Libraries (lib.rs)"]:::rustComponent
        lspHandler["LSP Handler (lsp.rs)"]:::rustComponent
        diagProcessor["Diagnostic Processor (bacon.rs)"]:::rustComponent
        nativeIntegrations["Native Integrations (native.rs)"]:::rustComponent
    end

    %% VSCode Extension Component
    subgraph "VSCode Extension"
        extension["Extension Logic (extension.ts)"]:::tsComponent
        package["package.json"]:::tsComponent
        tsconfig["tsconfig.json"]:::tsComponent
    end

    %% External Bacon Diagnostic Engine
    subgraph "External Processes"
        baconDiag["Bacon Diagnostic Engine (.bacon-locations)"]:::external
    end

    %% CI/CD Pipeline
    subgraph "CI/CD Pipeline"
        ci["GitHub Workflows (.github/workflows)"]:::ci
    end

    %% Relationships
    baconDiag -->|"diagnostic-file"| diagProcessor

    clients -->|"LSP-requests"| lspHandler
    lspHandler -->|"LSP-responses"| clients

    %% VSCode Extension flow (for VSCode specific integration)
    clients -->|"uses"| extension
    extension -->|"forwards-request"| lspHandler
    lspHandler -->|"sends-response"| extension
    extension -->|"delivers-response"| clients

    %% CI/CD influencing development lifecycle
    ci -->|"build&test"| init
    ci -->|"build&test"| extension

    %% Internal Core Server communication
    init -->|"initializes"| lib
    lib -->|"configures"| lspHandler
    lspHandler -->|"calls native"| nativeIntegrations

    %% Click Events for Rust Core Server
    click init "https://github.com/crisidev/bacon-ls/blob/main/src/main.rs"
    click lib "https://github.com/crisidev/bacon-ls/blob/main/src/lib.rs"
    click lspHandler "https://github.com/crisidev/bacon-ls/blob/main/src/lsp.rs"
    click diagProcessor "https://github.com/crisidev/bacon-ls/blob/main/src/bacon.rs"
    click nativeIntegrations "https://github.com/crisidev/bacon-ls/blob/main/src/native.rs"

    %% Click Events for VSCode Extension
    click extension "https://github.com/crisidev/bacon-ls/blob/main/vscode/extension.ts"
    click package "https://github.com/crisidev/bacon-ls/blob/main/package.json"
    click tsconfig "https://github.com/crisidev/bacon-ls/blob/main/tsconfig.json"

    %% Click Events for CI/CD Pipeline
    click ci "https://github.com/crisidev/bacon-ls/tree/main/.github/workflows"

    %% Styles
    classDef rustComponent fill:#f9c74f,stroke:#f9844a,stroke-width:2px;
    classDef tsComponent fill:#90be6d,stroke:#43aa8b,stroke-width:2px;
    classDef external fill:#577590,stroke:#277da1,stroke-width:2px;
    classDef ci fill:#f94144,stroke:#f3722c,stroke-width:2px;
    classDef clients fill:#277da1,stroke:#577590,stroke-width:2px;
```
