Move workspace folder functions to separate file
This commit is contained in:
@@ -2,12 +2,9 @@ import { join, relative, resolve, sep } from "path";
|
||||
import { outputFile, pathExists, readFile } from "fs-extra";
|
||||
import { dump as dumpYaml, load as loadYaml } from "js-yaml";
|
||||
import { minimatch } from "minimatch";
|
||||
import { CancellationToken, window, WorkspaceFolder } from "vscode";
|
||||
import { CancellationToken, window } from "vscode";
|
||||
import { CodeQLCliServer, QlpacksInfo } from "../codeql-cli/cli";
|
||||
import {
|
||||
getOnDiskWorkspaceFolders,
|
||||
getOnDiskWorkspaceFoldersObjects,
|
||||
} from "../common/vscode/workspace-folders";
|
||||
import { getOnDiskWorkspaceFolders } from "../common/vscode/workspace-folders";
|
||||
import { ProgressCallback } from "../common/vscode/progress";
|
||||
import { DatabaseItem } from "../databases/local-databases";
|
||||
import { getQlPackPath, QLPACK_FILENAMES } from "../pure/ql";
|
||||
@@ -23,6 +20,10 @@ import {
|
||||
parsePackName,
|
||||
validatePackName,
|
||||
} from "./extension-pack-name";
|
||||
import {
|
||||
askForWorkspaceFolder,
|
||||
autoPickWorkspaceFolder,
|
||||
} from "./extensions-workspace-folder";
|
||||
|
||||
const maxStep = 3;
|
||||
|
||||
@@ -395,57 +396,6 @@ async function autoCreateExtensionPack(
|
||||
return writeExtensionPack(packPath, packName, language);
|
||||
}
|
||||
|
||||
async function autoPickWorkspaceFolder(
|
||||
language: string,
|
||||
): Promise<WorkspaceFolder | undefined> {
|
||||
const workspaceFolders = getOnDiskWorkspaceFoldersObjects();
|
||||
|
||||
// If there's only 1 workspace folder, use that
|
||||
if (workspaceFolders.length === 1) {
|
||||
return workspaceFolders[0];
|
||||
}
|
||||
|
||||
// In the vscode-codeql-starter repository, all workspace folders are named "codeql-custom-queries-<language>",
|
||||
// so we can use that to find the workspace folder for the language
|
||||
const starterWorkspaceFolderForLanguage = workspaceFolders.find(
|
||||
(folder) => folder.name === `codeql-custom-queries-${language}`,
|
||||
);
|
||||
if (starterWorkspaceFolderForLanguage) {
|
||||
return starterWorkspaceFolderForLanguage;
|
||||
}
|
||||
|
||||
// Otherwise, try to find one that ends with "-<language>"
|
||||
const workspaceFolderForLanguage = workspaceFolders.find((folder) =>
|
||||
folder.name.endsWith(`-${language}`),
|
||||
);
|
||||
if (workspaceFolderForLanguage) {
|
||||
return workspaceFolderForLanguage;
|
||||
}
|
||||
|
||||
// If we can't find one, just ask the user
|
||||
return askForWorkspaceFolder();
|
||||
}
|
||||
|
||||
async function askForWorkspaceFolder(): Promise<WorkspaceFolder | undefined> {
|
||||
const workspaceFolders = getOnDiskWorkspaceFoldersObjects();
|
||||
const workspaceFolderOptions = workspaceFolders.map((folder) => ({
|
||||
label: folder.name,
|
||||
detail: folder.uri.fsPath,
|
||||
folder,
|
||||
}));
|
||||
|
||||
// We're not using window.showWorkspaceFolderPick because that also includes the database source folders while
|
||||
// we only want to include on-disk workspace folders.
|
||||
const workspaceFolder = await window.showQuickPick(workspaceFolderOptions, {
|
||||
title: "Select workspace folder to create extension pack in",
|
||||
});
|
||||
if (!workspaceFolder) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return workspaceFolder.folder;
|
||||
}
|
||||
|
||||
async function writeExtensionPack(
|
||||
packPath: string,
|
||||
packName: ExtensionPackName,
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
import { window, WorkspaceFolder } from "vscode";
|
||||
import { getOnDiskWorkspaceFoldersObjects } from "../common/vscode/workspace-folders";
|
||||
|
||||
export async function autoPickWorkspaceFolder(
|
||||
language: string,
|
||||
): Promise<WorkspaceFolder | undefined> {
|
||||
const workspaceFolders = getOnDiskWorkspaceFoldersObjects();
|
||||
|
||||
// If there's only 1 workspace folder, use that
|
||||
if (workspaceFolders.length === 1) {
|
||||
return workspaceFolders[0];
|
||||
}
|
||||
|
||||
// In the vscode-codeql-starter repository, all workspace folders are named "codeql-custom-queries-<language>",
|
||||
// so we can use that to find the workspace folder for the language
|
||||
const starterWorkspaceFolderForLanguage = workspaceFolders.find(
|
||||
(folder) => folder.name === `codeql-custom-queries-${language}`,
|
||||
);
|
||||
if (starterWorkspaceFolderForLanguage) {
|
||||
return starterWorkspaceFolderForLanguage;
|
||||
}
|
||||
|
||||
// Otherwise, try to find one that ends with "-<language>"
|
||||
const workspaceFolderForLanguage = workspaceFolders.find((folder) =>
|
||||
folder.name.endsWith(`-${language}`),
|
||||
);
|
||||
if (workspaceFolderForLanguage) {
|
||||
return workspaceFolderForLanguage;
|
||||
}
|
||||
|
||||
// If we can't find one, just ask the user
|
||||
return askForWorkspaceFolder();
|
||||
}
|
||||
|
||||
export async function askForWorkspaceFolder(): Promise<
|
||||
WorkspaceFolder | undefined
|
||||
> {
|
||||
const workspaceFolders = getOnDiskWorkspaceFoldersObjects();
|
||||
const workspaceFolderOptions = workspaceFolders.map((folder) => ({
|
||||
label: folder.name,
|
||||
detail: folder.uri.fsPath,
|
||||
folder,
|
||||
}));
|
||||
|
||||
// We're not using window.showWorkspaceFolderPick because that also includes the database source folders while
|
||||
// we only want to include on-disk workspace folders.
|
||||
const workspaceFolder = await window.showQuickPick(workspaceFolderOptions, {
|
||||
title: "Select workspace folder to create extension pack in",
|
||||
});
|
||||
if (!workspaceFolder) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return workspaceFolder.folder;
|
||||
}
|
||||
Reference in New Issue
Block a user