Skip to content

Commit 6ddedae

Browse files
authored
fix: Fix executing NoSQL query from command palette (#2269)
* Fix NoSQL query from command palette * Reorder entries in package.json
1 parent 678e202 commit 6ddedae

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -971,13 +971,13 @@
971971
"command": "cosmosDB.executeMongoCommand",
972972
"when": "editorLangId == 'mongo'"
973973
},
974-
{
975-
"command": "postgreSQL.executeQuery",
976-
"when": "editorLangId == 'postgres'"
977-
},
978974
{
979975
"command": "cosmosDB.executeNoSqlQuery",
980976
"when": "editorLangId == 'nosql'"
977+
},
978+
{
979+
"command": "postgreSQL.executeQuery",
980+
"when": "editorLangId == 'postgres'"
981981
}
982982
]
983983
},

src/docdb/commands/executeNoSqlQuery.ts

+14-2
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,29 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import { IActionContext } from "@microsoft/vscode-azext-utils";
7+
import * as vscode from "vscode";
78
import { ViewColumn } from "vscode";
89
import { KeyValueStore } from "../../KeyValueStore";
10+
import { localize } from "../../utils/localize";
911
import * as vscodeUtil from "../../utils/vscodeUtils";
1012
import { NoSqlQueryConnection, noSqlQueryConnectionKey } from "../NoSqlCodeLensProvider";
1113
import { getCosmosClient } from "../getCosmosClient";
1214

1315
export async function executeNoSqlQuery(_context: IActionContext, args: { queryText: string, populateQueryMetrics?: boolean }): Promise<void> {
16+
let queryText: string;
17+
let populateQueryMetrics: boolean;
1418
if (!args) {
15-
throw new Error("Unable to execute query due to missing args. Please connect to a Cosmos DB collection.");
19+
const activeEditor: vscode.TextEditor | undefined = vscode.window.activeTextEditor;
20+
21+
if (!activeEditor?.document) {
22+
throw new Error(localize('openQueryBeforeExecuting', 'Open a NoSQL query before executing.'));
23+
}
24+
queryText = activeEditor.document.getText();
25+
populateQueryMetrics = false;
26+
} else {
27+
queryText = args.queryText;
28+
populateQueryMetrics = !!args.populateQueryMetrics;
1629
}
17-
const { queryText, populateQueryMetrics } = args;
1830
const connectedCollection = KeyValueStore.instance.get(noSqlQueryConnectionKey);
1931
if (!connectedCollection) {
2032
throw new Error("Unable to execute query due to missing node data. Please connect to a Cosmos DB collection node.");

0 commit comments

Comments
 (0)