diff --git a/README.md b/README.md index 39e30a8..849000a 100644 --- a/README.md +++ b/README.md @@ -148,6 +148,7 @@ Required files (naming scheme can be configured in settings):
Settings for Competitive Companion integration + - `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 diff --git a/package.json b/package.json index db333d0..d0203f5 100644 --- a/package.json +++ b/package.json @@ -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, diff --git a/src/extension/extension.ts b/src/extension/extension.ts index e5bc76a..69e570c 100644 --- a/src/extension/extension.ts +++ b/src/extension/extension.ts @@ -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') { @@ -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) { @@ -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);