Commit 992cb827 authored by Timon Stampfli's avatar Timon Stampfli

structural change: saving state in store; adding samples view

parent 6b160101
Pipeline #4891 failed with stages
in 28 seconds
......@@ -47,9 +47,13 @@
"dark": "./images/soicode-activitybar-dark.svg"
}
},
{
"command": "soicode.openSample",
"title": "Opens a sample"
},
{
"command": "soicode.runSolutionOnSample",
"title": "Runs a Solution with a specific sample",
"title": "Run solution with one sample",
"icon": {
"light": "./images/icons/light/sample-run.svg",
"dark": "./images/icons/dark/sample-run.svg"
......@@ -57,7 +61,7 @@
},
{
"command": "soicode.runSolutionOnAllSamples",
"title": "Runs a solution on all samples",
"title": "Run solution on all samples",
"icon": {
"light": "./images/icons/light/sample-run-all.svg",
"dark": "./images/icons/dark/sample-run-all.svg"
......@@ -65,7 +69,7 @@
},
{
"command": "soicode.runSolutionWithManualInput",
"title": "Runs a solution with user input",
"title": "Run solution with user input",
"icon": {
"light": "./images/icons/light/sample-run-manual.svg",
"dark": "./images/icons/dark/sample-run-manual.svg"
......@@ -73,7 +77,7 @@
},
{
"command": "soicode.debugSolutionOnSample",
"title": "Starts the debugger for a solution run on a specific sample",
"title": "Debug with one sample",
"icon": {
"light": "./images/icons/light/sample-debug.svg",
"dark": "./images/icons/dark/sample-debug.svg"
......@@ -81,7 +85,7 @@
},
{
"command": "soicode.debugSolutionWithManualInput",
"title": "Starts the debugger for a solution with user input",
"title": "Debug with user input",
"icon": {
"light": "./images/icons/light/sample-debug-manual.svg",
"dark": "./images/icons/dark/sample-debug-manual.svg"
......@@ -89,7 +93,7 @@
},
{
"command": "soicode.compileCurrentSolution",
"title": "Compiles the currently open solution"
"title": "Compile open solution"
},
{
"command": "soicode.addSoitaskTemplate",
......@@ -164,8 +168,65 @@
"command": "soicode.compileCurrentSolution",
"when": "view == soicode-tasks"
}
],
"view/item/context": [
{
"command": "soicode.runSolutionOnAllSamples",
"when": "view == soicode-tasks && viewItem == soitask || view == soicode-tasks && viewItem == task || view == soicode-tasks && viewItem == solution"
},
{
"command": "soicode.runSolutionOnSample",
"when": "view == soicode-tasks && viewItem == soitask || view == soicode-tasks && viewItem == task || view == soicode-tasks && viewItem == solution"
},
{
"command": "soicode.runSolutionWithManualInput",
"when": "view == soicode-tasks && viewItem == soitask || view == soicode-tasks && viewItem == task || view == soicode-tasks && viewItem == solution"
},
{
"command": "soicode.debugSolutionOnSample",
"when": "view == soicode-tasks && viewItem == soitask || view == soicode-tasks && viewItem == task || view == soicode-tasks && viewItem == solution"
},
{
"command": "soicode.debugSolutionWithManualInput",
"when": "view == soicode-tasks && viewItem == soitask || view == soicode-tasks && viewItem == task || view == soicode-tasks && viewItem == solution"
}
],
"editor/context": [
{
"command": "soicode.runSolutionOnAllSamples",
"group": "soicode",
"when": "editorLangId == cpp || editorLangId == stoml"
},
{
"command": "soicode.runSolutionOnSample",
"group": "soicode",
"when": "editorLangId == cpp || editorLangId == stoml"
},
{
"command": "soicode.runSolutionWithManualInput",
"group": "soicode",
"when": "editorLangId == cpp || editorLangId == stoml"
},
{
"command": "soicode.debugSolutionOnSample",
"group": "soicode",
"when": "editorLangId == cpp || editorLangId == stoml"
},
{
"command": "soicode.debugSolutionWithManualInput",
"group": "soicode",
"when": "editorLangId == cpp || editorLangId == stoml"
}
]
},
"keybindings": [
{
"command": "soicode.runSolutionOnAllSamples",
"key": "ctrl+enter",
"mac": "ctrl+enter",
"when": "editorLangId == cpp || editorLangId == stoml"
}
],
"languages": [
{
"id": "stoml",
......@@ -190,7 +251,7 @@
"scopeName": "source.stoml",
"path": "./stoml-language/STOML.tmLanguage"
}
]
]
},
"extensionDependencies-deactivated": [
"ms-vscode.cpptools"
......
import { Store } from "./store";
import { getWorkspaceSettings } from "./soiworkspace";
import * as path from "path";
import * as fs from "fs-extra";
import * as https from "https";
// import * as fs from "fs-extra";
// import * as https from "https";
import { getWorkspaceOrShowError } from "./storeHelper";
export async function getCompilerPath(store: Store): Promise<string | null> {
let settings = await getWorkspaceSettings();
if (settings === null) {
return null;
}
if (settings.compiler.useManagedCompiler) {
return path.join(store.soicodeExtensionPath, "compiler", "clang++");
} else {
return settings.compiler.manualCompilePath;
}
export function getCompilerPath(store: Store): string {
if (getWorkspaceOrShowError(store).settings.compiler.useManagedCompiler) {
return path.join(store.soicodeExtensionDataPath, "compiler", "g++");
} else {
return getWorkspaceOrShowError(store).settings.compiler.manualCompilePath;
}
}
export async function getDebuggerPath(store: Store): Promise<string | null> {
let settings = await getWorkspaceSettings();
if (settings === null) {
return null;
}
if (settings.compiler.useManagedCompiler) {
return path.join(store.soicodeExtensionPath, "compiler", "clang++");
} else {
// return settings.compiler.manualCompilePath; // todo
return "/usr/bin/gdb";
}
export function getDebuggerPath(store: Store): string {
if (getWorkspaceOrShowError(store).settings.compiler.useManagedCompiler) {
return path.join(store.soicodeExtensionDataPath, "compiler", "gdb");
} else {
// return settings.compiler.manualCompilePath; // todo
return "/usr/bin/gdb";
}
}
export async function getDebuggerFlavor(store: Store): Promise<"gdb" | "lldb" | null> {
let debuggerPath = await getDebuggerPath(store);
if (debuggerPath === null) {
return null;
}
let flavor = path.basename(debuggerPath);
if (flavor === "gdb" || flavor === "lldb") {
return flavor;
}
return null;
export function getDebuggerFlavor(store: Store): "gdb" | "lldb" | null {
let debuggerPath = getDebuggerPath(store);
if (debuggerPath === null) {
return null;
}
let flavor = path.basename(debuggerPath);
if (flavor === "gdb" || flavor === "lldb") {
return flavor;
}
return null;
}
export async function getClangFormatPath(store: Store): Promise<string | null> {
let settings = await getWorkspaceSettings();
if (settings === null) {
return null;
}
if (settings.compiler.useManagedCompiler) { // todo needs on boolean flag since clangformat and compiler are independant
return path.join(store.soicodeExtensionPath, "compiler", "clang-format");
} else {
// return settings.compiler.manualCompilePath; // todo
return "";
}
export function getClangFormatPath(store: Store): string {
if (getWorkspaceOrShowError(store).settings.compiler.useManagedCompiler) {
// todo needs on boolean flag since clangformat and compiler are independant
return path.join(
store.soicodeExtensionDataPath,
"compiler",
"clang-format"
);
} else {
// return settings.compiler.manualCompilePath; // todo
return "";
}
}
export async function getCppHeaderPath(store: Store): Promise<string | null> {
let settings = await getWorkspaceSettings();
if (settings === null) {
return null;
}
if (settings.compiler.useManagedCompiler) { // todo needs on boolean flag since headers and compiler are independant
return path.join(store.soicodeExtensionPath, "compiler", "headers");
} else {
// return settings.compiler.manualCompilePath; // todo
return "";
}
if (getWorkspaceOrShowError(store).settings.compiler.useManagedCompiler) {
// todo needs on boolean flag since headers and compiler are independant
return path.join(store.soicodeExtensionDataPath, "compiler", "headers");
} else {
// return settings.compiler.manualCompilePath; // todo
return "";
}
}
export async function getSoiHeaderPath(store: Store): Promise<string | null> {
let settings = await getWorkspaceSettings();
if (settings === null) {
return null;
}
if (settings.compiler.useManagedCompiler) { // todo needs on boolean flag since soi headers and compiler are independant
return path.join(store.soicodeExtensionPath, "compiler", "soiHeaders");
} else {
// return settings.compiler.manualCompilePath; // todo
return "";
}
if (getWorkspaceOrShowError(store).settings.compiler.useManagedCompiler) {
// todo needs on boolean flag since soi headers and compiler are independant
return path.join(store.soicodeExtensionDataPath, "compiler", "soiHeaders");
} else {
// return settings.compiler.manualCompilePath; // todo
return "";
}
}
export async function downloadCompilerBundle(store: Store) {
let platform = "";
// also look at process.arch
switch (process.platform) {
case "darwin":
platform = "darwin-amd64";
case "win32":
platform = "windows-amd64";
case "linux":
platform = "linux-amd64";
}
await fs.mkdir(store.soicodeExtensionPath);
let file = fs.createWriteStream(path.join(store.soicodeExtensionPath, "helper"));
let response = await https.get("https://blob.dolansoft.org/soicode/helper-" + platform);
response.pipe(file);
}
// export async function downloadCompilerBundle(store: Store) {
// let platform = "";
// // also look at process.arch
// switch (process.platform) {
// case "darwin":
// platform = "darwin-amd64";
// case "win32":
// platform = "windows-amd64";
// case "linux":
// platform = "linux-amd64";
// }
// await fs.mkdir(store.soicodeExtensionPath);
// let file = fs.createWriteStream(
// path.join(store.soicodeExtensionPath, "helper")
// );
// let response = await https.get(
// "https://blob.dolansoft.org/soicode/helper-" + platform
// );
// response.pipe(file);
// }
......@@ -5,43 +5,45 @@ import { SamplesTreeViewProvider } from "./samplesTreeView";
import { initializeWorkspace } from "./soiworkspace";
import { createTask, createSoitaskFile, createCppFile } from "./soitask";
import { insertCppTemplate, subscribeInsertCppTemplateLens } from "./lenses/emptyCppLens";
import { subscribeInsertSoitaskTemplateLens, insertSoitaskTemplate } from "./lenses/emptySoitaskLens";
import {
insertCppTemplate,
subscribeInsertCppTemplateLens
} from "./lenses/emptyCppLens";
import {
subscribeInsertSoitaskTemplateLens,
insertSoitaskTemplate
} from "./lenses/emptySoitaskLens";
import { Runner } from "./runner";
import { Store } from "./store";
import { downloadHelperBinary } from "./helperBinary";
import { activate as activate_stoml } from './better-stoml/src/extension';
import { activate as activate_stoml } from "./better-stoml/src/extension";
import { HelperBinaryResultReceiver } from "./helperBinaryResultReceiver";
import { gotoSample } from "./sample";
export async function activate(context: vscode.ExtensionContext) {
let taskTreeViewProvider = new TaskTreeViewProvider(context);
let samplesTreeViewProvider = new SamplesTreeViewProvider(context, []);
vscode.window.createTreeView("soicode-tasks", {
treeDataProvider: taskTreeViewProvider
});
vscode.window.createTreeView("soicode-samples", {
treeDataProvider: samplesTreeViewProvider
});
let store = new Store(context.globalStoragePath);
let runner = new Runner(store);
const port = 16314;
export async function activate(context: vscode.ExtensionContext) {
let store = new Store(context);
let runner = new Runner(store, port);
let createTaskCommand = vscode.commands.registerCommand(
"soicode.createTask",
createTask
createTask.bind(undefined, store)
);
context.subscriptions.push(createTaskCommand);
let initializeWorkspaceCommand = vscode.commands.registerCommand(
"soicode.initializeWorkspace",
initializeWorkspace
initializeWorkspace.bind(undefined, store)
);
context.subscriptions.push(initializeWorkspaceCommand);
let openSampleCommand = vscode.commands.registerCommand(
"soicode.openSample",
gotoSample.bind(undefined, store)
);
context.subscriptions.push(openSampleCommand);
let runSolutionOnSampleCommand = vscode.commands.registerCommand(
"soicode.runSolutionOnSample",
......@@ -49,34 +51,29 @@ export async function activate(context: vscode.ExtensionContext) {
);
context.subscriptions.push(runSolutionOnSampleCommand);
let runSolutionOnAllSamplesCommand = vscode.commands.registerCommand(
"soicode.runSolutionOnAllSamples",
runner.runAllSamples.bind(runner)
);
context.subscriptions.push(runSolutionOnAllSamplesCommand);
let runSolutionWithManualInputCommand = vscode.commands.registerCommand(
"soicode.runSolutionWithManualInput",
runner.runWithManualInput.bind(runner)
);
context.subscriptions.push(runSolutionWithManualInputCommand);
let debugSolutionOnSampleCommand = vscode.commands.registerCommand(
"soicode.debugSolutionOnSample",
initializeWorkspace
);
context.subscriptions.push(debugSolutionOnSampleCommand);// Todo
context.subscriptions.push(debugSolutionOnSampleCommand); // Todo
let debugSolutionWithManualInputCommand = vscode.commands.registerCommand(
"soicode.debugSolutionWithManualInput",
runner.askAndDebugManually.bind(runner)
);
context.subscriptions.push(debugSolutionWithManualInputCommand);// Todo
context.subscriptions.push(debugSolutionWithManualInputCommand); // Todo
let compileCurrentSolutionCommand = vscode.commands.registerCommand(
"soicode.compileCurrentSolution",
......@@ -84,54 +81,48 @@ export async function activate(context: vscode.ExtensionContext) {
);
context.subscriptions.push(compileCurrentSolutionCommand);
let addSoitaskTemplateCommand = vscode.commands.registerCommand(
"soicode.addSoitaskTemplate",
insertSoitaskTemplate
insertSoitaskTemplate.bind(undefined)
);
context.subscriptions.push(addSoitaskTemplateCommand);
let addCppTemplateCommand = vscode.commands.registerCommand(
"soicode.addCppTemplate",
insertCppTemplate
insertCppTemplate.bind(undefined)
);
context.subscriptions.push(addCppTemplateCommand);
let createSoitaskForSolutionCommand = vscode.commands.registerCommand(
"soicode.createSoitaskForSolution",
createSoitaskFile
createSoitaskFile.bind(undefined, store)
);
context.subscriptions.push(createSoitaskForSolutionCommand);
let createSolutionForSoitaskCommand = vscode.commands.registerCommand(
"soicode.createSolutionForSoitask",
createCppFile
createCppFile.bind(undefined, store)
);
context.subscriptions.push(createSolutionForSoitaskCommand);
subscribeInsertCppTemplateLens(context);
subscribeInsertSoitaskTemplateLens(context);
let taskTreeViewProvider = new TaskTreeViewProvider(store);
let samplesTreeViewProvider = new SamplesTreeViewProvider(store);
let fswatcher = vscode.workspace.createFileSystemWatcher('**/*', false, false, false);
fswatcher.onDidChange((e) => {
taskTreeViewProvider.updateData();
});
fswatcher.onDidCreate((e) => {
taskTreeViewProvider.updateData();
vscode.window.createTreeView("soicode-tasks", {
treeDataProvider: taskTreeViewProvider
});
fswatcher.onDidDelete((e) => {
taskTreeViewProvider.updateData();
vscode.window.createTreeView("soicode-samples", {
treeDataProvider: samplesTreeViewProvider
});
context.subscriptions.push(
vscode.workspace.onDidSaveTextDocument((doc) => {
taskTreeViewProvider.updateData();
}));
subscribeInsertCppTemplateLens(context, store);
subscribeInsertSoitaskTemplateLens(context, store);
let helperBinaryResultReceiver = new HelperBinaryResultReceiver(store);
helperBinaryResultReceiver.startServer(port);
store.emitFsChange();
runner.startServer(16314);
await downloadHelperBinary(store);
activate_stoml(context);
......@@ -151,7 +142,7 @@ export async function activate(context: vscode.ExtensionContext) {
// }
// this method is called when your extension is deactivated
export function deactivate() { }
export function deactivate() {}
// function sleep(ms: number) {
// return new Promise(resolve => {
......
import { Store } from "./store";
import { getWorkspaceSettings } from "./soiworkspace";
import * as path from "path";
import * as fs from "fs-extra";
import * as https from "https";
import { getWorkspaceOrShowError } from "./storeHelper";
export async function getHelperPath(store: Store): Promise<string | null> {
let settings = await getWorkspaceSettings();
if (settings === null) {
return null;
}
if (settings.helper.useManagedHelper) {
return path.join(store.soicodeExtensionPath, "helper");
} else {
return settings.helper.manualHelperPath;
}
export function getHelperPath(store: Store): string {
if (getWorkspaceOrShowError(store).settings.helper.useManagedHelper) {
return path.join(store.soicodeExtensionDataPath, "helper");
} else {
return getWorkspaceOrShowError(store).settings.helper.manualHelperPath;
}
}
export async function downloadHelperBinary(store: Store) {
let platform = "";
// also look at process.arch
switch (process.platform) {
case "darwin":
platform = "darwin-amd64";
case "win32":
platform = "windows-amd64";
case "linux":
platform = "linux-amd64";
}
console.log("Fetching Helper binary for platform " + platform);
try {
await fs.mkdir(store.soicodeExtensionPath);
} catch (err) {
if (err.code !== "EEXIST") {
throw err;
}
}
let file = fs.createWriteStream(path.join(store.soicodeExtensionPath, "helper"), { mode: parseInt('755', 8) });
https.get("https://blob.dolansoft.org/soicode/helper-" + platform, response => {
response.pipe(file);
file.on("finish", () => {
file.close();
});
});
}
\ No newline at end of file
let platform = "";
// also look at process.arch
switch (process.platform) {
case "darwin":
platform = "darwin-amd64";
case "win32":
platform = "windows-amd64";
case "linux":
platform = "linux-amd64";
}
console.log("Fetching Helper binary for platform " + platform);
try {
await fs.mkdir(store.soicodeExtensionDataPath);
} catch (err) {
if (err.code !== "EEXIST") {
throw err;
}
}
let file = fs.createWriteStream(
path.join(store.soicodeExtensionDataPath, "helper"),
{ mode: parseInt("755", 8) }
);
https.get(
"https://blob.dolansoft.org/soicode/helper-" + platform,
response => {
response.pipe(file);
file.on("finish", () => {
file.close();
});
}
);
}
import { Store } from "./store";
import * as net from "net";
import { fspathToTasknameOrError } from "./soitask";
export interface SampleExecutionResult {
Stdin: string;
Stdout: string;
Stderr: string;
ProcessError: string;
}
function checkServerResponseTyped(
o: any
): [string, string, SampleExecutionResult] | null {
if (typeof o.Binarypath !== "string") {
return null;
}
if (typeof o.Samplename !== "string") {
return null;
}
if (typeof o.Result !== "object") {
return null;
}
if (typeof o.Result.Stdin !== "string") {
return null;
}
if (typeof o.Result.Stdout !== "string") {
return null;
}
if (typeof o.Result.Stderr !== "string") {
return null;
}
if (typeof o.Result.ProcessError !== "string") {