Skip to content

Commit

Permalink
Resolve #139: added an autoOpen option (#140)
Browse files Browse the repository at this point in the history
* added an autoOpen option

* fixed and bumped version

* fixed tests

Co-authored-by: Marcelo Fornet <[email protected]>
  • Loading branch information
ftiasch and mfornet authored Apr 21, 2022
1 parent 2f40c7f commit 504be4f
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 21 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"
}
}
}
Expand Down Expand Up @@ -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",
Expand Down
22 changes: 14 additions & 8 deletions src/companion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) => {
Expand Down
21 changes: 12 additions & 9 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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.
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
7 changes: 7 additions & 0 deletions src/webview/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 504be4f

Please sign in to comment.