@@ -297218,7 +297218,7 @@ var {
297218297218var fs6 = __toESM(require("fs"));
297219297219var path10 = __toESM(require("path"));
297220297220var vscode = __toESM(require("vscode"));
297221- var RETRY_DELAY2 = 100 ;
297221+ var RETRY_DELAY2 = 3e3 ;
297222297222var MAX_RETRIES = 5;
297223297223async function fetchTestCases(url) {
297224297224 const browser = await launch3({ headless: false });
@@ -297284,22 +297284,45 @@ async function fetchTestCasesWithRetry(page, url) {
297284297284 await loginToLeetCode(page);
297285297285 }
297286297286 console.log("Waiting for test cases to load...");
297287+ let testCases = [];
297287297288 try {
297288297289 await page.waitForSelector("pre", { timeout: 2e4 });
297290+ testCases = await page.$$eval("pre", (elements) => {
297291+ return elements.map((pre) => {
297292+ const inputMatch = pre.innerText.match(/Input:\s*(.+)/);
297293+ const outputMatch = pre.innerText.match(/Output:\s*(.+)/);
297294+ return {
297295+ input: inputMatch ? inputMatch[1].trim() : null,
297296+ output: outputMatch ? outputMatch[1].trim() : null
297297+ };
297298+ });
297299+ });
297289297300 } catch (error) {
297290- console.error("Failed to find <pre> tags in time:", error);
297291- return [];
297301+ console.error("Failed to extract test cases using <pre> selector:", error);
297302+ }
297303+ if (testCases.length === 0) {
297304+ try {
297305+ console.log("Trying to extract test cases using .example-block structure...");
297306+ await page.waitForSelector(".example-block", { timeout: 5e3 });
297307+ testCases = await page.$$eval(".example-block", (blocks) => {
297308+ return blocks.map((block) => {
297309+ const inputElement = block.querySelector('strong:contains("Input:") + span.example-io');
297310+ const outputElement = block.querySelector('strong:contains("Output:") + span.example-io');
297311+ return {
297312+ input: inputElement ? inputElement.innerText.trim() : null,
297313+ output: outputElement ? outputElement.innerText.trim() : null
297314+ };
297315+ });
297316+ });
297317+ if (testCases.length > 0) {
297318+ console.log("Test cases successfully extracted using .example-block structure.");
297319+ } else {
297320+ console.log("No test cases found using .example-block structure.");
297321+ }
297322+ } catch (error) {
297323+ console.error("Failed to extract test cases using .example-block structure:", error);
297324+ }
297292297325 }
297293- const testCases = await page.$$eval("pre", (elements) => {
297294- return elements.map((pre) => {
297295- const inputMatch = pre.innerText.match(/Input:\s*(.+)/);
297296- const outputMatch = pre.innerText.match(/Output:\s*(.+)/);
297297- return {
297298- input: inputMatch ? inputMatch[1].trim() : null,
297299- output: outputMatch ? outputMatch[1].trim() : null
297300- };
297301- });
297302- });
297303297326 return testCases;
297304297327}
297305297328async function loginToLeetCode(page) {
@@ -297542,14 +297565,14 @@ var CommandTreeDataProvider = class {
297542297565 constructor() {
297543297566 this._onDidChangeTreeData = new vscode2.EventEmitter();
297544297567 this.onDidChangeTreeData = this._onDidChangeTreeData.event;
297545- // Mapping of command IDs to their display names
297568+ // Mapping of command IDs to their display names, icons, and colors
297546297569 this.extensionCommands = {
297547- "leetcode-cph-helper-by-ashish.fetchLeetCodeTestCases": "\u{1F449}\u{1F3FB} Fetch Test Cases",
297548- "leetcode-cph-helper-by-ashish.runTestCases": "\u{1F449}\u{1F3FB} Run Test Cases",
297549- "leetcode-cph-helper-by-ashish.writeSolutionFile": "\u{1F449}\u{1F3FB} Write Solution File",
297550- "leetcode-test-case-manager.getSolutionFileDirectory": "\u{1F449}\u{1F3FB} Get Solution File Directory",
297551- "leetcode-cph-helper-by-ashish.getIOFileDirectory": "\u{1F449}\u{1F3FB} Get I/O File Directory",
297552- "leetcode-cph-helper-by-ashish.showLeetCodeProblemLinks": "\u{1F449}\u{1F3FB} Show LeetCode Problem Links "
297570+ "leetcode-cph-helper-by-ashish.fetchLeetCodeTestCases": { label: " Fetch Test Cases", icon: "cloud-download", color: "charts.green" } ,
297571+ "leetcode-cph-helper-by-ashish.runTestCases": { label: " Run Test Cases", icon: "play-circle", color: "charts.blue" } ,
297572+ "leetcode-cph-helper-by-ashish.writeSolutionFile": { label: " Write Solution File", icon: "file-code", color: "charts.yellow" } ,
297573+ "leetcode-test-case-manager.getSolutionFileDirectory": { label: " Get Solution File Directory", icon: "folder", color: "charts.orange" } ,
297574+ "leetcode-cph-helper-by-ashish.getIOFileDirectory": { label: " Get I/O File Directory", icon: "folder", color: "charts.red" } ,
297575+ "leetcode-cph-helper-by-ashish.showLeetCodeProblemLinks": { label: " Show LeetCode Problem Links", icon: "link", color: "charts.purple" }
297553297576 };
297554297577 }
297555297578 // Returns a TreeItem representation of the given element
@@ -297563,7 +297586,11 @@ var CommandTreeDataProvider = class {
297563297586 } else {
297564297587 const commands3 = vscode2.commands.getCommands(true);
297565297588 return commands3.then(
297566- (cmds) => cmds.filter((cmd) => Object.keys(this.extensionCommands).includes(cmd)).map((cmd) => new CommandTreeItem(cmd, this.extensionCommands[cmd]))
297589+ (cmds) => cmds.filter((cmd) => Object.keys(this.extensionCommands).includes(cmd)).map((cmd) => {
297590+ const commandInfo = this.extensionCommands[cmd];
297591+ const treeItem = new CommandTreeItem(cmd, commandInfo.label, commandInfo.icon, commandInfo.color);
297592+ return treeItem;
297593+ })
297567297594 );
297568297595 }
297569297596 }
@@ -297573,14 +297600,19 @@ var CommandTreeDataProvider = class {
297573297600 }
297574297601};
297575297602var CommandTreeItem = class extends vscode2.TreeItem {
297576- constructor(commandId, label) {
297603+ constructor(commandId, label, icon, color ) {
297577297604 super(label, vscode2.TreeItemCollapsibleState.None);
297578297605 this.commandId = commandId;
297579297606 this.label = label;
297607+ this.icon = icon;
297608+ this.color = color;
297609+ this.tooltip = this.label;
297610+ this.iconPath = new vscode2.ThemeIcon(this.icon);
297580297611 this.command = {
297581297612 command: commandId,
297582297613 title: ""
297583297614 };
297615+ this.resourceUri = vscode2.Uri.parse(`color:${this.color}`);
297584297616 }
297585297617};
297586297618
@@ -297675,68 +297707,14 @@ function activate(context2) {
297675297707 throw new Error("File creation cancelled.");
297676297708 }
297677297709 }
297678- const boilerplate = language === "python" ? `import os
297679-
297680- def run_test_case(test_case_number, function):
297681- # Determine the base directory dynamically
297682-
297683- base_directory = os.path.dirname(os.path.dirname(__file__))
297684-
297685- file_path = os.path.join(base_directory, 'test_cases', f"input_{test_case_number}.txt")
297686-
297687-
297688- try:
297689-
297690- # Read the input file
297691-
297692- with open(file_path, "r") as file:
297693-
297694- content = file.read().strip().splitlines() # Read file and split lines
297695-
297696-
297697- # Dynamically parse all lines as arguments
297698-
297699- args = [eval(line.strip()) for line in content] # Parse each line in the file
297700-
297701-
297702- # Call the provided function with all parsed arguments
297703-
297704- result = function(*args) # Unpack the arguments dynamically
297705-
297706- print(result) # Output the result
297707-
297708-
297709- except FileNotFoundError:
297710-
297711- print(f"Error: File not found at {file_path}. Check the file path and try again.")
297712-
297713- except ValueError as e:
297714-
297715- print(f"Error: {e}")
297716-
297717- except SyntaxError as e:
297718-
297719- print(f"Error: Check your input file format. {e}")
297720-
297721- except Exception as e:
297722-
297723- print(f"Unexpected Error: {e}")
297724-
297725-
297726-
297727- # WRITE YOUR FUNCTION HERE
297728- #-------------------------------------------------------------------------------
297729-
297730-
297731- #-------------------------------------------------------------------------------
297732-
297733-
297734- #run_test_case(ENTER THE TESTCASE NUMBER, ENTER THE FUNCTION NAME)
297735-
297736- # EXAMPLE:
297710+ const boilerplate = language === "python" ? `import os; run_test_case=lambda n,f: print((lambda p: (lambda a: f(*a))(eval(l.strip()) for l in open(p).read().strip().splitlines()) if os.path.isfile(p) else f"Error: File not found at {p}. Check the file path and try again.")((lambda d: os.path.join(d, 'test_cases', f"input_{n}.txt"))(os.path.dirname(os.path.dirname(file)))))
297711+ #WRITE YOUR CODE LOGIC HERE
297737297712
297738- run_test_case() # Replace with the relevant test case number and function name
297739- ` : `#include <bits/stdc++.h>
297713+ #---------------------------------------------------------------------------------------
297714+ # Example usage
297715+ # Provide the test case number and function name
297716+ #run_test_case(TEST_CASE_NUMBER, FUNCTION_NAME);
297717+ run_test_case()` : `#include <bits/stdc++.h>
297740297718#include <filesystem>
297741297719#include <functional>
297742297720#include <iostream>
0 commit comments