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

Function getTemplateItems

src/rmarkdown/draft.ts:21–73  ·  view source on GitHub ↗
(cwd: string)

Source from the content-addressed store, hash-verified

19}
20
21async function getTemplateItems(cwd: string): Promise<TemplateItem[] | undefined> {
22 const lim = '---vsc---';
23 const rPath = await getRpath();
24 if (!rPath) {
25 return undefined;
26 }
27 const options: cp.CommonOptions = {
28 cwd: cwd,
29 env: {
30 ...process.env,
31 VSCR_LIM: lim
32 }
33 };
34
35 const rScriptFile = extensionContext.asAbsolutePath('R/rmarkdown/templates.R');
36 const args = [
37 '--silent',
38 '--no-echo',
39 '--no-save',
40 '--no-restore',
41 '-f',
42 rScriptFile
43 ];
44
45 try {
46 const result = await spawnAsync(rPath, args, options);
47 if (result.status !== 0) {
48 throw result.error || new Error(result.stderr);
49 }
50 const re = new RegExp(`${lim}(.*)${lim}`, 'ms');
51 const match = re.exec(result.stdout);
52 if (!match || match.length !== 2) {
53 throw new Error('Could not parse R output.');
54 }
55 const json = match[1];
56 const templates = <TemplateInfo[]>JSON.parse(json) || [];
57 const items = templates.map((x) => {
58 return {
59 alwaysShow: false,
60 description: `{${x.package}}`,
61 label: x.name + (x.create_dir ? ' $(new-folder)' : ''),
62 detail: x.description,
63 picked: false,
64 info: x
65 };
66 });
67 return items;
68 } catch (e) {
69 console.log(e);
70 void window.showErrorMessage(catchAsError(e).message);
71 return undefined;
72 }
73}
74
75async function launchTemplatePicker(cwd: string): Promise<TemplateItem | undefined> {
76 const options: QuickPickOptions = {

Callers 1

launchTemplatePickerFunction · 0.85

Calls 3

getRpathFunction · 0.90
spawnAsyncFunction · 0.90
catchAsErrorFunction · 0.90

Tested by

no test coverage detected