Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions extensions/ql-vscode/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## [UNRELEASED]

- 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)

## 1.10.0 - 16 November 2023

- Add new CodeQL views for managing databases and queries:
Expand Down
8 changes: 8 additions & 0 deletions extensions/ql-vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,10 @@
"title": "Create query",
"icon": "$(new-file)"
},
{
Comment thread
charisk marked this conversation as resolved.
Outdated
"command": "codeQLQuickQuery.createQuery",
"title": "Create query from prompt"
},
{
"command": "codeQLVariantAnalysisRepositories.openConfigFile",
"title": "Open database configuration file",
Expand Down Expand Up @@ -1346,6 +1350,10 @@
"command": "codeQLQueries.createQuery",
"when": "false"
},
{
"command": "codeQLQuickQuery.createQuery",
"when": "false"
},
{
"command": "codeQL.runLocalQueryFromFileTab",
"when": "false"
Expand Down
1 change: 1 addition & 0 deletions extensions/ql-vscode/src/common/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ export type LocalQueryCommands = {
"codeQL.quickQuery": () => Promise<void>;
"codeQL.getCurrentQuery": () => Promise<string>;
"codeQL.createQuery": () => Promise<void>;
"codeQLQuickQuery.createQuery": () => Promise<void>;
};

// Debugger commands
Expand Down
5 changes: 3 additions & 2 deletions extensions/ql-vscode/src/local-queries/local-queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import { WebviewReveal } from "./webview";
import { asError, getErrorMessage } from "../common/helpers-pure";
import { CliVersionConstraint, CodeQLCliServer } from "../codeql-cli/cli";
import { LocalQueryCommands } from "../common/commands";
import { App } from "../common/app";
import { DisposableObject } from "../common/disposable-object";
import { SkeletonQueryWizard } from "./skeleton-query-wizard";
import { LocalQueryRun } from "./local-query-run";
Expand All @@ -51,6 +50,7 @@ import { findLanguage } from "../codeql-cli/query-language";
import type { QueryTreeViewItem } from "../queries-panel/query-tree-view-item";
import { tryGetQueryLanguage } from "../common/query-language";
import { LanguageContextStore } from "../language-context-store";
import { ExtensionApp } from "../common/vscode/vscode-app";

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

public constructor(
private readonly app: App,
private readonly app: ExtensionApp,
private readonly queryRunner: QueryRunner,
private readonly queryHistoryManager: QueryHistoryManager,
private readonly databaseManager: DatabaseManager,
Expand Down Expand Up @@ -119,6 +119,7 @@ export class LocalQueries extends DisposableObject {
return this.getCurrentQuery(true);
},
"codeQL.createQuery": this.createSkeletonQuery.bind(this),
"codeQLQuickQuery.createQuery": this.createSkeletonQuery.bind(this),
};
}

Expand Down
22 changes: 17 additions & 5 deletions extensions/ql-vscode/src/local-queries/quick-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { CancellationToken, window as Window, workspace, Uri } from "vscode";
import { LSPErrorCodes, ResponseError } from "vscode-languageclient";
import { CodeQLCliServer } from "../codeql-cli/cli";
import { DatabaseUI } from "../databases/local-databases-ui";
import { showBinaryChoiceDialog } from "../common/vscode/dialog";
import { getInitialQueryContents } from "./query-contents";
import { getPrimaryDbscheme, getQlPackForDbscheme } from "../databases/qlpack";
import {
Expand All @@ -15,6 +14,7 @@ import {
import { getErrorMessage } from "../common/helpers-pure";
import { FALLBACK_QLPACK_FILENAME, getQlPackPath } from "../common/ql";
import { App } from "../common/app";
import { ExtensionApp } from "../common/vscode/vscode-app";

const QUICK_QUERIES_DIR_NAME = "quick-queries";
const QUICK_QUERY_QUERY_NAME = "quick-query.ql";
Expand Down Expand Up @@ -52,7 +52,7 @@ function findExistingQuickQueryEditor() {
* Show a buffer the user can enter a simple query into.
*/
export async function displayQuickQuery(
app: App,
app: ExtensionApp,
cliServer: CodeQLCliServer,
databaseUI: DatabaseUI,
progress: ProgressCallback,
Expand Down Expand Up @@ -80,12 +80,24 @@ export async function displayQuickQuery(
// being undefined) just let the user know that they're in for a
// restart.
if (workspace.workspaceFile === undefined) {
const makeMultiRoot = await showBinaryChoiceDialog(
"Quick query requires multiple folders in the workspace. Reload workspace as multi-folder workspace?",
const createQueryOption = 'Run "Create query"';
const quickQueryOption = 'Run "Quick query" anyway';
const quickQueryPrompt = await Window.showWarningMessage(
'"Quick query" requires reloading your workspace as a multi-root workspace, which may cause query history and databases to be lost.',
{
modal: true,
detail:
'The "Create query" command does not require reloading the workspace.',
},
createQueryOption,
quickQueryOption,
);
if (makeMultiRoot) {
if (quickQueryPrompt === quickQueryOption) {
updateQuickQueryDir(queriesDir, workspaceFolders.length, 0);
}
if (quickQueryPrompt === createQueryOption) {
await app.queryServerCommands.execute("codeQLQuickQuery.createQuery");
}
return;
}

Expand Down
3 changes: 2 additions & 1 deletion extensions/ql-vscode/test/unit-tests/command-lint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ describe("commands declared in package.json", () => {
command.match(/^codeQLLanguageSelection\./) ||
command.match(/^codeQLDatabases\./) ||
command.match(/^codeQLQueries\./) ||
command.match(/^codeQLQuickQuery\./) ||
command.match(/^codeQLVariantAnalysisRepositories\./) ||
command.match(/^codeQLQueryHistory\./) ||
command.match(/^codeQLAstViewer\./) ||
Expand Down Expand Up @@ -114,7 +115,7 @@ describe("commands declared in package.json", () => {
expect(disabledInPalette.has(command)).toBe(false);
});

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