How tushar-81/cph-leetcode works
Project Type and Purpose
• This is a VS Code extension (see extension.js, package.json, vsc-extension-quickstart.md).
• Purpose: fetch and manage programming-challenge test cases, process user code (e.g. sample.cpp), and display results in a Webview.
File Structure
• Top‐level:
• extension.js – VS Code activation entry point
• package.json, jsconfig.json, eslint.config.mjs, .vscodeignore – config & metadata
• sample.cpp – example code file
• test/extension.test.js – unit tests for the extension
• src/basic/ – low-level utilities (processCode.js, transformArray.js, divideTestCases.js)
• src/core/ – core services for fetching, retrieving, storing test cases
• src/webview/ – front-end assets and scripts for the UI panel
• logos/, screenshots/ – assets for marketplace listing
(Sparse) README
• Lacks architecture details, so we infer design from code layout and naming.
• Core pattern: extension host triggers services → communicates with Webview → optionally reaches out to an external test‐case API → persists test cases locally.
Main Components
a. VS Code Extension Host
• extension.js (activation, command registration)
• Invokes modules in src/basic and src/core
b. Core Services Layer
• fetchTestCases (API client)
• retrieveTestCases (local cache read)
• storeTestCases (local cache write)
c. Utility Layer
• processCode.js (prepares/runs user code)
• transformArray.js, divideTestCases.js (data transforms)
d. Webview UI
• main.js (injected into Webview)
• script.js, theme.js (handles user interactions, theming)
• HTML/CSS assets (bundled in Webview)
e. External Services
• Remote Test‐Case API (HTTP/HTTPS endpoint)
f. Local Environment
• File system (for caching test cases)
• Child process or compiler toolchain (for compiling/running sample.cpp)
g. Tests
• extension.test.js – invokes extension activation in a mock host
Relationships and Data Flows
• User triggers command in VS Code (via Command Palette or UI).
• extension.js → calls core.fetchTestCases → external API → returns raw test cases.
• core.storeTestCases writes to local cache → core.retrieveTestCases reads from cache on demand.
• extension.js processes user code: calls basic.processCode → spawns child process (compiler) → obtains execution results.
• Results and test-case data passed to Webview via VS Code’s Webview API.
• Webview main.js renders data, handles UI events (e.g. “Run next test”), sends messages back to extension host.
Architectural Patterns and Design Principles
• Layered architecture: Utilities (basic) ← Core services ← Extension host ← Webview UI
• Clear separation of concerns: data fetching vs. data transformation vs. presentation
• Message‐based communication between Extension host and Webview
• Asynchronous flows (network I/O, child‐process I/O)
Essential Elements
• Two‐way Webview message channel