Skip to content

Commit 7fd45ef

Browse files
committed
Merge remote-tracking branch 'origin/main' into koesie10/fix-no-error-empty-repositories
2 parents 02c8df0 + 0f5117e commit 7fd45ef

33 files changed

Lines changed: 1502 additions & 377 deletions

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ To see what has changed in the last few versions of the extension, see the [Chan
2020

2121
This project will track new feature development in CodeQL and, whenever appropriate, bring that functionality to the Visual Studio Code experience.
2222

23+
## Dependencies
24+
25+
This extension depends on the following two extensions for required functionality. They will be installed automatically when you install VS Code CodeQL.
26+
27+
- [Test Adapter Converter](https://marketplace.visualstudio.com/items?itemName=ms-vscode.test-adapter-converter)
28+
- [Test Explorer UI](https://marketplace.visualstudio.com/items?itemName=hbenl.vscode-test-explorer)
29+
2330
## Contributing
2431

2532
This project welcomes contributions. See [CONTRIBUTING.md](CONTRIBUTING.md) for details on how to build, install, and contribute.

extensions/ql-vscode/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ For information about other configurations, see the separate [CodeQL help](https
1616

1717
### Quick start: Installing and configuring the extension
1818

19-
1. [Install the extension](#installing-the-extension).
19+
1. [Install the extension](#installing-the-extension).
20+
*Note: vscode-codeql installs the following dependencies for required functionality: [Test Adapter Converter](https://marketplace.visualstudio.com/items?itemName=ms-vscode.test-adapter-converter), [Test Explorer UI](https://marketplace.visualstudio.com/items?itemName=hbenl.vscode-test-explorer).*
21+
2022
1. [Check access to the CodeQL CLI](#checking-access-to-the-codeql-cli).
2123
1. [Clone the CodeQL starter workspace](#cloning-the-codeql-starter-workspace).
2224

extensions/ql-vscode/package-lock.json

Lines changed: 12 additions & 73 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

extensions/ql-vscode/package.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@
6161
"onCommand:codeQL.chooseDatabaseLgtm",
6262
"onCommand:codeQLDatabases.chooseDatabase",
6363
"onCommand:codeQLDatabases.setCurrentDatabase",
64+
"onCommand:codeQLDatabasesExperimental.openConfigFile",
65+
"onCommand:codeQLDatabasesExperimental.setSelectedItem",
6466
"onCommand:codeQL.quickQuery",
6567
"onCommand:codeQL.restartQueryServer",
6668
"onWebviewPanel:resultsView",
@@ -364,6 +366,11 @@
364366
"dark": "media/dark/edit.svg"
365367
}
366368
},
369+
{
370+
"command": "codeQLDatabasesExperimental.setSelectedItem",
371+
"title": "Select Item",
372+
"icon": "$(circle-small-filled)"
373+
},
367374
{
368375
"command": "codeQLDatabases.chooseDatabaseFolder",
369376
"title": "Choose Database from Folder",
@@ -795,6 +802,11 @@
795802
"group": "9_qlCommands",
796803
"when": "view == codeQLDatabases"
797804
},
805+
{
806+
"command": "codeQLDatabasesExperimental.setSelectedItem",
807+
"when": "view == codeQLDatabasesExperimental && viewItem == selectableDbItem",
808+
"group": "inline"
809+
},
798810
{
799811
"command": "codeQLQueryHistory.openQuery",
800812
"group": "9_qlCommands",
@@ -985,6 +997,10 @@
985997
"command": "codeQLDatabasesExperimental.openConfigFile",
986998
"when": "false"
987999
},
1000+
{
1001+
"command": "codeQLDatabasesExperimental.setSelectedItem",
1002+
"when": "false"
1003+
},
9881004
{
9891005
"command": "codeQLDatabases.setCurrentDatabase",
9901006
"when": "false"

extensions/ql-vscode/src/databases/config/db-config-store.ts

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import { pathExists, writeJSON, readJSON, readJSONSync } from "fs-extra";
22
import { join } from "path";
3-
import { cloneDbConfig, DbConfig } from "./db-config";
3+
import {
4+
cloneDbConfig,
5+
DbConfig,
6+
ExpandedDbItem,
7+
SelectedDbItem,
8+
} from "./db-config";
49
import * as chokidar from "chokidar";
510
import { DisposableObject, DisposeHandler } from "../../pure/disposable-object";
611
import { DbConfigValidator } from "./db-config-validator";
@@ -56,11 +61,44 @@ export class DbConfigStore extends DisposableObject {
5661
return this.configPath;
5762
}
5863

64+
public async setSelectedDbItem(dbItem: SelectedDbItem): Promise<void> {
65+
if (!this.config) {
66+
// If the app is trying to set the selected item without a config
67+
// being set it means that there is a bug in our code, so we throw
68+
// an error instead of just returning an error result.
69+
throw Error("Cannot select database item if config is not loaded");
70+
}
71+
72+
const config: DbConfig = {
73+
...this.config,
74+
selected: dbItem,
75+
};
76+
77+
await this.writeConfig(config);
78+
}
79+
80+
public async updateExpandedState(expandedItems: ExpandedDbItem[]) {
81+
if (!this.config) {
82+
throw Error("Cannot update expansion state if config is not loaded");
83+
}
84+
85+
const config: DbConfig = {
86+
...this.config,
87+
expanded: expandedItems,
88+
};
89+
90+
await this.writeConfig(config);
91+
}
92+
93+
private async writeConfig(config: DbConfig): Promise<void> {
94+
await writeJSON(this.configPath, config, {
95+
spaces: 2,
96+
});
97+
}
98+
5999
private async loadConfig(): Promise<void> {
60100
if (!(await pathExists(this.configPath))) {
61-
await writeJSON(this.configPath, this.createEmptyConfig(), {
62-
spaces: 2,
63-
});
101+
await this.writeConfig(this.createEmptyConfig());
64102
}
65103

66104
await this.readConfig();
@@ -117,6 +155,7 @@ export class DbConfigStore extends DisposableObject {
117155
databases: [],
118156
},
119157
},
158+
expanded: [],
120159
};
121160
}
122161
}

extensions/ql-vscode/src/databases/config/db-config.ts

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

33
export interface DbConfig {
44
databases: DbConfigDatabases;
5+
expanded: ExpandedDbItem[];
56
selected?: SelectedDbItem;
67
}
78

@@ -87,6 +88,37 @@ export interface LocalDatabase {
8788
storagePath: string;
8889
}
8990

91+
export type ExpandedDbItem =
92+
| RootLocalExpandedDbItem
93+
| LocalUserDefinedListExpandedDbItem
94+
| RootRemoteExpandedDbItem
95+
| RemoteUserDefinedListExpandedDbItem;
96+
97+
export enum ExpandedDbItemKind {
98+
RootLocal = "rootLocal",
99+
LocalUserDefinedList = "localUserDefinedList",
100+
RootRemote = "rootRemote",
101+
RemoteUserDefinedList = "remoteUserDefinedList",
102+
}
103+
104+
export interface RootLocalExpandedDbItem {
105+
kind: ExpandedDbItemKind.RootLocal;
106+
}
107+
108+
export interface LocalUserDefinedListExpandedDbItem {
109+
kind: ExpandedDbItemKind.LocalUserDefinedList;
110+
listName: string;
111+
}
112+
113+
export interface RootRemoteExpandedDbItem {
114+
kind: ExpandedDbItemKind.RootRemote;
115+
}
116+
117+
export interface RemoteUserDefinedListExpandedDbItem {
118+
kind: ExpandedDbItemKind.RemoteUserDefinedList;
119+
listName: string;
120+
}
121+
90122
export function cloneDbConfig(config: DbConfig): DbConfig {
91123
return {
92124
databases: {
@@ -108,6 +140,7 @@ export function cloneDbConfig(config: DbConfig): DbConfig {
108140
databases: config.databases.local.databases.map((db) => ({ ...db })),
109141
},
110142
},
143+
expanded: config.expanded.map(cloneDbConfigExpandedItem),
111144
selected: config.selected
112145
? cloneDbConfigSelectedItem(config.selected)
113146
: undefined,
@@ -150,3 +183,17 @@ function cloneDbConfigSelectedItem(selected: SelectedDbItem): SelectedDbItem {
150183
};
151184
}
152185
}
186+
187+
function cloneDbConfigExpandedItem(item: ExpandedDbItem): ExpandedDbItem {
188+
switch (item.kind) {
189+
case ExpandedDbItemKind.RootLocal:
190+
case ExpandedDbItemKind.RootRemote:
191+
return { kind: item.kind };
192+
case ExpandedDbItemKind.LocalUserDefinedList:
193+
case ExpandedDbItemKind.RemoteUserDefinedList:
194+
return {
195+
kind: item.kind,
196+
listName: item.listName,
197+
};
198+
}
199+
}

0 commit comments

Comments
 (0)