From 7205bdf98bee3968c71852116f461433e6e6ed5a Mon Sep 17 00:00:00 2001 From: Prajwal Pai <108796209+prajwal-pai77@users.noreply.github.com> Date: Wed, 16 Oct 2024 11:46:04 +0530 Subject: [PATCH] Add explain button next to run query (#427) Adds a explain button next to Run query --- images/dark/explain-query.svg | 20 +++++++++++++++++ images/light/explain-query.svg | 20 +++++++++++++++++ package-lock.json | 4 ++-- package.json | 24 +++++++++++++++++++- src/commands/extensionCommands/commands.ts | 1 + src/extension.ts | 26 ++++++++++++++++++++-- src/workbench/queryWorkbench.ts | 9 ++++++-- 7 files changed, 97 insertions(+), 7 deletions(-) create mode 100644 images/dark/explain-query.svg create mode 100644 images/light/explain-query.svg diff --git a/images/dark/explain-query.svg b/images/dark/explain-query.svg new file mode 100644 index 00000000..01d2915c --- /dev/null +++ b/images/dark/explain-query.svg @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/images/light/explain-query.svg b/images/light/explain-query.svg new file mode 100644 index 00000000..fc434e96 --- /dev/null +++ b/images/light/explain-query.svg @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 6546905e..341ac69e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "vscode-couchbase", - "version": "2.1.5", + "version": "2.1.6", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "vscode-couchbase", - "version": "2.1.5", + "version": "2.1.6", "license": "SEE LICENSE IN LICENSE", "dependencies": { "@aws-sdk/client-dynamodb": "^3.602.0", diff --git a/package.json b/package.json index a30e4d60..5d5dc03e 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "vscode-couchbase", "displayName": "Couchbase", "description": "", - "version": "2.1.5", + "version": "2.1.6", "engines": { "vscode": "^1.63.1" }, @@ -600,6 +600,17 @@ "tooltip": "Run Query", "enablement": "vscode-couchbase.runButtonEnabled" }, + { + "command": "vscode-couchbase.explainQuery", + "title": "Explain Query", + "category": "Couchbase", + "icon": { + "light": "images/light/explain-query.svg", + "dark": "images/dark/explain-query.svg" + }, + "tooltip": "Explain Query", + "enablement": "vscode-couchbase.runButtonEnabled" + }, { "command": "vscode-couchbase.getClusterOverview", "title": "Cluster Overview", @@ -768,6 +779,12 @@ "when": "(editorLangId == sqlpp || resourceFilename =~ /.sqlpp$/ || editorLangId == n1ql || resourceFilename =~ /.n1ql$/) && !isKVCluster", "group": "navigation@1" }, + { + "command": "vscode-couchbase.explainQuery", + "category": "Couchbase", + "when": "(editorLangId == sqlpp || resourceFilename =~ /.sqlpp$/ || editorLangId == n1ql || resourceFilename =~ /.n1ql$/) && !isKVCluster", + "group": "navigation@2" + }, { "command": "vscode-couchbase.runSearch", "category": "Couchbase", @@ -837,6 +854,11 @@ "when": "(editorLangId == sqlpp || resourceFilename =~ /.sqlpp$/ || editorLangId == n1ql || resourceFilename =~ /.n1ql$/) && !isKVCluster", "group": "navigation@1" }, + { + "command": "vscode-couchbase.explainQuery", + "when": "(editorLangId == sqlpp || resourceFilename =~ /.sqlpp$/ || editorLangId == n1ql || resourceFilename =~ /.n1ql$/) && !isKVCluster", + "group": "navigation@2" + }, { "command": "vscode-couchbase.runSearch", "when": "editorLangId == json && resourceFilename =~ /\\.cbs\\.json$/ && !isKVCluster && isSearchEnabled", diff --git a/src/commands/extensionCommands/commands.ts b/src/commands/extensionCommands/commands.ts index 617d2e33..61016cb1 100644 --- a/src/commands/extensionCommands/commands.ts +++ b/src/commands/extensionCommands/commands.ts @@ -43,6 +43,7 @@ export namespace Commands { export const loadMore: string = "vscode-couchbase.loadMore"; export const showOutputConsole: string = "vscode-couchbase.showOutputConsole"; export const runQuery: string = "vscode-couchbase.runQuery"; + export const explainQuery: string = "vscode-couchbase.explainQuery"; export const runSearchQuery: string = "vscode-couchbase.runSearch"; export const queryWorkbench: string = "vscode-couchbase.couchbase-query-workbench"; export const searchWorkbench: string = "vscode-couchbase.couchbase-search-workbench"; diff --git a/src/extension.ts b/src/extension.ts index 3d164b89..d7ddc4bf 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -888,7 +888,8 @@ context.subscriptions.push(disposable); ); await workbench.runCouchbaseQuery( workbenchWebviewProvider, - queryHistoryTreeProvider + queryHistoryTreeProvider, + false ); vscode.commands.executeCommand( "setContext", @@ -901,7 +902,28 @@ context.subscriptions.push(disposable); "setContext", "vscode-couchbase.runButtonEnabled", true - ); // Required to enable run query button at the start + ); + // Required to enable run query button at the start + + context.subscriptions.push( + vscode.commands.registerCommand(Commands.explainQuery, async () => { + vscode.commands.executeCommand( + "setContext", + "vscode-couchbase.runButtonEnabled", + undefined + ); + await workbench.runCouchbaseQuery( + workbenchWebviewProvider, + queryHistoryTreeProvider, + true + ); + vscode.commands.executeCommand( + "setContext", + "vscode-couchbase.runButtonEnabled", + true + ); + }) + ); context.subscriptions.push( vscode.commands.registerCommand(Commands.runSearchQuery, async (searchIndexNode: SearchIndexNode) => { diff --git a/src/workbench/queryWorkbench.ts b/src/workbench/queryWorkbench.ts index c5296001..a176cd28 100644 --- a/src/workbench/queryWorkbench.ts +++ b/src/workbench/queryWorkbench.ts @@ -37,7 +37,8 @@ export class QueryWorkbench { runCouchbaseQuery = async ( workbenchWebviewProvider: WorkbenchWebviewProvider, - queryHistoryTreeProvider: QueryHistoryTreeProvider + queryHistoryTreeProvider: QueryHistoryTreeProvider, + isExplainQuery: boolean ) => { const connection = getActiveConnection(); if (!connection) { @@ -51,7 +52,11 @@ export class QueryWorkbench { if (activeTextEditor && activeTextEditor.document.languageId === "SQL++") { // Get the text content of the active text editor. activeTextEditor.document.save(); - const query = activeTextEditor.selection.isEmpty ? activeTextEditor.document.getText() : activeTextEditor.document.getText(activeTextEditor.selection); + let query = activeTextEditor.selection.isEmpty ? activeTextEditor.document.getText() : activeTextEditor.document.getText(activeTextEditor.selection); + if (isExplainQuery) { + // Construct Explain Query + query = "EXPLAIN " + query; + } const queryContext = this.editorToContext.get(activeTextEditor.document.uri.toString()); const queryContextString = queryContext && (`${queryContext?.bucketName}.${queryContext?.scopeName}`); // Query context string is of format bucketName.ScopeName const queryParameters = getAllNamedParameters();