From 6d4bfa0b523540e7e85750155ac279bb96159272 Mon Sep 17 00:00:00 2001 From: ElianHugh Date: Thu, 30 Sep 2021 21:45:59 +1000 Subject: [PATCH 1/3] Respect cwd --- src/rmarkdown/manager.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/rmarkdown/manager.ts b/src/rmarkdown/manager.ts index 6bd98113c..33c961fd1 100644 --- a/src/rmarkdown/manager.ts +++ b/src/rmarkdown/manager.ts @@ -74,11 +74,12 @@ export abstract class RMarkdownManager { `-f`, `${scriptPath}` ]; - const processOptions = { + const processOptions: cp.SpawnOptions = { env: { ...process.env, ...scriptArgs - } + }, + cwd: vscode.workspace.workspaceFolders[0].uri.fsPath }; let childProcess: DisposableProcess; From 61cac905956e03c9dd44f4e8cec40fb85b266132 Mon Sep 17 00:00:00 2001 From: Kun Ren Date: Thu, 7 Oct 2021 10:39:10 +0800 Subject: [PATCH 2/3] Start knit process from knitWorkingDirectory --- src/rmarkdown/knit.ts | 1 + src/rmarkdown/manager.ts | 3 ++- src/rmarkdown/preview.ts | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/rmarkdown/knit.ts b/src/rmarkdown/knit.ts index 149d39290..f490d600d 100644 --- a/src/rmarkdown/knit.ts +++ b/src/rmarkdown/knit.ts @@ -64,6 +64,7 @@ export class RMarkdownKnitManager extends RMarkdownManager { return await this.knitWithProgress( { + workingDirectory: knitWorkingDir, fileName: docName, filePath: rDocumentPath, scriptArgs: scriptValues, diff --git a/src/rmarkdown/manager.ts b/src/rmarkdown/manager.ts index 33c961fd1..a271a344c 100644 --- a/src/rmarkdown/manager.ts +++ b/src/rmarkdown/manager.ts @@ -18,6 +18,7 @@ export interface IKnitRejection { const rMarkdownOutput: vscode.OutputChannel = vscode.window.createOutputChannel('R Markdown'); interface IKnitArgs { + workingDirectory: string; filePath: string; fileName: string; scriptArgs: Record; @@ -79,7 +80,7 @@ export abstract class RMarkdownManager { ...process.env, ...scriptArgs }, - cwd: vscode.workspace.workspaceFolders[0].uri.fsPath + cwd: args.workingDirectory, }; let childProcess: DisposableProcess; diff --git a/src/rmarkdown/preview.ts b/src/rmarkdown/preview.ts index e5a9466f6..645776153 100644 --- a/src/rmarkdown/preview.ts +++ b/src/rmarkdown/preview.ts @@ -328,6 +328,7 @@ export class RMarkdownPreviewManager extends RMarkdownManager { return await this.knitWithProgress( { + workingDirectory: knitWorkingDir, fileName: fileName, filePath: filePath, scriptPath: extensionContext.asAbsolutePath('R/rmarkdown/preview.R'), From a2a0a94f45ec33944f1d3f5c272f484f2cfd9d6f Mon Sep 17 00:00:00 2001 From: Kun Ren Date: Thu, 7 Oct 2021 14:17:33 +0800 Subject: [PATCH 3/3] Refine getKnitDir --- src/rmarkdown/manager.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rmarkdown/manager.ts b/src/rmarkdown/manager.ts index a271a344c..490eb039c 100644 --- a/src/rmarkdown/manager.ts +++ b/src/rmarkdown/manager.ts @@ -36,8 +36,7 @@ export abstract class RMarkdownManager { // so that we can't spam the knit/preview button protected busyUriStore: Set = new Set(); - protected getKnitDir(knitDir: string, docPath?: string): string { - const currentDocumentWorkspace = vscode.workspace.getWorkspaceFolder(vscode.Uri.file(docPath) ?? vscode.window.activeTextEditor?.document?.uri)?.uri?.fsPath ?? undefined; + protected getKnitDir(knitDir: string, docPath: string): string { switch (knitDir) { // the directory containing the R Markdown document case KnitWorkingDirectory.documentDirectory: { @@ -45,6 +44,7 @@ export abstract class RMarkdownManager { } // the root of the current workspace case KnitWorkingDirectory.workspaceRoot: { + const currentDocumentWorkspace = vscode.workspace.getWorkspaceFolder(vscode.Uri.file(docPath) ?? vscode.window.activeTextEditor?.document?.uri)?.uri?.fsPath ?? undefined; return currentDocumentWorkspace.replace(/\\/g, '/').replace(/['"]/g, '\\"'); } // the working directory of the attached terminal, NYI