@@ -124,6 +124,25 @@ async function findGitFolder(
124124 return closestFolder ?. [ 1 ] ;
125125}
126126
127+ /**
128+ * Finds a suitable directory for extension packs to be created in. This will
129+ * always be a path ending in `.github/codeql/extensions`. The parent directory
130+ * will be determined heuristically based on the on-disk workspace folders.
131+ *
132+ * The heuristic is as follows (`.github/codeql/extensions` is added automatically unless
133+ * otherwise specified):
134+ * 1. If there is only 1 workspace folder, use that folder
135+ * 2. If there is a workspace folder for which the path ends in `.github/codeql/extensions`, use that folder
136+ * - If there are multiple such folders, use the first one
137+ * - Does not append `.github/codeql/extensions` to the path
138+ * 3. If there is a workspace file (`<basename>.code-workspace`), use the directory containing that file
139+ * 4. If there is a common root directory for all workspace folders, use that directory
140+ * - Workspace folders in the system temp directory are ignored
141+ * - If the common root directory is the root of the filesystem, then it's not used
142+ * 5. If there is a .git directory in any workspace folder, use the directory containing that .git directory
143+ * for which the .git directory is closest to a workspace folder
144+ * 6. If none of the above apply, return `undefined`
145+ */
127146export async function autoPickExtensionsDirectory ( ) : Promise < Uri | undefined > {
128147 const workspaceFolders = getOnDiskWorkspaceFoldersObjects ( ) ;
129148
0 commit comments