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

Supply RSTUDIO_PANDOC to packaging tasks, including R Markdown render #3856

Merged
merged 1 commit into from
Jul 8, 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
23 changes: 23 additions & 0 deletions extensions/positron-r/src/pandoc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*---------------------------------------------------------------------------------------------
* Copyright (C) 2024 Posit Software, PBC. All rights reserved.
* Licensed under the Elastic License 2.0. See LICENSE.txt for license information.
*--------------------------------------------------------------------------------------------*/

import * as vscode from 'vscode';
import { existsSync } from 'fs';
import * as path from 'path';

/**
* Discovers the path to the pandoc executable that ships with Positron.
*
* @returns The path to the pandoc executable, if it exists.
*/
export function getPandocPath(): string | undefined {
const pandocPath = path.join(vscode.env.appRoot,
process.platform === 'darwin' ?
path.join('bin', 'pandoc') :
path.join('..', '..', 'bin', 'pandoc'));
if (existsSync(pandocPath)) {
return pandocPath;
}
}
9 changes: 3 additions & 6 deletions extensions/positron-r/src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { randomUUID } from 'crypto';
import { handleRCode } from './hyperlink';
import { RSessionManager } from './session-manager';
import { EXTENSION_ROOT_DIR } from './constants';
import { existsSync } from 'fs';
import { getPandocPath } from './pandoc';

interface RPackageInstallation {
packageName: string;
Expand Down Expand Up @@ -704,11 +704,8 @@ export function createJupyterKernelSpec(
//
// On MacOS, the binary path lives alongside the app bundle; on other
// platforms, it's a couple of directories up from the app root.
const pandocPath = path.join(vscode.env.appRoot,
process.platform === 'darwin' ?
path.join('bin', 'pandoc') :
path.join('..', '..', 'bin', 'pandoc'));
if (existsSync(pandocPath)) {
const pandocPath = getPandocPath();
if (pandocPath) {
env['RSTUDIO_PANDOC'] = pandocPath;
}

Expand Down
13 changes: 12 additions & 1 deletion extensions/positron-r/src/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import * as vscode from 'vscode';
import { RSessionManager } from './session-manager';
import { getEditorFilePathForCommand } from './commands';
import { getPandocPath } from './pandoc';

export class RPackageTaskProvider implements vscode.TaskProvider {

Expand Down Expand Up @@ -57,6 +58,15 @@ export async function getRPackageTasks(editorFilePath?: string): Promise<vscode.
package: 'rmarkdown'
}
];

// if we have a local copy of Pandoc available, forward it to the R session
// so that it can be used to render R Markdown documents (etc)
const env: any = {};
const pandocPath = getPandocPath();
if (pandocPath) {
env['RSTUDIO_PANDOC'] = pandocPath;
}

// the explicit quoting treatment is necessary to avoid headaches on Windows, with PowerShell
return taskData.map(data => new vscode.Task(
{ type: 'rPackageTask', task: data.task, pkg: data.package },
Expand All @@ -65,7 +75,8 @@ export async function getRPackageTasks(editorFilePath?: string): Promise<vscode.
'R',
new vscode.ShellExecution(
binpath,
['-e', { value: data.rcode, quoting: vscode.ShellQuoting.Strong }]
['-e', { value: data.rcode, quoting: vscode.ShellQuoting.Strong }],
{ env }
),
[]
));
Expand Down
Loading