Skip to content

Commit 0885128

Browse files
committed
Support discovering commands with a query
1 parent 5d5e158 commit 0885128

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

jupyterlab_commands_toolkit/tools.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def handle_command_result(event_data):
8585
future.set_result(event_data)
8686

8787

88-
async def list_all_commands() -> dict:
88+
async def list_all_commands(query: str) -> dict:
8989
"""
9090
Retrieve a list of all available JupyterLab commands.
9191
@@ -104,7 +104,7 @@ async def list_all_commands() -> dict:
104104
asyncio.TimeoutError: If the frontend doesn't respond within the timeout period
105105
"""
106106
return await emit_and_wait_for_result(
107-
{"name": "jupyterlab-commands-toolkit:list-all-commands", "args": {}}
107+
{"name": "jupyterlab-commands-toolkit:list-all-commands", "args": {"query": query}}
108108
)
109109

110110

src/index.ts

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ const plugin: JupyterFrontEndPlugin<void> = {
103103
describedBy: {
104104
args: {}
105105
},
106-
execute: async () => {
106+
execute: async (args: any) => {
107+
const query = args['query'] as string | undefined;
108+
107109
const commandList: Array<{
108110
id: string;
109111
label?: string;
@@ -112,23 +114,45 @@ const plugin: JupyterFrontEndPlugin<void> = {
112114
args?: any;
113115
}> = [];
114116

117+
// Get all command IDs
115118
const commandIds = commands.listCommands();
116119

117120
for (const id of commandIds) {
121+
// Get command metadata using various CommandRegistry methods
118122
const description = await commands.describedBy(id);
119123
const label = commands.label(id);
120124
const caption = commands.caption(id);
121125
const usage = commands.usage(id);
122126

123-
commandList.push({
127+
const command = {
124128
id,
125129
label: label || undefined,
126130
caption: caption || undefined,
127131
description: usage || undefined,
128132
args: description?.args || undefined
129-
});
133+
};
134+
135+
// Filter by query if provided
136+
if (query) {
137+
const searchTerm = query.toLowerCase();
138+
const matchesQuery =
139+
id.toLowerCase().includes(searchTerm) ||
140+
label?.toLowerCase().includes(searchTerm) ||
141+
caption?.toLowerCase().includes(searchTerm) ||
142+
usage?.toLowerCase().includes(searchTerm);
143+
144+
if (matchesQuery) {
145+
commandList.push(command);
146+
}
147+
} else {
148+
commandList.push(command);
149+
}
130150
}
131-
return commandList;
151+
return {
152+
success: true,
153+
commandCount: commandList.length,
154+
commands: commandList
155+
};
132156
}
133157
});
134158
}

0 commit comments

Comments
 (0)