This VS Code extension allows users to fetch test cases for LeetCode problems directly from their VS Code environment. It also provides a feature to run the test cases against your code and get feedback. The extension automates the process of extracting input and output test cases from LeetCode problem pages and provides an easy-to-use interface for fetching and running test cases.
Features
Fetch Test Cases: Automatically retrieves test cases (input and output) from a given LeetCode problem URL.
Run Test Cases: Allows users to run the fetched test cases against their code and shows the results.
Organized Test Case Files: Saves the fetched test cases in a folder named testCase within the project directory.
Requirements
Node.js (v12.x or later)
VS Code (v1.60 or later)
Installation
Installing from the Marketplace
Open VS Code.
Navigate to the Extensions view by clicking on the Extensions icon in the Activity Bar on the side of the window.
Search for "Competitive Programming Helper: Leetcode (CPH)".
Click Install.
Alternatively, you can download the extension directly from the Marketplace.
Manually Install
Clone or download this repository:
git clone https://github.com/skmachra/cph-leetcode.git
cd cph-leetcode
Install dependencies:
npm install
Open the project folder in VS Code.
Press F5 to launch the extension in a new Extension Development Host window.
Usage
Fetch Test Cases
Open a LeetCode problem URL in your VS Code editor.
From the Command Palette (Ctrl + Shift + P), run the CPH: Fetch Test Cases command.
Enter the LeetCode problem URL in the input prompt.
Wait for the extension to fetch the test cases and save them in the testCase folder.
Run Test Cases
Once the test cases are fetched, you can run them against your code by running the CPH: Run Test Cases command from the Command Palette.
The extension will execute your code and compare its output with the expected results.
Test Case Folder
The test cases will be saved in a testCase folder in your workspace directory. The folder will contain input/output files:
File Description:
Input Files: Each input_X.txt file contains the input values for the corresponding test case.
Output Files: Each output_X.txt file contains the expected output for the corresponding test case.
Commands
CPH: Fetch Test Cases: Prompts the user for a LeetCode problem URL, fetches the test cases, and saves them in the testCase folder.
CPH: Run Test Cases: Runs the fetched test cases against the user's code and shows the results.
Keybindings and Menus
Keybindings:
Ctrl + Alt + F (Windows/Linux) / Cmd + Alt + F (Mac): Fetch Test Cases.
Ctrl + Alt + R (Windows/Linux) / Cmd + Alt + R (Mac): Run Test Cases.
These keybindings are available when the editor window is focused.
Menus:
The CPH: Fetch Test Cases and CPH: Run Test Cases commands are also available in the editor context menu when the file is a supported language (C++, Python, or JavaScript).
Demo Video
Watch the demo video below to see how the Competitive Programming Helper: Leetcode (CPH) extension works:
CPH Extension Demo
Configuration
The extension supports the following settings to customize the fetch and run behavior: