|
4 | 4 | *--------------------------------------------------------------------------------------------*/
|
5 | 5 |
|
6 | 6 | import { IActionContext } from "@microsoft/vscode-azext-utils";
|
| 7 | +import * as vscode from "vscode"; |
7 | 8 | import { ViewColumn } from "vscode";
|
8 | 9 | import { KeyValueStore } from "../../KeyValueStore";
|
| 10 | +import { localize } from "../../utils/localize"; |
9 | 11 | import * as vscodeUtil from "../../utils/vscodeUtils";
|
10 | 12 | import { NoSqlQueryConnection, noSqlQueryConnectionKey } from "../NoSqlCodeLensProvider";
|
11 | 13 | import { getCosmosClient } from "../getCosmosClient";
|
12 | 14 |
|
13 | 15 | export async function executeNoSqlQuery(_context: IActionContext, args: { queryText: string, populateQueryMetrics?: boolean }): Promise<void> {
|
| 16 | + let queryText: string; |
| 17 | + let populateQueryMetrics: boolean; |
14 | 18 | 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; |
16 | 29 | }
|
17 |
| - const { queryText, populateQueryMetrics } = args; |
18 | 30 | const connectedCollection = KeyValueStore.instance.get(noSqlQueryConnectionKey);
|
19 | 31 | if (!connectedCollection) {
|
20 | 32 | throw new Error("Unable to execute query due to missing node data. Please connect to a Cosmos DB collection node.");
|
|
0 commit comments