Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Look for Quarto in the app root (for Positron) #503

Merged
merged 2 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions apps/vscode/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
32 changes: 29 additions & 3 deletions packages/quarto-core/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
Expand Down Expand Up @@ -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");
Expand All @@ -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) {
Expand Down