Skip to content

Commit

Permalink
closes #2, closes #3, closes #4
Browse files Browse the repository at this point in the history
  • Loading branch information
Divyanshu Agrawal committed Oct 24, 2019
1 parent 3d9c139 commit 7f6753f
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 31 deletions.
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Competitive Programming Helper
# Competitive Programming Helper (v0.0.7)

Download from here : https://marketplace.visualstudio.com/items?itemName=DivyanshuAgrawal.competitive-programming-helper or search in the VS Code Extensions within the application.

This extension helps you to quickly run codeforces testcases for a given problem automatically. You can also add custom testcases to the generated ```.testcases``` file. If the file you are testing in ```A.cpp``` then the generated testcases file is ```A.cpp.testcases```, in which you can add your own testcases.
This extension helps you to quickly run codeforces testcases for a given problem automatically. You can also add custom testcases to the generated ```.tcs``` file. If the file you are testing in ```A.cpp``` then the generated testcases file is ```A.cpp.tcs```, in which you can add your own testcases.

Tip : Use the shortcut ```Ctrl/Cmd + Alt + B``` to activate.
Tip : Use the shortcut ```Ctrl/Cmd + Alt + 0``` to open testcases file.
Expand All @@ -18,7 +18,7 @@ Or Use the shortcut ```Ctrl/Cmd + Alt + B``` to activate.


* The first line of your C++ code should be a comment containing the URL of the codeforces page. The comment should be single line, ie, start with ```//``` and not ```/*```
* You can edit the generated .testcases file to add your own testcases.
* You can edit the generated .tcs file to add your own testcases.

![Use a comment as the first line](screenshots/1.png)

