Skip to content
Open
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
125 changes: 120 additions & 5 deletions extensions/ql-vscode/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion extensions/ql-vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2082,7 +2082,7 @@
"d3": "^7.9.0",
"d3-graphviz": "^5.6.0",
"fs-extra": "^11.1.1",
"js-yaml": "^4.2.0",
"js-yaml": "^5.0.0",
"koffi": "^2.15.5",
"msw": "^2.14.6",
"nanoid": "^5.0.7",
Expand Down
5 changes: 4 additions & 1 deletion extensions/ql-vscode/src/packaging/qlpack-file-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ const qlpackFileValidate = ajv.compile(qlpackFileSchemaJson);
export async function loadQlpackFile(path: string): Promise<QlPackFile> {
const qlpackFileText = await readFile(path, "utf8");

let qlPack = load(qlpackFileText) as QlPackFile | undefined;
let qlPack: QlPackFile | undefined;
if (qlpackFileText.trim()) {
qlPack = load(qlpackFileText) as QlPackFile | undefined;
}

if (qlPack === undefined || qlPack === null) {
// An empty file is not valid according to the schema since it's not an object,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,13 @@ export class QueryHistoryManager extends DisposableObject {
}

async handleRemoveHistoryItem(items: QueryHistoryInfo[]) {
// Capture the current item before any async operations. VS Code may fire
// onDidChangeSelection asynchronously during awaits below (e.g. after the
// tree is refreshed by remove()), changing treeDataProvider.getCurrent() to
// an unexpected item. By saving it up front we can restore the correct
// selection afterwards.
const previousCurrent = this.treeDataProvider.getCurrent();

await Promise.all(
items.map(async (item) => {
if (item.t === "local") {
Expand Down Expand Up @@ -602,8 +609,22 @@ export class QueryHistoryManager extends DisposableObject {
);

await this.writeQueryHistory();
const current = this.treeDataProvider.getCurrent();

// If the previously-current item is still in history (i.e. it was not one
// of the items being removed), keep it as the current item. Otherwise fall
// back to whatever getCurrent() returns, which was set by remove() when the
// current item itself was deleted.
const current =
previousCurrent !== undefined &&
this.treeDataProvider.allHistory.includes(previousCurrent)
? previousCurrent
: this.treeDataProvider.getCurrent();

if (current !== undefined) {
// Explicitly sync the internal current-item state before revealing, in
// case a deferred onDidChangeSelection event changed it during the awaits
// above.
this.treeDataProvider.setCurrentItem(current);
await this.treeView.reveal(current, { select: true });
await this.openQueryResults(current);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ describe("getQlPackLanguage", () => {
await expect(getQlPackLanguage(tmpDir.name)).rejects.toBeDefined();
});

it("should find nothing when the qlpack file is empty", async () => {
await outputFile(qlpackPath, "");

const result = await getQlPackLanguage(qlpackPath);
expect(result).toEqual(undefined);
});

it("should throw when the file is invalid YAML", async () => {
await outputFile(qlpackPath, `name: test\n foo: bar`);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,10 +331,9 @@ describe("QueryHistoryManager", () => {
.spyOn(dialog, "showBinaryChoiceDialog")
.mockResolvedValue(true);

showInformationMessageWithActionSpy = jest.spyOn(
dialog,
"showInformationMessageWithAction",
);
showInformationMessageWithActionSpy = jest
.spyOn(dialog, "showInformationMessageWithAction")
.mockResolvedValue(false);
});

describe("when in progress", () => {
Expand Down