Skip to content

Commit 9e914c9

Browse files
authored
Don't add database source archive folders by default (#3047)
1 parent 5770eda commit 9e914c9

File tree

6 files changed

+46
-12
lines changed

6 files changed

+46
-12
lines changed

extensions/ql-vscode/CHANGELOG.md

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

33
## [UNRELEASED]
44

5+
- When adding a CodeQL database, we no longer add the database source folder to the workspace by default (since this caused bugs in single-folder workspaces). [#3047](https://github.com/github/vscode-codeql/pull/3047)
6+
- You can manually add individual database source folders to the workspace with the "Add Database Source to Workspace" right-click command in the databases view.
7+
- To restore the old behavior of adding all database source folders by default, set the `codeQL.addingDatabases.addDatabaseSourceToWorkspace` setting to `true`.
8+
- Rename the `codeQL.databaseDownload.allowHttp` setting to `codeQL.addingDatabases.allowHttp`, so that database-related settings are grouped together in the Settings UI. [#3047](https://github.com/github/vscode-codeql/pull/3047)
59
- The "Sort by Language" action in the databases view now sorts by name within each language. [#3055](https://github.com/github/vscode-codeql/pull/3055)
610

711
## 1.9.4 - 6 November 2023

extensions/ql-vscode/package.json

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,13 +372,23 @@
372372
},
373373
{
374374
"type": "object",
375-
"title": "Downloading databases",
375+
"title": "Adding databases",
376376
"order": 6,
377377
"properties": {
378+
"codeQL.addingDatabases.allowHttp": {
379+
"type": "boolean",
380+
"default": false,
381+
"description": "Allow databases to be downloaded via HTTP. Warning: enabling this option will allow downloading from insecure servers."
382+
},
378383
"codeQL.databaseDownload.allowHttp": {
384+
"type": "boolean",
385+
"markdownDeprecationMessage": "**Deprecated**: Please use `#codeQL.addingDatabases.allowHttp#` instead.",
386+
"deprecationMessage": "Deprecated: Please use codeQL.addingDatabases.allowHttp instead."
387+
},
388+
"codeQL.addingDatabases.addDatabaseSourceToWorkspace": {
379389
"type": "boolean",
380390
"default": false,
381-
"description": "Allow database to be downloaded via HTTP. Warning: enabling this option will allow downloading from insecure servers."
391+
"markdownDescription": "When adding a CodeQL database, automatically add the database's source folder as a workspace folder. Warning: enabling this option in a single-folder workspace will cause the workspace to reload as a [multi-root workspace](https://code.visualstudio.com/docs/editor/multi-root-workspaces). This may cause query history and database lists to be reset."
382392
}
383393
}
384394
},

extensions/ql-vscode/src/config.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -641,14 +641,23 @@ export function isCodespacesTemplate() {
641641
return !!CODESPACES_TEMPLATE.getValue<boolean>();
642642
}
643643

644-
const DATABASE_DOWNLOAD_SETTING = new Setting("databaseDownload", ROOT_SETTING);
644+
const ADDING_DATABASES_SETTING = new Setting("addingDatabases", ROOT_SETTING);
645645

646-
const ALLOW_HTTP_SETTING = new Setting("allowHttp", DATABASE_DOWNLOAD_SETTING);
646+
const ALLOW_HTTP_SETTING = new Setting("allowHttp", ADDING_DATABASES_SETTING);
647647

648648
export function allowHttp(): boolean {
649649
return ALLOW_HTTP_SETTING.getValue<boolean>() || false;
650650
}
651651

652+
const ADD_DATABASE_SOURCE_TO_WORKSPACE_SETTING = new Setting(
653+
"addDatabaseSourceToWorkspace",
654+
ADDING_DATABASES_SETTING,
655+
);
656+
657+
export function addDatabaseSourceToWorkspace(): boolean {
658+
return ADD_DATABASE_SOURCE_TO_WORKSPACE_SETTING.getValue<boolean>() || false;
659+
}
660+
652661
/**
653662
* Parent setting for all settings related to the "Create Query" command.
654663
*/

extensions/ql-vscode/src/databases/database-fetcher.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import {
2929
} from "../common/github-url-identifier-helper";
3030
import { Credentials } from "../common/authentication";
3131
import { AppCommandManager } from "../common/commands";
32-
import { allowHttp } from "../config";
32+
import { addDatabaseSourceToWorkspace, allowHttp } from "../config";
3333
import { showAndLogInformationMessage } from "../common/logging";
3434
import { AppOctokit } from "../common/octokit";
3535
import { getLanguageDisplayName } from "../common/query-language";
@@ -99,7 +99,7 @@ export async function promptImportGithubDatabase(
9999
cli?: CodeQLCliServer,
100100
language?: string,
101101
makeSelected = true,
102-
addSourceArchiveFolder = true,
102+
addSourceArchiveFolder = addDatabaseSourceToWorkspace(),
103103
): Promise<DatabaseItem | undefined> {
104104
const githubRepo = await askForGitHubRepo(progress);
105105
if (!githubRepo) {
@@ -178,7 +178,7 @@ export async function downloadGitHubDatabase(
178178
cli?: CodeQLCliServer,
179179
language?: string,
180180
makeSelected = true,
181-
addSourceArchiveFolder = true,
181+
addSourceArchiveFolder = addDatabaseSourceToWorkspace(),
182182
): Promise<DatabaseItem | undefined> {
183183
const nwo = getNwoFromGitHubUrl(githubRepo) || githubRepo;
184184
if (!isValidGitHubNwo(nwo)) {
@@ -295,7 +295,7 @@ async function databaseArchiveFetcher(
295295
progress: ProgressCallback,
296296
cli?: CodeQLCliServer,
297297
makeSelected = true,
298-
addSourceArchiveFolder = true,
298+
addSourceArchiveFolder = addDatabaseSourceToWorkspace(),
299299
): Promise<DatabaseItem> {
300300
progress({
301301
message: "Getting database",
@@ -476,7 +476,7 @@ async function checkForFailingResponse(
476476
return response;
477477
}
478478

479-
// An error downloading the database. Attempt to extract the resaon behind it.
479+
// An error downloading the database. Attempt to extract the reason behind it.
480480
const text = await response.text();
481481
let msg: string;
482482
try {

extensions/ql-vscode/src/databases/local-databases/database-manager.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { QueryRunner } from "../../query-server";
77
import * as cli from "../../codeql-cli/cli";
88
import { ProgressCallback, withProgress } from "../../common/vscode/progress";
99
import {
10+
addDatabaseSourceToWorkspace,
1011
getAutogenerateQlPacks,
1112
isCodespacesTemplate,
1213
setAutogenerateQlPacks,
@@ -135,7 +136,7 @@ export class DatabaseManager extends DisposableObject {
135136
displayName?: string,
136137
{
137138
isTutorialDatabase = false,
138-
addSourceArchiveFolder = true,
139+
addSourceArchiveFolder = addDatabaseSourceToWorkspace(),
139140
}: OpenDatabaseOptions = {},
140141
): Promise<DatabaseItem> {
141142
const databaseItem = await this.createDatabaseItem(uri, displayName);
@@ -158,7 +159,7 @@ export class DatabaseManager extends DisposableObject {
158159
databaseItem: DatabaseItemImpl,
159160
makeSelected: boolean,
160161
isTutorialDatabase?: boolean,
161-
addSourceArchiveFolder = true,
162+
addSourceArchiveFolder = addDatabaseSourceToWorkspace(),
162163
): Promise<DatabaseItem> {
163164
const existingItem = this.findDatabaseItem(databaseItem.databaseUri);
164165
if (existingItem !== undefined) {

extensions/ql-vscode/test/vscode-tests/minimal-workspace/local-queries/local-databases.test.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,17 @@ describe("local databases", () => {
739739
expect(setCurrentDatabaseItemSpy).toBeCalledTimes(1);
740740
});
741741

742-
it("should add database source archive folder", async () => {
742+
it("should not add database source archive folder when `codeQL.addingDatabases.addDatabaseSourceToWorkspace` is `false`", async () => {
743+
jest.spyOn(config, "addDatabaseSourceToWorkspace").mockReturnValue(false);
744+
745+
await databaseManager.openDatabase(mockDbItem.databaseUri);
746+
747+
expect(addDatabaseSourceArchiveFolderSpy).toBeCalledTimes(0);
748+
});
749+
750+
it("should add database source archive folder when `codeQL.addingDatabases.addDatabaseSourceToWorkspace` is `true`", async () => {
751+
jest.spyOn(config, "addDatabaseSourceToWorkspace").mockReturnValue(true);
752+
743753
await databaseManager.openDatabase(mockDbItem.databaseUri);
744754

745755
expect(addDatabaseSourceArchiveFolderSpy).toBeCalledTimes(1);

0 commit comments

Comments
 (0)