Merge pull request #2298 from github/elena/yer-a-windows-query
Fix problem with detecting storage folder on windows
This commit is contained in:
@@ -381,6 +381,8 @@ export class LocalQueries extends DisposableObject {
|
|||||||
await withProgress(
|
await withProgress(
|
||||||
async (progress: ProgressCallback, token: CancellationToken) => {
|
async (progress: ProgressCallback, token: CancellationToken) => {
|
||||||
const credentials = isCanary() ? this.app.credentials : undefined;
|
const credentials = isCanary() ? this.app.credentials : undefined;
|
||||||
|
const contextStoragePath =
|
||||||
|
this.app.workspaceStoragePath || this.app.globalStoragePath;
|
||||||
const skeletonQueryWizard = new SkeletonQueryWizard(
|
const skeletonQueryWizard = new SkeletonQueryWizard(
|
||||||
this.cliServer,
|
this.cliServer,
|
||||||
progress,
|
progress,
|
||||||
@@ -388,6 +390,7 @@ export class LocalQueries extends DisposableObject {
|
|||||||
extLogger,
|
extLogger,
|
||||||
this.databaseManager,
|
this.databaseManager,
|
||||||
token,
|
token,
|
||||||
|
contextStoragePath,
|
||||||
);
|
);
|
||||||
await skeletonQueryWizard.execute();
|
await skeletonQueryWizard.execute();
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { join } from "path";
|
import { join, dirname } from "path";
|
||||||
import { CancellationToken, Uri, workspace, window as Window } from "vscode";
|
import { CancellationToken, Uri, workspace, window as Window } from "vscode";
|
||||||
import { CodeQLCliServer } from "./cli";
|
import { CodeQLCliServer } from "./cli";
|
||||||
import { OutputChannelLogger } from "./common";
|
import { OutputChannelLogger } from "./common";
|
||||||
@@ -27,7 +27,7 @@ export const QUERY_LANGUAGE_TO_DATABASE_REPO: QueryLanguagesToDatabaseMap = {
|
|||||||
export class SkeletonQueryWizard {
|
export class SkeletonQueryWizard {
|
||||||
private language: string | undefined;
|
private language: string | undefined;
|
||||||
private fileName = "example.ql";
|
private fileName = "example.ql";
|
||||||
private storagePath: string | undefined;
|
private qlPackStoragePath: string | undefined;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private readonly cliServer: CodeQLCliServer,
|
private readonly cliServer: CodeQLCliServer,
|
||||||
@@ -36,6 +36,7 @@ export class SkeletonQueryWizard {
|
|||||||
private readonly extLogger: OutputChannelLogger,
|
private readonly extLogger: OutputChannelLogger,
|
||||||
private readonly databaseManager: DatabaseManager,
|
private readonly databaseManager: DatabaseManager,
|
||||||
private readonly token: CancellationToken,
|
private readonly token: CancellationToken,
|
||||||
|
private readonly databaseStoragePath: string | undefined,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
private get folderName() {
|
private get folderName() {
|
||||||
@@ -49,7 +50,7 @@ export class SkeletonQueryWizard {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.storagePath = this.getFirstStoragePath();
|
this.qlPackStoragePath = this.getFirstStoragePath();
|
||||||
|
|
||||||
const skeletonPackAlreadyExists = isFolderAlreadyInWorkspace(
|
const skeletonPackAlreadyExists = isFolderAlreadyInWorkspace(
|
||||||
this.folderName,
|
this.folderName,
|
||||||
@@ -72,12 +73,12 @@ export class SkeletonQueryWizard {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async openExampleFile() {
|
private async openExampleFile() {
|
||||||
if (this.folderName === undefined || this.storagePath === undefined) {
|
if (this.folderName === undefined || this.qlPackStoragePath === undefined) {
|
||||||
throw new Error("Path to folder is undefined");
|
throw new Error("Path to folder is undefined");
|
||||||
}
|
}
|
||||||
|
|
||||||
const queryFileUri = Uri.file(
|
const queryFileUri = Uri.file(
|
||||||
join(this.storagePath, this.folderName, this.fileName),
|
join(this.qlPackStoragePath, this.folderName, this.fileName),
|
||||||
);
|
);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -99,15 +100,16 @@ export class SkeletonQueryWizard {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const firstFolder = workspaceFolders[0];
|
const firstFolder = workspaceFolders[0];
|
||||||
|
const firstFolderFsPath = firstFolder.uri.fsPath;
|
||||||
|
|
||||||
// For the vscode-codeql-starter repo, the first folder will be a ql pack
|
// For the vscode-codeql-starter repo, the first folder will be a ql pack
|
||||||
// so we need to get the parent folder
|
// so we need to get the parent folder
|
||||||
if (firstFolder.uri.path.includes("codeql-custom-queries")) {
|
if (firstFolderFsPath.includes("codeql-custom-queries")) {
|
||||||
// slice off the last part of the path and return the parent folder
|
// return the parent folder
|
||||||
return firstFolder.uri.path.split("/").slice(0, -1).join("/");
|
return dirname(firstFolderFsPath);
|
||||||
} else {
|
} else {
|
||||||
// if the first folder is not a ql pack, then we are in a normal workspace
|
// if the first folder is not a ql pack, then we are in a normal workspace
|
||||||
return firstFolder.uri.path;
|
return firstFolderFsPath;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,7 +139,7 @@ export class SkeletonQueryWizard {
|
|||||||
this.folderName,
|
this.folderName,
|
||||||
this.language as QueryLanguage,
|
this.language as QueryLanguage,
|
||||||
this.cliServer,
|
this.cliServer,
|
||||||
this.storagePath,
|
this.qlPackStoragePath,
|
||||||
);
|
);
|
||||||
|
|
||||||
await qlPackGenerator.generate();
|
await qlPackGenerator.generate();
|
||||||
@@ -165,7 +167,7 @@ export class SkeletonQueryWizard {
|
|||||||
this.folderName,
|
this.folderName,
|
||||||
this.language as QueryLanguage,
|
this.language as QueryLanguage,
|
||||||
this.cliServer,
|
this.cliServer,
|
||||||
this.storagePath,
|
this.qlPackStoragePath,
|
||||||
);
|
);
|
||||||
|
|
||||||
this.fileName = await this.determineNextFileName(this.folderName);
|
this.fileName = await this.determineNextFileName(this.folderName);
|
||||||
@@ -178,11 +180,11 @@ export class SkeletonQueryWizard {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async determineNextFileName(folderName: string): Promise<string> {
|
private async determineNextFileName(folderName: string): Promise<string> {
|
||||||
if (this.storagePath === undefined) {
|
if (this.qlPackStoragePath === undefined) {
|
||||||
throw new Error("Workspace storage path is undefined");
|
throw new Error("Workspace storage path is undefined");
|
||||||
}
|
}
|
||||||
|
|
||||||
const folderUri = Uri.file(join(this.storagePath, folderName));
|
const folderUri = Uri.file(join(this.qlPackStoragePath, folderName));
|
||||||
const files = await workspace.fs.readDirectory(folderUri);
|
const files = await workspace.fs.readDirectory(folderUri);
|
||||||
const qlFiles = files.filter(([filename, _fileType]) =>
|
const qlFiles = files.filter(([filename, _fileType]) =>
|
||||||
filename.match(/example[0-9]*.ql/),
|
filename.match(/example[0-9]*.ql/),
|
||||||
@@ -192,10 +194,14 @@ export class SkeletonQueryWizard {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async downloadDatabase() {
|
private async downloadDatabase() {
|
||||||
if (this.storagePath === undefined) {
|
if (this.qlPackStoragePath === undefined) {
|
||||||
throw new Error("Workspace storage path is undefined");
|
throw new Error("Workspace storage path is undefined");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.databaseStoragePath === undefined) {
|
||||||
|
throw new Error("Database storage path is undefined");
|
||||||
|
}
|
||||||
|
|
||||||
if (this.language === undefined) {
|
if (this.language === undefined) {
|
||||||
throw new Error("Language is undefined");
|
throw new Error("Language is undefined");
|
||||||
}
|
}
|
||||||
@@ -219,7 +225,7 @@ export class SkeletonQueryWizard {
|
|||||||
await databaseFetcher.downloadGitHubDatabase(
|
await databaseFetcher.downloadGitHubDatabase(
|
||||||
chosenRepo,
|
chosenRepo,
|
||||||
this.databaseManager,
|
this.databaseManager,
|
||||||
this.storagePath,
|
this.databaseStoragePath,
|
||||||
this.credentials,
|
this.credentials,
|
||||||
this.progress,
|
this.progress,
|
||||||
this.token,
|
this.token,
|
||||||
@@ -233,7 +239,7 @@ export class SkeletonQueryWizard {
|
|||||||
throw new Error("Language is undefined");
|
throw new Error("Language is undefined");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.storagePath === undefined) {
|
if (this.qlPackStoragePath === undefined) {
|
||||||
throw new Error("Workspace storage path is undefined");
|
throw new Error("Workspace storage path is undefined");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -83,11 +83,11 @@ describe("SkeletonQueryWizard", () => {
|
|||||||
jest.spyOn(workspace, "workspaceFolders", "get").mockReturnValue([
|
jest.spyOn(workspace, "workspaceFolders", "get").mockReturnValue([
|
||||||
{
|
{
|
||||||
name: `codespaces-codeql`,
|
name: `codespaces-codeql`,
|
||||||
uri: { path: storagePath },
|
uri: { fsPath: storagePath },
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "/second/folder/path",
|
name: "/second/folder/path",
|
||||||
uri: { path: storagePath },
|
uri: { fsPath: storagePath },
|
||||||
},
|
},
|
||||||
] as WorkspaceFolder[]);
|
] as WorkspaceFolder[]);
|
||||||
|
|
||||||
@@ -114,6 +114,7 @@ describe("SkeletonQueryWizard", () => {
|
|||||||
extLogger,
|
extLogger,
|
||||||
mockDatabaseManager,
|
mockDatabaseManager,
|
||||||
token,
|
token,
|
||||||
|
storagePath,
|
||||||
);
|
);
|
||||||
|
|
||||||
askForGitHubRepoSpy = jest
|
askForGitHubRepoSpy = jest
|
||||||
@@ -244,6 +245,7 @@ describe("SkeletonQueryWizard", () => {
|
|||||||
extLogger,
|
extLogger,
|
||||||
mockDatabaseManagerWithItems,
|
mockDatabaseManagerWithItems,
|
||||||
token,
|
token,
|
||||||
|
storagePath,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -305,8 +307,8 @@ describe("SkeletonQueryWizard", () => {
|
|||||||
it("should return the first workspace folder", async () => {
|
it("should return the first workspace folder", async () => {
|
||||||
jest.spyOn(workspace, "workspaceFolders", "get").mockReturnValue([
|
jest.spyOn(workspace, "workspaceFolders", "get").mockReturnValue([
|
||||||
{
|
{
|
||||||
name: "codeql-custom-queries-cpp",
|
name: "codespaces-codeql",
|
||||||
uri: { path: "codespaces-codeql" },
|
uri: { fsPath: "codespaces-codeql" },
|
||||||
},
|
},
|
||||||
] as WorkspaceFolder[]);
|
] as WorkspaceFolder[]);
|
||||||
|
|
||||||
@@ -317,6 +319,7 @@ describe("SkeletonQueryWizard", () => {
|
|||||||
extLogger,
|
extLogger,
|
||||||
mockDatabaseManager,
|
mockDatabaseManager,
|
||||||
token,
|
token,
|
||||||
|
storagePath,
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(wizard.getFirstStoragePath()).toEqual("codespaces-codeql");
|
expect(wizard.getFirstStoragePath()).toEqual("codespaces-codeql");
|
||||||
@@ -327,11 +330,21 @@ describe("SkeletonQueryWizard", () => {
|
|||||||
jest.spyOn(workspace, "workspaceFolders", "get").mockReturnValue([
|
jest.spyOn(workspace, "workspaceFolders", "get").mockReturnValue([
|
||||||
{
|
{
|
||||||
name: "codeql-custom-queries-cpp",
|
name: "codeql-custom-queries-cpp",
|
||||||
uri: { path: "vscode-codeql-starter/codeql-custom-queries-cpp" },
|
uri: {
|
||||||
|
fsPath: join(
|
||||||
|
"vscode-codeql-starter",
|
||||||
|
"codeql-custom-queries-cpp",
|
||||||
|
),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "codeql-custom-queries-csharp",
|
name: "codeql-custom-queries-csharp",
|
||||||
uri: { path: "vscode-codeql-starter/codeql-custom-queries-csharp" },
|
uri: {
|
||||||
|
fsPath: join(
|
||||||
|
"vscode-codeql-starter",
|
||||||
|
"codeql-custom-queries-csharp",
|
||||||
|
),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
] as WorkspaceFolder[]);
|
] as WorkspaceFolder[]);
|
||||||
|
|
||||||
@@ -342,6 +355,7 @@ describe("SkeletonQueryWizard", () => {
|
|||||||
extLogger,
|
extLogger,
|
||||||
mockDatabaseManager,
|
mockDatabaseManager,
|
||||||
token,
|
token,
|
||||||
|
storagePath,
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(wizard.getFirstStoragePath()).toEqual("vscode-codeql-starter");
|
expect(wizard.getFirstStoragePath()).toEqual("vscode-codeql-starter");
|
||||||
|
|||||||
Reference in New Issue
Block a user