How otnansirk/vscode-casing-convention works
Project Type and Purpose
• Type: A VSCode editor extension implemented in TypeScript
• Purpose: Provide a suite of text transformation commands (casing conversions, JSON tools, base64, UUIDs, translation) via the VSCode Command, CodeAction, and Hover APIs
High-Level Architectural Components
• VSCode Host (Extension Host process)
• Activation & Registration Module (src/extension.ts)
• Command Module (src/commands)
• Code Action Module (src/code-actions)
• Hover Module (src/hovers)
• Handler Functions (src/commands/handler, src/code-actions/handler, src/hovers/handler)
• Helper Library (src/helpers)
• Exception Layer (src/exception)
• External Services
– Translation service via google-translate-token (@types/google-translate-token.d.ts)
Component Relationships & Data Flows
1. Extension Activation
– VSCode starts the extension by invoking the activate function in src/extension.ts
– Registers components with VSCode API:
• commands via commands.registerCommand
• code actions via CodeActionProvider
• hover provider via HoverProvider
2. User Interaction
– User invokes a command (via Command Palette or keybinding) OR
– VSCode requests code actions OR
– User hovers over text
3. Command/CodeAction/Hover Dispatch
– VSCode routes the request to the appropriate provider (command handler, code action handler, or hover handler)
– The module’s register file (e.g., src/commands/commandRegister.ts) maps identifiers (e.g., “casing-convention.camelCase”) to handler functions
4. Handler Execution
– Handler receives editor context and selected text
– Uses helper functions (src/helpers) for splitting, case transformations, JSON operations, etc.
– May throw custom exceptions (src/exception/HasNoSelected.ts) if preconditions fail
– For translation handlers, calls out to the external translation token library and translation API
5. VSCode Edit
– Handlers create and apply TextEdit operations via the VSCode API to transform the document
Architectural Patterns & Design Principles
• Modular separation: commands, code-actions, hovers are isolated sub-systems
• Command Pattern: each transformation encapsulated in a handler with a clear interface
• Single Responsibility: helpers handle utility tasks, exceptions isolate error types
• Lazy activation: extension activates on commands, minimizing startup cost
Details to Capture
• Activation flow in extension.ts (how and when modules register)
• Registry files (commandProvider.ts, codeActionRegister.ts, codeActionRegister.ts, codeActionRegister.ts)
• Handler grouping by feature (casing, JSON, base64, UUID, translation)
• Helper functions for low-level tasks (object2UrlParams, splitWords)
• Custom exception for missing selection