MCPcopy Create free account
hub / github.com/REditorSupport/vscode-R / knitDocument

Function knitDocument

src/rmarkdown/manager.ts:57–187  ·  view source on GitHub ↗
(args: IKnitArgs, token?: vscode.CancellationToken, progress?: vscode.Progress<unknown>)

Source from the content-addressed store, hash-verified

55 }
56
57 protected async knitDocument(args: IKnitArgs, token?: vscode.CancellationToken, progress?: vscode.Progress<unknown>): Promise<DisposableProcess | IKnitRejection> {
58 // vscode.Progress auto-increments progress, so we use this
59 // variable to set progress to a specific number
60 let currentProgress = 0;
61 let printOutput = true;
62
63 return await new Promise<DisposableProcess>(
64 (resolve, reject) => {
65 const scriptArgs = args.scriptArgs;
66 const scriptPath = args.scriptPath;
67 const fileName = args.fileName;
68 // const cmd = `${this.rPath} --silent --no-echo --no-save --no-restore -f "${scriptPath}"`;
69 const cpArgs = [
70 '--silent',
71 '--no-echo',
72 '--no-save',
73 '--no-restore',
74 '-f',
75 scriptPath
76 ];
77 // When there's no LANG variable, we should try to set to a UTF-8 compatible one, as R relies
78 // on locale setting (based on LANG) to render certain characters.
79 // See https://github.com/REditorSupport/vscode-R/issues/933
80 const env = process.env;
81 if (env.LANG === undefined) {
82 env.LANG = 'en_US.UTF-8';
83 }
84 const processOptions: cp.SpawnOptions = {
85 env: {
86 ...env,
87 ...scriptArgs
88 },
89 cwd: args.workingDirectory,
90 };
91
92 let childProcess: DisposableProcess | undefined = undefined;
93 try {
94 if (!this.rPath) {
95 throw new Error('R path not defined');
96 }
97
98 childProcess = spawn(this.rPath, cpArgs, processOptions, () => {
99 rMarkdownOutput.appendLine('[VSC-R] terminating R process');
100 printOutput = false;
101 });
102 progress?.report({
103 increment: 0,
104 message: '0%'
105 });
106 } catch (e: unknown) {
107 console.warn(`[VSC-R] error: ${e as string}`);
108 reject({ cp: childProcess, wasCancelled: false });
109 return;
110 }
111
112 this.rMarkdownOutput.appendLine(`[VSC-R] ${fileName} process started`);
113
114 if (args.rCmd) {

Callers

nothing calls this directly

Calls 2

spawnFunction · 0.90
callbackMethod · 0.45

Tested by

no test coverage detected