Skip to content

Commit f67f53d

Browse files
committed
Merge remote-tracking branch 'origin/main' into koesie10/split-helpers-3
2 parents c16d363 + c6c5628 commit f67f53d

File tree

17 files changed

+119
-253
lines changed

17 files changed

+119
-253
lines changed

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@ 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";
127

138
export interface App {
149
createEventEmitter<T>(): AppEventEmitter<T>;
@@ -19,8 +14,6 @@ export interface App {
1914
readonly globalStoragePath: string;
2015
readonly workspaceStoragePath?: string;
2116
readonly workspaceState: Memento;
22-
readonly workspaceFolders: readonly WorkspaceFolder[] | undefined;
23-
readonly onDidChangeWorkspaceFolders: Event<WorkspaceFoldersChangeEvent>;
2417
readonly credentials: Credentials;
2518
readonly commands: AppCommandManager;
2619
readonly environment: EnvironmentContext;

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

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

43-
public get workspaceFolders(): readonly vscode.WorkspaceFolder[] | undefined {
44-
return vscode.workspace.workspaceFolders;
45-
}
46-
47-
public get onDidChangeWorkspaceFolders(): vscode.Event<vscode.WorkspaceFoldersChangeEvent> {
48-
return vscode.workspace.onDidChangeWorkspaceFolders;
49-
}
50-
5143
public get subscriptions(): Disposable[] {
5244
return this.extensionContext.subscriptions;
5345
}

extensions/ql-vscode/src/data-extensions-editor/extension-pack-picker.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { getQlPackPath, QLPACK_FILENAMES } from "../pure/ql";
1414
import { getErrorMessage } from "../pure/helpers-pure";
1515
import { ExtensionPack, ExtensionPackModelFile } from "./shared/extension-pack";
1616
import { showAndLogErrorMessage } from "../common/vscode/log";
17+
import { containsPath } from "../pure/files";
1718

1819
const maxStep = 3;
1920

@@ -347,11 +348,7 @@ async function pickNewModelFile(
347348
return "File already exists";
348349
}
349350

350-
const notInExtensionPack = relative(
351-
extensionPack.path,
352-
path,
353-
).startsWith("..");
354-
if (notInExtensionPack) {
351+
if (!containsPath(extensionPack.path, path)) {
355352
return "File must be in the extension pack";
356353
}
357354

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

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -147,14 +147,10 @@ export class DbConfigStore extends DisposableObject {
147147
await this.writeConfig(config);
148148
}
149149

150-
/**
151-
* Adds a list of remote repositories to an existing repository list and removes duplicates.
152-
* @returns a list of repositories that were not added because the list reached 1000 entries.
153-
*/
154150
public async addRemoteReposToList(
155151
repoNwoList: string[],
156152
parentList: string,
157-
): Promise<string[]> {
153+
): Promise<void> {
158154
if (!this.config) {
159155
throw Error("Cannot add variant analysis repos if config is not loaded");
160156
}
@@ -172,21 +168,15 @@ export class DbConfigStore extends DisposableObject {
172168
...new Set([...parent.repositories, ...repoNwoList]),
173169
];
174170

175-
parent.repositories = newRepositoriesList.slice(0, 1000);
176-
const truncatedRepositories = newRepositoriesList.slice(1000);
171+
parent.repositories = newRepositoriesList;
177172

178173
await this.writeConfig(config);
179-
return truncatedRepositories;
180174
}
181175

182-
/**
183-
* Adds one remote repository
184-
* @returns either nothing, or, if a parentList is given AND the number of repos on that list reaches 1000 returns the repo that was not added.
185-
*/
186176
public async addRemoteRepo(
187177
repoNwo: string,
188178
parentList?: string,
189-
): Promise<string[]> {
179+
): Promise<void> {
190180
if (!this.config) {
191181
throw Error("Cannot add variant analysis repo if config is not loaded");
192182
}
@@ -201,7 +191,6 @@ export class DbConfigStore extends DisposableObject {
201191
);
202192
}
203193

204-
const truncatedRepositories = [];
205194
const config = cloneDbConfig(this.config);
206195
if (parentList) {
207196
const parent = config.databases.variantAnalysis.repositoryLists.find(
@@ -210,15 +199,12 @@ export class DbConfigStore extends DisposableObject {
210199
if (!parent) {
211200
throw Error(`Cannot find parent list '${parentList}'`);
212201
} else {
213-
const newRepositories = [...parent.repositories, repoNwo];
214-
parent.repositories = newRepositories.slice(0, 1000);
215-
truncatedRepositories.push(...newRepositories.slice(1000));
202+
parent.repositories = [...parent.repositories, repoNwo];
216203
}
217204
} else {
218205
config.databases.variantAnalysis.repositories.push(repoNwo);
219206
}
220207
await this.writeConfig(config);
221-
return truncatedRepositories;
222208
}
223209

224210
public async addRemoteOwner(owner: string): Promise<void> {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,15 @@ export class DbManager extends DisposableObject {
101101
public async addNewRemoteRepo(
102102
nwo: string,
103103
parentList?: string,
104-
): Promise<string[]> {
105-
return await this.dbConfigStore.addRemoteRepo(nwo, parentList);
104+
): Promise<void> {
105+
await this.dbConfigStore.addRemoteRepo(nwo, parentList);
106106
}
107107

108108
public async addNewRemoteReposToList(
109109
nwoList: string[],
110110
parentList: string,
111-
): Promise<string[]> {
112-
return await this.dbConfigStore.addRemoteReposToList(nwoList, parentList);
111+
): Promise<void> {
112+
await this.dbConfigStore.addRemoteReposToList(nwoList, parentList);
113113
}
114114

115115
public async addNewRemoteOwner(owner: string): Promise<void> {

extensions/ql-vscode/src/databases/local-databases/database-item-impl.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import * as cli from "../../codeql-cli/cli";
33
import vscode from "vscode";
44
import { FullDatabaseOptions } from "./database-options";
5-
import { basename, dirname, extname, join, relative } from "path";
5+
import { basename, dirname, extname, join } from "path";
66
import {
77
decodeSourceArchiveUri,
88
encodeArchiveBasePath,
@@ -12,7 +12,7 @@ import {
1212
import { DatabaseItem, PersistedDatabaseItem } from "./database-item";
1313
import { isLikelyDatabaseRoot } from "./db-contents-heuristics";
1414
import { stat } from "fs-extra";
15-
import { pathsEqual } from "../../pure/files";
15+
import { containsPath, pathsEqual } from "../../pure/files";
1616
import { DatabaseContents } from "./database-contents";
1717

1818
export class DatabaseItemImpl implements DatabaseItem {
@@ -199,15 +199,14 @@ export class DatabaseItemImpl implements DatabaseItem {
199199
try {
200200
const stats = await stat(testPath);
201201
if (stats.isDirectory()) {
202-
return !relative(testPath, databasePath).startsWith("..");
202+
return containsPath(testPath, databasePath);
203203
} else {
204204
// database for /one/two/three/test.ql is at /one/two/three/three.testproj
205205
const testdir = dirname(testPath);
206206
const testdirbase = basename(testdir);
207207
return pathsEqual(
208208
databasePath,
209209
join(testdir, `${testdirbase}.testproj`),
210-
process.platform,
211210
);
212211
}
213212
} catch {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ export class DatabaseManager extends DisposableObject {
652652
private isExtensionControlledLocation(uri: vscode.Uri) {
653653
const storageUri = this.ctx.storageUri || this.ctx.globalStorageUri;
654654
if (storageUri) {
655-
return containsPath(storageUri.fsPath, uri.fsPath, process.platform);
655+
return containsPath(storageUri.fsPath, uri.fsPath);
656656
}
657657
return false;
658658
}

extensions/ql-vscode/src/databases/ui/db-panel.ts

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -183,14 +183,7 @@ export class DbPanel extends DisposableObject {
183183
return;
184184
}
185185

186-
const truncatedRepositories = await this.dbManager.addNewRemoteRepo(
187-
nwo,
188-
parentList,
189-
);
190-
191-
if (parentList) {
192-
this.reportAnyTruncatedRepos(truncatedRepositories, parentList);
193-
}
186+
await this.dbManager.addNewRemoteRepo(nwo, parentList);
194187
}
195188

196189
private async addNewRemoteOwner(): Promise<void> {
@@ -415,26 +408,11 @@ export class DbPanel extends DisposableObject {
415408

416409
progress.report({ increment: 10, message: "Processing results..." });
417410

418-
const truncatedRepositories =
419-
await this.dbManager.addNewRemoteReposToList(repositories, listName);
420-
this.reportAnyTruncatedRepos(truncatedRepositories, listName);
411+
await this.dbManager.addNewRemoteReposToList(repositories, listName);
421412
},
422413
);
423414
}
424415

425-
private reportAnyTruncatedRepos(
426-
truncatedRepositories: string[],
427-
listName: string,
428-
) {
429-
if (truncatedRepositories.length > 0) {
430-
void showAndLogErrorMessage(
431-
`Some repositories were not added to '${listName}' because a list can only have 1000 entries. Excluded repositories: ${truncatedRepositories.join(
432-
", ",
433-
)}`,
434-
);
435-
}
436-
}
437-
438416
private async onDidCollapseElement(
439417
event: TreeViewExpansionEvent<DbTreeViewItem>,
440418
): Promise<void> {

extensions/ql-vscode/src/pure/files.ts

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { pathExists, stat, readdir, opendir } from "fs-extra";
2-
import { join, resolve } from "path";
2+
import { isAbsolute, join, relative, resolve } from "path";
33

44
/**
55
* Recursively finds all .ql files in this set of Uris.
@@ -51,36 +51,32 @@ export async function getDirectoryNamesInsidePath(
5151
return dirNames;
5252
}
5353

54-
function normalizePath(path: string, platform: NodeJS.Platform): string {
54+
function normalizePath(path: string): string {
5555
// On Windows, "C:/", "C:\", and "c:/" are all equivalent. We need
5656
// to normalize the paths to ensure they all get resolved to the
5757
// same format. On Windows, we also need to do the comparison
5858
// case-insensitively.
5959
path = resolve(path);
60-
if (platform === "win32") {
60+
if (process.platform === "win32") {
6161
path = path.toLowerCase();
6262
}
6363
return path;
6464
}
6565

66-
export function pathsEqual(
67-
path1: string,
68-
path2: string,
69-
platform: NodeJS.Platform,
70-
): boolean {
71-
return normalizePath(path1, platform) === normalizePath(path2, platform);
66+
export function pathsEqual(path1: string, path2: string): boolean {
67+
return normalizePath(path1) === normalizePath(path2);
7268
}
7369

7470
/**
75-
* Returns true if path1 contains path2.
71+
* Returns true if `parent` contains `child`, or if they are equal.
7672
*/
77-
export function containsPath(
78-
path1: string,
79-
path2: string,
80-
platform: NodeJS.Platform,
81-
): boolean {
82-
return normalizePath(path2, platform).startsWith(
83-
normalizePath(path1, platform),
73+
export function containsPath(parent: string, child: string): boolean {
74+
const relativePath = relative(parent, child);
75+
return (
76+
!relativePath.startsWith("..") &&
77+
// On windows, if the two paths are in different drives, then the
78+
// relative path will be an absolute path to the other drive.
79+
!isAbsolute(relativePath)
8480
);
8581
}
8682

extensions/ql-vscode/src/queries-panel/queries-module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export class QueriesModule extends DisposableObject {
1919
}
2020
void extLogger.log("Initializing queries panel.");
2121

22-
const queryDiscovery = new QueryDiscovery(app, cliServer);
22+
const queryDiscovery = new QueryDiscovery(app.environment, cliServer);
2323
this.push(queryDiscovery);
2424
void queryDiscovery.refresh();
2525

0 commit comments

Comments
 (0)