From 504be4f366715af5ae910fe1630e51e8697474ee Mon Sep 17 00:00:00 2001 From: Xiaoxu Guo Date: Thu, 21 Apr 2022 09:56:21 +0000 Subject: [PATCH] Resolve #139: added an autoOpen option (#140) * added an autoOpen option * fixed and bumped version * fixed tests Co-authored-by: Marcelo Fornet --- package-lock.json | 4 ++-- package.json | 10 ++++++++-- src/companion.ts | 22 ++++++++++++++-------- src/extension.ts | 21 ++++++++++++--------- src/webview/types.ts | 7 +++++++ 5 files changed, 43 insertions(+), 21 deletions(-) diff --git a/package-lock.json b/package-lock.json index e37d818..095f5fa 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "acmx", - "version": "0.3.6", + "version": "0.3.7", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "acmx", - "version": "0.3.6", + "version": "0.3.7", "license": "MIT", "dependencies": { "body-parser": "^1.19.0", diff --git a/package.json b/package.json index be4b1c9..0ca6339 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "Competitive Programming made simple", "icon": "images/logo.png", "publisher": "marx24", - "version": "0.3.6", + "version": "0.3.7", "license": "MIT", "keywords": [ "acm", @@ -173,6 +173,12 @@ "default": false, "description": "Whether to retain webview context (may case rendering issues).", "scope": "resource" + }, + "acmx.configuration.autoOpen": { + "type": "boolean", + "default": true, + "description": "Whether to open the folder after a problem is added.", + "scope": "resource" } } } @@ -393,7 +399,7 @@ "lint": "eslint src/ --ext .ts,.tsx", "watch": "tsc -watch -p ./", "pretest": "npm run compile && npm run lint", - "test": "node ./out/test/runTest.js", + "test": "node ./dist/test/runTest.js", "webpack-production": "webpack --mode production", "webpack-frontend-production": "webpack --mode production --config ./webpack.frontend.config.js", "vscode:prepublish": "npm run webpack-frontend-production && npm run webpack-production", diff --git a/src/companion.ts b/src/companion.ts index 33ee943..4427f0d 100644 --- a/src/companion.ts +++ b/src/companion.ts @@ -4,6 +4,7 @@ import sanitize from "sanitize-filename"; import express from "express"; import bodyParser = require("body-parser"); import { debug } from "./utils"; +import { getAutoOpen } from "./webview/types"; export class CompanionConfig { name: string; @@ -65,14 +66,19 @@ export function startCompetitiveCompanionService() { "" ); - await vscode.commands - .executeCommand("vscode.openFolder", vscode.Uri.file(contestPath)) - .then(async () => { - await vscode.commands.executeCommand( - "vscode.open", - vscode.Uri.file(mainSolution) - ); - }); + if (getAutoOpen()) { + await vscode.commands + .executeCommand( + "vscode.openFolder", + vscode.Uri.file(contestPath) + ) + .then(async () => { + await vscode.commands.executeCommand( + "vscode.open", + vscode.Uri.file(mainSolution) + ); + }); + } }); app.listen(port, (err: any) => { diff --git a/src/extension.ts b/src/extension.ts index 94bb4a1..e5bc4e5 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -50,7 +50,7 @@ import { checkLaunchWebview, } from "./webview/editorChange"; -import { getRetainWebviewContextPref } from "./webview/types"; +import { getAutoOpen, getRetainWebviewContextPref } from "./webview/types"; import JudgeViewProvider from "./webview/JudgeView"; import { RunTestCases } from "./webview/core"; @@ -61,6 +61,15 @@ export const getJudgeViewProvider = () => { return judgeViewProvider; }; +function openFolder(path: string) { + if (getAutoOpen()) { + vscode.commands.executeCommand( + "vscode.openFolder", + vscode.Uri.file(path) + ); + } +} + // Create a new problem export async function addProblem() { // Use default site when creating a problem from the vscode. @@ -80,10 +89,7 @@ export async function addProblem() { const problemPath = newProblemFromId(path, site, id); - await vscode.commands.executeCommand( - "vscode.openFolder", - vscode.Uri.file(problemPath) - ); + openFolder(problemPath); } function parseNumberOfProblems(numberOfProblems: string | undefined) { @@ -138,10 +144,7 @@ async function addContest() { const contestPath = await newContestFromId(path!, site, id); - vscode.commands.executeCommand( - "vscode.openFolder", - vscode.Uri.file(contestPath) - ); + openFolder(contestPath); } async function debugTestCase(path: string, tcId: string) { diff --git a/src/webview/types.ts b/src/webview/types.ts index 131010e..1e055a7 100644 --- a/src/webview/types.ts +++ b/src/webview/types.ts @@ -37,6 +37,13 @@ export function getRetainWebviewContextPref(): boolean { return x ?? false; } +export function getAutoOpen(): boolean { + const x: boolean | undefined = vscode.workspace + .getConfiguration("acmx.configuration", null) + .get("autoOpen"); + return x ?? true; +} + export type Language = { name: LangNames; compiler: string;