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

structural change: saving state in store; adding samples view

parent 6b160101
Pipeline #4891 failed with stages
in 28 seconds
...@@ -47,9 +47,13 @@ ...@@ -47,9 +47,13 @@
"dark": "./images/soicode-activitybar-dark.svg" "dark": "./images/soicode-activitybar-dark.svg"
} }
}, },
{
"command": "soicode.openSample",
"title": "Opens a sample"
},
{ {
"command": "soicode.runSolutionOnSample", "command": "soicode.runSolutionOnSample",
"title": "Runs a Solution with a specific sample", "title": "Run solution with one sample",
"icon": { "icon": {
"light": "./images/icons/light/sample-run.svg", "light": "./images/icons/light/sample-run.svg",
"dark": "./images/icons/dark/sample-run.svg" "dark": "./images/icons/dark/sample-run.svg"
...@@ -57,7 +61,7 @@ ...@@ -57,7 +61,7 @@
}, },
{ {
"command": "soicode.runSolutionOnAllSamples", "command": "soicode.runSolutionOnAllSamples",
"title": "Runs a solution on all samples", "title": "Run solution on all samples",
"icon": { "icon": {
"light": "./images/icons/light/sample-run-all.svg", "light": "./images/icons/light/sample-run-all.svg",
"dark": "./images/icons/dark/sample-run-all.svg" "dark": "./images/icons/dark/sample-run-all.svg"
...@@ -65,7 +69,7 @@ ...@@ -65,7 +69,7 @@
}, },
{ {
"command": "soicode.runSolutionWithManualInput", "command": "soicode.runSolutionWithManualInput",
"title": "Runs a solution with user input", "title": "Run solution with user input",
"icon": { "icon": {
"light": "./images/icons/light/sample-run-manual.svg", "light": "./images/icons/light/sample-run-manual.svg",
"dark": "./images/icons/dark/sample-run-manual.svg" "dark": "./images/icons/dark/sample-run-manual.svg"
...@@ -73,7 +77,7 @@ ...@@ -73,7 +77,7 @@
}, },
{ {
"command": "soicode.debugSolutionOnSample", "command": "soicode.debugSolutionOnSample",
"title": "Starts the debugger for a solution run on a specific sample", "title": "Debug with one sample",
"icon": { "icon": {
"light": "./images/icons/light/sample-debug.svg", "light": "./images/icons/light/sample-debug.svg",
"dark": "./images/icons/dark/sample-debug.svg" "dark": "./images/icons/dark/sample-debug.svg"
...@@ -81,7 +85,7 @@ ...@@ -81,7 +85,7 @@
}, },
{ {
"command": "soicode.debugSolutionWithManualInput", "command": "soicode.debugSolutionWithManualInput",
"title": "Starts the debugger for a solution with user input", "title": "Debug with user input",
"icon": { "icon": {
"light": "./images/icons/light/sample-debug-manual.svg", "light": "./images/icons/light/sample-debug-manual.svg",
"dark": "./images/icons/dark/sample-debug-manual.svg" "dark": "./images/icons/dark/sample-debug-manual.svg"
...@@ -89,7 +93,7 @@ ...@@ -89,7 +93,7 @@
}, },
{ {
"command": "soicode.compileCurrentSolution", "command": "soicode.compileCurrentSolution",
"title": "Compiles the currently open solution" "title": "Compile open solution"
}, },
{ {
"command": "soicode.addSoitaskTemplate", "command": "soicode.addSoitaskTemplate",
...@@ -164,8 +168,65 @@ ...@@ -164,8 +168,65 @@
"command": "soicode.compileCurrentSolution", "command": "soicode.compileCurrentSolution",
"when": "view == soicode-tasks" "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": [ "languages": [
{ {
"id": "stoml", "id": "stoml",
......
import { Store } from "./store"; import { Store } from "./store";
import { getWorkspaceSettings } from "./soiworkspace";
import * as path from "path"; import * as path from "path";
import * as fs from "fs-extra"; // import * as fs from "fs-extra";
import * as https from "https"; // import * as https from "https";
import { getWorkspaceOrShowError } from "./storeHelper";
export async function getCompilerPath(store: Store): Promise<string | null> { export function getCompilerPath(store: Store): string {
let settings = await getWorkspaceSettings(); if (getWorkspaceOrShowError(store).settings.compiler.useManagedCompiler) {
if (settings === null) { return path.join(store.soicodeExtensionDataPath, "compiler", "g++");
return null;
}
if (settings.compiler.useManagedCompiler) {
return path.join(store.soicodeExtensionPath, "compiler", "clang++");
} else { } else {
return settings.compiler.manualCompilePath; return getWorkspaceOrShowError(store).settings.compiler.manualCompilePath;
} }
} }
export async function getDebuggerPath(store: Store): Promise<string | null> { export function getDebuggerPath(store: Store): string {
let settings = await getWorkspaceSettings(); if (getWorkspaceOrShowError(store).settings.compiler.useManagedCompiler) {
if (settings === null) { return path.join(store.soicodeExtensionDataPath, "compiler", "gdb");
return null;
}
if (settings.compiler.useManagedCompiler) {
return path.join(store.soicodeExtensionPath, "compiler", "clang++");
} else { } else {
// return settings.compiler.manualCompilePath; // todo // return settings.compiler.manualCompilePath; // todo
return "/usr/bin/gdb"; return "/usr/bin/gdb";
} }
} }
export async function getDebuggerFlavor(store: Store): Promise<"gdb" | "lldb" | null> { export function getDebuggerFlavor(store: Store): "gdb" | "lldb" | null {
let debuggerPath = await getDebuggerPath(store); let debuggerPath = getDebuggerPath(store);
if (debuggerPath === null) { if (debuggerPath === null) {
return null; return null;
} }
...@@ -41,13 +31,14 @@ export async function getDebuggerFlavor(store: Store): Promise<"gdb" | "lldb" | ...@@ -41,13 +31,14 @@ export async function getDebuggerFlavor(store: Store): Promise<"gdb" | "lldb" |
} }
return null; return null;
} }
export async function getClangFormatPath(store: Store): Promise<string | null> { export function getClangFormatPath(store: Store): string {
let settings = await getWorkspaceSettings(); if (getWorkspaceOrShowError(store).settings.compiler.useManagedCompiler) {
if (settings === null) { // todo needs on boolean flag since clangformat and compiler are independant
return null; return path.join(
} store.soicodeExtensionDataPath,
if (settings.compiler.useManagedCompiler) { // todo needs on boolean flag since clangformat and compiler are independant "compiler",
return path.join(store.soicodeExtensionPath, "compiler", "clang-format"); "clang-format"
);
} else { } else {
// return settings.compiler.manualCompilePath; // todo // return settings.compiler.manualCompilePath; // todo
return ""; return "";
...@@ -55,12 +46,9 @@ export async function getClangFormatPath(store: Store): Promise<string | null> { ...@@ -55,12 +46,9 @@ export async function getClangFormatPath(store: Store): Promise<string | null> {
} }
export async function getCppHeaderPath(store: Store): Promise<string | null> { export async function getCppHeaderPath(store: Store): Promise<string | null> {
let settings = await getWorkspaceSettings(); if (getWorkspaceOrShowError(store).settings.compiler.useManagedCompiler) {
if (settings === null) { // todo needs on boolean flag since headers and compiler are independant
return null; return path.join(store.soicodeExtensionDataPath, "compiler", "headers");
}
if (settings.compiler.useManagedCompiler) { // todo needs on boolean flag since headers and compiler are independant
return path.join(store.soicodeExtensionPath, "compiler", "headers");
} else { } else {
// return settings.compiler.manualCompilePath; // todo // return settings.compiler.manualCompilePath; // todo
return ""; return "";
...@@ -68,32 +56,32 @@ export async function getCppHeaderPath(store: Store): Promise<string | null> { ...@@ -68,32 +56,32 @@ export async function getCppHeaderPath(store: Store): Promise<string | null> {
} }
export async function getSoiHeaderPath(store: Store): Promise<string | null> { export async function getSoiHeaderPath(store: Store): Promise<string | null> {
let settings = await getWorkspaceSettings(); if (getWorkspaceOrShowError(store).settings.compiler.useManagedCompiler) {
if (settings === null) { // todo needs on boolean flag since soi headers and compiler are independant
return null; return path.join(store.soicodeExtensionDataPath, "compiler", "soiHeaders");
}
if (settings.compiler.useManagedCompiler) { // todo needs on boolean flag since soi headers and compiler are independant
return path.join(store.soicodeExtensionPath, "compiler", "soiHeaders");
} else { } else {
// return settings.compiler.manualCompilePath; // todo // return settings.compiler.manualCompilePath; // todo
return ""; return "";
} }
} }
export async function downloadCompilerBundle(store: Store) { // export async function downloadCompilerBundle(store: Store) {
let platform = ""; // let platform = "";
// also look at process.arch // // also look at process.arch
switch (process.platform) { // switch (process.platform) {
case "darwin": // case "darwin":
platform = "darwin-amd64"; // platform = "darwin-amd64";
case "win32": // case "win32":
platform = "windows-amd64"; // platform = "windows-amd64";
case "linux": // case "linux":
platform = "linux-amd64"; // platform = "linux-amd64";
} // }
await fs.mkdir(store.soicodeExtensionPath); // await fs.mkdir(store.soicodeExtensionPath);
let file = fs.createWriteStream(path.join(store.soicodeExtensionPath, "helper")); // let file = fs.createWriteStream(
let response = await https.get("https://blob.dolansoft.org/soicode/helper-" + platform); // path.join(store.soicodeExtensionPath, "helper")
response.pipe(file); // );
// let response = await https.get(
} // "https://blob.dolansoft.org/soicode/helper-" + platform
// );
// response.pipe(file);
// }
...@@ -5,43 +5,45 @@ import { SamplesTreeViewProvider } from "./samplesTreeView"; ...@@ -5,43 +5,45 @@ import { SamplesTreeViewProvider } from "./samplesTreeView";
import { initializeWorkspace } from "./soiworkspace"; import { initializeWorkspace } from "./soiworkspace";
import { createTask, createSoitaskFile, createCppFile } from "./soitask"; import { createTask, createSoitaskFile, createCppFile } from "./soitask";
import { insertCppTemplate, subscribeInsertCppTemplateLens } from "./lenses/emptyCppLens"; import {
import { subscribeInsertSoitaskTemplateLens, insertSoitaskTemplate } from "./lenses/emptySoitaskLens"; insertCppTemplate,
subscribeInsertCppTemplateLens
} from "./lenses/emptyCppLens";
import {
subscribeInsertSoitaskTemplateLens,
insertSoitaskTemplate
} from "./lenses/emptySoitaskLens";
import { Runner } from "./runner"; import { Runner } from "./runner";
import { Store } from "./store"; import { Store } from "./store";
import { downloadHelperBinary } from "./helperBinary"; 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";
export async function activate(context: vscode.ExtensionContext) { import { gotoSample } from "./sample";
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( let createTaskCommand = vscode.commands.registerCommand(
"soicode.createTask", "soicode.createTask",
createTask createTask.bind(undefined, store)
); );
context.subscriptions.push(createTaskCommand); context.subscriptions.push(createTaskCommand);
let initializeWorkspaceCommand = vscode.commands.registerCommand( let initializeWorkspaceCommand = vscode.commands.registerCommand(
"soicode.initializeWorkspace", "soicode.initializeWorkspace",
initializeWorkspace initializeWorkspace.bind(undefined, store)
); );
context.subscriptions.push(initializeWorkspaceCommand); context.subscriptions.push(initializeWorkspaceCommand);
let openSampleCommand = vscode.commands.registerCommand(
"soicode.openSample",
gotoSample.bind(undefined, store)
);
context.subscriptions.push(openSampleCommand);
let runSolutionOnSampleCommand = vscode.commands.registerCommand( let runSolutionOnSampleCommand = vscode.commands.registerCommand(
"soicode.runSolutionOnSample", "soicode.runSolutionOnSample",
...@@ -49,34 +51,29 @@ export async function activate(context: vscode.ExtensionContext) { ...@@ -49,34 +51,29 @@ export async function activate(context: vscode.ExtensionContext) {
); );
context.subscriptions.push(runSolutionOnSampleCommand); context.subscriptions.push(runSolutionOnSampleCommand);
let runSolutionOnAllSamplesCommand = vscode.commands.registerCommand( let runSolutionOnAllSamplesCommand = vscode.commands.registerCommand(
"soicode.runSolutionOnAllSamples", "soicode.runSolutionOnAllSamples",
runner.runAllSamples.bind(runner) runner.runAllSamples.bind(runner)
); );
context.subscriptions.push(runSolutionOnAllSamplesCommand); context.subscriptions.push(runSolutionOnAllSamplesCommand);
let runSolutionWithManualInputCommand = vscode.commands.registerCommand( let runSolutionWithManualInputCommand = vscode.commands.registerCommand(
"soicode.runSolutionWithManualInput", "soicode.runSolutionWithManualInput",
runner.runWithManualInput.bind(runner) runner.runWithManualInput.bind(runner)
); );
context.subscriptions.push(runSolutionWithManualInputCommand); context.subscriptions.push(runSolutionWithManualInputCommand);
let debugSolutionOnSampleCommand = vscode.commands.registerCommand( let debugSolutionOnSampleCommand = vscode.commands.registerCommand(
"soicode.debugSolutionOnSample", "soicode.debugSolutionOnSample",
initializeWorkspace initializeWorkspace
); );
context.subscriptions.push(debugSolutionOnSampleCommand);// Todo context.subscriptions.push(debugSolutionOnSampleCommand); // Todo
let debugSolutionWithManualInputCommand = vscode.commands.registerCommand( let debugSolutionWithManualInputCommand = vscode.commands.registerCommand(
"soicode.debugSolutionWithManualInput", "soicode.debugSolutionWithManualInput",
runner.askAndDebugManually.bind(runner) runner.askAndDebugManually.bind(runner)
); );
context.subscriptions.push(debugSolutionWithManualInputCommand);// Todo context.subscriptions.push(debugSolutionWithManualInputCommand); // Todo
let compileCurrentSolutionCommand = vscode.commands.registerCommand( let compileCurrentSolutionCommand = vscode.commands.registerCommand(
"soicode.compileCurrentSolution", "soicode.compileCurrentSolution",
...@@ -84,54 +81,48 @@ export async function activate(context: vscode.ExtensionContext) { ...@@ -84,54 +81,48 @@ export async function activate(context: vscode.ExtensionContext) {
); );
context.subscriptions.push(compileCurrentSolutionCommand); context.subscriptions.push(compileCurrentSolutionCommand);
let addSoitaskTemplateCommand = vscode.commands.registerCommand( let addSoitaskTemplateCommand = vscode.commands.registerCommand(
"soicode.addSoitaskTemplate", "soicode.addSoitaskTemplate",
insertSoitaskTemplate insertSoitaskTemplate.bind(undefined)
); );
context.subscriptions.push(addSoitaskTemplateCommand); context.subscriptions.push(addSoitaskTemplateCommand);
let addCppTemplateCommand = vscode.commands.registerCommand( let addCppTemplateCommand = vscode.commands.registerCommand(
"soicode.addCppTemplate", "soicode.addCppTemplate",
insertCppTemplate insertCppTemplate.bind(undefined)
); );
context.subscriptions.push(addCppTemplateCommand); context.subscriptions.push(addCppTemplateCommand);
let createSoitaskForSolutionCommand = vscode.commands.registerCommand( let createSoitaskForSolutionCommand = vscode.commands.registerCommand(
"soicode.createSoitaskForSolution", "soicode.createSoitaskForSolution",
createSoitaskFile createSoitaskFile.bind(undefined, store)
); );
context.subscriptions.push(createSoitaskForSolutionCommand); context.subscriptions.push(createSoitaskForSolutionCommand);
let createSolutionForSoitaskCommand = vscode.commands.registerCommand( let createSolutionForSoitaskCommand = vscode.commands.registerCommand(
"soicode.createSolutionForSoitask", "soicode.createSolutionForSoitask",
createCppFile createCppFile.bind(undefined, store)
); );
context.subscriptions.push(createSolutionForSoitaskCommand); context.subscriptions.push(createSolutionForSoitaskCommand);
subscribeInsertCppTemplateLens(context); let taskTreeViewProvider = new TaskTreeViewProvider(store);
subscribeInsertSoitaskTemplateLens(context); let samplesTreeViewProvider = new SamplesTreeViewProvider(store);
let fswatcher = vscode.workspace.createFileSystemWatcher('**/*', false, false, false); vscode.window.createTreeView("soicode-tasks", {
fswatcher.onDidChange((e) => { treeDataProvider: taskTreeViewProvider
taskTreeViewProvider.updateData();
});
fswatcher.onDidCreate((e) => {
taskTreeViewProvider.updateData();
}); });
fswatcher.onDidDelete((e) => { vscode.window.createTreeView("soicode-samples", {
taskTreeViewProvider.updateData(); treeDataProvider: samplesTreeViewProvider
}); });
context.subscriptions.push( subscribeInsertCppTemplateLens(context, store);
vscode.workspace.onDidSaveTextDocument((doc) => { subscribeInsertSoitaskTemplateLens(context, store);
taskTreeViewProvider.updateData();
})); let helperBinaryResultReceiver = new HelperBinaryResultReceiver(store);
helperBinaryResultReceiver.startServer(port);
store.emitFsChange();
runner.startServer(16314);
await downloadHelperBinary(store); await downloadHelperBinary(store);
activate_stoml(context); activate_stoml(context);
...@@ -151,7 +142,7 @@ export async function activate(context: vscode.ExtensionContext) { ...@@ -151,7 +142,7 @@ export async function activate(context: vscode.ExtensionContext) {
// } // }
// this method is called when your extension is deactivated // this method is called when your extension is deactivated
export function deactivate() { } export function deactivate() {}
// function sleep(ms: number) { // function sleep(ms: number) {
// return new Promise(resolve => { // return new Promise(resolve => {
......
import { Store } from "./store"; import { Store } from "./store";
import { getWorkspaceSettings } from "./soiworkspace";
import * as path from "path"; import * as path from "path";
import * as fs from "fs-extra"; import * as fs from "fs-extra";
import * as https from "https"; import * as https from "https";
import { getWorkspaceOrShowError } from "./storeHelper";
export async function getHelperPath(store: Store): Promise<string | null> { export function getHelperPath(store: Store): string {
let settings = await getWorkspaceSettings(); if (getWorkspaceOrShowError(store).settings.helper.useManagedHelper) {
if (settings === null) { return path.join(store.soicodeExtensionDataPath, "helper");
return null;
}
if (settings.helper.useManagedHelper) {
return path.join(store.soicodeExtensionPath, "helper");
} else { } else {
return settings.helper.manualHelperPath; return getWorkspaceOrShowError(store).settings.helper.manualHelperPath;
} }
} }
...@@ -30,19 +26,23 @@ export async function downloadHelperBinary(store: Store) { ...@@ -30,19 +26,23 @@ export async function downloadHelperBinary(store: Store) {
} }
console.log("Fetching Helper binary for platform " + platform); console.log("Fetching Helper binary for platform " + platform);
try { try {
await fs.mkdir(store.soicodeExtensionPath); await fs.mkdir(store.soicodeExtensionDataPath);
} catch (err) {