Skip to content

Commit

Permalink
fix: Fix executing NoSQL query from command palette (#2269)
Browse files Browse the repository at this point in the history
* Fix NoSQL query from command palette

* Reorder entries in package.json
  • Loading branch information
JasonYeMSFT authored Mar 13, 2024
1 parent 678e202 commit 6ddedae
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -971,13 +971,13 @@
"command": "cosmosDB.executeMongoCommand",
"when": "editorLangId == 'mongo'"
},
{
"command": "postgreSQL.executeQuery",
"when": "editorLangId == 'postgres'"
},
{
"command": "cosmosDB.executeNoSqlQuery",
"when": "editorLangId == 'nosql'"
},
{
"command": "postgreSQL.executeQuery",
"when": "editorLangId == 'postgres'"
}
]
},
Expand Down
16 changes: 14 additions & 2 deletions src/docdb/commands/executeNoSqlQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,29 @@
*--------------------------------------------------------------------------------------------*/

import { IActionContext } from "@microsoft/vscode-azext-utils";
import * as vscode from "vscode";
import { ViewColumn } from "vscode";
import { KeyValueStore } from "../../KeyValueStore";
import { localize } from "../../utils/localize";
import * as vscodeUtil from "../../utils/vscodeUtils";
import { NoSqlQueryConnection, noSqlQueryConnectionKey } from "../NoSqlCodeLensProvider";
import { getCosmosClient } from "../getCosmosClient";

export async function executeNoSqlQuery(_context: IActionContext, args: { queryText: string, populateQueryMetrics?: boolean }): Promise<void> {
let queryText: string;
let populateQueryMetrics: boolean;
if (!args) {
throw new Error("Unable to execute query due to missing args. Please connect to a Cosmos DB collection.");
const activeEditor: vscode.TextEditor | undefined = vscode.window.activeTextEditor;

if (!activeEditor?.document) {
throw new Error(localize('openQueryBeforeExecuting', 'Open a NoSQL query before executing.'));
}
queryText = activeEditor.document.getText();
populateQueryMetrics = false;
} else {
queryText = args.queryText;
populateQueryMetrics = !!args.populateQueryMetrics;
}
const { queryText, populateQueryMetrics } = args;
const connectedCollection = KeyValueStore.instance.get(noSqlQueryConnectionKey);
if (!connectedCollection) {
throw new Error("Unable to execute query due to missing node data. Please connect to a Cosmos DB collection node.");
Expand Down

0 comments on commit 6ddedae

Please sign in to comment.