Skip to content

Commit

Permalink
Add an option to control whether competitve compenion support should …
Browse files Browse the repository at this point in the history
…open selected files
  • Loading branch information
sam20908 committed Dec 16, 2024
1 parent 1e35bcb commit 03d3e47
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ Required files (naming scheme can be configured in settings):
<details>
<summary>Settings for Competitive Companion integration</summary>

- `openSelectedFiles` (default: `true`): Whether to open all the selected files
- `askForWhichFile` (default: `false`): Ask for which file to write testcase onto, even when a file is currently opened and only a single problem has been received
- `includePattern` (default: `**/*`): Glob pattern to filter in the included files for asking prompt
- `excludePattern` (default: *empty*): Glob pattern to filter out the included files for asking prompt
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,11 @@
{
"title": "Competitive Companion",
"properties": {
"fastolympiccoding.openSelectedFiles": {
"type": "boolean",
"default": true,
"description": "Whether to open all the selected files for the testcases."
},
"fastolympiccoding.askForWhichFile": {
"type": "boolean",
"default": false,
Expand Down
19 changes: 11 additions & 8 deletions src/extension/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ function registerCommands(context: vscode.ExtensionContext): void {

function listenForCompetitiveCompanion() {
let problemDatas: any[] = [];
let filePaths: string[] = [];
let cnt = 0;
const server = http.createServer((req, res) => {
if (req.method !== 'POST') {
Expand All @@ -111,13 +110,16 @@ function listenForCompetitiveCompanion() {

const file = vscode.window.activeTextEditor?.document.fileName;
const workspace = vscode.workspace.workspaceFolders?.at(0)?.uri.fsPath ?? '';
const askForWhichFile = vscode.workspace.getConfiguration('fastolympiccoding').get('askForWhichFile', false);
const includePattern = vscode.workspace.getConfiguration('fastolympiccoding').get('includePattern')! as string;
const excludePattern = vscode.workspace.getConfiguration('fastolympiccoding').get('excludePattern')! as string;
const config = vscode.workspace.getConfiguration('fastolympiccoding')
const openSelectedFiles = config.get('openSelectedFiles')! as boolean;
const askForWhichFile = config.get('askForWhichFile')! as boolean;
const includePattern = config.get('includePattern')! as string;
const excludePattern = config.get('excludePattern')! as string;
const files = (await vscode.workspace.findFiles(includePattern, excludePattern)).map(file => ({
label: path.parse(file.fsPath).base,
description: path.parse(path.relative(workspace, file.fsPath)).dir,
}));
let filePaths: string[] = [];
for (let i = 0; i < problemDatas.length; i++) {
let fileTo = problemDatas[i].batch.size === 1 && file ? path.relative(workspace, file) : '';
if (askForWhichFile || problemDatas[i].batch.size > 1 || !file) {
Expand Down Expand Up @@ -156,12 +158,13 @@ function listenForCompetitiveCompanion() {
testcasesViewProvider.addFromCompetitiveCompanion(fileTo, problemDatas[i]);
filePaths.push(fileTo);
}
for (const filePath of filePaths) {
const document = await vscode.workspace.openTextDocument(vscode.Uri.file(filePath));
await vscode.window.showTextDocument(document);
if (openSelectedFiles) {
for (const filePath of filePaths) {
const document = await vscode.workspace.openTextDocument(vscode.Uri.file(filePath));
await vscode.window.showTextDocument(document);
}
}
problemDatas = [];
filePaths = [];
});
});
server.listen(1327);
Expand Down

0 comments on commit 03d3e47

Please sign in to comment.