Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,15 @@
"light": "./resources/light/add-scratchpad-python.svg"
}
},
{
"category": "KX",
"command": "kdb.scratchpad.sql.create",
"title": "New Workbook (SQL)",
"icon": {
"dark": "./resources/dark/sql.svg",
"light": "./resources/light/sql.svg"
}
},
{
"category": "KX",
"command": "kdb.connections.content.selectView",
Expand Down Expand Up @@ -686,6 +695,10 @@
"command": "kdb.scratchpad.python.create",
"when": "true"
},
{
"command": "kdb.scratchpad.sql.create",
"when": "true"
},
{
"command": "kdb.connections.content.selectView",
"when": "false"
Expand Down Expand Up @@ -915,10 +928,15 @@
"group": "navigation@2"
},
{
"command": "kdb.scratchpad.explorer.refresh",
"command": "kdb.scratchpad.sql.create",
"when": "view == kdb-scratchpad-explorer",
"group": "navigation@3"
},
{
"command": "kdb.scratchpad.explorer.refresh",
"when": "view == kdb-scratchpad-explorer",
"group": "navigation@4"
},
{
"command": "kdb.queryHistory.clear",
"when": "view == kdb-query-history",
Expand Down
7 changes: 4 additions & 3 deletions ref_card.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
| KX: Install KDB-X | KX: New Notebook | KX: Focus on Datasources view |
| KX: Start REPL | KX: New Workbook (q) | KX: Focus on Workbooks view |
| KX: Import Connections | KX: New Workbook (Python) | KX: Focus on Query History view |
| KX: Export Connections | KX: New Datasource | KX: Focus on Help and Feedback view |
| KX: Export Connections | KX: New Workbook (SQL) | KX: Focus on Help and Feedback view |
| | KX: New Datasource | |

## Keybindings

Expand Down Expand Up @@ -60,10 +61,10 @@
| :--------- | :--: | :--: | :---: | :------: | :----: | :----: | :------------: |
| File `q` ||||| | ||
| File `py` ||||| | ||
| File `sql` || | || | ||
| File `sql` || | || | ||
| Cell `q` ||||| | ||
| Cell `py` ||||| | ||
| Cell `sql` || | || | ||
| Cell `sql` || | || | ||
| Datasource | | | |||||

`REPL` and `My q` requires [PyKX](https://github.com/KxSystems/kx-vscode/wiki/Use-PyKX-Within-REPL) for Python support.
3 changes: 3 additions & 0 deletions resources/dark/sql-active.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions resources/dark/sql-connected.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions resources/dark/sql.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions resources/light/sql-active.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions resources/light/sql-connected.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions resources/light/sql.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 6 additions & 1 deletion src/commands/serverCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ import {
formatScratchpadStacktrace,
resultToBase64,
needsScratchpad,
getSQLWrapper,
} from "../utils/queryUtils";
import { openUrl } from "../utils/uriUtils";
import {
Expand Down Expand Up @@ -1126,8 +1127,12 @@ export async function runQuery(
variable = await inputVariable();
}

if (isSql && !isInsights) {
query = getSQLWrapper(query);
}

const runner = Runner.create((_, token) => {
return target || isSql
return target || (isSql && isInsights)
? variable
? populateScratchpad(
getPartialDatasourceFile(query, target, isSql, isPython),
Expand Down
18 changes: 8 additions & 10 deletions src/commands/workspaceCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,14 @@ function isPython(uri: Uri | undefined) {
}

function isWorkbook(uri: Uri | undefined) {
return uri && (uri.path.endsWith(".kdb.q") || uri.path.endsWith(".kdb.py"));
/* c8 ignore start */
return (
uri &&
(uri.path.endsWith(".kdb.q") ||
uri.path.endsWith(".kdb.py") ||
uri.path.endsWith(".kdb.sql"))
);
/* c8 ignore stop */
}

function isDataSource(uri: Uri | undefined) {
Expand Down Expand Up @@ -538,15 +545,6 @@ export async function runActiveEditor(type?: ExecutionTypes) {
const target = isInsights ? getTargetForUri(uri) : undefined;
const isSql = executorName.endsWith(".sql");

if (isSql && !isInsights) {
notify(
`SQL execution is not supported on ${conn.connLabel}.`,
MessageKind.ERROR,
{ logger },
);
return;
}

if (type === ExecutionTypes.PopulateScratchpad && !isInsights) {
notify(
`Populating scratchpad is not supported on ${conn.connLabel}.`,
Expand Down
21 changes: 20 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export async function activate(context: vscode.ExtensionContext) {
ext.context.extensionUri,
);
ext.scratchpadTreeProvider = new WorkspaceTreeProvider(
"**/*.kdb.{q,py}",
"**/*.kdb.{q,py,sql}",
"scratchpad",
);
ext.dataSourceTreeProvider = new WorkspaceTreeProvider(
Expand Down Expand Up @@ -561,6 +561,25 @@ function registerScratchpadCommands(): CommandRegistration[] {
}
},
},
{
command: "kdb.scratchpad.sql.create",
callback: async (item: FileTreeItem) => {
if (hasWorkspaceOrShowOption("adding workbooks")) {
const uri = await addWorkspaceFile(
item ? item.resourceUri : undefined,
"workbook",
".kdb.sql",
);
await vscode.workspace.openTextDocument(uri);
await vscode.window.showTextDocument(uri);
await vscode.commands.executeCommand(
"workbench.action.files.save",
uri,
);
await setServerForUri(uri, undefined);
}
},
},
{
command: "kdb.scratchpad.explorer.refresh",
callback: () => {
Expand Down
12 changes: 7 additions & 5 deletions src/services/notebookController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,6 @@ export class KxNotebookController {
const variable = cell.metadata?.variable;

if (!isInsights) {
if (kind === CellKind.SQL) {
throw new Error(`SQL is not supported on ${conn.connLabel}`);
}
if (target) {
throw new Error(
`Setting execution target (${target}) is not supported on ${conn.connLabel}.`,
Expand All @@ -253,7 +250,10 @@ export class KxNotebookController {
): Promise<any> {
const executorName = getBasename(cell.notebook.uri);

if (target || kind === CellKind.SQL) {
if (
target ||
(kind === CellKind.SQL && conn instanceof InsightsConnection)
) {
const params = getPartialDatasourceFile(
cell.document.getText(),
target,
Expand All @@ -265,7 +265,9 @@ export class KxNotebookController {
: runDataSource(params, conn.connLabel, executorName);
} else {
return executeQuery(
cell.document.getText(),
kind === CellKind.SQL
? getSQLWrapper(cell.document.getText())
: cell.document.getText(),
conn.connLabel,
executorName,
".",
Expand Down
6 changes: 5 additions & 1 deletion src/services/workspaceTreeProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,17 @@ export class FileTreeItem extends TreeItem {
}

private getFileIconType(fileName: string) {
/* c8 ignore start */
if (fileName.endsWith(".kdb.json")) {
this.baseIcon = "datasource";
} else if (fileName.endsWith(".kdb.q")) {
this.baseIcon = "scratchpad";
} else {
} else if (fileName.endsWith(".kdb.py")) {
this.baseIcon = "python";
} else {
this.baseIcon = "sql";
}
/* c8 ignore stop */
}

async getChildren(): Promise<FileTreeItem[]> {
Expand Down
1 change: 1 addition & 0 deletions test/suite/commands/commands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ describe("Commands", () => {
"kdb.datasource.create",
"kdb.scratchpad.create",
"kdb.scratchpad.python.create",
"kdb.scratchpad.sql.create",
"kdb.connections.add",
"kdb.repl.start",
"kdb.createNotebook",
Expand Down