Skip to content

Commit 081ee25

Browse files
committed
add commands to the palette depending on context
1 parent 976e34a commit 081ee25

File tree

3 files changed

+128
-32
lines changed

3 files changed

+128
-32
lines changed

package.json

Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@
235235
{
236236
"category": "KX",
237237
"command": "kdb.file.pickConnection",
238-
"title": "Chooses Connection",
238+
"title": "Choose Connection",
239239
"shortTitle": "Connection",
240240
"icon": "$(cloud)"
241241
},
@@ -252,7 +252,6 @@
252252
"title": "Input Variable Name"
253253
},
254254
{
255-
"category": "KX",
256255
"command": "kdb.file.populateScratchpad",
257256
"title": "KX: Populate Scratchpad",
258257
"icon": "$(debug-rerun)"
@@ -376,25 +375,21 @@
376375
"title": "Start REPL"
377376
},
378377
{
379-
"category": "KX",
380378
"command": "kdb.execute.selectedQuery",
381379
"title": "KX: Execute Current Selection",
382380
"icon": "$(run-above)"
383381
},
384382
{
385-
"category": "KX",
386383
"command": "kdb.execute.fileQuery",
387384
"title": "KX: Execute Entire File",
388385
"icon": "$(run)"
389386
},
390387
{
391-
"category": "KX",
392388
"command": "kdb.scratchpad.python.run",
393389
"title": "KX: Execute Current Selection",
394390
"icon": "$(run-above)"
395391
},
396392
{
397-
"category": "KX",
398393
"command": "kdb.scratchpad.python.run.file",
399394
"title": "KX: Execute Entire File",
400395
"icon": "$(run)"
@@ -415,15 +410,14 @@
415410
"title": "Delete"
416411
},
417412
{
418-
"category": "KX",
419413
"command": "kdb.execute.block",
420414
"title": "KX: Execute Current Block",
421415
"icon": "$(run-below)"
422416
},
423417
{
424418
"category": "KX",
425419
"command": "kdb.toggleParameterCache",
426-
"title": "KX: Toggle Parameter Cache"
420+
"title": "Toggle Parameter Cache"
427421
},
428422
{
429423
"category": "KX",
@@ -495,7 +489,7 @@
495489
"command": "kdb.scratchpad.editor.reset",
496490
"key": "ctrl+shift+delete",
497491
"mac": "cmd+shift+delete",
498-
"when": "resourceFilename =~ /\\.(?:q|py|sql)$/i"
492+
"when": "resourceFilename =~ /\\.(?:q|py|sql|kxnb)$/i"
499493
},
500494
{
501495
"command": "kdb.file.populateScratchpad",
@@ -645,12 +639,6 @@
645639
}
646640
]
647641
},
648-
"viewsWelcome": [
649-
{
650-
"view": "kdb-servers",
651-
"contents": "No connections registered.\n[Add Connection](command:kdb.connections.add)"
652-
}
653-
],
654642
"menus": {
655643
"commandPalette": [
656644
{
@@ -703,19 +691,19 @@
703691
},
704692
{
705693
"command": "kdb.file.pickConnection",
706-
"when": "false"
694+
"when": "resourceFilename =~ /\\.(?:q|py|sql|kxnb)$/i"
707695
},
708696
{
709697
"command": "kdb.file.pickTarget",
710-
"when": "false"
698+
"when": "resourceFilename =~ /\\.(?:q|py|sql)$/i"
711699
},
712700
{
713701
"command": "kdb.file.inputVariable",
714702
"when": "false"
715703
},
716704
{
717705
"command": "kdb.file.populateScratchpad",
718-
"when": "false"
706+
"when": "resourceFilename =~ /\\.(?:q|py|sql)$/i"
719707
},
720708
{
721709
"command": "kdb.scratchpad.run",
@@ -727,7 +715,7 @@
727715
},
728716
{
729717
"command": "kdb.scratchpad.editor.reset",
730-
"when": "false"
718+
"when": "resourceFilename =~ /\\.(?:q|py|sql|kxnb)$/i"
731719
},
732720
{
733721
"command": "kdb.connections.add",
@@ -811,19 +799,19 @@
811799
},
812800
{
813801
"command": "kdb.execute.selectedQuery",
814-
"when": "false"
802+
"when": "resourceFilename =~ /\\.(?:q|sql)$/i"
815803
},
816804
{
817805
"command": "kdb.execute.fileQuery",
818-
"when": "false"
806+
"when": "resourceFilename =~ /\\.(?:q|sql)$/i"
819807
},
820808
{
821809
"command": "kdb.scratchpad.python.run",
822-
"when": "false"
810+
"when": "resourceFilename =~ /\\.(?:py)$/i"
823811
},
824812
{
825813
"command": "kdb.scratchpad.python.run.file",
826-
"when": "false"
814+
"when": "resourceFilename =~ /\\.(?:py)$/i"
827815
},
828816
{
829817
"command": "kdb.ls.q.lint",
@@ -839,11 +827,11 @@
839827
},
840828
{
841829
"command": "kdb.execute.block",
842-
"when": "false"
830+
"when": "resourceFilename =~ /\\.(?:q)$/i"
843831
},
844832
{
845833
"command": "kdb.toggleParameterCache",
846-
"when": "false"
834+
"when": "resourceFilename =~ /\\.(?:q)$/i"
847835
},
848836
{
849837
"command": "kdb.connections.labels.rename",
@@ -1073,7 +1061,7 @@
10731061
{
10741062
"command": "kdb.execute.block",
10751063
"group": "q1@2",
1076-
"when": "resourceFilename =~ /\\.(?:q|sql)$/i"
1064+
"when": "resourceFilename =~ /\\.(?:q)$/i"
10771065
},
10781066
{
10791067
"command": "kdb.file.populateScratchpad",
@@ -1095,18 +1083,13 @@
10951083
{
10961084
"command": "kdb.execute.block",
10971085
"group": "q@2",
1098-
"when": "resourceFilename =~ /\\.(?:q|sql)$/i"
1086+
"when": "resourceFilename =~ /\\.(?:q)$/i"
10991087
},
11001088
{
11011089
"command": "kdb.file.populateScratchpad",
11021090
"group": "q2@0",
11031091
"when": "resourceFilename =~ /\\.(?:q|py|sql)$/i"
11041092
},
1105-
{
1106-
"command": "kdb.toggleParameterCache",
1107-
"group": "q2@1",
1108-
"when": "resourceFilename =~ /\\.(?:q)$/i"
1109-
},
11101093
{
11111094
"command": "kdb.scratchpad.python.run.file",
11121095
"group": "p@0",

src/commands/workspaceCommand.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,10 @@ export async function pickConnection(uri: Uri) {
252252

253253
export async function pickTarget(uri: Uri, cell?: NotebookCell) {
254254
/* c8 ignore start */
255+
let server = getServerForUri(uri);
256+
if (!server) server = await pickConnection(uri);
257+
if (!server || server === ext.REPL) return;
258+
255259
const conn = await findConnection(uri);
256260
const isInsights = conn instanceof InsightsConnection;
257261

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/*
2+
* Copyright (c) 1998-2025 KX Systems Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the
5+
* License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an
10+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11+
* specific language governing permissions and limitations under the License.
12+
*/
13+
14+
import * as assert from "assert";
15+
import { readFileSync } from "node:fs";
16+
import { resolve } from "node:path";
17+
18+
describe("Commands", () => {
19+
const commands = new Map();
20+
let palette: any;
21+
let keybindings: any;
22+
23+
before(() => {
24+
const config = JSON.parse(
25+
readFileSync(resolve(__dirname, "..", "..", "..", "..", "package.json"), {
26+
encoding: "utf8",
27+
}),
28+
);
29+
config.contributes.commands.forEach((cmd: any) =>
30+
commands.set(cmd.command, cmd.title),
31+
);
32+
palette = config.contributes.menus.commandPalette;
33+
keybindings = config.contributes.keybindings;
34+
});
35+
36+
describe("Command Palette", () => {
37+
it("should include all commands", () => {
38+
assert.strictEqual(palette.length, commands.size);
39+
for (const cmd of palette) {
40+
assert.ok(commands.get(cmd.command));
41+
}
42+
});
43+
it("should have certain always visible commands", () => {
44+
const visible = [
45+
"kdb.show.welcome",
46+
"kdb.install.kdbx",
47+
"kdb.connections.export.all",
48+
"kdb.connections.import",
49+
"kdb.datasource.create",
50+
"kdb.scratchpad.create",
51+
"kdb.scratchpad.python.create",
52+
"kdb.connections.add",
53+
"kdb.repl.start",
54+
"kdb.createNotebook",
55+
];
56+
const shown = palette.filter((cmd: any) => cmd.when === "true");
57+
assert.strictEqual(shown.length, visible.length);
58+
for (let i = 0; i < visible.length; i++) {
59+
assert.strictEqual(visible[i], shown[i].command);
60+
}
61+
});
62+
it("should have certain visible commands depending on context", () => {
63+
const visible = [
64+
"kdb.file.pickConnection",
65+
"kdb.file.pickTarget",
66+
"kdb.file.populateScratchpad",
67+
"kdb.scratchpad.editor.reset",
68+
"kdb.execute.selectedQuery",
69+
"kdb.execute.fileQuery",
70+
"kdb.scratchpad.python.run",
71+
"kdb.scratchpad.python.run.file",
72+
"kdb.execute.block",
73+
"kdb.toggleParameterCache",
74+
];
75+
const shown = palette.filter(
76+
(cmd: any) => cmd.when !== "true" && cmd.when !== "false",
77+
);
78+
assert.strictEqual(shown.length, visible.length);
79+
for (let i = 0; i < visible.length; i++) {
80+
assert.strictEqual(visible[i], shown[i].command);
81+
}
82+
});
83+
});
84+
85+
describe("Keybindings", () => {
86+
it("should have a valid command", () => {
87+
for (const cmd of keybindings) {
88+
assert.ok(commands.get(cmd.command));
89+
}
90+
});
91+
it("should exist for certain commands", () => {
92+
const bindings = [
93+
"kdb.execute.selectedQuery",
94+
"kdb.execute.fileQuery",
95+
"kdb.scratchpad.python.run",
96+
"kdb.scratchpad.python.run.file",
97+
"kdb.scratchpad.editor.reset",
98+
"kdb.file.populateScratchpad",
99+
"kdb.execute.block",
100+
"kdb.toggleParameterCache",
101+
"kdb.file.pickTarget",
102+
];
103+
assert.strictEqual(bindings.length, keybindings.length);
104+
for (let i = 0; i < bindings.length; i++) {
105+
assert.strictEqual(bindings[i], keybindings[i].command);
106+
}
107+
});
108+
});
109+
});

0 commit comments

Comments
 (0)