Expand All @@ -45,6 +45,12 @@ The GNU C++ Compiler ( GCC ) must be installed and should be accesible from the
This extension was created by Divyanshu Agrawal (https://github.com/agrawal-d). Please report bugs to [email protected]. Thank you for using this extension.

## Release Notes
* Version 0.0.7
* Fixes many UI and UX issues
* Files are auto saved on execution.
* .bin files are deleted after testcase evauation
* .testcases files as now .tcs
* The UI adapts to VS Code theme
* Version 0.0.6
* Use cheerio for DOM traversal to fix testcase parsing issues.
* Version 0.0.5
Expand Down
4 changes: 2 additions & 2 deletions createTestcasesFile.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
let fs = require("fs");
/**
* Creates a .testcases file in the given filepath with the given input and output arrays
* Creates a .tcs file in the given filepath with the given input and output arrays
*/
function createTestCasesFile(inp, op, filepath) {
console.log("Creating a file at", filepath);
Expand All @@ -16,7 +16,7 @@ function createTestCasesFile(inp, op, filepath) {
}

try {
fs.writeFileSync(filepath + ".testcases", strings);
fs.writeFileSync(filepath + ".tcs", strings);
} catch (err) {
console.log(err);
return 1;
Expand Down
4 changes: 2 additions & 2 deletions dist/extension.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/extension.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions extension.bkp.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function executePrimaryTask() {

function runTestCases() {
try {
fs.accessSync(filepath + ".testcases")
fs.accessSync(filepath + ".tcs")
} catch (err) {
var html = downloadCodeforcesPage(codeforcesURL);
html.then(string => {
Expand Down Expand Up @@ -140,7 +140,7 @@ function executePrimaryTask() {
return html;
} else {
oc.clear();
oc.append("Error!\nYou must do either of these two things : \nCreate a comment with the URL of the codeforces problem on line 1 first.\nOr Create a .testcases file containing the testcases. If your current filename is A.cpp then create a file A.cpp.testcases");
oc.append("Error!\nYou must do either of these two things : \nCreate a comment with the URL of the codeforces problem on line 1 first.\nOr Create a .tcs file containing the testcases. If your current filename is A.cpp then create a file A.cpp.tcs");
oc.show();
return false;
}
Expand Down
41 changes: 25 additions & 16 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const vscode = require('vscode');
const request = require('request');
var rp = require('request-promise-native');
const { spawn } = require('child_process');
const { spawn, exec } = require('child_process');
const parseCodeforces = require("./parseCodeforces");
const createTestacesFile = require("./createTestcasesFile");
const parseTestCasesFile = require("./parseTestCasesFile");
Expand All @@ -16,6 +16,8 @@ const statusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignmen
statusBarItem.text = " ▶ Run Testcases";
statusBarItem.show();
statusBarItem.command = "extension.runCodeforcesTestcases";
var oc = vscode.window.createOutputChannel("competitive");


// main extension commands are in this function

Expand All @@ -26,13 +28,13 @@ function openTestcaseFile() {
return;
} else {
try {
fs.accessSync(filepath + ".testcases");
fs.accessSync(filepath + ".tcs");
} catch (err) {
testCasesHelper(filepath);
return;
}

vscode.workspace.openTextDocument(filepath + ".testcases").then(document => {
vscode.workspace.openTextDocument(filepath + ".tcs").then(document => {
vscode.window.showTextDocument(document, vscode.ViewColumn.Beside)
})

Expand All @@ -55,12 +57,15 @@ function startWebView() {
}
}

function appendProblemURLToFile(problemURL) {
function appendProblemURLToFile(problemURL, callback) {
const editor = vscode.window.activeTextEditor;
vscode.window.activeTextEditor.edit(editBuilder => {
const document = editor.document;
const position = new vscode.Position(0, 0);
editBuilder.insert(position, "//" + problemURL + "\n");
vscode.commands.executeCommand("workbench.action.files.save").then((response) => {
callback();
})
})
}

Expand All @@ -70,34 +75,37 @@ function testCasesHelper(filepath) {
}
vscode
.window.
showQuickPick(["Download testcases from Codeforces", "Create a new .testcases file"], {
showQuickPick(["Download testcases from Codeforces", "Create a new .tcs testcase file"], {
placeHolder: "Choose one of the options to get testcases"
})
.then(selection => {
.then((selection) => {
if (selection === "Download testcases from Codeforces") {
vscode.window.showInputBox({
placeHolder: "Enter the complete URL of the codeforces problem"
}).then((problemURL) => {
appendProblemURLToFile(problemURL);
}).then(async (problemURL) => {
appendProblemURLToFile(problemURL, executePrimaryTask);
return;
})
} else if (selection === "Create a new .testcases file") {
} else if (selection === "Create a new .tcs testcase file") {
try {
fs.writeFileSync(
filepath + ".testcases",
"input\n1\n1 2 3\n4 3\noutput\nYES\n1 2 3\n-----------------\ninput\n1\n2\n5\noutput\n500\n4\n-----------------\n"
filepath + ".tcs",
"input\n1\n2\n5 0 92 0302\noutput\n500\n4\n-----------------\ninput\n1 2 4\njohn mary 20 30\noutput\n500\n-----------------\n"
)
vscode.workspace.openTextDocument(filepath + ".testcases").then(document => {
vscode.workspace.openTextDocument(filepath + ".tcs").then(document => {
console.log(document.getText())
vscode.window.showTextDocument(document, vscode.ViewColumn.Beside)
})

} catch (err) {
console.error(err);
}
}
})
}

function executePrimaryTask() {
async function executePrimaryTask() {
const saveFile = await vscode.commands.executeCommand("workbench.action.files.save");
var codeforcesURL = vscode.window.activeTextEditor.document.getText();
var filepath = vscode.window.activeTextEditor.document.fileName;
var cases;
Expand All @@ -111,7 +119,6 @@ function executePrimaryTask() {
codeforcesURL = codeforcesURL.split("\n")[0];
codeforcesURL = codeforcesURL.substring(2);
var compilationError = false;
var oc = vscode.window.createOutputChannel("competitive");


function evaluateResults(result, isFinal) {
Expand All @@ -124,7 +131,7 @@ function executePrimaryTask() {
let passed_cases = [];
function runTestCases(caseNum) {
try {
fs.accessSync(filepath + ".testcases")
fs.accessSync(filepath + ".tcs")
} catch (err) {
var html = downloadCodeforcesPage(codeforcesURL);
html.then(string => {
Expand Down Expand Up @@ -190,6 +197,8 @@ function executePrimaryTask() {
}
if (caseNum == (cases.numCases - 1)) {
evaluateResults(passed_cases, true);
spawn("rm", [filepath + ".bin"]);

} else {
evaluateResults(passed_cases, false);
}
Expand Down Expand Up @@ -251,7 +260,7 @@ function executePrimaryTask() {
} else {
testCasesHelper(filepath);
// oc.clear();
// oc.append("Error - \nYou must do either of these two things : \nCreate a comment with the URL of the codeforces problem on line 1 first.\nOr Create a .testcases file containing the testcases. If your current filename is A.cpp then create a file A.cpp.testcases");
// oc.append("Error - \nYou must do either of these two things : \nCreate a comment with the URL of the codeforces problem on line 1 first.\nOr Create a .tcs file containing the testcases. If your current filename is A.cpp then create a file A.cpp.tcs");
// oc.show();
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions generateResultsHtml.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ ${element.got}</pre>
<title>Document</title>
<style>
.case {
background: rgb(26, 26, 26);
background: rgba(0,0,0,0.1);
padding: 10px;
margin-bottom: 5px;
}
pre {
background: rgb(24, 24, 24);
background: rgba(0,0,0,0.2);
color: bisque;
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"c++",
"testcases"
],
"version": "0.0.6",
"version": "0.0.7",
"icon": "icon.png",
"engines": {
"vscode": "^1.39.0"
Expand Down
4 changes: 2 additions & 2 deletions parseTestCasesFile.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/**
* Parses a .testcases file and returns an object - containing inputs and outputs and no of testcases
* Parses a .tcs file and returns an object - containing inputs and outputs and no of testcases
*/

const fs = require("fs");

function parseTestCasesFile(sourceCodePath) {
var filePath = sourceCodePath + ".testcases";
var filePath = sourceCodePath + ".tcs";
try { var txt = fs.readFileSync(filePath).toString() }
catch (err) { console.error(err); return; }
var tcNum = 0;
Expand Down

0 comments on commit 7f6753f

Please sign in to comment.