From 35cdcd85d04dc0f19ba2837ed8302ef853beed47 Mon Sep 17 00:00:00 2001 From: Jonathan McPherson Date: Thu, 1 Aug 2024 13:30:10 -0700 Subject: [PATCH 1/2] accept additional paths to search for Quarto --- packages/quarto-core/src/context.ts | 32 ++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/packages/quarto-core/src/context.ts b/packages/quarto-core/src/context.ts index 1e4ce848..037c0560 100644 --- a/packages/quarto-core/src/context.ts +++ b/packages/quarto-core/src/context.ts @@ -33,11 +33,26 @@ export interface QuartoContext { runPandoc: (options: ExecFileSyncOptions, ...args: string[]) => string; } +/** + * Initialize a Quarto context. + * + * @param quartoPath A path to a user-specified Quarto executable. If + * supplied, this will be used in preference to other methods of detecting + * Quarto. + * @param workspaceFolder The workspace folder to use for resolving relative + * paths. + * @param additionalSearchPaths Additional paths to search for Quarto. These will only be used if + * Quarto is not found in the default locations or the system path. + * @param showWarning A function to call to show a warning message. + * + * @returns A Quarto context. + */ export function initQuartoContext( quartoPath?: string, workspaceFolder?: string, + additionalSearchPaths?: string[], showWarning?: (msg: string) => void -) { +): QuartoContext { // default warning to log showWarning = showWarning || console.log; @@ -57,7 +72,7 @@ export function initQuartoContext( // if still not found, scan for versions of quarto in known locations if (!quartoInstall) { - quartoInstall = scanForQuarto(); + quartoInstall = scanForQuarto(additionalSearchPaths); } // return if we got them @@ -174,7 +189,14 @@ function detectUserSpecifiedQuarto( return detectQuarto(quartoPath); } -function scanForQuarto(): QuartoInstallation | undefined { +/** + * Scan for Quarto in known locations. + * + * @param additionalSearchPaths Additional paths to search for Quarto (optional) + * + * @returns A Quarto installation if found, otherwise undefined + */ +function scanForQuarto(additionalSearchPaths?: string[]): QuartoInstallation | undefined { const scanPaths: string[] = []; if (os.platform() === "win32") { scanPaths.push("C:\\Program Files\\Quarto\\bin"); @@ -196,6 +218,10 @@ function scanForQuarto(): QuartoInstallation | undefined { scanPaths.push("/usr/lib/rstudio-server/bin/quarto/bin"); } + if (additionalSearchPaths) { + scanPaths.push(...additionalSearchPaths); + } + for (const scanPath of scanPaths.filter(fs.existsSync)) { const install = detectQuarto(path.join(scanPath, "quarto")); if (install) { From a4d14e94ea2af4fc32c2ff9726592ab4360d09a1 Mon Sep 17 00:00:00 2001 From: Jonathan McPherson Date: Fri, 2 Aug 2024 09:57:16 -0700 Subject: [PATCH 2/2] look for quarto in app root --- apps/vscode/src/main.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/apps/vscode/src/main.ts b/apps/vscode/src/main.ts index 3b996985..c9195e58 100644 --- a/apps/vscode/src/main.ts +++ b/apps/vscode/src/main.ts @@ -55,6 +55,8 @@ export async function activate(context: vscode.ExtensionContext) { const quartoContext = initQuartoContext( quartoPath, workspaceFolder, + // Look for quarto in the app root; this is where Positron installs it + [path.join(vscode.env.appRoot, 'quarto', 'bin')], vscode.window.showWarningMessage ); if (quartoContext.available) {