Skip to content

Commit e91e9d2

Browse files
authored
Merge branch 'main' into koesie10/unsupported-cli-version-check
2 parents 791a445 + 4ea1bb5 commit e91e9d2

File tree

13 files changed

+241
-135
lines changed

13 files changed

+241
-135
lines changed

extensions/ql-vscode/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
## [UNRELEASED]
44

55
- Add settings `codeQL.variantAnalysis.defaultResultsFilter` and `codeQL.variantAnalysis.defaultResultsSort` for configuring how variant analysis results are filtered and sorted in the results view. The default is to show all repositories, and to sort by the number of results. [#2392](https://github.com/github/vscode-codeql/pull/2392)
6+
- Fix bug to ensure error messages have complete stack trace in message logs. [#2425](https://github.com/github/vscode-codeql/pull/2425)
67
- Fix bug where the `CodeQL: Compare Query` command did not work for comparing quick-eval queries. [#2422](https://github.com/github/vscode-codeql/pull/2422)
8+
- Update text of copy and export buttons in variant analysis results view to clarify that they only copy/export the selected/filtered results. [#2427](https://github.com/github/vscode-codeql/pull/2427)
79
- Add warning when using unsupported CodeQL CLI version. [#2428](https://github.com/github/vscode-codeql/pull/2428)
810

911
## 1.8.4 - 3 May 2023

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ import { AppEventEmitter } from "./events";
44
import { Logger } from "./logging";
55
import { Memento } from "./memento";
66
import { AppCommandManager } from "./commands";
7+
import type {
8+
WorkspaceFolder,
9+
Event,
10+
WorkspaceFoldersChangeEvent,
11+
} from "vscode";
712

813
export interface App {
914
createEventEmitter<T>(): AppEventEmitter<T>;
@@ -14,6 +19,8 @@ export interface App {
1419
readonly globalStoragePath: string;
1520
readonly workspaceStoragePath?: string;
1621
readonly workspaceState: Memento;
22+
readonly workspaceFolders: readonly WorkspaceFolder[] | undefined;
23+
readonly onDidChangeWorkspaceFolders: Event<WorkspaceFoldersChangeEvent>;
1724
readonly credentials: Credentials;
1825
readonly commands: AppCommandManager;
1926
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
import { basename, dirname, join } from "path";
2+
import { env } from "vscode";
3+
4+
/**
5+
* A node in the tree of files. This will be either a `FileTreeDirectory` or a `FileTreeLeaf`.
6+
*/
7+
export abstract class FileTreeNode {
8+
constructor(private _path: string, private _name: string) {}
9+
10+
public get path(): string {
11+
return this._path;
12+
}
13+
14+
public get name(): string {
15+
return this._name;
16+
}
17+
18+
public abstract get children(): readonly FileTreeNode[];
19+
20+
public abstract finish(): void;
21+
}
22+
23+
/**
24+
* A directory containing one or more files or other directories.
25+
*/
26+
export class FileTreeDirectory extends FileTreeNode {
27+
constructor(
28+
_path: string,
29+
_name: string,
30+
private _children: FileTreeNode[] = [],
31+
) {
32+
super(_path, _name);
33+
}
34+
35+
public get children(): readonly FileTreeNode[] {
36+
return this._children;
37+
}
38+
39+
public addChild(child: FileTreeNode): void {
40+
this._children.push(child);
41+
}
42+
43+
public createDirectory(relativePath: string): FileTreeDirectory {
44+
const dirName = dirname(relativePath);
45+
if (dirName === ".") {
46+
return this.createChildDirectory(relativePath);
47+
} else {
48+
const parent = this.createDirectory(dirName);
49+
return parent.createDirectory(basename(relativePath));
50+
}
51+
}
52+
53+
public finish(): void {
54+
// remove empty directories
55+
this._children.filter(
56+
(child) => child instanceof FileTreeLeaf || child.children.length > 0,
57+
);
58+
this._children.sort((a, b) => a.name.localeCompare(b.name, env.language));
59+
this._children.forEach((child, i) => {
60+
child.finish();
61+
if (
62+
child.children?.length === 1 &&
63+
child.children[0] instanceof FileTreeDirectory
64+
) {
65+
// collapse children
66+
const replacement = new FileTreeDirectory(
67+
child.children[0].path,
68+
`${child.name} / ${child.children[0].name}`,
69+
Array.from(child.children[0].children),
70+
);
71+
this._children[i] = replacement;
72+
}
73+
});
74+
}
75+
76+
private createChildDirectory(name: string): FileTreeDirectory {
77+
const existingChild = this._children.find((child) => child.name === name);
78+
if (existingChild !== undefined) {
79+
return existingChild as FileTreeDirectory;
80+
} else {
81+
const newChild = new FileTreeDirectory(join(this.path, name), name);
82+
this.addChild(newChild);
83+
return newChild;
84+
}
85+
}
86+
}
87+
88+
/**
89+
* A single file.
90+
*/
91+
export class FileTreeLeaf extends FileTreeNode {
92+
constructor(_path: string, _name: string) {
93+
super(_path, _name);
94+
}
95+
96+
public get children(): readonly FileTreeNode[] {
97+
return [];
98+
}
99+
100+
public finish(): void {
101+
/**/
102+
}
103+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ export function registerCommandWithErrorHandling(
4949
const errorMessage = redactableError(error)`${
5050
getErrorMessage(e) || e
5151
} (${commandId})`;
52-
const errorStack = getErrorStack(e);
5352
if (e instanceof UserCancellationException) {
5453
// User has cancelled this action manually
5554
if (e.silent) {
@@ -61,6 +60,7 @@ export function registerCommandWithErrorHandling(
6160
}
6261
} else {
6362
// Include the full stack in the error log only.
63+
const errorStack = getErrorStack(e);
6464
const fullMessage = errorStack
6565
? `${errorMessage.fullMessage}\n${errorStack}`
6666
: errorMessage.fullMessage;

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ export class ExtensionApp implements App {
3939
return this.extensionContext.workspaceState;
4040
}
4141

42+
public get workspaceFolders(): readonly vscode.WorkspaceFolder[] | undefined {
43+
return vscode.workspace.workspaceFolders;
44+
}
45+
46+
public get onDidChangeWorkspaceFolders(): vscode.Event<vscode.WorkspaceFoldersChangeEvent> {
47+
return vscode.workspace.onDidChangeWorkspaceFolders;
48+
}
49+
4250
public get subscriptions(): Disposable[] {
4351
return this.extensionContext.subscriptions;
4452
}

extensions/ql-vscode/src/helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export async function showAndLogErrorMessage(
9898
return internalShowAndLog(
9999
dropLinesExceptInitial(message),
100100
Window.showErrorMessage,
101-
options,
101+
{ fullMessage: message, ...options },
102102
);
103103
}
104104

extensions/ql-vscode/src/query-testing/qltest-discovery.ts

Lines changed: 10 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -1,117 +1,16 @@
1-
import { dirname, basename, join, normalize, relative, extname } from "path";
1+
import { dirname, basename, normalize, relative, extname } from "path";
22
import { Discovery } from "../common/discovery";
33
import {
44
EventEmitter,
55
Event,
66
Uri,
77
RelativePattern,
88
WorkspaceFolder,
9-
env,
109
} from "vscode";
1110
import { MultiFileSystemWatcher } from "../common/vscode/multi-file-system-watcher";
1211
import { CodeQLCliServer } from "../codeql-cli/cli";
1312
import { pathExists } from "fs-extra";
14-
15-
/**
16-
* A node in the tree of tests. This will be either a `QLTestDirectory` or a `QLTestFile`.
17-
*/
18-
export abstract class QLTestNode {
19-
constructor(private _path: string, private _name: string) {}
20-
21-
public get path(): string {
22-
return this._path;
23-
}
24-
25-
public get name(): string {
26-
return this._name;
27-
}
28-
29-
public abstract get children(): readonly QLTestNode[];
30-
31-
public abstract finish(): void;
32-
}
33-
34-
/**
35-
* A directory containing one or more QL tests or other test directories.
36-
*/
37-
export class QLTestDirectory extends QLTestNode {
38-
constructor(
39-
_path: string,
40-
_name: string,
41-
private _children: QLTestNode[] = [],
42-
) {
43-
super(_path, _name);
44-
}
45-
46-
public get children(): readonly QLTestNode[] {
47-
return this._children;
48-
}
49-
50-
public addChild(child: QLTestNode): void {
51-
this._children.push(child);
52-
}
53-
54-
public createDirectory(relativePath: string): QLTestDirectory {
55-
const dirName = dirname(relativePath);
56-
if (dirName === ".") {
57-
return this.createChildDirectory(relativePath);
58-
} else {
59-
const parent = this.createDirectory(dirName);
60-
return parent.createDirectory(basename(relativePath));
61-
}
62-
}
63-
64-
public finish(): void {
65-
// remove empty directories
66-
this._children.filter(
67-
(child) => child instanceof QLTestFile || child.children.length > 0,
68-
);
69-
this._children.sort((a, b) => a.name.localeCompare(b.name, env.language));
70-
this._children.forEach((child, i) => {
71-
child.finish();
72-
if (
73-
child.children?.length === 1 &&
74-
child.children[0] instanceof QLTestDirectory
75-
) {
76-
// collapse children
77-
const replacement = new QLTestDirectory(
78-
child.children[0].path,
79-
`${child.name} / ${child.children[0].name}`,
80-
Array.from(child.children[0].children),
81-
);
82-
this._children[i] = replacement;
83-
}
84-
});
85-
}
86-
87-
private createChildDirectory(name: string): QLTestDirectory {
88-
const existingChild = this._children.find((child) => child.name === name);
89-
if (existingChild !== undefined) {
90-
return existingChild as QLTestDirectory;
91-
} else {
92-
const newChild = new QLTestDirectory(join(this.path, name), name);
93-
this.addChild(newChild);
94-
return newChild;
95-
}
96-
}
97-
}
98-
99-
/**
100-
* A single QL test. This will be either a `.ql` file or a `.qlref` file.
101-
*/
102-
export class QLTestFile extends QLTestNode {
103-
constructor(_path: string, _name: string) {
104-
super(_path, _name);
105-
}
106-
107-
public get children(): readonly QLTestNode[] {
108-
return [];
109-
}
110-
111-
public finish(): void {
112-
/**/
113-
}
114-
}
13+
import { FileTreeDirectory, FileTreeLeaf } from "../common/file-tree-nodes";
11514

11615
/**
11716
* The results of discovering QL tests.
@@ -120,7 +19,7 @@ interface QLTestDiscoveryResults {
12019
/**
12120
* A directory that contains one or more QL Tests, or other QLTestDirectories.
12221
*/
123-
testDirectory: QLTestDirectory | undefined;
22+
testDirectory: FileTreeDirectory | undefined;
12423

12524
/**
12625
* The file system path to a directory to watch. If any ql or qlref file changes in
@@ -137,7 +36,7 @@ export class QLTestDiscovery extends Discovery<QLTestDiscoveryResults> {
13736
private readonly watcher: MultiFileSystemWatcher = this.push(
13837
new MultiFileSystemWatcher(),
13938
);
140-
private _testDirectory: QLTestDirectory | undefined;
39+
private _testDirectory: FileTreeDirectory | undefined;
14140

14241
constructor(
14342
private readonly workspaceFolder: WorkspaceFolder,
@@ -159,7 +58,7 @@ export class QLTestDiscovery extends Discovery<QLTestDiscoveryResults> {
15958
* The root directory. There is at least one test in this directory, or
16059
* in a subdirectory of this.
16160
*/
162-
public get testDirectory(): QLTestDirectory | undefined {
61+
public get testDirectory(): FileTreeDirectory | undefined {
16362
return this._testDirectory;
16463
}
16564

@@ -194,10 +93,10 @@ export class QLTestDiscovery extends Discovery<QLTestDiscoveryResults> {
19493
* @returns A `QLTestDirectory` object describing the contents of the directory, or `undefined` if
19594
* no tests were found.
19695
*/
197-
private async discoverTests(): Promise<QLTestDirectory> {
96+
private async discoverTests(): Promise<FileTreeDirectory> {
19897
const fullPath = this.workspaceFolder.uri.fsPath;
19998
const name = this.workspaceFolder.name;
200-
const rootDirectory = new QLTestDirectory(fullPath, name);
99+
const rootDirectory = new FileTreeDirectory(fullPath, name);
201100

202101
// Don't try discovery on workspace folders that don't exist on the filesystem
203102
if (await pathExists(fullPath)) {
@@ -208,7 +107,9 @@ export class QLTestDiscovery extends Discovery<QLTestDiscoveryResults> {
208107
const relativePath = normalize(relative(fullPath, testPath));
209108
const dirName = dirname(relativePath);
210109
const parentDirectory = rootDirectory.createDirectory(dirName);
211-
parentDirectory.addChild(new QLTestFile(testPath, basename(testPath)));
110+
parentDirectory.addChild(
111+
new FileTreeLeaf(testPath, basename(testPath)),
112+
);
212113
}
213114

214115
rootDirectory.finish();

0 commit comments

Comments
 (0)