Skip to content

Commit

Permalink
Add explain button next to run query (#427)
Browse files Browse the repository at this point in the history
Adds a explain button next to Run query
  • Loading branch information
prajwal-pai77 authored Oct 16, 2024
1 parent 0c76f89 commit 7205bdf
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 7 deletions.
20 changes: 20 additions & 0 deletions images/dark/explain-query.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions images/light/explain-query.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 23 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "vscode-couchbase",
"displayName": "Couchbase",
"description": "",
"version": "2.1.5",
"version": "2.1.6",
"engines": {
"vscode": "^1.63.1"
},
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions src/commands/extensionCommands/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
26 changes: 24 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,8 @@ context.subscriptions.push(disposable);
);
await workbench.runCouchbaseQuery(
workbenchWebviewProvider,
queryHistoryTreeProvider
queryHistoryTreeProvider,
false
);
vscode.commands.executeCommand(
"setContext",
Expand All @@ -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) => {
Expand Down
9 changes: 7 additions & 2 deletions src/workbench/queryWorkbench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ export class QueryWorkbench {

runCouchbaseQuery = async (
workbenchWebviewProvider: WorkbenchWebviewProvider,
queryHistoryTreeProvider: QueryHistoryTreeProvider
queryHistoryTreeProvider: QueryHistoryTreeProvider,
isExplainQuery: boolean
) => {
const connection = getActiveConnection();
if (!connection) {
Expand All @@ -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();
Expand Down

0 comments on commit 7205bdf

Please sign in to comment.