Skip to content
Snippets Groups Projects
Commit 72c7aefc authored by Sytze de Witte's avatar Sytze de Witte
Browse files

Added: analysis results open in editor

parent f59621ee
No related branches found
No related tags found
No related merge requests found
......@@ -36,8 +36,8 @@
"command": "analysisResults.copyValue",
"title": "Copy value",
"icon": {
"light": "media/light/copy.svg",
"dark": "media/dark/copy.svg"
"light": "media/light/copy.svg",
"dark": "media/dark/copy.svg"
}
},
{
......@@ -51,9 +51,13 @@
{
"command": "analysisResults.export",
"title": "Export to JSON file"
},
{
"command": "analysisResults.openInEditor",
"title": "Open in editor"
}
],
"menus":{
"menus": {
"view/title": [
{
"command": "analysisResults.load",
......@@ -66,9 +70,9 @@
],
"view/item/context": [
{
"command": "analysisResults.copyValue",
"when": "view == analysisResults",
"group": "inline"
"command": "analysisResults.copyValue",
"when": "view == analysisResults",
"group": "inline"
},
{
"command": "analysisResults.copyValue",
......@@ -77,6 +81,10 @@
{
"command": "analysisResults.copyItem",
"when": "view == analysisResults"
},
{
"command": "analysisResults.openInEditor",
"when": "view == analysisResults"
}
]
},
......
......@@ -11,12 +11,14 @@ export class AnalysisResultsProvider
readonly onDidChangeTreeData: vscode.Event<Result | undefined | null | void> =
this._onDidChangeTreeData.event;
private jsonObject: any | null;
private jsonObject: any;
private jsonPath: string;
private modestFile: string;
constructor() {
this.jsonPath = "";
this.jsonObject = null;
this.jsonPath = "";
this.modestFile = "";
}
refresh(): void {
......@@ -46,8 +48,9 @@ export class AnalysisResultsProvider
}
}
setJsonObject(jsonObject: JSON) {
setJsonObject(jsonObject: JSON | any) {
this.jsonObject = jsonObject;
this.modestFile = jsonObject["file"].split("/").pop().replace(".modest", "");
this.refresh();
}
......@@ -57,10 +60,12 @@ export class AnalysisResultsProvider
}
setJsonPath(newPath: string) {
this.jsonPath = newPath;
var jsonFile = fs.readFileSync(newPath, "utf-8");
var jsonObject = JSON.parse(jsonFile.trim());
this.setJsonObject(jsonObject);
if (this.pathExists(newPath)) {
this.jsonPath = newPath;
var jsonFile = fs.readFileSync(newPath, "utf-8");
var jsonObject = JSON.parse(jsonFile.trim());
this.setJsonObject(jsonObject);
}
}
dataToResult(data: JSON[]) {
......@@ -120,6 +125,14 @@ export class AnalysisResultsProvider
return this.jsonObject;
}
getJsonPath() {
return this.jsonPath;
}
getModestFile() {
return this.modestFile;
}
private pathExists(p: string): boolean {
try {
fs.accessSync(p);
......
......@@ -210,6 +210,11 @@ export function activate(context: ExtensionContext) {
(res: Result) => copyToClipboard(`${res.getLabel()}: ${res.getValue()}`)
);
vscode.commands.registerCommand(
"analysisResults.openInEditor",
(res: Result) => openInEditor(res.getLabel(), res.getValue())
);
vscode.commands.registerCommand(
"analysisResults.load",
() => loadResults(analysisResultsProvider)
......@@ -312,6 +317,27 @@ function exportResults(provider: AnalysisResultsProvider) {
});
}
function openInEditor(label: string, value: string) {
if(vscode.workspace.workspaceFolders !== undefined) {
let wsPath = vscode.workspace.workspaceFolders[0].uri.path;
const date = new Date().toISOString().split('.')[0];
const newFile = vscode.Uri.parse(`untitled:${wsPath}/analysis/${label}-${date}.txt`);
vscode.workspace.openTextDocument(newFile).then(async document => {
const edit = new vscode.WorkspaceEdit();
const regex = new RegExp('(\\)|\\.),', 'gm');
var newText = value.replace(regex, "$1,\n");
console.log(newText);
edit.insert(newFile, new vscode.Position(0, 0), newText);
const success = await vscode.workspace.applyEdit(edit);
if (success) {
vscode.window.showTextDocument(document);
} else {
vscode.window.showInformationMessage(`Could not open ${label} in editor.`);
}
});
}
}
class ModestSidebarProvider implements vscode.WebviewViewProvider {
public static readonly viewType = "modest.modestSidebar";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment