Skip to content
Open
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

93 changes: 87 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,21 @@
}
}
},
{
"id": "vscode-db2i.examples",
"title": "Examples",
"properties": {
"vscode-db2i.examples.customExampleDirectories": {
"type": "array",
"items": {
"type": "string",
"description": "The directory containing SQL example files."
},
"markdownDescription": "Set of custom directories containing SQL example files to be shown in the `Examples` view. All SQL files in the specified directories and at most one subdirectory level deeper will be picked up.\n\nBy default, the folder name will be the category and the file name will be the name of the example. This can be customized by optionally including a comment in the file with the tags `category` and `description`.",
"default": []
}
}
},
{
"id": "vscode-db2i.syntax",
"title": "SQL Syntax Options",
Expand Down Expand Up @@ -772,6 +787,33 @@
"category": "Db2 for i (Examples)",
"icon": "$(clear-all)"
},
{
"command": "vscode-db2i.examples.reload",
"title": "Refresh Examples",
"category": "Db2 for i (Examples)",
"icon": "$(refresh)"
},
{
"command": "vscode-db2i.examples.save",
"title": "Save As New Example",
"category": "Db2 for i (Examples)",
"icon": "$(save)"
},
{
"command": "vscode-db2i.examples.add",
"title": "Add...",
"category": "Db2 for i (Examples)"
},
{
"command": "vscode-db2i.examples.remove",
"title": "Remove...",
"category": "Db2 for i (Examples)"
},
{
"command": "vscode-db2i.examples.edit",
"title": "Edit Example",
"category": "Db2 for i (Examples)"
},
{
"command": "vscode-db2i.notebook.fromSqlUri",
"title": "Open as Notebook",
Expand Down Expand Up @@ -930,6 +972,10 @@
"command": "vscode-db2i.jobManager.deleteConfig",
"when": "never"
},
{
"command": "vscode-db2i.examples.edit",
"when": "never"
},
{
"command": "vscode-db2i.notebook.fromSqlUri",
"when": "never"
Expand Down Expand Up @@ -999,13 +1045,13 @@
"when": "view == vscode-db2i.dove.node"
},
{
"command": "vscode-db2i.queryHistory.clear",
"group": "navigation",
"command": "vscode-db2i.queryHistory.find",
"group": "navigation@0",
"when": "view == queryHistory"
},
{
"command": "vscode-db2i.queryHistory.find",
"group": "navigation",
"command": "vscode-db2i.queryHistory.clear",
"group": "navigation@1",
"when": "view == queryHistory"
},
{
Expand Down Expand Up @@ -1070,12 +1116,27 @@
},
{
"command": "vscode-db2i.examples.setFilter",
"group": "navigation",
"group": "navigation@0",
"when": "view == exampleBrowser"
},
{
"command": "vscode-db2i.examples.clearFilter",
"group": "navigation",
"group": "navigation@1",
"when": "view == exampleBrowser"
},
{
"command": "vscode-db2i.examples.save",
"group": "navigation@2",
"when": "view == exampleBrowser"
},
{
"submenu": "vscode-db2i.customExampleDirectories",
"group": "navigation@3",
"when": "view == exampleBrowser"
},
{
"command": "vscode-db2i.examples.reload",
"group": "navigation@4",
"when": "view == exampleBrowser"
}
],
Expand Down Expand Up @@ -1248,6 +1309,11 @@
"command": "vscode-db2i.self.explainSelf",
"when": "view == vscode-db2i.self.nodes && viewItem == selfCodeNode && vscode-db2i:continueExtensionActive",
"group": "navigation"
},
{
"command": "vscode-db2i.examples.edit",
"when": "view == exampleBrowser && viewItem == example.custom",
"group": "0_open"
}
],
"editor/title": [
Expand Down Expand Up @@ -1309,6 +1375,16 @@
"group": "navigation_notebook@1"
}
],
"vscode-db2i.customExampleDirectories": [
{
"command": "vscode-db2i.examples.add",
"group": "navigation@0"
},
{
"command": "vscode-db2i.examples.remove",
"group": "navigation@1"
}
],
"notebook/toolbar": [
{
"command": "vscode-db2i.notebook.exportAsHtml",
Expand All @@ -1322,6 +1398,11 @@
"icon": "$(notebook-execute)",
"id": "sql/editor/context",
"label": "Run SQL statement"
},
{
"id": "vscode-db2i.customExampleDirectories",
"label": "Custom Example Directories",
"icon": "$(folder-library)"
}
],
"keybindings": [
Expand Down
113 changes: 57 additions & 56 deletions src/notebooks/logic/statement.ts
Original file line number Diff line number Diff line change
@@ -1,57 +1,58 @@
import { ChartDetail, chartTypes } from "./chart";
import { ChartJsType, chartJsTypes } from "./chartJs";

export interface StatementSettings {
chart?: ChartJsType;
title?: string;
y?: string;
hideStatement?: string;
[key: string]: string
};

export function getStatementDetail(content: string, eol: string) {
let chartDetail: ChartDetail = {};
let settings: StatementSettings = {};

// Strip out starting comments
if (content.startsWith(`--`)) {
const lines = content.split(eol);
const firstNonCommentLine = lines.findIndex(line => !line.startsWith(`--`));

const startingComments = lines.slice(0, firstNonCommentLine).map(line => line.substring(2).trim());
content = lines.slice(firstNonCommentLine).join(eol);

for (let comment of startingComments) {
const sep = comment.indexOf(`:`);
const key = comment.substring(0, sep).trim();
const value = comment.substring(sep + 1).trim();
settings[key] = value;
}

// Chart settings defined by comments
if (settings[`chart`] && chartJsTypes.includes(settings[`chart`])) {
chartDetail.type = settings[`chart`];
}

if (settings[`title`]) {
chartDetail.title = settings[`title`];
}

if (settings[`y`]) {
chartDetail.y = settings[`y`];
}
}

// Remove trailing semicolon. The Service Component doesn't like it.
if (content.endsWith(`;`)) {
content = content.substring(0, content.length - 1);
}

// Perhaps the chart type is defined by the statement prefix
const chartType: ChartJsType | undefined = chartTypes.find(type => content.startsWith(`${type}:`));
if (chartType) {
chartDetail.type = chartType;
content = content.substring(chartType.length + 1);
}
return { chartDetail, content, settings };
import { ChartDetail, chartTypes } from "./chart";
import { ChartJsType, chartJsTypes } from "./chartJs";

export interface StatementSettings {
chart?: ChartJsType;
title?: string;
y?: string;
hideStatement?: string;
[key: string]: string
};

export function getStatementDetail(content: string, eol: string) {
let chartDetail: ChartDetail = {};
let settings: StatementSettings = {};

// Strip out starting comments
if (content.startsWith(`--`)) {
const lines = content.split(eol);
const firstNonCommentLine = lines.findIndex(line => !line.startsWith(`--`));

const startingCommentLines = firstNonCommentLine === -1 ? lines : lines.slice(0, firstNonCommentLine);
const startingComments = startingCommentLines.map(line => line.substring(2).trim());
content = lines.slice(firstNonCommentLine).join(eol);

for (let comment of startingComments) {
const sep = comment.indexOf(`:`);
const key = comment.substring(0, sep).trim();
const value = comment.substring(sep + 1).trim();
settings[key] = value;
}

// Chart settings defined by comments
if (settings[`chart`] && chartJsTypes.includes(settings[`chart`])) {
chartDetail.type = settings[`chart`];
}

if (settings[`title`]) {
chartDetail.title = settings[`title`];
}

if (settings[`y`]) {
chartDetail.y = settings[`y`];
}
}

// Remove trailing semicolon. The Service Component doesn't like it.
if (content.endsWith(`;`)) {
content = content.substring(0, content.length - 1);
}

// Perhaps the chart type is defined by the statement prefix
const chartType: ChartJsType | undefined = chartTypes.find(type => content.startsWith(`${type}:`));
if (chartType) {
chartDetail.type = chartType;
content = content.substring(chartType.length + 1);
}
return { chartDetail, content, settings };
}
Loading
Loading