# sangwookyoo/vscode-unity-sw-pack architecture

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

- Interactive diagram: https://gitdiagram.com/sangwookyoo/vscode-unity-sw-pack
- Repository: https://github.com/sangwookyoo/vscode-unity-sw-pack

## Overview

##### Project Type & Purpose
- This is a VS Code Extension written in TypeScript (see package.json, tsconfig.json).
- Purpose: enrich Unity C# development in VS Code by providing snippets, CodeLens (event bindings & lifecycle messages), hover‐tooltips, meta-file sync, documentation search, coroutine toggles, and a custom theme.

##### File Structure
Top-level:
- configuration: .eslintrc.json, tsconfig.json, package.json, .vscodeignore
- assets: gifs/, images/, theme/unity-sw-theme.json
- source: src/…
– extension.ts (activation & command registration)
– feature modules: AssetParser.ts, Hover.ts, MetaFileSync.ts, Parser.ts, SearchUnityDocs.ts, TypeToggle.ts, UnityEventMessage.ts, UsageScenePrefab.ts
– event-lens subfolder: providers, grammar (.g4), ANTLR‐generated parser code, unity-scene-reader.ts, unity-lens.ts
- tests: src/test/runTest.ts, suite/...

##### Extract Architecture from README
- Activation via (extension.ts) on workspace open or user command
- Uses VS Code API to register:
- CodeLensProviders (unity event & message lenses, scene/prefab usage)
- HoverProvider (Unity lifecycle doc)
- FileSystemWatcher (meta-file sync)
- Commands (search docs, toggle coroutine)
- ANTLR grammar & parser drive the event-lens static analysis
- Relies on external Unity & .NET tools only for prerequisites

##### Main Components & Their Interactions
a. VS Code Host
– Activation & lifecycle managed by VS Code extension host
– Hosts Feature Modules via extension.ts
b. Extension Core (extension.ts)
– Registers Providers & Commands with VS Code API
– Initializes File System Watchers
c. Feature Modules
- Snippet Manager (snippets/…)
- CodeLens Providers
– UnityEventMessage.ts
– event-lens/unity-lens.ts + connected-member-finder.ts + scene reader
– UsageScenePrefab.ts
- HoverProvider (Hover.ts)
- TypeToggle (TypeToggle.ts)
- MetaFileSync (MetaFileSync.ts)
- SearchUnityDocs (SearchUnityDocs.ts)
- AssetParser & Parser (AssetParser.ts, Parser.ts)
d. ANTLR Parser Subsystem
– Grammar (.g4) → Generated TS parsers (.ts)
– Provides AST & traversal for event-lens analysis
e. External Dependencies
- VS Code API (vscode module)
- ANTLR4 runtime
- .NET SDK / Mono (at runtime outside VS Code)

##### Architectural Patterns & Principles
- Modular feature registration: each feature encapsulated in its own module/class
- Event-driven: reacts to file changes, text-document events, hover requests
- Static analysis pipeline: ANTLR grammar → AST → code‐lens decoration
- Separation of concerns: parsing, UI decoration (CodeLens/Hover), command execution, file‐watch logic

