From caa41898dadf2ea43995784ee2d60810abf6d935 Mon Sep 17 00:00:00 2001 From: ajshedivy Date: Wed, 19 Jun 2024 14:26:04 -0500 Subject: [PATCH 1/3] activate data-table extension for notebooks --- package.json | 4 +++- src/notebooks/Controller.ts | 9 ++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 16180c3e..5093b74a 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,9 @@ "onLanguage:sql" ], "extensionDependencies": [ - "halcyontechltd.code-for-ibmi" + "halcyontechltd.code-for-ibmi", + "RandomFractalsInc.vscode-data-table" + ], "main": "./dist/extension.js", "contributes": { diff --git a/src/notebooks/Controller.ts b/src/notebooks/Controller.ts index b2d59902..69c98d06 100644 --- a/src/notebooks/Controller.ts +++ b/src/notebooks/Controller.ts @@ -10,6 +10,10 @@ import { JobStatus } from '../connection/sqlJob'; import { ChartDetail, generateChart } from './logic/chart'; import { getStatementDetail } from './logic/statement'; +async function dataTableExtentionActivation() { + await vscode.extensions.getExtension('RandomFractalsInc.vscode-data-table')?.activate(); +} + export class IBMiController { readonly controllerId = `db2i-notebook-controller-id`; readonly notebookType = `db2i-notebook`; @@ -27,6 +31,9 @@ export class IBMiController { this.label ); + // activate vscode-data-table extention + dataTableExtentionActivation(); + this._controller.supportedLanguages = this.supportedLanguages; this._controller.supportsExecutionOrder = true; this._controller.executeHandler = this._execute.bind(this); @@ -115,7 +122,7 @@ export class IBMiController { } if (fallbackToTable) { - items.push(vscode.NotebookCellOutputItem.text(mdTable(table, columns), `text/markdown`)); + items.push(vscode.NotebookCellOutputItem.text(JSON.stringify(table), `text/plain`)); } } else { items.push(vscode.NotebookCellOutputItem.stderr(`No rows returned from statement.`)); From 2b44e8f7f3513e02b8f774061b8d143badfc2c94 Mon Sep 17 00:00:00 2001 From: ajshedivy Date: Wed, 19 Jun 2024 16:39:36 -0500 Subject: [PATCH 2/3] clear outputs from cell if they exist --- src/notebooks/Controller.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/notebooks/Controller.ts b/src/notebooks/Controller.ts index 69c98d06..769baecb 100644 --- a/src/notebooks/Controller.ts +++ b/src/notebooks/Controller.ts @@ -67,7 +67,10 @@ export class IBMiController { const execution = this._controller.createNotebookCellExecution(cell); execution.executionOrder = ++this._executionOrder; execution.start(Date.now()); // Keep track of elapsed time to execute cell. - + if (cell.outputs.length > 0) { + execution.clearOutput(); + } + const selected = JobManager.getSelection(); execution.token.onCancellationRequested(() => { From ebea1257e48ea40a375c8a073d7c48e186fbe352 Mon Sep 17 00:00:00 2001 From: worksofliam Date: Thu, 20 Jun 2024 09:05:49 -0400 Subject: [PATCH 3/3] Format the JSON and use JSON mime type Signed-off-by: worksofliam --- src/notebooks/Controller.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/notebooks/Controller.ts b/src/notebooks/Controller.ts index 769baecb..a86822d3 100644 --- a/src/notebooks/Controller.ts +++ b/src/notebooks/Controller.ts @@ -125,7 +125,7 @@ export class IBMiController { } if (fallbackToTable) { - items.push(vscode.NotebookCellOutputItem.text(JSON.stringify(table), `text/plain`)); + items.push(vscode.NotebookCellOutputItem.text(JSON.stringify(table, null, 2), `application/json`)); } } else { items.push(vscode.NotebookCellOutputItem.stderr(`No rows returned from statement.`));