Skip to content

Commit 19a0bc1

Browse files
committed
added leetcode code problems url
1 parent 2070010 commit 19a0bc1

16 files changed

+307
-142
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
5353

5454
### Added
5555
- added a new command show leetcode problems where links of every question on leetcode is availabe you can run this command and a text file will get opened and you can use (ctrl+f) to search for the specific leetcode question
56+
- added test_runner.py just
57+
5658

5759
### Changed
5860
- updated extension.ts to ensure proper execution of showleetcodeproblem command
5961
- updated commandTreeDataProvider.ts to add a new command to the panel
60-
- updated package.json file too
62+
- updated package.json file too
63+
- updated the logic for fetchTestCases.ts (basically adding logic for second selector to account for every question on leetcode)

README.md

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# LeetCode Helper Extension
22

3-
![LeetCode Helper](resources/leetcode_helper_banner.png)
3+
![LeetCode Helper]
44

55
## Overview
66

@@ -13,7 +13,7 @@ LeetCode Helper is a Visual Studio Code extension designed to streamline the pro
1313
- **Solution File Management**: Automatically generate and manage solution files.
1414
- **Error Handling**: Detailed error messages to help you debug your code.
1515

16-
![Features](resources/features.png)
16+
![Features]
1717

1818
## Installation
1919

@@ -29,7 +29,7 @@ LeetCode Helper is a Visual Studio Code extension designed to streamline the pro
2929
3. Write your solution in the generated file.
3030
4. Run your test cases using `LeetCode Helper: Run Test Cases`.
3131

32-
![Usage](resources/usage.png)
32+
![Usage]
3333

3434
## Extension Settings
3535

@@ -45,18 +45,10 @@ This extension contributes the following settings:
4545

4646
## Release Notes
4747

48-
### 1.0.1
49-
50-
- Fixed issue with capturing actual output in failed test cases.
51-
- Improved error handling and logging.
52-
5348
### 1.0.0
5449

5550
- Initial release of LeetCode Helper.
5651

57-
## Contributing
58-
59-
Contributions are welcome! Please read the [contributing guidelines](CONTRIBUTING.md) first.
6052

6153
## License
6254

@@ -69,4 +61,4 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
6961
- **Logging**: Enhanced logging for better debugging.
7062
- **Solution File Management**: Automatically generate and manage solution files.
7163

72-
![Footer](resources/footer.png)
64+
![Footer]

a.exe

44.9 KB
Binary file not shown.

dist/extension.js

Lines changed: 61 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -297218,7 +297218,7 @@ var {
297218297218
var fs6 = __toESM(require("fs"));
297219297219
var path10 = __toESM(require("path"));
297220297220
var vscode = __toESM(require("vscode"));
297221-
var RETRY_DELAY2 = 100;
297221+
var RETRY_DELAY2 = 3e3;
297222297222
var MAX_RETRIES = 5;
297223297223
async 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
}
297305297328
async 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
};
297575297602
var 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>

