Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion extensions/ql-vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
CliConfigListener,
DistributionConfigListener,
isCanary,
isCodespacesTemplate,
joinOrderWarningThreshold,
MAX_QUERIES,
QueryHistoryConfigListener,
Expand Down Expand Up @@ -234,7 +235,10 @@ export async function activate(
const distributionConfigListener = new DistributionConfigListener();
await initializeLogging(ctx);
await initializeTelemetry(extension, ctx);
addUnhandledRejectionListener();
if (!isCodespacesTemplate()) {
addUnhandledRejectionListener();
}

Comment on lines +238 to +241
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm concerned about just disabling the unhandled rejection listener for the template. It means that none of our new users will get the benefits of it. I think we'd be better off inspecting the stack frames for references to our sources (as we discussed on our chat).

My biggest concern is that we're going to display errors from other extensions (I think it's even possible for this to happen now, just no one has reported it yet).

install();

const codelensProvider = new QuickEvalCodeLensProvider();
Expand Down
25 changes: 17 additions & 8 deletions extensions/ql-vscode/src/local-databases-ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -379,15 +379,8 @@ export class DatabaseUI extends DisposableObject {
);

let databaseItem = this.databaseManager.findDatabaseItem(uri);
const isTutorialDatabase = true;
if (databaseItem === undefined) {
databaseItem = await this.databaseManager.openDatabase(
progress,
token,
uri,
"CodeQL Tutorial Database",
isTutorialDatabase,
);
databaseItem = await this.openTutorialDatabase(progress, token, uri);
}
await this.databaseManager.setCurrentDatabaseItem(databaseItem);
}
Expand All @@ -401,6 +394,22 @@ export class DatabaseUI extends DisposableObject {
}
};

// Opens the tutorial database for the CodeQL Tour.
// We set the database name as "CodeQL Tutorial Database" in purpose. This means
// we won't attempt to create a skeleton QL pack for this database.
openTutorialDatabase = async (
progress: ProgressCallback,
token: CancellationToken,
uri: Uri,
): Promise<DatabaseItem> => {
return await this.databaseManager.openDatabase(
progress,
token,
uri,
"CodeQL Tutorial Database",
);
};

handleRemoveOrphanedDatabases = async (): Promise<void> => {
void extLogger.log("Removing orphaned databases from workspace storage.");
let dbDirs = undefined;
Expand Down
3 changes: 1 addition & 2 deletions extensions/ql-vscode/src/local-databases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,6 @@ export class DatabaseManager extends DisposableObject {
token: vscode.CancellationToken,
uri: vscode.Uri,
displayName?: string,
isTutorialDatabase?: boolean,
): Promise<DatabaseItem> {
const contents = await DatabaseResolver.resolveDatabaseContents(uri);
// Ignore the source archive for QLTest databases by default.
Expand All @@ -631,7 +630,7 @@ export class DatabaseManager extends DisposableObject {
await this.addDatabaseItem(progress, token, databaseItem);
await this.addDatabaseSourceArchiveFolder(databaseItem);

if (isCodespacesTemplate() && !isTutorialDatabase) {
if (isCodespacesTemplate() && displayName !== "CodeQL Tutorial Database") {
await this.createSkeletonPacks(databaseItem);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -715,14 +715,11 @@ describe("local databases", () => {
it("should not offer to create a skeleton QL pack", async () => {
jest.spyOn(Setting.prototype, "getValue").mockReturnValue(true);

const isTutorialDatabase = true;

await databaseManager.openDatabase(
{} as ProgressCallback,
{} as CancellationToken,
mockDbItem.databaseUri,
"CodeQL Tutorial Database",
isTutorialDatabase,
);

expect(createSkeletonPacksSpy).toBeCalledTimes(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ import {
createFileSync,
pathExistsSync,
} from "fs-extra";
import { Uri } from "vscode";
import { CancellationToken, Uri } from "vscode";

import { DatabaseUI } from "../../../src/local-databases-ui";
import { testDisposeHandler } from "../test-dispose-handler";
import { createMockApp } from "../../__mocks__/appMock";
import { QueryLanguage } from "../../../src/common/query-language";
import { App } from "../../../src/common/app";
import { ProgressCallback } from "../../../src/commandRunner";

describe("local-databases-ui", () => {
describe("fixDbUri", () => {
Expand Down Expand Up @@ -116,6 +118,51 @@ describe("local-databases-ui", () => {
databaseUI.dispose(testDisposeHandler);
});

describe("openTutorialDatabase", () => {
let app: App;
let databaseUI: DatabaseUI;
let openDatabaseSpy: jest.SpyInstance;
let databaseManager: any;

beforeEach(async () => {
app = createMockApp({});
openDatabaseSpy = jest.fn();

databaseManager = {
databaseItems: [],
openDatabase: openDatabaseSpy,
onDidChangeDatabaseItem: () => {
/**/
},
onDidChangeCurrentDatabaseItem: () => {
/**/
},
};
databaseUI = new DatabaseUI(
app,
databaseManager as any,
{} as any,
"",
"",
);
});

it("should call openDatase with 'CodeQL Tutorial Database' as displayName", async () => {
await databaseUI.openTutorialDatabase(
{} as ProgressCallback,
{} as CancellationToken,
Uri.parse(""),
);

expect(openDatabaseSpy).toHaveBeenCalledWith(
expect.anything(),
expect.anything(),
expect.anything(),
"CodeQL Tutorial Database",
);
});
});

function createDatabase(
storageDir: string,
dbName: string,
Expand Down