Skip to content

Commit 732b6ae

Browse files
authored
Positron: Improve execution of ggsql code (#296)
* Respond with null to unknown comms to avoid RPC timeouts * cargo fmt * Add Source Current File button
1 parent 4542d91 commit 732b6ae

3 files changed

Lines changed: 56 additions & 2 deletions

File tree

ggsql-jupyter/src/kernel.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -648,9 +648,27 @@ impl KernelServer {
648648
self.handle_data_explorer_rpc(method, rpc_id, comm_id, parent, identities)
649649
.await?;
650650
}
651-
// Unknown comm
651+
// Unknown comm — still respond to avoid RPC timeouts
652652
else {
653-
tracing::warn!("Message for unknown comm_id: {}", comm_id);
653+
tracing::warn!(
654+
"JSON-RPC request for unknown comm_id: {}, method: {}",
655+
comm_id,
656+
method
657+
);
658+
self.send_shell_reply(
659+
"comm_msg",
660+
json!({
661+
"comm_id": comm_id,
662+
"data": {
663+
"jsonrpc": "2.0",
664+
"id": rpc_id,
665+
"result": null
666+
}
667+
}),
668+
parent,
669+
identities,
670+
)
671+
.await?;
654672
}
655673
}
656674

ggsql-vscode/package.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,27 @@
5555
"languageId": "ggsql"
5656
}
5757
],
58+
"commands": [
59+
{
60+
"command": "ggsql.sourceCurrentFile",
61+
"category": "ggsql",
62+
"title": "Source Current File",
63+
"icon": "$(play)"
64+
}
65+
],
66+
"menus": {
67+
"editor/title/run": [
68+
{
69+
"command": "ggsql.sourceCurrentFile",
70+
"group": "navigation@0",
71+
"when": "resourceLangId == ggsql && !isInDiffEditor"
72+
},
73+
{
74+
"command": "workbench.action.positronConsole.executeCode",
75+
"when": "resourceLangId == ggsql && !isInDiffEditor"
76+
}
77+
]
78+
},
5879
"configuration": {
5980
"type": "object",
6081
"title": "ggsql",

ggsql-vscode/src/extension.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,21 @@ export function activate(context: vscode.ExtensionContext): void {
5252
}
5353

5454
log(`Registered ${drivers.length} connection drivers`);
55+
56+
// Register "Source Current File" command for the editor run button
57+
context.subscriptions.push(
58+
vscode.commands.registerCommand('ggsql.sourceCurrentFile', async () => {
59+
const editor = vscode.window.activeTextEditor;
60+
if (!editor || editor.document.languageId !== 'ggsql') {
61+
return;
62+
}
63+
const code = editor.document.getText();
64+
if (code.trim().length === 0) {
65+
return;
66+
}
67+
positronApi.runtime.executeCode('ggsql', code, true);
68+
})
69+
);
5570
}
5671

5772
/**

0 commit comments

Comments
 (0)