- Blue = VS Code API / Host
- Green = Extension Core & Features
- Orange = Parser / Analysis
- Gray = External (.NET SDK, Unity Docs)

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "VS Code Host Layer"
        VS["VS Code Host"]:::host
    end

    subgraph "Extension Core Layer"
        ExtCore["extension.ts"]:::core
    end

    VS -->|"activates"| ExtCore

    subgraph "Feature Modules Layer"
        subgraph "Snippet & Theme"
            SnippetMgr["Snippet Manager"]:::feature
            Theme["Custom Theme"]:::feature
        end

        subgraph "CodeLens Providers"
            UEM["UnityEventMessage.ts"]:::feature
            ELC["code-lens-provider.ts"]:::feature
            CMF["connected-member-finder.ts"]:::feature
            UL["unity-lens.ts"]:::feature
            USP["UsageScenePrefab.ts"]:::feature
        end

        subgraph "Hover Providers"
            HP["Hover.ts"]:::feature
            EHover["hover-provider.ts"]:::feature
        end

        MF["MetaFileSync.ts"]:::feature
        SD["SearchUnityDocs.ts"]:::feature
        TT["TypeToggle.ts"]:::feature

        subgraph "Asset Parsing Modules"
            AP["AssetParser.ts"]:::feature
            GP["Parser.ts"]:::feature
        end
    end

    ExtCore -->|"registers snippets"| SnippetMgr
    ExtCore -->|"registers theme"| Theme
    ExtCore -->|"registers CodeLens"| UEM
    ExtCore -->|"registers CodeLens"| ELC
    ExtCore -->|"registers CodeLens"| USP
    ExtCore -->|"registers Hover"| HP
    ExtCore -->|"registers Hover"| EHover
    ExtCore -->|"initializes FileWatcher"| MF
    ExtCore -->|"registers command"| SD
    ExtCore -->|"registers command"| TT
    ExtCore -->|"initializes parser"| AP

    UEM -->|"uses analysis"| Grammar
    ELC -->|"uses analysis"| Grammar
    CMF -->|"uses analysis"| Grammar
    UL -->|"uses analysis"| Grammar

    subgraph "Parser Subsystem Layer"
        Grammar["Grammar Definitions (.g4)"]:::parser
        GenParser["Generated Parser Code"]:::parser
    end

    Grammar -->|"generates"| GenParser

    subgraph "External Dependencies Layer"
        VSCAPI["VS Code API"]:::external
        ANTLR4["ANTLR4 Runtime"]:::external
        DotNet[".NET SDK / Mono"]:::external
        UnityDocs["Unity Docs API"]:::external
    end

    ExtCore -->|"calls API"| VSCAPI
    GenParser -->|"requires"| ANTLR4
    ExtCore -->|"requires runtime"| DotNet
    SD -->|"queries"| UnityDocs

    click ExtCore "https://github.com/sangwookyoo/vscode-unity-sw-pack/blob/master/src/extension.ts"
    click SnippetMgr "https://github.com/sangwookyoo/vscode-unity-sw-pack/tree/master/src/snippets/"
    click Theme "https://github.com/sangwookyoo/vscode-unity-sw-pack/blob/master/theme/unity-sw-theme.json"
    click UEM "https://github.com/sangwookyoo/vscode-unity-sw-pack/blob/master/src/UnityEventMessage.ts"
    click ELC "https://github.com/sangwookyoo/vscode-unity-sw-pack/blob/master/src/event-lens/code-lens-provider.ts"
    click CMF "https://github.com/sangwookyoo/vscode-unity-sw-pack/blob/master/src/event-lens/connected-member-finder.ts"
    click UL "https://github.com/sangwookyoo/vscode-unity-sw-pack/blob/master/src/event-lens/unity-lens.ts"
    click USP "https://github.com/sangwookyoo/vscode-unity-sw-pack/blob/master/src/UsageScenePrefab.ts"
    click HP "https://github.com/sangwookyoo/vscode-unity-sw-pack/blob/master/src/Hover.ts"
    click EHover "https://github.com/sangwookyoo/vscode-unity-sw-pack/blob/master/src/event-lens/hover-provider.ts"
    click MF "https://github.com/sangwookyoo/vscode-unity-sw-pack/blob/master/src/MetaFileSync.ts"
    click SD "https://github.com/sangwookyoo/vscode-unity-sw-pack/blob/master/src/SearchUnityDocs.ts"
    click TT "https://github.com/sangwookyoo/vscode-unity-sw-pack/blob/master/src/TypeToggle.ts"
    click AP "https://github.com/sangwookyoo/vscode-unity-sw-pack/blob/master/src/AssetParser.ts"
    click GP "https://github.com/sangwookyoo/vscode-unity-sw-pack/blob/master/src/Parser.ts"
    click Grammar "https://github.com/sangwookyoo/vscode-unity-sw-pack/tree/master/src/event-lens/grammar/"
    click GenParser "https://github.com/sangwookyoo/vscode-unity-sw-pack/tree/master/src/event-lens/parser/"

    classDef host fill:#bbdefb,stroke:#1e88e5
    classDef core fill:#c8e6c9,stroke:#43a047
    classDef feature fill:#a5d6a7,stroke:#2e7d32
    classDef parser fill:#ffe0b2,stroke:#fb8c00
    classDef external fill:#eeeeee,stroke:#757575
```
