Skip to content

Commit 0b964f0

Browse files
committed
Merge remote-tracking branch 'origin/main' into koesie10/add-database-source
2 parents 5df9dfc + 9e914c9 commit 0b964f0

File tree

22 files changed

+153
-61
lines changed

22 files changed

+153
-61
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/common/vscode/workspace-folders.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ export function getFirstWorkspaceFolder() {
4343
const workspaceFolders = getOnDiskWorkspaceFolders();
4444

4545
if (!workspaceFolders || workspaceFolders.length === 0) {
46-
throw new Error("No workspace folders found");
46+
throw new Error(
47+
"No workspace folders found. Please open a folder or workspace in VS Code.",
48+
);
4749
}
4850

4951
const firstFolderFsPath = workspaceFolders[0];

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";
@@ -104,7 +104,7 @@ export async function promptImportGithubDatabase(
104104
cli?: CodeQLCliServer,
105105
language?: string,
106106
makeSelected = true,
107-
addSourceArchiveFolder = true,
107+
addSourceArchiveFolder = addDatabaseSourceToWorkspace(),
108108
): Promise<DatabaseItem | undefined> {
109109
const githubRepo = await askForGitHubRepo(progress);
110110
if (!githubRepo) {
@@ -183,7 +183,7 @@ export async function downloadGitHubDatabase(
183183
cli?: CodeQLCliServer,
184184
language?: string,
185185
makeSelected = true,
186-
addSourceArchiveFolder = true,
186+
addSourceArchiveFolder = addDatabaseSourceToWorkspace(),
187187
): Promise<DatabaseItem | undefined> {
188188
const nwo = getNwoFromGitHubUrl(githubRepo) || githubRepo;
189189
if (!isValidGitHubNwo(nwo)) {
@@ -311,7 +311,7 @@ async function databaseArchiveFetcher(
311311
progress: ProgressCallback,
312312
cli?: CodeQLCliServer,
313313
makeSelected = true,
314-
addSourceArchiveFolder = true,
314+
addSourceArchiveFolder = addDatabaseSourceToWorkspace(),
315315
): Promise<DatabaseItem> {
316316
progress({
317317
message: "Getting database",
@@ -493,7 +493,7 @@ async function checkForFailingResponse(
493493
return response;
494494
}
495495

496-
// An error downloading the database. Attempt to extract the resaon behind it.
496+
// An error downloading the database. Attempt to extract the reason behind it.
497497
const text = await response.text();
498498
let msg: string;
499499
try {

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

Lines changed: 4 additions & 3 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,
@@ -137,7 +138,7 @@ export class DatabaseManager extends DisposableObject {
137138
displayName?: string,
138139
{
139140
isTutorialDatabase = false,
140-
addSourceArchiveFolder = true,
141+
addSourceArchiveFolder = addDatabaseSourceToWorkspace(),
141142
}: OpenDatabaseOptions = {},
142143
): Promise<DatabaseItem> {
143144
const databaseItem = await this.createDatabaseItem(
@@ -164,7 +165,7 @@ export class DatabaseManager extends DisposableObject {
164165
databaseItem: DatabaseItemImpl,
165166
makeSelected: boolean,
166167
isTutorialDatabase?: boolean,
167-
addSourceArchiveFolder = true,
168+
addSourceArchiveFolder = addDatabaseSourceToWorkspace(),
168169
): Promise<DatabaseItem> {
169170
const existingItem = this.findDatabaseItem(databaseItem.databaseUri);
170171
if (existingItem !== undefined) {
@@ -274,7 +275,7 @@ export class DatabaseManager extends DisposableObject {
274275
`We've noticed you don't have a CodeQL pack available to analyze this database. Can we set up a query pack for you?`,
275276
);
276277

277-
if (answer === "No") {
278+
if (answer === "No" || answer === undefined) {
278279
return;
279280
}
280281

extensions/ql-vscode/src/model-editor/modeled-method.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,38 @@ export function isModelAccepted(
126126
modeledMethod.provenance !== "ai-generated"
127127
);
128128
}
129+
130+
/**
131+
* Calculates the new provenance for a modeled method based on the current provenance.
132+
* @param modeledMethod The modeled method if there is one.
133+
* @returns The new provenance.
134+
*/
135+
export function calculateNewProvenance(
136+
modeledMethod: ModeledMethod | undefined,
137+
) {
138+
if (!modeledMethod || !modeledMethodSupportsProvenance(modeledMethod)) {
139+
// If nothing has been modeled or the modeled method does not support
140+
// provenance, we assume that the user has entered it manually.
141+
return "manual";
142+
}
143+
144+
switch (modeledMethod.provenance) {
145+
case "df-generated":
146+
// If the method has been generated and there has been a change, we assume
147+
// that the user has manually edited it.
148+
return "df-manual";
149+
case "df-manual":
150+
// If the method has had manual edits, we want the provenance to stay the same.
151+
return "df-manual";
152+
case "ai-generated":
153+
// If the method has been generated and there has been a change, we assume
154+
// that the user has manually edited it.
155+
return "ai-manual";
156+
case "ai-manual":
157+
// If the method has had manual edits, we want the provenance to stay the same.
158+
return "ai-manual";
159+
default:
160+
// The method has been modeled manually.
161+
return "manual";
162+
}
163+
}

extensions/ql-vscode/src/view/common/DeterminateProgressRing.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { styled } from "styled-components";
33

44
type Props = {
55
percent: number;
6-
label?: string;
76
};
87

98
const Circle = styled.div`
@@ -33,10 +32,7 @@ const progressSegments = 44;
3332
// See https://github.com/microsoft/fast/blob/21c210f2164c5cf285cade1a328460c67e4b97e6/packages/web-components/fast-foundation/src/progress-ring/progress-ring.template.ts
3433
// Once the determinate progress ring is available in the VSCode webview UI toolkit, we should use that instead
3534

36-
export const DeterminateProgressRing = ({
37-
percent,
38-
label = "Loading...",
39-
}: Props) => (
35+
export const DeterminateProgressRing = ({ percent }: Props) => (
4036
<Circle
4137
role="progressbar"
4238
aria-valuemin={0}

extensions/ql-vscode/src/view/model-editor/LibraryRow.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,6 @@ export const LibraryRow = ({
226226
<>
227227
<SectionDivider />
228228
<ModeledMethodDataGrid
229-
packageName={title}
230229
methods={methods}
231230
modeledMethodsMap={modeledMethodsMap}
232231
modifiedSignatures={modifiedSignatures}

extensions/ql-vscode/src/view/model-editor/ModelInputDropdown.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as React from "react";
22
import { ChangeEvent, useCallback, useMemo } from "react";
33
import {
44
ModeledMethod,
5+
calculateNewProvenance,
56
isModelAccepted,
67
modeledMethodSupportsInput,
78
} from "../../model-editor/modeled-method";
@@ -53,6 +54,7 @@ export const ModelInputDropdown = ({
5354

5455
onChange({
5556
...modeledMethod,
57+
provenance: calculateNewProvenance(modeledMethod),
5658
input: target.value,
5759
});
5860
},

0 commit comments

Comments
 (0)