How sangwookyoo/vscode-unity-sw-pack works
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)