Skip to content

Commit d3a969d

Browse files
committed
Ability to hide SQL in export
Signed-off-by: worksofliam <[email protected]>
1 parent fce1554 commit d3a969d

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

src/notebooks/logic/export.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,14 @@ export const exportNotebookAsHtml = vscode.commands.registerCommand(`vscode-db2i
7070
const eol = cell.document.eol === vscode.EndOfLine.CRLF ? `\r\n` : `\n`;
7171

7272
let content = cell.document.getText().trim();
73-
let chartDetail: ChartDetail | undefined;
7473

75-
({ chartDetail, content } = getStatementDetail(content, eol));
74+
const detail = getStatementDetail(content, eol);
7675

77-
cellContents.push(`<pre>${content}</pre>`);
76+
content = detail.content;
77+
78+
if (detail.settings.hideStatement !== `true`) {
79+
cellContents.push(`<pre>${content}</pre>`);
80+
}
7881

7982
// Execute the query
8083
const query = selected.job.query(content);
@@ -98,6 +101,7 @@ export const exportNotebookAsHtml = vscode.commands.registerCommand(`vscode-db2i
98101

99102
let fallbackToTable = true;
100103

104+
const { chartDetail } = detail;
101105
if (chartDetail.type) {
102106
if (chartJsTypes.includes(chartDetail.type as ChartJsType)) {
103107
const possibleChart = generateChart(executionId, chartDetail, columns, table, generateChartHTMLEmbedded);

src/notebooks/logic/statement.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
import { ChartDetail, chartTypes } from "./chart";
22
import { ChartJsType, chartJsTypes } from "./chartJs";
33

4+
export interface StatementSettings {
5+
chart?: ChartJsType;
6+
title?: string;
7+
y?: string;
8+
hideStatement?: string;
9+
[key: string]: string
10+
};
11+
412
export function getStatementDetail(content: string, eol: string) {
513
let chartDetail: ChartDetail = {};
14+
let settings: StatementSettings = {};
615

716
// Strip out starting comments
817
if (content.startsWith(`--`)) {
@@ -12,8 +21,6 @@ export function getStatementDetail(content: string, eol: string) {
1221
const startingComments = lines.slice(0, firstNonCommentLine).map(line => line.substring(2).trim());
1322
content = lines.slice(firstNonCommentLine).join(eol);
1423

15-
let settings = {};
16-
1724
for (let comment of startingComments) {
1825
const sep = comment.indexOf(`:`);
1926
const key = comment.substring(0, sep).trim();
@@ -46,5 +53,5 @@ export function getStatementDetail(content: string, eol: string) {
4653
chartDetail.type = chartType;
4754
content = content.substring(chartType.length + 1);
4855
}
49-
return { chartDetail, content };
56+
return { chartDetail, content, settings };
5057
}

0 commit comments

Comments
 (0)