Skip to content

Commit 424e8d3

Browse files
authored
Discourage use of "Quick query" in single-folder workspaces (#3082)
1 parent 208efb5 commit 424e8d3

File tree

5 files changed

+25
-8
lines changed

5 files changed

+25
-8
lines changed

extensions/ql-vscode/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## [UNRELEASED]
44

5+
- Add a prompt to the "Quick query" command to encourage users in single-folder workspaces to use "Create query" instead. [#3082](https://github.com/github/vscode-codeql/pull/3082)
6+
57
## 1.10.0 - 16 November 2023
68

79
- Add new CodeQL views for managing databases and queries:

extensions/ql-vscode/src/common/commands.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ export type LocalQueryCommands = {
146146
"codeQL.quickQuery": () => Promise<void>;
147147
"codeQL.getCurrentQuery": () => Promise<string>;
148148
"codeQL.createQuery": () => Promise<void>;
149+
"codeQLQuickQuery.createQuery": () => Promise<void>;
149150
};
150151

151152
// Debugger commands

extensions/ql-vscode/src/local-queries/local-queries.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ import { WebviewReveal } from "./webview";
4242
import { asError, getErrorMessage } from "../common/helpers-pure";
4343
import { CliVersionConstraint, CodeQLCliServer } from "../codeql-cli/cli";
4444
import { LocalQueryCommands } from "../common/commands";
45-
import { App } from "../common/app";
4645
import { DisposableObject } from "../common/disposable-object";
4746
import { SkeletonQueryWizard } from "./skeleton-query-wizard";
4847
import { LocalQueryRun } from "./local-query-run";
@@ -51,6 +50,7 @@ import { findLanguage } from "../codeql-cli/query-language";
5150
import type { QueryTreeViewItem } from "../queries-panel/query-tree-view-item";
5251
import { tryGetQueryLanguage } from "../common/query-language";
5352
import { LanguageContextStore } from "../language-context-store";
53+
import { ExtensionApp } from "../common/vscode/vscode-app";
5454

5555
interface DatabaseQuickPickItem extends QuickPickItem {
5656
databaseItem: DatabaseItem;
@@ -66,7 +66,7 @@ export class LocalQueries extends DisposableObject {
6666
private selectedQueryTreeViewItems: readonly QueryTreeViewItem[] = [];
6767

6868
public constructor(
69-
private readonly app: App,
69+
private readonly app: ExtensionApp,
7070
private readonly queryRunner: QueryRunner,
7171
private readonly queryHistoryManager: QueryHistoryManager,
7272
private readonly databaseManager: DatabaseManager,
@@ -119,6 +119,7 @@ export class LocalQueries extends DisposableObject {
119119
return this.getCurrentQuery(true);
120120
},
121121
"codeQL.createQuery": this.createSkeletonQuery.bind(this),
122+
"codeQLQuickQuery.createQuery": this.createSkeletonQuery.bind(this),
122123
};
123124
}
124125

extensions/ql-vscode/src/local-queries/quick-query.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { CancellationToken, window as Window, workspace, Uri } from "vscode";
55
import { LSPErrorCodes, ResponseError } from "vscode-languageclient";
66
import { CodeQLCliServer } from "../codeql-cli/cli";
77
import { DatabaseUI } from "../databases/local-databases-ui";
8-
import { showBinaryChoiceDialog } from "../common/vscode/dialog";
98
import { getInitialQueryContents } from "./query-contents";
109
import { getPrimaryDbscheme, getQlPackForDbscheme } from "../databases/qlpack";
1110
import {
@@ -15,6 +14,7 @@ import {
1514
import { getErrorMessage } from "../common/helpers-pure";
1615
import { FALLBACK_QLPACK_FILENAME, getQlPackPath } from "../common/ql";
1716
import { App } from "../common/app";
17+
import { ExtensionApp } from "../common/vscode/vscode-app";
1818

1919
const QUICK_QUERIES_DIR_NAME = "quick-queries";
2020
const QUICK_QUERY_QUERY_NAME = "quick-query.ql";
@@ -52,7 +52,7 @@ function findExistingQuickQueryEditor() {
5252
* Show a buffer the user can enter a simple query into.
5353
*/
5454
export async function displayQuickQuery(
55-
app: App,
55+
app: ExtensionApp,
5656
cliServer: CodeQLCliServer,
5757
databaseUI: DatabaseUI,
5858
progress: ProgressCallback,
@@ -80,12 +80,24 @@ export async function displayQuickQuery(
8080
// being undefined) just let the user know that they're in for a
8181
// restart.
8282
if (workspace.workspaceFile === undefined) {
83-
const makeMultiRoot = await showBinaryChoiceDialog(
84-
"Quick query requires multiple folders in the workspace. Reload workspace as multi-folder workspace?",
83+
const createQueryOption = 'Run "Create query"';
84+
const quickQueryOption = 'Run "Quick query" anyway';
85+
const quickQueryPrompt = await Window.showWarningMessage(
86+
'"Quick query" requires reloading your workspace as a multi-root workspace, which may cause query history and databases to be lost.',
87+
{
88+
modal: true,
89+
detail:
90+
'The "Create query" command does not require reloading the workspace.',
91+
},
92+
createQueryOption,
93+
quickQueryOption,
8594
);
86-
if (makeMultiRoot) {
95+
if (quickQueryPrompt === quickQueryOption) {
8796
updateQuickQueryDir(queriesDir, workspaceFolders.length, 0);
8897
}
98+
if (quickQueryPrompt === createQueryOption) {
99+
await app.queryServerCommands.execute("codeQLQuickQuery.createQuery");
100+
}
89101
return;
90102
}
91103

extensions/ql-vscode/test/unit-tests/command-lint.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ describe("commands declared in package.json", () => {
4141
command.match(/^codeQLLanguageSelection\./) ||
4242
command.match(/^codeQLDatabases\./) ||
4343
command.match(/^codeQLQueries\./) ||
44+
command.match(/^codeQLQuickQuery\./) ||
4445
command.match(/^codeQLVariantAnalysisRepositories\./) ||
4546
command.match(/^codeQLQueryHistory\./) ||
4647
command.match(/^codeQLAstViewer\./) ||
@@ -114,7 +115,7 @@ describe("commands declared in package.json", () => {
114115
expect(disabledInPalette.has(command)).toBe(false);
115116
});
116117

117-
// Commands in contribContextMenuCmds may reasonbly be enabled or
118+
// Commands in contribContextMenuCmds may reasonably be enabled or
118119
// disabled in the command palette; for example, codeQL.runQuery
119120
// is available there, since we heuristically figure out which
120121
// query to run, but codeQL.setCurrentDatabase is not.

0 commit comments

Comments
 (0)