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
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

All notable changes to the **kdb VS Code extension** are documented in this file.

# v1.11.0

### Enhancements

- Add from UDAs tab to the Datasource Files
- Add reset scratchpad for insights connections version 1.13 or higher

### Fixes

# v1.10.2

### Fixes
Expand Down
25 changes: 25 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,16 @@
"command": "kdb.runScratchpad",
"title": "Run workbook"
},
{
"category": "KX",
"command": "kdb.scratchpad.reset",
"title": "Reset scratchpad"
},
{
"category": "KX",
"command": "kdb.scratchpad.resetEditorConnection",
"title": "Reset editor connection"
},
{
"category": "KX",
"command": "kdb.startLocalProcess",
Expand Down Expand Up @@ -491,6 +501,12 @@
"mac": "cmd+shift+d",
"when": "editorLangId == python && (resourceFilename =~ /.kdb.py/ || kdb.pythonEnabled)"
},
{
"command": "kdb.scratchpad.resetEditorConnection",
"key": "ctrl+shift+delete",
"mac": "cmd+shift+delete",
"when": "(editorLangId == python && (resourceFilename =~ /.kdb.py/ || kdb.pythonEnabled)) || editorLangId == q"
},
{
"command": "kdb.terminal.run",
"key": "ctrl+shift+r",
Expand Down Expand Up @@ -660,6 +676,10 @@
"command": "kdb.open.meta",
"when": "false"
},
{
"command": "kdb.scratchpad.resetEditorConnection",
"when": "false"
},
{
"command": "kdb.connect.via.dialog",
"when": "false"
Expand Down Expand Up @@ -815,6 +835,11 @@
"when": "view == kdb-servers && (viewItem in kdb.rootNodes || viewItem in kdb.insightsNodes)",
"group": "connection@6"
},
{
"command": "kdb.scratchpad.reset",
"when": "view == kdb-servers && viewItem in kdb.connected && viewItem in kdb.insightsNodes",
"group": "connection@7"
},
{
"command": "kdb.startLocalProcess",
"when": "view == kdb-servers && viewItem in kdb.local && viewItem not in kdb.running && viewItem in kdb.rootNodes",
Expand Down
2 changes: 1 addition & 1 deletion src/classes/insightsConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ export class InsightsConnection {
importSql: "servicebroker/scratchpad/import/sql",
importQsql: "servicebroker/scratchpad/import/qsql",
importUDA: "servicebroker/scratchpad/import/uda",
reset: "servicebroker/scratchpad/reset",
reset: "scratchpadmanager/reset",
},
serviceGateway: {
meta: "servicegateway/meta",
Expand Down
4 changes: 2 additions & 2 deletions src/commands/serverCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -759,9 +759,9 @@ export function activeConnection(viewItem: KdbNode | InsightsNode): void {
ext.serverProvider.reload();
}

export async function resetScratchPad(): Promise<void> {
export async function resetScratchpad(connName?: string): Promise<void> {
const connMngService = new ConnectionManagementService();
await connMngService.resetScratchpad();
await connMngService.resetScratchpad(connName);
}

export async function refreshGetMeta(connLabel?: string): Promise<void> {
Expand Down
19 changes: 18 additions & 1 deletion src/commands/workspaceCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
import { ext } from "../extensionVariables";
import { ConnectionManagementService } from "../services/connectionManagerService";
import { InsightsNode, KdbNode, LabelNode } from "../services/kdbTreeProvider";
import { runQuery } from "./serverCommand";
import { resetScratchpad, runQuery } from "./serverCommand";
import { ExecutionTypes } from "../models/execution";
import { importOldDsFiles, oldFilesExists } from "../utils/dataSource";
import { kdbOutputLog, offerConnectAction } from "../utils/core";
Expand Down Expand Up @@ -291,6 +291,23 @@ export async function runActiveEditor(type?: ExecutionTypes) {
}
}

export async function resetScratchpadFromEditor(): Promise<void> {
if (ext.activeTextEditor) {
const uri = ext.activeTextEditor.document.uri;
const isWorkbook = uri.path.endsWith(".kdb.q");
let server = getServerForUri(uri);
if (!server && isWorkbook) {
server = await pickConnection(uri);
}
if (!server) {
server = "";
}
const connection = await getConnectionForServer(server);
server = connection?.label || "";
resetScratchpad(server);
}
}

function update(uri: Uri) {
if (isDataSource(uri)) {
ext.dataSourceTreeProvider.reload();
Expand Down
20 changes: 15 additions & 5 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ import {
refreshGetMeta,
removeConnection,
rerunQuery,
resetScratchPad,
resetScratchpad,
} from "./commands/serverCommand";
import { showInstallationDetails } from "./commands/walkthroughCommand";
import { ext } from "./extensionVariables";
Expand Down Expand Up @@ -98,6 +98,7 @@ import {
connectWorkspaceCommands,
importOldDSFiles,
pickConnection,
resetScratchpadFromEditor,
runActiveEditor,
setServerForUri,
} from "./commands/workspaceCommand";
Expand Down Expand Up @@ -469,10 +470,19 @@ export async function activate(context: ExtensionContext) {
commands.registerCommand("kdb.execute.pythonScratchpadQuery", async () => {
await runActiveEditor(ExecutionTypes.PythonQuerySelection);
}),
// TODO renable it when the scratchpad reset API is fixed
// commands.registerCommand("kdb.scratchpad.reset", async () => {
// await resetScratchPad();
// }),
commands.registerCommand(
"kdb.scratchpad.reset",
async (viewItem?: InsightsNode) => {
const connLabel = viewItem ? viewItem.label : undefined;
await resetScratchpad(connLabel);
},
),
commands.registerCommand(
"kdb.scratchpad.resetEditorConnection",
async () => {
await resetScratchpadFromEditor();
},
),
commands.registerCommand(
"kdb.execute.pythonFileScratchpadQuery",
async (item) => {
Expand Down
53 changes: 36 additions & 17 deletions src/services/connectionManagerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,35 +353,54 @@ export class ConnectionManagementService {
}
}

public async resetScratchpad(): Promise<void> {
if (
!ext.activeConnection ||
!(ext.activeConnection instanceof InsightsConnection)
) {
kdbOutputLog(
"[RESET SCRATCHPAD] Please activate an Insights connection to use this feature.",
"ERROR",
);
return;
public async resetScratchpad(connLabel?: string): Promise<void> {
let conn: InsightsConnection | undefined;
if (connLabel) {
const retrievedConn = this.retrieveConnectedConnection(connLabel);
if (retrievedConn instanceof InsightsConnection) {
conn = retrievedConn;
} else {
kdbOutputLog(
"[RESET SCRATCHPAD] Please connect to an Insights connection to use this feature.",
"ERROR",
);
return;
}
}
if (!conn) {
if (
!ext.activeConnection ||
!(ext.activeConnection instanceof InsightsConnection)
) {
kdbOutputLog(
"[RESET SCRATCHPAD] Please activate an Insights connection to use this feature.",
"ERROR",
);
return;
}
conn = ext.activeConnection;
}

if (
ext.activeConnection.insightsVersion &&
compareVersions(ext.activeConnection.insightsVersion, 1.12)
) {
const confirmationPrompt = `Are you sure you want to reset the scratchpad from the connection ${ext.activeConnection.connLabel}?`;
if (conn.insightsVersion && compareVersions(conn.insightsVersion, 1.13)) {
const confirmationPrompt = `Are you sure you want to reset the scratchpad from the connection ${conn.connLabel}?`;
const selection = await window.showInformationMessage(
confirmationPrompt,
"Yes",
"No",
);

if (selection === "Yes") {
await ext.activeConnection.resetScratchpad();
await conn.resetScratchpad();
} else {
kdbOutputLog(
"[RESET SCRATCHPAD] The user canceled the scratchpad reset.",
"INFO",
);
return;
}
} else {
kdbOutputLog(
"[RESET SCRATCHPAD] Please connect to an Insights connection with version superior to 1.11",
"[RESET SCRATCHPAD] Please connect to an Insights connection with version 1.13 or higher.",
"ERROR",
);
}
Expand Down
63 changes: 62 additions & 1 deletion test/suite/commands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1797,7 +1797,7 @@ describe("serverCommand", () => {
ConnectionManagementService.prototype,
"resetScratchpad",
);
await serverCommand.resetScratchPad();
await serverCommand.resetScratchpad();
sinon.assert.calledOnce(resetScratchpadStub);
sinon.restore();
});
Expand Down Expand Up @@ -2625,6 +2625,67 @@ describe("workspaceCommand", () => {
);
});
});

describe("resetScratchpadFromEditor", () => {
let getServerForUriStub: sinon.SinonStub;
let pickConnectionStub: sinon.SinonStub;
let getConnectionForServerStub: sinon.SinonStub;
let resetScratchpadStub: sinon.SinonStub;

const insightsNode = new InsightsNode(
[],
"insightsnode1",
{
server: "https://insightsservername.com/",
alias: "insightsserveralias",
auth: true,
},
vscode.TreeItemCollapsibleState.None,
);

beforeEach(() => {
ext.activeTextEditor = <vscode.TextEditor>{
options: { insertSpaces: true, indentSize: 4 },
selection: { active: new vscode.Position(0, 0) },
document: {
uri: vscode.Uri.file("/tmp/some.q"),
getText: () => "",
},
};

getServerForUriStub = sinon.stub(workspaceCommand, "getServerForUri");
pickConnectionStub = sinon.stub(workspaceCommand, "pickConnection");
getConnectionForServerStub = sinon
.stub(workspaceCommand, "getConnectionForServer")
.resolves(insightsNode);
resetScratchpadStub = sinon
.stub(serverCommand, "resetScratchpad")
.resolves();
});

afterEach(() => {
sinon.restore();
});

it("should call resetScratchpad with empty server label", async () => {
getServerForUriStub.returns("");
await workspaceCommand.resetScratchpadFromEditor();
assert.strictEqual(resetScratchpadStub.calledWith(""), true);
});

it("should set server to an empty string if no server is found", async () => {
getServerForUriStub.returns(undefined);
pickConnectionStub.resolves(undefined);
await workspaceCommand.resetScratchpadFromEditor();
assert.strictEqual(resetScratchpadStub.calledWith(""), true);
});

it("should not call resetScratchpad if activeTextEditor is not set", async () => {
ext.activeTextEditor = undefined;
await workspaceCommand.resetScratchpadFromEditor();
assert.strictEqual(resetScratchpadStub.called, false);
});
});
});

describe("clientCommands", () => {
Expand Down
39 changes: 37 additions & 2 deletions test/suite/services.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1353,6 +1353,7 @@ describe("connectionManagerService", () => {

describe("resetScratchpad", () => {
let connMngService: ConnectionManagementService;
let retrieveConnectedConnectionStub: sinon.SinonStub;
let resetScratchpadStub: sinon.SinonStub;
let kdbOutputLogStub: sinon.SinonStub;
let showInformationMessageStub: sinon.SinonStub;
Expand All @@ -1361,7 +1362,11 @@ describe("connectionManagerService", () => {
beforeEach(() => {
connMngService = new ConnectionManagementService();
ext.activeConnection = insightsConn;
resetScratchpadStub = sinon.stub(ext.activeConnection, "resetScratchpad");
resetScratchpadStub = sinon.stub(insightsConn, "resetScratchpad");
retrieveConnectedConnectionStub = sinon.stub(
connMngService,
"retrieveConnectedConnection",
);
kdbOutputLogStub = sinon.stub(coreUtils, "kdbOutputLog");
showInformationMessageStub = sinon.stub(window, "showInformationMessage");
showErrorMessageStub = sinon.stub(window, "showErrorMessage");
Expand Down Expand Up @@ -1393,12 +1398,42 @@ describe("connectionManagerService", () => {

it("should reset the scratchpad if the active connection is an InsightsConnection", async () => {
ext.activeConnection = insightsConn;
ext.activeConnection.insightsVersion = 1.12;
ext.activeConnection.insightsVersion = 1.13;
showInformationMessageStub.resolves("Yes");
await connMngService.resetScratchpad();
sinon.assert.calledOnce(resetScratchpadStub);
});

it("should retrieve insights connection and procced with resetScratchpad", async () => {
insightsConn.insightsVersion = 1.13;
retrieveConnectedConnectionStub.returns(insightsConn);
showInformationMessageStub.resolves("Yes");
await connMngService.resetScratchpad("test");
sinon.assert.calledOnce(retrieveConnectedConnectionStub);
});

it("should retrieve insights connection and procced with resetScratchpad", async () => {
insightsConn.insightsVersion = 1.13;
retrieveConnectedConnectionStub.returns(insightsConn);
showInformationMessageStub.resolves("No");
await connMngService.resetScratchpad("test");
sinon.assert.calledWith(
kdbOutputLogStub,
"[RESET SCRATCHPAD] The user canceled the scratchpad reset.",
"INFO",
);
});

it("should retrieve kdb connection not proceed", async () => {
retrieveConnectedConnectionStub.returns(localConn);
await connMngService.resetScratchpad("test");
sinon.assert.calledWith(
kdbOutputLogStub,
"[RESET SCRATCHPAD] Please connect to an Insights connection to use this feature.",
"ERROR",
);
});

it("should log an error if insightsVersion is less than or equal to 1.11", async () => {
ext.activeConnection = insightsConn;
ext.activeConnection.insightsVersion = 1.11;
Expand Down