dist/extension.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# Code Citations
2+
3+
## License: unknown
4+
https://github.com/townmi/blog_node/blob/8e9ed96a49b57ade537267eabb2d9c3266efe31e/source/_posts/%E9%A1%B5%E9%9D%A2%E5%8A%A0%E8%BD%BD%E4%B8%8E%E9%98%BB%E5%A1%9E.md
5+
6+
```
7+
`<!DOCTYPE html>
8+
```
9+
10+
11+
## License: unknown
12+
https://github.com/townmi/blog_node/blob/8e9ed96a49b57ade537267eabb2d9c3266efe31e/source/_posts/%E9%A1%B5%E9%9D%A2%E5%8A%A0%E8%BD%BD%E4%B8%8E%E9%98%BB%E5%A1%9E.md
13+
14+
```
15+
`<!DOCTYPE html>
16+
<html lang="en">
17+
```
18+
19+
20+
## License: unknown
21+
https://github.com/townmi/blog_node/blob/8e9ed96a49b57ade537267eabb2d9c3266efe31e/source/_posts/%E9%A1%B5%E9%9D%A2%E5%8A%A0%E8%BD%BD%E4%B8%8E%E9%98%BB%E5%A1%9E.md
22+
23+
```
24+
`<!DOCTYPE html>
25+
<html lang="en">
26+
<head>
27+
<meta
28+
```
29+
30+
31+
## License: unknown
32+
https://github.com/townmi/blog_node/blob/8e9ed96a49b57ade537267eabb2d9c3266efe31e/source/_posts/%E9%A1%B5%E9%9D%A2%E5%8A%A0%E8%BD%BD%E4%B8%8E%E9%98%BB%E5%A1%9E.md
33+
34+
```
35+
`<!DOCTYPE html>
36+
<html lang="en">
37+
<head>
38+
<meta charset="UTF-8">
39+
40+
```
41+
42+
43+
## License: unknown
44+
https://github.com/townmi/blog_node/blob/8e9ed96a49b57ade537267eabb2d9c3266efe31e/source/_posts/%E9%A1%B5%E9%9D%A2%E5%8A%A0%E8%BD%BD%E4%B8%8E%E9%98%BB%E5%A1%9E.md
45+
46+
```
47+
`<!DOCTYPE html>
48+
<html lang="en">
49+
<head>
50+
<meta charset="UTF-8">
51+
<meta name="viewport" content="
52+
```
53+
54+
55+
## License: unknown
56+
https://github.com/townmi/blog_node/blob/8e9ed96a49b57ade537267eabb2d9c3266efe31e/source/_posts/%E9%A1%B5%E9%9D%A2%E5%8A%A0%E8%BD%BD%E4%B8%8E%E9%98%BB%E5%A1%9E.md
57+
58+
```
59+
`<!DOCTYPE html>
60+
<html lang="en">
61+
<head>
62+
<meta charset="UTF-8">
63+
<meta name="viewport" content="width=device-
64+
```
65+
66+
67+
## License: unknown
68+
https://github.com/townmi/blog_node/blob/8e9ed96a49b57ade537267eabb2d9c3266efe31e/source/_posts/%E9%A1%B5%E9%9D%A2%E5%8A%A0%E8%BD%BD%E4%B8%8E%E9%98%BB%E5%A1%9E.md
69+
70+
```
71+
`<!DOCTYPE html>
72+
<html lang="en">
73+
<head>
74+
<meta charset="UTF-8">
75+
<meta name="viewport" content="width=device-width, initial-scale=1.
76+
```
77+
78+
79+
## License: unknown
80+
https://github.com/townmi/blog_node/blob/8e9ed96a49b57ade537267eabb2d9c3266efe31e/source/_posts/%E9%A1%B5%E9%9D%A2%E5%8A%A0%E8%BD%BD%E4%B8%8E%E9%98%BB%E5%A1%9E.md
81+
82+
```
83+
`<!DOCTYPE html>
84+
<html lang="en">
85+
<head>
86+
<meta charset="UTF-8">
87+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
88+
<title>
89+
```
90+

dist/test_cases/solution.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,14 @@ void run_test_case(int test_case_number, const function<void(const T&)>& solutio
9696
// -------------------- SOLUTION TEMPLATE --------------------
9797
// MODIFY THIS SECTION FOR YOUR SPECIFIC PROBLEM
9898

99-
void solution(const vector<string>& args) {
99+
void solution(const vector<int>& args) {
100100
// Example parsing different types of inputs
101101
// Modify according to your problem requirements
102102

103103
// For array input: [1,2,3]
104104
if (!args.empty() && args[0][0] == '[') {
105105
auto arr = parseArray<int>(args[0]);
106+
106107
}
107108

108109
// For string input: "hello"
@@ -113,7 +114,6 @@ void solution(const vector<string>& args) {
113114
// For integer input: 42
114115
if (args.size() >= 3) {
115116
int num = parseValue<int>(args[2]);
116-
cout << "Input Integer: " << num << endl;
117117
}
118118

119119
// YOUR SOLUTION LOGIC GOES HERE
@@ -123,8 +123,8 @@ void solution(const vector<string>& args) {
123123

124124
int main() {
125125
// Run single test case
126-
run_test_case<int>(1, solutionInt); // For integer input
127-
run_test_case<string>(2, solutionString); // For string input
128-
run_test_case<vector<int>>(3, solutionVectorInt); // For array input
126+
run_test_case<vector<int>>(1, solution);
127+
128+
129129
return 0;
130130
}

dist/test_cases/solution.exe

44.9 KB
Binary file not shown.

0 commit comments

Comments
 (0)