From ae9926c207eefcecb929ed47aa2fcc1e1ddde96f Mon Sep 17 00:00:00 2001 From: Kun Ren Date: Thu, 28 Apr 2022 13:42:09 +0800 Subject: [PATCH 1/2] Use loadNamespace --- R/help/getAliases.R | 2 +- R/rmarkdown/templates.R | 4 ++-- src/rmarkdown/draft.ts | 13 +++++++++++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/R/help/getAliases.R b/R/help/getAliases.R index 50e35fd7c..00985ea47 100644 --- a/R/help/getAliases.R +++ b/R/help/getAliases.R @@ -1,4 +1,4 @@ -requireNamespace("jsonlite") +loadNamespace("jsonlite") ip <- installed.packages() diff --git a/R/rmarkdown/templates.R b/R/rmarkdown/templates.R index dec8b97d0..93a7a0a81 100644 --- a/R/rmarkdown/templates.R +++ b/R/rmarkdown/templates.R @@ -1,5 +1,5 @@ -requireNamespace("jsonlite") -requireNamespace("yaml") +loadNamespace("jsonlite") +loadNamespace("yaml") pkgs <- .packages(all.available = TRUE) templates <- new.env() diff --git a/src/rmarkdown/draft.ts b/src/rmarkdown/draft.ts index 4a716e27e..17fb8cd9b 100644 --- a/src/rmarkdown/draft.ts +++ b/src/rmarkdown/draft.ts @@ -65,6 +65,7 @@ async function getTemplateItems(cwd: string): Promise { } catch (e) { console.log(e); void window.showErrorMessage((<{ message: string }>e).message); + return undefined; } } @@ -80,8 +81,16 @@ async function launchTemplatePicker(cwd: string): Promise { const items = await getTemplateItems(cwd); - const selection: TemplateItem = await window.showQuickPick(items, options); - return selection; + if (items) { + if (items.length > 0) { + const selection = await window.showQuickPick(items, options); + return selection; + } else { + void window.showInformationMessage('No templates found.'); + } + } else { + return undefined; + } } async function makeDraft(file: string, template: TemplateItem, cwd: string): Promise { From a9326faa1d460261f4fb202556de2cdc550a7ca5 Mon Sep 17 00:00:00 2001 From: Kun Ren Date: Thu, 28 Apr 2022 14:22:50 +0800 Subject: [PATCH 2/2] Update launchTemplatePicker --- src/rmarkdown/draft.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/rmarkdown/draft.ts b/src/rmarkdown/draft.ts index 17fb8cd9b..8b1ca2193 100644 --- a/src/rmarkdown/draft.ts +++ b/src/rmarkdown/draft.ts @@ -88,9 +88,8 @@ async function launchTemplatePicker(cwd: string): Promise { } else { void window.showInformationMessage('No templates found.'); } - } else { - return undefined; } + return undefined; } async function makeDraft(file: string, template: TemplateItem, cwd: string): Promise {