diff --git a/src/samplesTreeView.ts b/src/samplesTreeView.ts index 27b102552924b2237ebc32f1bf3a7493f5f61ef4..ce9e4649fcf7f7502bedcb229ac5f3fb9809d73a 100644 --- a/src/samplesTreeView.ts +++ b/src/samplesTreeView.ts @@ -2,6 +2,7 @@ import * as vscode from "vscode"; import { Store } from "./store"; import * as path from "path"; import { toSortedKeys } from "./util"; +import { EOL } from "os"; export class SamplesTreeViewProvider implements vscode.TreeDataProvider { @@ -24,13 +25,47 @@ export class SamplesTreeViewProvider sample, vscode.TreeItemCollapsibleState.None ); + + let sampleData = this.store.samples.get(sample); + if (sampleData === undefined) { + vscode.window.showErrorMessage( + "Internal error when showing the sample tree" + ); + throw new Error("Internal error when showing the sample tree"); + } + + let input = ""; + let output = ""; + sampleData.data.forEach(entry => { + if (entry.key === "input") { + input = entry.value; + } + + if (entry.key === "output") { + output = entry.value; + } + }); + let inplines = input.split(EOL); + let outlines = output.split(EOL); + let tooltip = + "*Input*: \n" + + (inplines.length < 12 + ? input + : inplines.slice(0, 12).join("\n") + + `\n... ${inplines.length - 12} more lines`) + + "*Output*: \n" + + (outlines.length < 12 + ? output + : outlines.slice(0, 12).join("\n") + + `\n... ${outlines.length - 12} more lines`); + item.contextValue = "sample"; item.command = { command: "soicode.openSample", title: "Open Sample", - arguments: [sample], - tooltip: "Open Sample" - }; // todo register as command + arguments: [sample] + }; + item.tooltip = tooltip; // switch(this.state.samples.get){ {