11import { ensureDirSync , pathExists , ensureDir , writeFile } from "fs-extra" ;
2- import { join , dirname } from "path" ;
2+ import { join } from "path" ;
33import { dirSync } from "tmp-promise" ;
4- import { Uri , window as Window , workspace , env , WorkspaceFolder } from "vscode" ;
4+ import { Uri , window as Window , workspace , env } from "vscode" ;
55import { CodeQLCliServer } from "./codeql-cli/cli" ;
66import { UserCancellationException } from "./common/vscode/progress" ;
77import { extLogger , OutputChannelLogger } from "./common" ;
@@ -11,6 +11,7 @@ import { RedactableError } from "./pure/errors";
1111import { isQueryLanguage , QueryLanguage } from "./common/query-language" ;
1212import { isCodespacesTemplate } from "./config" ;
1313import { AppCommandManager } from "./common/commands" ;
14+ import { getOnDiskWorkspaceFolders } from "./common/vscode/workspace-folders" ;
1415
1516// Shared temporary folder for the extension.
1617export const tmpDir = dirSync ( {
@@ -232,13 +233,6 @@ export async function showInformationMessageWithAction(
232233 return chosenItem === actionItem ;
233234}
234235
235- /** Returns true if the specified workspace folder is on the file system. */
236- export function isWorkspaceFolderOnDisk (
237- workspaceFolder : WorkspaceFolder ,
238- ) : boolean {
239- return workspaceFolder . uri . scheme === "file" ;
240- }
241-
242236/**
243237 * Opens a modal dialog for the user to make a choice between yes/no/never be asked again.
244238 *
@@ -279,26 +273,6 @@ export async function showNeverAskAgainDialog(
279273 return chosenItem ?. title ;
280274}
281275
282- /** Gets all active workspace folders that are on the filesystem. */
283- export function getOnDiskWorkspaceFoldersObjects ( ) {
284- const workspaceFolders = workspace . workspaceFolders ?? [ ] ;
285- return workspaceFolders . filter ( isWorkspaceFolderOnDisk ) ;
286- }
287-
288- /** Gets all active workspace folders that are on the filesystem. */
289- export function getOnDiskWorkspaceFolders ( ) {
290- return getOnDiskWorkspaceFoldersObjects ( ) . map ( ( folder ) => folder . uri . fsPath ) ;
291- }
292-
293- /** Check if folder is already present in workspace */
294- export function isFolderAlreadyInWorkspace ( folderName : string ) {
295- const workspaceFolders = workspace . workspaceFolders || [ ] ;
296-
297- return ! ! workspaceFolders . find (
298- ( workspaceFolder ) => workspaceFolder . name === folderName ,
299- ) ;
300- }
301-
302276/** Check if the current workspace is the CodeTour and open the workspace folder.
303277 * Without this, we can't run the code tour correctly.
304278 **/
@@ -448,39 +422,3 @@ export async function createTimestampFile(storagePath: string) {
448422 await ensureDir ( storagePath ) ;
449423 await writeFile ( timestampPath , Date . now ( ) . toString ( ) , "utf8" ) ;
450424}
451-
452- /**
453- * Returns the path of the first folder in the workspace.
454- * This is used to decide where to create skeleton QL packs.
455- *
456- * If the first folder is a QL pack, then the parent folder is returned.
457- * This is because the vscode-codeql-starter repo contains a ql pack in
458- * the first folder.
459- *
460- * This is a temporary workaround until we can retire the
461- * vscode-codeql-starter repo.
462- */
463-
464- export function getFirstWorkspaceFolder ( ) {
465- const workspaceFolders = getOnDiskWorkspaceFolders ( ) ;
466-
467- if ( ! workspaceFolders || workspaceFolders . length === 0 ) {
468- throw new Error ( "No workspace folders found" ) ;
469- }
470-
471- const firstFolderFsPath = workspaceFolders [ 0 ] ;
472-
473- // For the vscode-codeql-starter repo, the first folder will be a ql pack
474- // so we need to get the parent folder
475- if (
476- firstFolderFsPath . includes (
477- join ( "vscode-codeql-starter" , "codeql-custom-queries" ) ,
478- )
479- ) {
480- // return the parent folder
481- return dirname ( firstFolderFsPath ) ;
482- } else {
483- // if the first folder is not a ql pack, then we are in a normal workspace
484- return firstFolderFsPath ;
485- }
486- }
0 commit comments