Skip to content

Commit

Permalink
add option to select default language (#22)
Browse files Browse the repository at this point in the history
* add option to select default language

* update readme and other minor changes

* Update package.json

* Fix minor nits

Co-authored-by: Divyanshu Agrawal <agrawal.divyanshu@outlook.com>
  • Loading branch information
arcane810 and agrawal-d authored Apr 8, 2020
1 parent 45c549c commit c92b6af
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Click on the ![Green plus](screenshots/companion.png) on your browser address ba

- Use the shortcut `Ctrl + Alt + B` to activate.
- You can choose additional compiler flags and save location from VSCode settings.
- You can choose a default language that will be used when you import a problem through Competitive Companion from VSCode settings.

![Settings](screenshots/settings.gif)
Change settings to hoose custom compiler flags and testcase/binary save location and more.
Expand Down
19 changes: 16 additions & 3 deletions companionHandler.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const vscode = require("vscode");
const parseTestCasesFile = require("./parseTestCasesFile");
const createTestacesFile = require("./createTestcasesFile");
const preferences = require("./preferencesHelper");
const locationHelper = require("./locationHelper");
const path = require("path");
const fs = require("fs");
Expand All @@ -22,9 +23,21 @@ function handleCompanion(problem) {
const dir = vscode.workspace.workspaceFolders[0].uri.fsPath;
const languageChoices = Object.keys(config.extensions);

vscode.window.showQuickPick(languageChoices, {
placeHolder: "Select the language"
})
const defaultLanguage = preferences().get("defaultLanguage");
const selectLanguage = new Promise( (resolve) => {
if(defaultLanguage != "None") {
resolve(defaultLanguage);
}
else {
vscode.window.showQuickPick(languageChoices, {
placeHolder: "Select the language"
})
.then(language => {
resolve(language);
})
}
});
selectLanguage
.then(async language => {
const ext = config.extensions[language];
if (!ext)
Expand Down
13 changes: 13 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,19 @@
"type": "boolean",
"default": true,
"description": "A welcome message is shown when you run a testcase for the first time."
},
"competitive-programming-helper.defaultLanguage": {
"title": "Default language for new problems",
"type": "string",
"default": "",
"enum": [
"None",
"C",
"C++",
"Python",
"Rust"
],
"description": "The default language for problems imported via Competitive Companion (None will give option to select language on importing problem every time)"
}
}
},
Expand Down

0 comments on commit c92b6af

Please sign in to comment.