From 2beef0aefe0cf3ff19443d13f1c1349d23175c9d Mon Sep 17 00:00:00 2001 From: "Elian H. Thiele-Evans" <60372411+ElianHugh@users.noreply.github.com> Date: Thu, 5 Aug 2021 22:12:20 +1000 Subject: [PATCH 01/17] PoF accessing VSC settings ** proof of concept ** Load R-related vsc settings and set as R option --- R/getSettings.R | 16 ++++++++ package.json | 98 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 114 insertions(+) create mode 100644 R/getSettings.R diff --git a/R/getSettings.R b/R/getSettings.R new file mode 100644 index 000000000..e591b1282 --- /dev/null +++ b/R/getSettings.R @@ -0,0 +1,16 @@ +fileCon <- file("~/.config/Code/User/settings.json") +vsc_settings <- jsonlite::fromJSON(paste(readLines(fileCon), collapse = "")) +ops <- vsc_settings[grep("r.rOptions", names(vsc_settings))]$r.rOptions + + +.vsc.setOption <- function(x) { + val <- ops[[x]] + switch( + x, + "vsc.plot" = options("vsc.plot" = val), + "vsc.globalenv" = options("vsc.globalenv" = val) + # etc. + ) +} + +lapply(names(ops), .vsc.setOption) diff --git a/package.json b/package.json index 161d8e60f..fdb5485ac 100644 --- a/package.json +++ b/package.json @@ -1408,6 +1408,104 @@ "type": "string", "default": "", "markdownDescription": "Path to a custom CSS file to be used when `#r.plot.defaults.colorTheme#` is `vscode`. Replaces the default CSS overwrites!" + }, + "r.rOptions": { + "type": "object", + "default": { + "vsc.plot": "Two", + "vsc.browser": "Two", + "vsc.viewer": "Two", + "vsc.pageViewer": "Two", + "vsc.view": "Two", + "vsc.helpPanel": "Two", + "vsc.strMaxLevel": "2", + "vsc.showObjectSize": true, + "vsc.useHttpgd": false, + "vsc.globalEnv": true + }, + "properties": { + "vsc.plot": { + "type": "string", + "enum": [ + "Two", + "Active", + "Beside", + "FALSE" + ], + "default": "Two" + }, + "vsc.browser": { + "type": "string", + "enum": [ + "Two", + "Active", + "Beside", + "FALSE" + ], + "default": "Two" + }, + "vsc.viewer": { + "type": "string", + "enum": [ + "Two", + "Active", + "Beside", + "FALSE" + ], + "default": "Two" + }, + "vsc.pageViewer": { + "type": "string", + "enum": [ + "Two", + "Active", + "Beside", + "FALSE" + ], + "default": "Two" + }, + "vsc.view": { + "type": "string", + "enum": [ + "Two", + "Active", + "Beside", + "FALSE" + ], + "default": "Two" + }, + "vsc.helpPanel": { + "type": "string", + "enum": [ + "Two", + "Active", + "Beside", + "FALSE" + ], + "default": "Two" + }, + "vsc.strMaxLevel": { + "type": "string", + "enum": [ + "0", + "2" + ], + "default": "2" + }, + "vsc.useHttpgd": { + "type": "boolean", + "default": false + }, + "vsc.globalEnv": { + "type": "boolean", + "default": true + }, + "vsc.showObjectSize": { + "type": "boolean", + "default": true + } + }, + "additionalProperties": false } } }, From a6d16fc9f3dd5351f201a3595fc1cc27936cf52e Mon Sep 17 00:00:00 2001 From: ElianHugh Date: Fri, 6 Aug 2021 02:27:01 +1000 Subject: [PATCH 02/17] Update getSettings.R --- R/getSettings.R | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/R/getSettings.R b/R/getSettings.R index e591b1282..86caee680 100644 --- a/R/getSettings.R +++ b/R/getSettings.R @@ -1,16 +1,29 @@ -fileCon <- file("~/.config/Code/User/settings.json") +fileCon <- if (file.exists("~/.config/Code/User/settings.json")) { + # windows + file("~/.config/Code/User/settings.json") +} else if (file.exists("~/Library/Application Support/Code/User/settings.json")) { + # mac + file("~/.config/Code/User/settings.json") +} else if (file.exists("~/.config/Code/User/settings.json")) { + # linux + file("~/.config/Code/User/settings.json") +} else if (file.exists(paste0("/mnt///c/Users/", Sys.getenv("USER"), "/AppData/Roaming/Code/User/settings.json"))) { + # WSL + file(paste0("/mnt///c/Users/", Sys.getenv("USER"), "/AppData/Roaming/Code/User/settings.json")) +} else { + NULL +} + + vsc_settings <- jsonlite::fromJSON(paste(readLines(fileCon), collapse = "")) ops <- vsc_settings[grep("r.rOptions", names(vsc_settings))]$r.rOptions -.vsc.setOption <- function(x) { +lapply(names(ops), function(x) { val <- ops[[x]] - switch( - x, + switch(x, "vsc.plot" = options("vsc.plot" = val), "vsc.globalenv" = options("vsc.globalenv" = val) # etc. ) -} - -lapply(names(ops), .vsc.setOption) +}) From 5fd65856a70ddb16d476155dfdf415a5cb13cffe Mon Sep 17 00:00:00 2001 From: "Elian H. Thiele-Evans" <60372411+ElianHugh@users.noreply.github.com> Date: Fri, 6 Aug 2021 10:38:48 +1000 Subject: [PATCH 03/17] Fiddle with configurations --- R/getSettings.R | 20 ++++++++++++++++---- package.json | 28 ++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/R/getSettings.R b/R/getSettings.R index 86caee680..aee6a19dd 100644 --- a/R/getSettings.R +++ b/R/getSettings.R @@ -18,12 +18,24 @@ fileCon <- if (file.exists("~/.config/Code/User/settings.json")) { vsc_settings <- jsonlite::fromJSON(paste(readLines(fileCon), collapse = "")) ops <- vsc_settings[grep("r.rOptions", names(vsc_settings))]$r.rOptions +get_val <- function(x) { + switch(EXPR = x, + "Two" = "Two", + "Active" = "Active", + "Beside" = "Beside", + "FALSE" = FALSE, + "TRUE" = TRUE, + "0" = 0, + "2" = 2, + x + ) +} -lapply(names(ops), function(x) { - val <- ops[[x]] - switch(x, +suppressMessages(lapply(names(ops), function(x) { + val <- get_val(ops[[x]]) + switch(EXPR = x, "vsc.plot" = options("vsc.plot" = val), "vsc.globalenv" = options("vsc.globalenv" = val) # etc. ) -}) +})) diff --git a/package.json b/package.json index fdb5485ac..67f06b33e 100644 --- a/package.json +++ b/package.json @@ -1409,6 +1409,34 @@ "default": "", "markdownDescription": "Path to a custom CSS file to be used when `#r.plot.defaults.colorTheme#` is `vscode`. Replaces the default CSS overwrites!" }, + "r.rOption.bools": { + "type": "object", + "default": { + "vsc.rstudioapi": false, + "vsc.useHttpgd": false, + "vsc.globalenv": true, + "vsc.showObjectSize": true + }, + "properties": { + "vsc.rstudioapi": { + "type": "boolean", + "default": false + }, + "vsc.useHttpgd": { + "type": "boolean", + "default": false + }, + "vsc.globalEnv": { + "type": "boolean", + "default": true + }, + "vsc.showObjectSize": { + "type": "boolean", + "default": true + } + }, + "additionalProperties": false + }, "r.rOptions": { "type": "object", "default": { From ed4713658a554d27620c4537d84bbc99e6f2103e Mon Sep 17 00:00:00 2001 From: ElianHugh Date: Fri, 6 Aug 2021 15:39:22 +1000 Subject: [PATCH 04/17] Setup example usage --- R/getSettings.R | 57 +++++++++++++++++++++++++++++++++++-------------- R/init.R | 3 +++ package.json | 37 +++++++++++--------------------- 3 files changed, 56 insertions(+), 41 deletions(-) diff --git a/R/getSettings.R b/R/getSettings.R index aee6a19dd..4fd10d5ac 100644 --- a/R/getSettings.R +++ b/R/getSettings.R @@ -1,3 +1,6 @@ +# try to find the VSC settings file. +# can be tricky for specific platforms, such as WSL, +# where the settings are located on the window's side fileCon <- if (file.exists("~/.config/Code/User/settings.json")) { # windows file("~/.config/Code/User/settings.json") @@ -14,28 +17,50 @@ fileCon <- if (file.exists("~/.config/Code/User/settings.json")) { NULL } +# settings.json can result in errors if read via fromJSON +vsc_settings <- suppressWarnings(jsonlite::fromJSON(paste(readLines(fileCon), collapse = ""))) +ops <- Reduce(c, vsc_settings[grep("r.rOptions", names(vsc_settings))]) -vsc_settings <- jsonlite::fromJSON(paste(readLines(fileCon), collapse = "")) -ops <- vsc_settings[grep("r.rOptions", names(vsc_settings))]$r.rOptions - +# non-string values have to be converted from +# strings due to VSC settings limitations get_val <- function(x) { - switch(EXPR = x, - "Two" = "Two", - "Active" = "Active", - "Beside" = "Beside", - "FALSE" = FALSE, - "TRUE" = TRUE, - "0" = 0, - "2" = 2, + if (is.logical(x)) { x - ) + } else { + switch(EXPR = x, + "Two" = "Two", + "Active" = "Active", + "Beside" = "Beside", + "FALSE" = FALSE, + "TRUE" = TRUE, + "0" = 0, + "2" = 2, + x + ) + } } -suppressMessages(lapply(names(ops), function(x) { + +lapply(names(ops), function(x) { val <- get_val(ops[[x]]) + + # lhs = vscode setting name + # rhs name = R options name switch(EXPR = x, + # arrays "vsc.plot" = options("vsc.plot" = val), - "vsc.globalenv" = options("vsc.globalenv" = val) - # etc. + "vsc.browser" = options("vsc.browser" = val), + "vsc.viewer" = options("vsc.viewer" = val), + "vsc.pageViewer" = options("vsc.page_viewer" = val), + "vsc.view" = options("vsc.view" = val), + "vsc.helpPanel" = options("vsc.helpPanel" = val), + "vsc.strMaxLevel" = options("vsc.str.max.level" = val), + # bools + "vsc.rstudioapi" = options("vsc.rstudioapi" = val), + "vsc.useHttpgd" = options("vsc.use_httpgd" = val), + "vsc.globalEnv" = options("vsc.globalenv" = val), + "vsc.showObjectSize" = options("vsc.show_object_size" = val) ) -})) +}) + +close(fileCon) \ No newline at end of file diff --git a/R/init.R b/R/init.R index cd6b67065..d2d095c1e 100644 --- a/R/init.R +++ b/R/init.R @@ -100,9 +100,12 @@ init_last <- function() { rm(".First.sys", envir = globalenv()) ) + # Attach to vscode exports$.vsc.attach() + source(file.path(dir_init, "getSettings.R"), local = TRUE) + invisible() } diff --git a/package.json b/package.json index 67f06b33e..a674d133c 100644 --- a/package.json +++ b/package.json @@ -1409,13 +1409,14 @@ "default": "", "markdownDescription": "Path to a custom CSS file to be used when `#r.plot.defaults.colorTheme#` is `vscode`. Replaces the default CSS overwrites!" }, - "r.rOption.bools": { + "r.rOptions.bools": { "type": "object", + "markdownDescription": "Toggle vsc bools", "default": { "vsc.rstudioapi": false, "vsc.useHttpgd": false, "vsc.globalenv": true, - "vsc.showObjectSize": true + "vsc.showObjectSize": false }, "properties": { "vsc.rstudioapi": { @@ -1432,24 +1433,22 @@ }, "vsc.showObjectSize": { "type": "boolean", - "default": true + "default": false } }, "additionalProperties": false }, - "r.rOptions": { + "r.rOptions.arrays": { "type": "object", + "markdownDescription": "Set vsc options", "default": { "vsc.plot": "Two", - "vsc.browser": "Two", + "vsc.browser": "Active", "vsc.viewer": "Two", - "vsc.pageViewer": "Two", + "vsc.pageViewer": "Active", "vsc.view": "Two", "vsc.helpPanel": "Two", - "vsc.strMaxLevel": "2", - "vsc.showObjectSize": true, - "vsc.useHttpgd": false, - "vsc.globalEnv": true + "vsc.strMaxLevel": "0" }, "properties": { "vsc.plot": { @@ -1470,7 +1469,7 @@ "Beside", "FALSE" ], - "default": "Two" + "default": "Active" }, "vsc.viewer": { "type": "string", @@ -1490,7 +1489,7 @@ "Beside", "FALSE" ], - "default": "Two" + "default": "Active" }, "vsc.view": { "type": "string", @@ -1518,19 +1517,7 @@ "0", "2" ], - "default": "2" - }, - "vsc.useHttpgd": { - "type": "boolean", - "default": false - }, - "vsc.globalEnv": { - "type": "boolean", - "default": true - }, - "vsc.showObjectSize": { - "type": "boolean", - "default": true + "default": "0" } }, "additionalProperties": false From f6331edfa4f07973800010f42c93eac6d289fc26 Mon Sep 17 00:00:00 2001 From: ElianHugh Date: Fri, 6 Aug 2021 17:53:14 +1000 Subject: [PATCH 05/17] Write settings.json to .vscode-R folder --- R/getSettings.R | 106 +++++++++++++++++++++++------------------------- src/session.ts | 12 ++++++ 2 files changed, 62 insertions(+), 56 deletions(-) diff --git a/R/getSettings.R b/R/getSettings.R index 4fd10d5ac..b6e5d18af 100644 --- a/R/getSettings.R +++ b/R/getSettings.R @@ -1,66 +1,60 @@ -# try to find the VSC settings file. -# can be tricky for specific platforms, such as WSL, -# where the settings are located on the window's side -fileCon <- if (file.exists("~/.config/Code/User/settings.json")) { - # windows - file("~/.config/Code/User/settings.json") -} else if (file.exists("~/Library/Application Support/Code/User/settings.json")) { - # mac - file("~/.config/Code/User/settings.json") -} else if (file.exists("~/.config/Code/User/settings.json")) { - # linux - file("~/.config/Code/User/settings.json") -} else if (file.exists(paste0("/mnt///c/Users/", Sys.getenv("USER"), "/AppData/Roaming/Code/User/settings.json"))) { - # WSL - file(paste0("/mnt///c/Users/", Sys.getenv("USER"), "/AppData/Roaming/Code/User/settings.json")) +homedir <- Sys.getenv( + if (.Platform$OS.type == "windows") "USERPROFILE" else "HOME" +) + +fileCon <- if (file.exists(file.path(homedir, ".vscode-R", "settings.json"))) { + file(file.path(homedir, ".vscode-R", "settings.json")) } else { NULL } -# settings.json can result in errors if read via fromJSON -vsc_settings <- suppressWarnings(jsonlite::fromJSON(paste(readLines(fileCon), collapse = ""))) -ops <- Reduce(c, vsc_settings[grep("r.rOptions", names(vsc_settings))]) +if (!is.null(fileCon)) { + # settings.json can result in errors if read via fromJSON + vsc_settings <- suppressWarnings( + jsonlite::fromJSON(paste(readLines(fileCon), collapse = ""))[["rOptions"]] + ) + ops <- Reduce(c, vsc_settings) -# non-string values have to be converted from -# strings due to VSC settings limitations -get_val <- function(x) { - if (is.logical(x)) { - x - } else { - switch(EXPR = x, - "Two" = "Two", - "Active" = "Active", - "Beside" = "Beside", - "FALSE" = FALSE, - "TRUE" = TRUE, - "0" = 0, - "2" = 2, + # non-string values have to be converted from + # strings due to VSC settings limitations + get_val <- function(x) { + if (is.logical(x)) { x - ) + } else { + switch(EXPR = x, + "Two" = "Two", + "Active" = "Active", + "Beside" = "Beside", + "FALSE" = FALSE, + "TRUE" = TRUE, + "0" = 0, + "2" = 2, + x + ) + } } -} + lapply(names(ops), function(x) { + val <- get_val(ops[[x]]) -lapply(names(ops), function(x) { - val <- get_val(ops[[x]]) - - # lhs = vscode setting name - # rhs name = R options name - switch(EXPR = x, - # arrays - "vsc.plot" = options("vsc.plot" = val), - "vsc.browser" = options("vsc.browser" = val), - "vsc.viewer" = options("vsc.viewer" = val), - "vsc.pageViewer" = options("vsc.page_viewer" = val), - "vsc.view" = options("vsc.view" = val), - "vsc.helpPanel" = options("vsc.helpPanel" = val), - "vsc.strMaxLevel" = options("vsc.str.max.level" = val), - # bools - "vsc.rstudioapi" = options("vsc.rstudioapi" = val), - "vsc.useHttpgd" = options("vsc.use_httpgd" = val), - "vsc.globalEnv" = options("vsc.globalenv" = val), - "vsc.showObjectSize" = options("vsc.show_object_size" = val) - ) -}) + # lhs = vscode setting name + # rhs name = R options name + switch(EXPR = x, + # arrays + "vsc.plot" = options("vsc.plot" = val), + "vsc.browser" = options("vsc.browser" = val), + "vsc.viewer" = options("vsc.viewer" = val), + "vsc.pageViewer" = options("vsc.page_viewer" = val), + "vsc.view" = options("vsc.view" = val), + "vsc.helpPanel" = options("vsc.helpPanel" = val), + "vsc.strMaxLevel" = options("vsc.str.max.level" = val), + # bools + "vsc.rstudioapi" = options("vsc.rstudioapi" = val), + "vsc.useHttpgd" = options("vsc.use_httpgd" = val), + "vsc.globalEnv" = options("vsc.globalenv" = val), + "vsc.showObjectSize" = options("vsc.show_object_size" = val) + ) + }) -close(fileCon) \ No newline at end of file + close(fileCon) +} \ No newline at end of file diff --git a/src/session.ts b/src/session.ts index a702bb90d..3fa108fed 100644 --- a/src/session.ts +++ b/src/session.ts @@ -46,6 +46,13 @@ export function deploySessionWatcher(extensionPath: string): void { const initPath = path.join(extensionPath, 'R', 'init.R'); const linkPath = path.join(homeExtDir(), 'init.R'); fs.writeFileSync(linkPath, `local(source("${initPath.replace(/\\/g, '\\\\')}", chdir = TRUE, local = TRUE))\n`); + + writeSettings(); + workspace.onDidChangeConfiguration(event => { + if (event.affectsConfiguration('r')) { + writeSettings(); + } + }); } export function startRequestWatcher(sessionStatusBarItem: StatusBarItem): void { @@ -103,6 +110,11 @@ export function removeSessionFiles(): void { console.info('[removeSessionFiles] Done'); } +function writeSettings() { + const settingPath = path.join(homeExtDir(), 'settings.json'); + fs.writeFileSync(settingPath, JSON.stringify(config())); +} + function updateSessionWatcher() { console.info(`[updateSessionWatcher] PID: ${pid}`); console.info('[updateSessionWatcher] Create globalEnvWatcher'); From 9260b6bcd0cd19e892942c7d13cbf238b9530238 Mon Sep 17 00:00:00 2001 From: ElianHugh Date: Fri, 6 Aug 2021 22:27:31 +1000 Subject: [PATCH 06/17] Source vscode settings first --- R/.Rprofile | 66 +++++++++++++++++++++++++++++++++++++++++++++++++ R/getSettings.R | 60 -------------------------------------------- R/init.R | 2 -- 3 files changed, 66 insertions(+), 62 deletions(-) delete mode 100644 R/getSettings.R diff --git a/R/.Rprofile b/R/.Rprofile index 3b25c0d93..2dbb1f58f 100644 --- a/R/.Rprofile +++ b/R/.Rprofile @@ -1,3 +1,69 @@ +# Source VSCode-R options +# * source this first, so that +# * .Rprofile settings are respected +local({ + homedir <- Sys.getenv( + if (.Platform$OS.type == "windows") "USERPROFILE" else "HOME" + ) + + fileCon <- if (file.exists(file.path(homedir, ".vscode-R", "settings.json"))) { + file(file.path(homedir, ".vscode-R", "settings.json")) + } else { + NULL + } + + if (!is.null(fileCon)) { + # settings.json can result in errors if read via fromJSON + vsc_settings <- suppressWarnings( + jsonlite::fromJSON(paste(readLines(fileCon), collapse = ""))[["rOptions"]] + ) + ops <- Reduce(c, vsc_settings) + + # non-string values have to be converted from + # strings due to VSC settings limitations + get_val <- function(x) { + if (is.logical(x)) { + x + } else { + switch(EXPR = x, + "Two" = "Two", + "Active" = "Active", + "Beside" = "Beside", + "FALSE" = FALSE, + "TRUE" = TRUE, + "0" = 0, + "2" = 2, + x + ) + } + } + + lapply(names(ops), function(x) { + val <- get_val(ops[[x]]) + + # lhs = vscode setting name + # rhs name = R options name + switch(EXPR = x, + # arrays + "vsc.plot" = options("vsc.plot" = val), + "vsc.browser" = options("vsc.browser" = val), + "vsc.viewer" = options("vsc.viewer" = val), + "vsc.pageViewer" = options("vsc.page_viewer" = val), + "vsc.view" = options("vsc.view" = val), + "vsc.helpPanel" = options("vsc.helpPanel" = val), + "vsc.strMaxLevel" = options("vsc.str.max.level" = val), + # bools + "vsc.rstudioapi" = options("vsc.rstudioapi" = val), + "vsc.useHttpgd" = options("vsc.use_httpgd" = val), + "vsc.globalEnv" = options("vsc.globalenv" = val), + "vsc.showObjectSize" = options("vsc.show_object_size" = val) + ) + }) + + close(fileCon) + } +}) + # Source the original .Rprofile local({ try_source <- function(file) { diff --git a/R/getSettings.R b/R/getSettings.R deleted file mode 100644 index b6e5d18af..000000000 --- a/R/getSettings.R +++ /dev/null @@ -1,60 +0,0 @@ -homedir <- Sys.getenv( - if (.Platform$OS.type == "windows") "USERPROFILE" else "HOME" -) - -fileCon <- if (file.exists(file.path(homedir, ".vscode-R", "settings.json"))) { - file(file.path(homedir, ".vscode-R", "settings.json")) -} else { - NULL -} - -if (!is.null(fileCon)) { - # settings.json can result in errors if read via fromJSON - vsc_settings <- suppressWarnings( - jsonlite::fromJSON(paste(readLines(fileCon), collapse = ""))[["rOptions"]] - ) - ops <- Reduce(c, vsc_settings) - - # non-string values have to be converted from - # strings due to VSC settings limitations - get_val <- function(x) { - if (is.logical(x)) { - x - } else { - switch(EXPR = x, - "Two" = "Two", - "Active" = "Active", - "Beside" = "Beside", - "FALSE" = FALSE, - "TRUE" = TRUE, - "0" = 0, - "2" = 2, - x - ) - } - } - - lapply(names(ops), function(x) { - val <- get_val(ops[[x]]) - - # lhs = vscode setting name - # rhs name = R options name - switch(EXPR = x, - # arrays - "vsc.plot" = options("vsc.plot" = val), - "vsc.browser" = options("vsc.browser" = val), - "vsc.viewer" = options("vsc.viewer" = val), - "vsc.pageViewer" = options("vsc.page_viewer" = val), - "vsc.view" = options("vsc.view" = val), - "vsc.helpPanel" = options("vsc.helpPanel" = val), - "vsc.strMaxLevel" = options("vsc.str.max.level" = val), - # bools - "vsc.rstudioapi" = options("vsc.rstudioapi" = val), - "vsc.useHttpgd" = options("vsc.use_httpgd" = val), - "vsc.globalEnv" = options("vsc.globalenv" = val), - "vsc.showObjectSize" = options("vsc.show_object_size" = val) - ) - }) - - close(fileCon) -} \ No newline at end of file diff --git a/R/init.R b/R/init.R index d2d095c1e..fa2bddafd 100644 --- a/R/init.R +++ b/R/init.R @@ -104,8 +104,6 @@ init_last <- function() { # Attach to vscode exports$.vsc.attach() - source(file.path(dir_init, "getSettings.R"), local = TRUE) - invisible() } From 89cff2a8258fc878fd600691bbf5d48a4588a369 Mon Sep 17 00:00:00 2001 From: "Elian H. Thiele-Evans" <60372411+ElianHugh@users.noreply.github.com> Date: Sat, 7 Aug 2021 12:07:26 +1000 Subject: [PATCH 07/17] Move import back to init, only replace ops if null --- R/.Rprofile | 66 ----------------------------------------------- R/init.R | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 65 ++++++++++++++++++++++++++++++++++++++++++----- 3 files changed, 130 insertions(+), 73 deletions(-) diff --git a/R/.Rprofile b/R/.Rprofile index 2dbb1f58f..3b25c0d93 100644 --- a/R/.Rprofile +++ b/R/.Rprofile @@ -1,69 +1,3 @@ -# Source VSCode-R options -# * source this first, so that -# * .Rprofile settings are respected -local({ - homedir <- Sys.getenv( - if (.Platform$OS.type == "windows") "USERPROFILE" else "HOME" - ) - - fileCon <- if (file.exists(file.path(homedir, ".vscode-R", "settings.json"))) { - file(file.path(homedir, ".vscode-R", "settings.json")) - } else { - NULL - } - - if (!is.null(fileCon)) { - # settings.json can result in errors if read via fromJSON - vsc_settings <- suppressWarnings( - jsonlite::fromJSON(paste(readLines(fileCon), collapse = ""))[["rOptions"]] - ) - ops <- Reduce(c, vsc_settings) - - # non-string values have to be converted from - # strings due to VSC settings limitations - get_val <- function(x) { - if (is.logical(x)) { - x - } else { - switch(EXPR = x, - "Two" = "Two", - "Active" = "Active", - "Beside" = "Beside", - "FALSE" = FALSE, - "TRUE" = TRUE, - "0" = 0, - "2" = 2, - x - ) - } - } - - lapply(names(ops), function(x) { - val <- get_val(ops[[x]]) - - # lhs = vscode setting name - # rhs name = R options name - switch(EXPR = x, - # arrays - "vsc.plot" = options("vsc.plot" = val), - "vsc.browser" = options("vsc.browser" = val), - "vsc.viewer" = options("vsc.viewer" = val), - "vsc.pageViewer" = options("vsc.page_viewer" = val), - "vsc.view" = options("vsc.view" = val), - "vsc.helpPanel" = options("vsc.helpPanel" = val), - "vsc.strMaxLevel" = options("vsc.str.max.level" = val), - # bools - "vsc.rstudioapi" = options("vsc.rstudioapi" = val), - "vsc.useHttpgd" = options("vsc.use_httpgd" = val), - "vsc.globalEnv" = options("vsc.globalenv" = val), - "vsc.showObjectSize" = options("vsc.show_object_size" = val) - ) - }) - - close(fileCon) - } -}) - # Source the original .Rprofile local({ try_source <- function(file) { diff --git a/R/init.R b/R/init.R index fa2bddafd..256a905be 100644 --- a/R/init.R +++ b/R/init.R @@ -104,6 +104,78 @@ init_last <- function() { # Attach to vscode exports$.vsc.attach() + # Import VSC-R settings + local({ + homedir <- Sys.getenv( + if (.Platform$OS.type == "windows") "USERPROFILE" else "HOME" + ) + + fileCon <- if (file.exists(file.path(homedir, ".vscode-R", "settings.json"))) { + file(file.path(homedir, ".vscode-R", "settings.json")) + } else { + NULL + } + + if (!is.null(fileCon)) { + # settings.json can result in errors if read via fromJSON + vsc_settings <- suppressWarnings( + jsonlite::fromJSON(paste(readLines(fileCon), collapse = ""))[["rOptions"]] + ) + ops <- Reduce(c, vsc_settings) + + # non-string values have to be converted from + # strings due to VSC settings limitations + get_val <- function(x) { + if (is.logical(x)) { + x + } else { + switch(EXPR = x, + "Two" = "Two", + "Active" = "Active", + "Beside" = "Beside", + "FALSE" = FALSE, + "TRUE" = TRUE, + "0" = 0, + "2" = 2, + x + ) + } + } + + setOption <- function(lhs, rhs) { + if (is.null(options()[[lhs]])) { + ops <- list(rhs) + names(ops) <- lhs + options(ops) + } + } + + lapply(names(ops), function(x) { + val <- get_val(ops[[x]]) + + # lhs = vscode setting name + # rhs name = R options name + switch(EXPR = x, + # arrays + "vsc.plot" = setOption("vsc.plot", val), + "vsc.browser" = setOption("vsc.browser", val), + "vsc.viewer" = setOption("vsc.viewer", val), + "vsc.pageViewer" = setOption("vsc.page_viewer", val), + "vsc.view" = setOption("vsc.view", val), + "vsc.helpPanel" = setOption("vsc.helpPanel", val), + "vsc.strMaxLevel" = setOption("vsc.str.max.level", val), + # bools + "vsc.rstudioapi" = setOption("vsc.rstudioapi", val), + "vsc.useHttpgd" = setOption("vsc.use_httpgd", val), + "vsc.globalEnv" = setOption("vsc.globalenv", val), + "vsc.showObjectSize" = setOption("vsc.show_object_size", val) + ) + }) + + close(fileCon) + } + }) + invisible() } diff --git a/package.json b/package.json index a674d133c..bc7065d3f 100644 --- a/package.json +++ b/package.json @@ -1411,7 +1411,7 @@ }, "r.rOptions.bools": { "type": "object", - "markdownDescription": "Toggle vsc bools", + "markdownDescription": "Toggle vsc bools TODO", "default": { "vsc.rstudioapi": false, "vsc.useHttpgd": false, @@ -1421,26 +1421,30 @@ "properties": { "vsc.rstudioapi": { "type": "boolean", - "default": false + "default": false, + "description": "Emulate rstudioapi for addin support" }, "vsc.useHttpgd": { "type": "boolean", - "default": false + "default": false, + "description": "Use the httpgd-based plot viewer" }, - "vsc.globalEnv": { + "vsc.globalenv": { "type": "boolean", - "default": true + "default": true, + "description": "Watch global environment symbols to provide hover and autocompletions" }, "vsc.showObjectSize": { "type": "boolean", - "default": false + "default": false, + "description": "Show object size when hovering over a workspace viewer item" } }, "additionalProperties": false }, "r.rOptions.arrays": { "type": "object", - "markdownDescription": "Set vsc options", + "markdownDescription": "Set vsc options TODO", "default": { "vsc.plot": "Two", "vsc.browser": "Active", @@ -1453,70 +1457,117 @@ "properties": { "vsc.plot": { "type": "string", + "description": "Which view column to show the plot file on graphics update?", "enum": [ "Two", "Active", "Beside", "FALSE" ], + "enumDescriptions": [ + "Display plots in editor group 2.", + "Display plots in the active editor.", + "Display plots beside the active editor.", + "Do not use the VSCode-R plot viewer." + ], "default": "Two" }, "vsc.browser": { "type": "string", + "description": "Which view column to show the WebView triggered by browser (e.g. shiny apps)?", "enum": [ "Two", "Active", "Beside", "FALSE" ], + "enumDescriptions": [ + "Display browser in editor group 2.", + "Display browser in the active editor.", + "Display browser beside the active editor.", + "Do not use the VSCode-R browser." + ], "default": "Active" }, "vsc.viewer": { "type": "string", + "description": "Which view column to show the WebView triggered by viewer (e.g. htmlwidgets)?", "enum": [ "Two", "Active", "Beside", "FALSE" ], + "enumDescriptions": [ + "Display viewer in editor group 2.", + "Display viewer in the active editor.", + "Display viewer beside the active editor.", + "Do not use the VSCode-R viewer." + ], "default": "Two" }, "vsc.pageViewer": { "type": "string", + "description": "Which view column to show the WebView triggered by the page viewer (e.g. profvis)?", "enum": [ "Two", "Active", "Beside", "FALSE" ], + "enumDescriptions": [ + "Display page viewer in editor group 2.", + "Display page viewer in the active editor.", + "Display page viewer beside the active editor.", + "Do not use the VSCode-R page viewer." + ], "default": "Active" }, "vsc.view": { "type": "string", + "description": "Which view column to show the WebView triggered by View()?", "enum": [ "Two", "Active", "Beside", "FALSE" ], + "enumDescriptions": [ + "Display view output in editor group 2.", + "Display view output in the active editor.", + "Display view output beside the active editor.", + "Do not use the VSCode-R view command." + ], "default": "Two" }, "vsc.helpPanel": { "type": "string", + "description": "Which view column to show the WebView triggered by the help panel?", "enum": [ "Two", "Active", "Beside", "FALSE" ], + "enumDescriptions": [ + "Display help panel in editor group 2.", + "Display help panel in the active editor.", + "Display help panel beside the active editor.", + "Do not use the VSCode-R help panel." + ], "default": "Two" }, "vsc.strMaxLevel": { "type": "string", + "description": "How much of the object to show on hover, autocompletion, and in the workspace viewer?", "enum": [ "0", "2" ], + "enumDescriptions": [ + "Display literal values and object types only", + "Display list content, data frame column values, and example values" + ], "default": "0" } }, From 6a88d34aa1fcd3ea83dbcbc5bedaff5e63d450a3 Mon Sep 17 00:00:00 2001 From: "Elian H. Thiele-Evans" <60372411+ElianHugh@users.noreply.github.com> Date: Sat, 7 Aug 2021 16:47:09 +1000 Subject: [PATCH 08/17] Update package.json --- package.json | 88 ++++++++++++++++++++++++++-------------------------- 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/package.json b/package.json index bc7065d3f..1a1e3f546 100644 --- a/package.json +++ b/package.json @@ -1411,7 +1411,7 @@ }, "r.rOptions.bools": { "type": "object", - "markdownDescription": "Toggle vsc bools TODO", + "markdownDescription": "Toggle vsc bools TODO. \n\n\n*Can be overwritten by options defined in a user's `.Rprofile`*", "default": { "vsc.rstudioapi": false, "vsc.useHttpgd": false, @@ -1444,7 +1444,7 @@ }, "r.rOptions.arrays": { "type": "object", - "markdownDescription": "Set vsc options TODO", + "markdownDescription": "Set vsc options TODO. \n\n\n*Can be overwritten by options defined in a user's `.Rprofile`*", "default": { "vsc.plot": "Two", "vsc.browser": "Active", @@ -1458,19 +1458,19 @@ "vsc.plot": { "type": "string", "description": "Which view column to show the plot file on graphics update?", - "enum": [ - "Two", - "Active", - "Beside", - "FALSE" - ], - "enumDescriptions": [ - "Display plots in editor group 2.", - "Display plots in the active editor.", - "Display plots beside the active editor.", - "Do not use the VSCode-R plot viewer." - ], - "default": "Two" + "enum": [ + "Two", + "Active", + "Beside", + "FALSE" + ], + "enumDescriptions": [ + "Display plots in editor group 2.", + "Display plots in the active editor.", + "Display plots beside the active editor.", + "Do not use the VSCode-R plot viewer." + ], + "default": "Two" }, "vsc.browser": { "type": "string", @@ -1482,11 +1482,11 @@ "FALSE" ], "enumDescriptions": [ - "Display browser in editor group 2.", - "Display browser in the active editor.", - "Display browser beside the active editor.", - "Do not use the VSCode-R browser." - ], + "Display browser in editor group 2.", + "Display browser in the active editor.", + "Display browser beside the active editor.", + "Do not use the VSCode-R browser." + ], "default": "Active" }, "vsc.viewer": { @@ -1499,11 +1499,11 @@ "FALSE" ], "enumDescriptions": [ - "Display viewer in editor group 2.", - "Display viewer in the active editor.", - "Display viewer beside the active editor.", - "Do not use the VSCode-R viewer." - ], + "Display viewer in editor group 2.", + "Display viewer in the active editor.", + "Display viewer beside the active editor.", + "Do not use the VSCode-R viewer." + ], "default": "Two" }, "vsc.pageViewer": { @@ -1516,11 +1516,11 @@ "FALSE" ], "enumDescriptions": [ - "Display page viewer in editor group 2.", - "Display page viewer in the active editor.", - "Display page viewer beside the active editor.", - "Do not use the VSCode-R page viewer." - ], + "Display page viewer in editor group 2.", + "Display page viewer in the active editor.", + "Display page viewer beside the active editor.", + "Do not use the VSCode-R page viewer." + ], "default": "Active" }, "vsc.view": { @@ -1533,11 +1533,11 @@ "FALSE" ], "enumDescriptions": [ - "Display view output in editor group 2.", - "Display view output in the active editor.", - "Display view output beside the active editor.", - "Do not use the VSCode-R view command." - ], + "Display view output in editor group 2.", + "Display view output in the active editor.", + "Display view output beside the active editor.", + "Do not use the VSCode-R view command." + ], "default": "Two" }, "vsc.helpPanel": { @@ -1550,11 +1550,11 @@ "FALSE" ], "enumDescriptions": [ - "Display help panel in editor group 2.", - "Display help panel in the active editor.", - "Display help panel beside the active editor.", - "Do not use the VSCode-R help panel." - ], + "Display help panel in editor group 2.", + "Display help panel in the active editor.", + "Display help panel beside the active editor.", + "Do not use the VSCode-R help panel." + ], "default": "Two" }, "vsc.strMaxLevel": { @@ -1565,9 +1565,9 @@ "2" ], "enumDescriptions": [ - "Display literal values and object types only", - "Display list content, data frame column values, and example values" - ], + "Display literal values and object types only", + "Display list content, data frame column values, and example values" + ], "default": "0" } }, @@ -1646,4 +1646,4 @@ "ws": "^7.4.6", "vscode-languageclient": "^7.0.0" } -} +} \ No newline at end of file From ba560940aa544ada43ec2f4819203a6d1d688c6d Mon Sep 17 00:00:00 2001 From: "Elian H. Thiele-Evans" <60372411+ElianHugh@users.noreply.github.com> Date: Tue, 10 Aug 2021 10:43:19 +1000 Subject: [PATCH 09/17] Descriptive names, move settings under categories --- R/init.R | 47 ++++++--- package.json | 276 ++++++++++++++++++++++++--------------------------- 2 files changed, 163 insertions(+), 160 deletions(-) diff --git a/R/init.R b/R/init.R index 256a905be..37eb29ee5 100644 --- a/R/init.R +++ b/R/init.R @@ -117,11 +117,27 @@ init_last <- function() { } if (!is.null(fileCon)) { + rSettings <- c( + "plot.useHttpgd", + "workspaceViewer.showObjectSize", + "session.emulateRStudioAPI", + "session.levelOfObjectDetail", + "session.watchGlobalEnvironment", + "session.viewers.Plot Column", + "session.viewers.Browser Column", + "session.viewers.Viewer Column", + "session.viewers.Page Viewer Column", + "session.viewers.View Column", + "session.viewers.Help Panel Column" + ) + # settings.json can result in errors if read via fromJSON vsc_settings <- suppressWarnings( - jsonlite::fromJSON(paste(readLines(fileCon), collapse = ""))[["rOptions"]] + unlist( + jsonlite::fromJSON(paste(readLines(fileCon), collapse = "")) + ) ) - ops <- Reduce(c, vsc_settings) + ops <- na.omit(vsc_settings[rSettings]) # non-string values have to be converted from # strings due to VSC settings limitations @@ -133,10 +149,11 @@ init_last <- function() { "Two" = "Two", "Active" = "Active", "Beside" = "Beside", + "Disable" = FALSE, "FALSE" = FALSE, "TRUE" = TRUE, - "0" = 0, - "2" = 2, + "Minimal" = 0, + "Detailed" = 2, x ) } @@ -157,18 +174,18 @@ init_last <- function() { # rhs name = R options name switch(EXPR = x, # arrays - "vsc.plot" = setOption("vsc.plot", val), - "vsc.browser" = setOption("vsc.browser", val), - "vsc.viewer" = setOption("vsc.viewer", val), - "vsc.pageViewer" = setOption("vsc.page_viewer", val), - "vsc.view" = setOption("vsc.view", val), - "vsc.helpPanel" = setOption("vsc.helpPanel", val), - "vsc.strMaxLevel" = setOption("vsc.str.max.level", val), + `session.viewers.Plot Column` = setOption("vsc.plot", val), + `session.viewers.Browser Column` = setOption("vsc.browser", val), + `session.viewers.Viewer Column` = setOption("vsc.viewer", val), + `session.viewers.Page Viewer Column` = setOption("vsc.page_viewer", val), + `session.viewers.View Column` = setOption("vsc.view", val), + `session.viewers.Help Panel Column` = setOption("vsc.helpPanel", val), + `session.levelOfObjectDetail` = setOption("vsc.str.max.level", val), # bools - "vsc.rstudioapi" = setOption("vsc.rstudioapi", val), - "vsc.useHttpgd" = setOption("vsc.use_httpgd", val), - "vsc.globalEnv" = setOption("vsc.globalenv", val), - "vsc.showObjectSize" = setOption("vsc.show_object_size", val) + `plot.useHttpgd` = setOption("vsc.use_httpgd", val), + `session.emulateRStudioAPI` = setOption("vsc.rstudioapi", val), + `session.watchGlobalEnvironment` = setOption("vsc.globalenv", val), + `workspaceViewer.showObjectSize` = setOption("vsc.show_object_size", val) ) }) diff --git a/package.json b/package.json index 1a1e3f546..d9641d4dc 100644 --- a/package.json +++ b/package.json @@ -1326,143 +1326,49 @@ "default": true, "description": "Enable R session watcher. Required for workspace viewer and most features to work with an R session. Restart required to take effect." }, - "r.rtermSendDelay": { - "type": "integer", - "default": 8, - "description": "Delay in milliseconds before sending each line to rterm (only applies if r.bracketedPaste is false)" - }, - "r.workspaceViewer.removeHiddenItems": { - "type": "boolean", - "default": false, - "description": "Remove hidden items when clearing workspace." - }, - "r.workspaceViewer.clearPrompt": { + "r.session.watchGlobalEnvironment": { "type": "boolean", "default": true, - "description": "Prompt the user for confirmation when clearing the workspace." + "markdownDescription": "Watch the global environment to provide hover, autocompletions, and workspace viewer information. Changes the option `vsc.globalenv` in R. Requires `#r.sessionWatcher#` to be set to `true`." }, - "r.liveShare.timeout": { - "type": "integer", - "default": 10000, - "description": "Time in milliseconds before aborting attempt to connect to Live Share API" - }, - "r.liveShare.defaults.commandForward": { - "type": "boolean", - "default": false, - "description": "Default boolean value for guest command forwarding." - }, - "r.liveShare.defaults.shareWorkspace": { - "type": "boolean", - "default": true, - "description": "Default boolean value for sharing the R workspace with guests." - }, - "r.liveShare.defaults.shareBrowser": { - "type": "boolean", - "default": false, - "description": "Default boolean value for automatically sharing R browser ports with guests." - }, - "r.plot.defaults.colorTheme": { + "r.session.levelOfObjectDetail": { "type": "string", - "default": "original", + "markdownDescription": "How much of the object to show on hover, autocompletion, and in the workspace viewer? Changes the option `vsc.str.max.level` in R. Requires `#r.sessionWatcher#` to be set to `true`.", + "default": "Minimal", "enum": [ - "vscode", - "original" - ], - "markdownEnumDescriptions": [ - "Match background and primary stroke color to the current color theme (Or apply custom CSS overwrites, if specified in `#r.plot.customStyleOverwrites#`)", - "Use original colors" - ], - "markdownDescription": "Which color theme to use when launching the plot viewer." - }, - "r.plot.defaults.plotPreviewLayout": { - "type": "string", - "default": "multirow", - "enum": [ - "multirow", - "scroll", - "hidden" + "Minimal", + "Detailed" ], "enumDescriptions": [ - "Show in multiple rows", - "Show scrollbar", - "Don't show preview plots" - ], - "markdownDescription": "How to display plot previews if more than one row required." + "Display literal values and object types only", + "Display list content, data frame column values, and example values" + ] }, - "r.plot.defaults.fullWindowMode": { + "r.session.emulateRStudioAPI": { "type": "boolean", "default": false, - "markdownDescription": "Whether to use full window mode when launching the plot viewer." - }, - "r.plot.timing.resizeInterval": { - "type": "number", - "default": 100, - "markdownDescription": "Interval in ms to wait between plot resizes." - }, - "r.plot.timing.refreshInterval": { - "type": "number", - "default": 10, - "markdownDescription": "Interval in ms to wait between plot refreshs." + "markdownDescription": "Emulate the RStudio API for addin support and other {rstudioapi} calls. Changes the option `vsc.rstudioapi` in R.Requires `#r.sessionWatcher#` to be set to `true`." }, - "r.plot.customStyleOverwrites": { - "type": "string", - "default": "", - "markdownDescription": "Path to a custom CSS file to be used when `#r.plot.defaults.colorTheme#` is `vscode`. Replaces the default CSS overwrites!" - }, - "r.rOptions.bools": { - "type": "object", - "markdownDescription": "Toggle vsc bools TODO. \n\n\n*Can be overwritten by options defined in a user's `.Rprofile`*", - "default": { - "vsc.rstudioapi": false, - "vsc.useHttpgd": false, - "vsc.globalenv": true, - "vsc.showObjectSize": false - }, - "properties": { - "vsc.rstudioapi": { - "type": "boolean", - "default": false, - "description": "Emulate rstudioapi for addin support" - }, - "vsc.useHttpgd": { - "type": "boolean", - "default": false, - "description": "Use the httpgd-based plot viewer" - }, - "vsc.globalenv": { - "type": "boolean", - "default": true, - "description": "Watch global environment symbols to provide hover and autocompletions" - }, - "vsc.showObjectSize": { - "type": "boolean", - "default": false, - "description": "Show object size when hovering over a workspace viewer item" - } - }, - "additionalProperties": false - }, - "r.rOptions.arrays": { + "r.session.viewers": { "type": "object", - "markdownDescription": "Set vsc options TODO. \n\n\n*Can be overwritten by options defined in a user's `.Rprofile`*", + "markdownDescription": "Set vsc options TODO. Requires `#r.sessionWatcher#` to be set to `true`.", "default": { - "vsc.plot": "Two", - "vsc.browser": "Active", - "vsc.viewer": "Two", - "vsc.pageViewer": "Active", - "vsc.view": "Two", - "vsc.helpPanel": "Two", - "vsc.strMaxLevel": "0" + "Plot Column": "Two", + "Browser Column": "Active", + "Viewer Column": "Two", + "Page Viewer Column": "Active", + "View Column": "Two", + "Help Panel Column": "Two" }, "properties": { - "vsc.plot": { + "Plot Column": { "type": "string", - "description": "Which view column to show the plot file on graphics update?", + "description": "Which view column to show the plot file on graphics update? \n\nChanges the option 'vsc.plot' in R", "enum": [ "Two", "Active", "Beside", - "FALSE" + "Disable" ], "enumDescriptions": [ "Display plots in editor group 2.", @@ -1472,14 +1378,14 @@ ], "default": "Two" }, - "vsc.browser": { + "Browser Column": { "type": "string", - "description": "Which view column to show the WebView triggered by browser (e.g. shiny apps)?", + "description": "Which view column to show the WebView triggered by browser (e.g. shiny apps)? \n\nChanges the option 'vsc.browser' in R", "enum": [ "Two", "Active", "Beside", - "FALSE" + "Disable" ], "enumDescriptions": [ "Display browser in editor group 2.", @@ -1489,14 +1395,14 @@ ], "default": "Active" }, - "vsc.viewer": { + "Viewer Column": { "type": "string", - "description": "Which view column to show the WebView triggered by viewer (e.g. htmlwidgets)?", + "description": "Which view column to show the WebView triggered by viewer (e.g. htmlwidgets)? \n\nChanges the option 'vsc.viewer' in R.", "enum": [ "Two", "Active", "Beside", - "FALSE" + "Disable" ], "enumDescriptions": [ "Display viewer in editor group 2.", @@ -1506,14 +1412,14 @@ ], "default": "Two" }, - "vsc.pageViewer": { + "Page Viewer Column": { "type": "string", - "description": "Which view column to show the WebView triggered by the page viewer (e.g. profvis)?", + "description": "Which view column to show the WebView triggered by the page viewer (e.g. profvis)? \n\nChanges the option 'vsc.page_viewer' in R.", "enum": [ "Two", "Active", "Beside", - "FALSE" + "Disable" ], "enumDescriptions": [ "Display page viewer in editor group 2.", @@ -1523,14 +1429,14 @@ ], "default": "Active" }, - "vsc.view": { + "View Column": { "type": "string", - "description": "Which view column to show the WebView triggered by View()?", + "description": "Which view column to show the WebView triggered by View()? \n\nChanges the option 'vsc.plot' in R.", "enum": [ "Two", "Active", "Beside", - "FALSE" + "Disable" ], "enumDescriptions": [ "Display view output in editor group 2.", @@ -1540,14 +1446,14 @@ ], "default": "Two" }, - "vsc.helpPanel": { + "Help Panel Column": { "type": "string", - "description": "Which view column to show the WebView triggered by the help panel?", + "description": "Which view column to show the WebView triggered by the help panel? \n\nChanges the option 'vsc.help_panel' in R", "enum": [ "Two", "Active", "Beside", - "FALSE" + "Disable" ], "enumDescriptions": [ "Display help panel in editor group 2.", @@ -1556,22 +1462,102 @@ "Do not use the VSCode-R help panel." ], "default": "Two" - }, - "vsc.strMaxLevel": { - "type": "string", - "description": "How much of the object to show on hover, autocompletion, and in the workspace viewer?", - "enum": [ - "0", - "2" - ], - "enumDescriptions": [ - "Display literal values and object types only", - "Display list content, data frame column values, and example values" - ], - "default": "0" } }, "additionalProperties": false + }, + "r.rtermSendDelay": { + "type": "integer", + "default": 8, + "description": "Delay in milliseconds before sending each line to rterm (only applies if r.bracketedPaste is false)" + }, + "r.workspaceViewer.showObjectSize": { + "type": "boolean", + "default": false, + "description": "Show object size when hovering over a workspace viewer item \n\nChanges the option `vsc.show_object_size` in R." + }, + "r.workspaceViewer.removeHiddenItems": { + "type": "boolean", + "default": false, + "description": "Remove hidden items when clearing workspace." + }, + "r.workspaceViewer.clearPrompt": { + "type": "boolean", + "default": true, + "description": "Prompt the user for confirmation when clearing the workspace." + }, + "r.liveShare.timeout": { + "type": "integer", + "default": 10000, + "description": "Time in milliseconds before aborting attempt to connect to Live Share API" + }, + "r.liveShare.defaults.commandForward": { + "type": "boolean", + "default": false, + "description": "Default boolean value for guest command forwarding." + }, + "r.liveShare.defaults.shareWorkspace": { + "type": "boolean", + "default": true, + "description": "Default boolean value for sharing the R workspace with guests." + }, + "r.liveShare.defaults.shareBrowser": { + "type": "boolean", + "default": false, + "description": "Default boolean value for automatically sharing R browser ports with guests." + }, + "r.plot.useHttpgd": { + "type": "boolean", + "default": false, + "description": "Use the httpgd-based plot viewer instead of the base VSCode-R plot viewer \n\nChanges the option 'vsc.use_httpgd' in R" + }, + "r.plot.defaults.colorTheme": { + "type": "string", + "default": "original", + "enum": [ + "vscode", + "original" + ], + "markdownEnumDescriptions": [ + "Match background and primary stroke color to the current color theme (Or apply custom CSS overwrites, if specified in `#r.plot.customStyleOverwrites#`)", + "Use original colors" + ], + "markdownDescription": "Which color theme to use when launching the plot viewer." + }, + "r.plot.defaults.plotPreviewLayout": { + "type": "string", + "default": "multirow", + "enum": [ + "multirow", + "scroll", + "hidden" + ], + "enumDescriptions": [ + "Show in multiple rows", + "Show scrollbar", + "Don't show preview plots" + ], + "markdownDescription": "How to display plot previews if more than one row required." + }, + "r.plot.defaults.fullWindowMode": { + "type": "boolean", + "default": false, + "markdownDescription": "Whether to use full window mode when launching the plot viewer." + }, + "r.plot.timing.resizeInterval": { + "type": "number", + "default": 100, + "markdownDescription": "Interval in ms to wait between plot resizes." + }, + "r.plot.timing.refreshInterval": { + "type": "number", + "default": 10, + "markdownDescription": "Interval in ms to wait between plot refreshs." + }, + "r.plot.customStyleOverwrites": { + "type": "string", + "default": "", + "markdownDescription": "Path to a custom CSS file to be used when `#r.plot.defaults.colorTheme#` is `vscode`. Replaces the default CSS overwrites!" } } }, From 61cbd66916464ac01889193113c2ab1d1ff885b8 Mon Sep 17 00:00:00 2001 From: ElianHugh Date: Tue, 10 Aug 2021 14:51:45 +1000 Subject: [PATCH 10/17] Change setting names --- R/init.R | 24 ++++++++++++------------ package.json | 30 +++++++++++++++--------------- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/R/init.R b/R/init.R index 37eb29ee5..a6555548b 100644 --- a/R/init.R +++ b/R/init.R @@ -123,12 +123,12 @@ init_last <- function() { "session.emulateRStudioAPI", "session.levelOfObjectDetail", "session.watchGlobalEnvironment", - "session.viewers.Plot Column", - "session.viewers.Browser Column", - "session.viewers.Viewer Column", - "session.viewers.Page Viewer Column", - "session.viewers.View Column", - "session.viewers.Help Panel Column" + "session.viewers.viewColumn.plot", + "session.viewers.viewColumn.browser", + "session.viewers.viewColumn.viewer", + "session.viewers.viewColumn.pageViewer", + "session.viewers.viewColumn.view", + "session.viewers.viewColumn.helpPanel " ) # settings.json can result in errors if read via fromJSON @@ -174,12 +174,12 @@ init_last <- function() { # rhs name = R options name switch(EXPR = x, # arrays - `session.viewers.Plot Column` = setOption("vsc.plot", val), - `session.viewers.Browser Column` = setOption("vsc.browser", val), - `session.viewers.Viewer Column` = setOption("vsc.viewer", val), - `session.viewers.Page Viewer Column` = setOption("vsc.page_viewer", val), - `session.viewers.View Column` = setOption("vsc.view", val), - `session.viewers.Help Panel Column` = setOption("vsc.helpPanel", val), + `session.viewers.viewColumn.plot` = setOption("vsc.plot", val), + `session.viewers.viewColumn.browser` = setOption("vsc.browser", val), + `session.viewers.viewColumn.viewer` = setOption("vsc.viewer", val), + `session.viewers.viewColumn.pageViewer` = setOption("vsc.page_viewer", val), + `session.viewers.viewColumn.view` = setOption("vsc.view", val), + `session.viewers.viewColumn.helpPanel` = setOption("vsc.helpPanel", val), `session.levelOfObjectDetail` = setOption("vsc.str.max.level", val), # bools `plot.useHttpgd` = setOption("vsc.use_httpgd", val), diff --git a/package.json b/package.json index d9641d4dc..553261ef6 100644 --- a/package.json +++ b/package.json @@ -1349,19 +1349,19 @@ "default": false, "markdownDescription": "Emulate the RStudio API for addin support and other {rstudioapi} calls. Changes the option `vsc.rstudioapi` in R.Requires `#r.sessionWatcher#` to be set to `true`." }, - "r.session.viewers": { + "r.session.viewers.viewColumn": { "type": "object", "markdownDescription": "Set vsc options TODO. Requires `#r.sessionWatcher#` to be set to `true`.", "default": { - "Plot Column": "Two", - "Browser Column": "Active", - "Viewer Column": "Two", - "Page Viewer Column": "Active", - "View Column": "Two", - "Help Panel Column": "Two" + "plot": "Two", + "browser": "Active", + "viewer": "Two", + "pageViewer": "Active", + "view": "Two", + "helpPanel": "Two" }, "properties": { - "Plot Column": { + "plot": { "type": "string", "description": "Which view column to show the plot file on graphics update? \n\nChanges the option 'vsc.plot' in R", "enum": [ @@ -1378,7 +1378,7 @@ ], "default": "Two" }, - "Browser Column": { + "browser": { "type": "string", "description": "Which view column to show the WebView triggered by browser (e.g. shiny apps)? \n\nChanges the option 'vsc.browser' in R", "enum": [ @@ -1395,7 +1395,7 @@ ], "default": "Active" }, - "Viewer Column": { + "viewer": { "type": "string", "description": "Which view column to show the WebView triggered by viewer (e.g. htmlwidgets)? \n\nChanges the option 'vsc.viewer' in R.", "enum": [ @@ -1412,7 +1412,7 @@ ], "default": "Two" }, - "Page Viewer Column": { + "pageViewer": { "type": "string", "description": "Which view column to show the WebView triggered by the page viewer (e.g. profvis)? \n\nChanges the option 'vsc.page_viewer' in R.", "enum": [ @@ -1429,7 +1429,7 @@ ], "default": "Active" }, - "View Column": { + "view": { "type": "string", "description": "Which view column to show the WebView triggered by View()? \n\nChanges the option 'vsc.plot' in R.", "enum": [ @@ -1446,7 +1446,7 @@ ], "default": "Two" }, - "Help Panel Column": { + "helpPanel": { "type": "string", "description": "Which view column to show the WebView triggered by the help panel? \n\nChanges the option 'vsc.help_panel' in R", "enum": [ @@ -1474,7 +1474,7 @@ "r.workspaceViewer.showObjectSize": { "type": "boolean", "default": false, - "description": "Show object size when hovering over a workspace viewer item \n\nChanges the option `vsc.show_object_size` in R." + "markdownDescription": "Show object size when hovering over a workspace viewer item. Changes the option `vsc.show_object_size` in R." }, "r.workspaceViewer.removeHiddenItems": { "type": "boolean", @@ -1509,7 +1509,7 @@ "r.plot.useHttpgd": { "type": "boolean", "default": false, - "description": "Use the httpgd-based plot viewer instead of the base VSCode-R plot viewer \n\nChanges the option 'vsc.use_httpgd' in R" + "markdownDescription": "Use the httpgd-based plot viewer instead of the base VSCode-R plot viewer. Changes the option `vsc.use_httpgd` in R." }, "r.plot.defaults.colorTheme": { "type": "string", From 18a3e8c05d864864d9c977b035f545460ea6b93d Mon Sep 17 00:00:00 2001 From: Kun Ren Date: Wed, 11 Aug 2021 00:47:48 +0800 Subject: [PATCH 11/17] Load settings before attach --- R/init.R | 90 -------------------------------------------------------- R/vsc.R | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+), 90 deletions(-) diff --git a/R/init.R b/R/init.R index a6555548b..cd6b67065 100644 --- a/R/init.R +++ b/R/init.R @@ -100,99 +100,9 @@ init_last <- function() { rm(".First.sys", envir = globalenv()) ) - # Attach to vscode exports$.vsc.attach() - # Import VSC-R settings - local({ - homedir <- Sys.getenv( - if (.Platform$OS.type == "windows") "USERPROFILE" else "HOME" - ) - - fileCon <- if (file.exists(file.path(homedir, ".vscode-R", "settings.json"))) { - file(file.path(homedir, ".vscode-R", "settings.json")) - } else { - NULL - } - - if (!is.null(fileCon)) { - rSettings <- c( - "plot.useHttpgd", - "workspaceViewer.showObjectSize", - "session.emulateRStudioAPI", - "session.levelOfObjectDetail", - "session.watchGlobalEnvironment", - "session.viewers.viewColumn.plot", - "session.viewers.viewColumn.browser", - "session.viewers.viewColumn.viewer", - "session.viewers.viewColumn.pageViewer", - "session.viewers.viewColumn.view", - "session.viewers.viewColumn.helpPanel " - ) - - # settings.json can result in errors if read via fromJSON - vsc_settings <- suppressWarnings( - unlist( - jsonlite::fromJSON(paste(readLines(fileCon), collapse = "")) - ) - ) - ops <- na.omit(vsc_settings[rSettings]) - - # non-string values have to be converted from - # strings due to VSC settings limitations - get_val <- function(x) { - if (is.logical(x)) { - x - } else { - switch(EXPR = x, - "Two" = "Two", - "Active" = "Active", - "Beside" = "Beside", - "Disable" = FALSE, - "FALSE" = FALSE, - "TRUE" = TRUE, - "Minimal" = 0, - "Detailed" = 2, - x - ) - } - } - - setOption <- function(lhs, rhs) { - if (is.null(options()[[lhs]])) { - ops <- list(rhs) - names(ops) <- lhs - options(ops) - } - } - - lapply(names(ops), function(x) { - val <- get_val(ops[[x]]) - - # lhs = vscode setting name - # rhs name = R options name - switch(EXPR = x, - # arrays - `session.viewers.viewColumn.plot` = setOption("vsc.plot", val), - `session.viewers.viewColumn.browser` = setOption("vsc.browser", val), - `session.viewers.viewColumn.viewer` = setOption("vsc.viewer", val), - `session.viewers.viewColumn.pageViewer` = setOption("vsc.page_viewer", val), - `session.viewers.viewColumn.view` = setOption("vsc.view", val), - `session.viewers.viewColumn.helpPanel` = setOption("vsc.helpPanel", val), - `session.levelOfObjectDetail` = setOption("vsc.str.max.level", val), - # bools - `plot.useHttpgd` = setOption("vsc.use_httpgd", val), - `session.emulateRStudioAPI` = setOption("vsc.rstudioapi", val), - `session.watchGlobalEnvironment` = setOption("vsc.globalenv", val), - `workspaceViewer.showObjectSize` = setOption("vsc.show_object_size", val) - ) - }) - - close(fileCon) - } - }) - invisible() } diff --git a/R/vsc.R b/R/vsc.R index 3b3889b73..c693b4156 100644 --- a/R/vsc.R +++ b/R/vsc.R @@ -7,6 +7,91 @@ homedir <- Sys.getenv( dir_watcher <- Sys.getenv("VSCODE_WATCHER_DIR", file.path(homedir, ".vscode-R")) request_file <- file.path(dir_watcher, "request.log") request_lock_file <- file.path(dir_watcher, "request.lock") +settings_file <- file.path(dir_watcher, "settings.json") +user_options <- names(options()) + +load_settings <- function() { + if (!file.exists(settings_file)) { + return(FALSE) + } + + rSettings <- c( + "plot.useHttpgd", + "workspaceViewer.showObjectSize", + "session.emulateRStudioAPI", + "session.levelOfObjectDetail", + "session.watchGlobalEnvironment", + "session.viewers.viewColumn.plot", + "session.viewers.viewColumn.browser", + "session.viewers.viewColumn.viewer", + "session.viewers.viewColumn.pageViewer", + "session.viewers.viewColumn.view", + "session.viewers.viewColumn.helpPanel " + ) + + # settings.json can result in errors if read via fromJSON + vsc_settings <- suppressWarnings( + unlist( + jsonlite::fromJSON(paste(readLines(settings_file), collapse = "")) + ) + ) + ops <- na.omit(vsc_settings[rSettings]) + + # non-string values have to be converted from + # strings due to VSC settings limitations + get_val <- function(x) { + if (is.logical(x)) { + x + } else { + switch(EXPR = x, + "Two" = "Two", + "Active" = "Active", + "Beside" = "Beside", + "Disable" = FALSE, + "FALSE" = FALSE, + "TRUE" = TRUE, + "Minimal" = 0, + "Detailed" = 2, + x + ) + } + } + + setOption <- function(lhs, rhs) { + if (!(lhs %in% user_options)) { + ops <- list(rhs) + names(ops) <- lhs + options(ops) + } + } + + lapply(names(ops), function(x) { + val <- get_val(ops[[x]]) + + # lhs = vscode setting name + # rhs name = R options name + switch(EXPR = x, + # arrays + `session.viewers.viewColumn.plot` = setOption("vsc.plot", val), + `session.viewers.viewColumn.browser` = setOption("vsc.browser", val), + `session.viewers.viewColumn.viewer` = setOption("vsc.viewer", val), + `session.viewers.viewColumn.pageViewer` = setOption("vsc.page_viewer", val), + `session.viewers.viewColumn.view` = setOption("vsc.view", val), + `session.viewers.viewColumn.helpPanel` = setOption("vsc.helpPanel", val), + `session.levelOfObjectDetail` = setOption("vsc.str.max.level", val), + # bools + `plot.useHttpgd` = setOption("vsc.use_httpgd", val), + `session.emulateRStudioAPI` = setOption("vsc.rstudioapi", val), + `session.watchGlobalEnvironment` = setOption("vsc.globalenv", val), + `workspaceViewer.showObjectSize` = setOption("vsc.show_object_size", val) + ) + NULL + }) + + options() +} + +load_settings() if (is.null(getOption("help_type"))) { options(help_type = "html") @@ -396,6 +481,7 @@ if (show_view) { } attach <- function() { + load_settings() if (rstudioapi_enabled()) { rstudioapi_util_env$update_addin_registry(addin_registry) } From 7653afa0b35862abe29e040923c290fbdd297bb6 Mon Sep 17 00:00:00 2001 From: Kun Ren Date: Wed, 11 Aug 2021 09:31:34 +0800 Subject: [PATCH 12/17] Refine load_settings --- R/vsc.R | 99 +++++++++++++++++++++------------------------------------ 1 file changed, 36 insertions(+), 63 deletions(-) diff --git a/R/vsc.R b/R/vsc.R index c693b4156..4a6d8fa2d 100644 --- a/R/vsc.R +++ b/R/vsc.R @@ -15,80 +15,53 @@ load_settings <- function() { return(FALSE) } - rSettings <- c( - "plot.useHttpgd", - "workspaceViewer.showObjectSize", - "session.emulateRStudioAPI", - "session.levelOfObjectDetail", - "session.watchGlobalEnvironment", - "session.viewers.viewColumn.plot", - "session.viewers.viewColumn.browser", - "session.viewers.viewColumn.viewer", - "session.viewers.viewColumn.pageViewer", - "session.viewers.viewColumn.view", - "session.viewers.viewColumn.helpPanel " + mapping <- c( + "plot.useHttpgd" = "vsc.use_httpgd", + "workspaceViewer.showObjectSize" = "vsc.show_object_size", + "session.emulateRStudioAPI" = "vsc.rstudioapi", + "session.levelOfObjectDetail" = "vsc.str.max.level", + "session.watchGlobalEnvironment" = "vsc.globalenv", + "session.viewers.viewColumn.plot" = "vsc.plot", + "session.viewers.viewColumn.browser" = "vsc.browser", + "session.viewers.viewColumn.viewer" = "vsc.viewer", + "session.viewers.viewColumn.pageViewer" = "vsc.page_viewer", + "session.viewers.viewColumn.view" = "vsc.view", + "session.viewers.viewColumn.helpPanel" = "vsc.helpPanel" ) - # settings.json can result in errors if read via fromJSON - vsc_settings <- suppressWarnings( - unlist( - jsonlite::fromJSON(paste(readLines(settings_file), collapse = "")) - ) - ) - ops <- na.omit(vsc_settings[rSettings]) + vsc_settings <- tryCatch(jsonlite::read_json(settings_file), error = function(e) { + message("Error occurs when reading VS Code settings: ", conditionMessage(e)) + }) - # non-string values have to be converted from - # strings due to VSC settings limitations - get_val <- function(x) { - if (is.logical(x)) { - x - } else { - switch(EXPR = x, - "Two" = "Two", - "Active" = "Active", - "Beside" = "Beside", - "Disable" = FALSE, - "FALSE" = FALSE, - "TRUE" = TRUE, - "Minimal" = 0, - "Detailed" = 2, - x - ) - } + if (is.null(vsc_settings)) { + return(FALSE) } - setOption <- function(lhs, rhs) { - if (!(lhs %in% user_options)) { - ops <- list(rhs) - names(ops) <- lhs - options(ops) - } - } + vsc_settings <- as.character(unlist(vsc_settings)) + ops <- vsc_settings[names(vsc_settings) %in% names(mapping)] + + # map VS Code settings to R options + names(ops) <- mapping[names(ops)] - lapply(names(ops), function(x) { - val <- get_val(ops[[x]]) + # exclude options set by user on startup + ops <- ops[!(names(ops) %in% user_options)] - # lhs = vscode setting name - # rhs name = R options name + # translate VS Code setting values to R option values + r_options <- lapply(ops, function(x) { switch(EXPR = x, - # arrays - `session.viewers.viewColumn.plot` = setOption("vsc.plot", val), - `session.viewers.viewColumn.browser` = setOption("vsc.browser", val), - `session.viewers.viewColumn.viewer` = setOption("vsc.viewer", val), - `session.viewers.viewColumn.pageViewer` = setOption("vsc.page_viewer", val), - `session.viewers.viewColumn.view` = setOption("vsc.view", val), - `session.viewers.viewColumn.helpPanel` = setOption("vsc.helpPanel", val), - `session.levelOfObjectDetail` = setOption("vsc.str.max.level", val), - # bools - `plot.useHttpgd` = setOption("vsc.use_httpgd", val), - `session.emulateRStudioAPI` = setOption("vsc.rstudioapi", val), - `session.watchGlobalEnvironment` = setOption("vsc.globalenv", val), - `workspaceViewer.showObjectSize` = setOption("vsc.show_object_size", val) + "Two" = "Two", + "Active" = "Active", + "Beside" = "Beside", + "Disable" = FALSE, + "FALSE" = FALSE, + "TRUE" = TRUE, + "Minimal" = 0, + "Detailed" = 2, + x ) - NULL }) - options() + options(r_options) } load_settings() From c7b74901e4d56a684a4131202f772588c60b2956 Mon Sep 17 00:00:00 2001 From: Kun Ren Date: Wed, 11 Aug 2021 09:34:41 +0800 Subject: [PATCH 13/17] Fix --- R/vsc.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/vsc.R b/R/vsc.R index 4a6d8fa2d..bc7c71e15 100644 --- a/R/vsc.R +++ b/R/vsc.R @@ -37,7 +37,7 @@ load_settings <- function() { return(FALSE) } - vsc_settings <- as.character(unlist(vsc_settings)) + vsc_settings <- unlist(vsc_settings) ops <- vsc_settings[names(vsc_settings) %in% names(mapping)] # map VS Code settings to R options From 002b1e91c35575e000338f3ed9d56457f826a8f8 Mon Sep 17 00:00:00 2001 From: "Elian H. Thiele-Evans" <60372411+ElianHugh@users.noreply.github.com> Date: Wed, 11 Aug 2021 14:00:21 +1000 Subject: [PATCH 14/17] Update viewColumn setting Update the viewColumn item's description --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 553261ef6..56f53eb95 100644 --- a/package.json +++ b/package.json @@ -1351,7 +1351,7 @@ }, "r.session.viewers.viewColumn": { "type": "object", - "markdownDescription": "Set vsc options TODO. Requires `#r.sessionWatcher#` to be set to `true`.", + "markdownDescription": "which view column should R-related webviews be displayed?. Requires `#r.sessionWatcher#` to be set to `true`.", "default": { "plot": "Two", "browser": "Active", From a32e6d9cb498bd45ad1efe0a7c66c576e4fa1ef7 Mon Sep 17 00:00:00 2001 From: Manuel Hentschel <53863351+ManuelHentschel@users.noreply.github.com> Date: Wed, 11 Aug 2021 11:12:53 +0200 Subject: [PATCH 15/17] Minor typos --- package.json | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 56f53eb95..3bfe79637 100644 --- a/package.json +++ b/package.json @@ -1340,18 +1340,18 @@ "Detailed" ], "enumDescriptions": [ - "Display literal values and object types only", - "Display list content, data frame column values, and example values" + "Display literal values and object types only.", + "Display list content, data frame column values, and example values." ] }, "r.session.emulateRStudioAPI": { "type": "boolean", "default": false, - "markdownDescription": "Emulate the RStudio API for addin support and other {rstudioapi} calls. Changes the option `vsc.rstudioapi` in R.Requires `#r.sessionWatcher#` to be set to `true`." + "markdownDescription": "Emulate the RStudio API for addin support and other {rstudioapi} calls. Changes the option `vsc.rstudioapi` in R. Requires `#r.sessionWatcher#` to be set to `true`." }, "r.session.viewers.viewColumn": { "type": "object", - "markdownDescription": "which view column should R-related webviews be displayed?. Requires `#r.sessionWatcher#` to be set to `true`.", + "markdownDescription": "Which view column should R-related webviews be displayed? Requires `#r.sessionWatcher#` to be set to `true`.", "default": { "plot": "Two", "browser": "Active", @@ -1363,7 +1363,7 @@ "properties": { "plot": { "type": "string", - "description": "Which view column to show the plot file on graphics update? \n\nChanges the option 'vsc.plot' in R", + "description": "Which view column to show the plot file on graphics update? \n\nChanges the option 'vsc.plot' in R.", "enum": [ "Two", "Active", @@ -1380,7 +1380,7 @@ }, "browser": { "type": "string", - "description": "Which view column to show the WebView triggered by browser (e.g. shiny apps)? \n\nChanges the option 'vsc.browser' in R", + "description": "Which view column to show the WebView triggered by browser (e.g. shiny apps)? \n\nChanges the option 'vsc.browser' in R.", "enum": [ "Two", "Active", @@ -1448,7 +1448,7 @@ }, "helpPanel": { "type": "string", - "description": "Which view column to show the WebView triggered by the help panel? \n\nChanges the option 'vsc.help_panel' in R", + "description": "Which view column to show the WebView triggered by the help panel? \n\nChanges the option 'vsc.help_panel' in R.", "enum": [ "Two", "Active", From 8810f9337fd435c28e5737c6f85e62ca501b20fb Mon Sep 17 00:00:00 2001 From: Kun Ren Date: Wed, 11 Aug 2021 19:11:22 +0800 Subject: [PATCH 16/17] Use expression mapping --- R/vsc.R | 49 ++++++++++++++++++++++--------------------------- 1 file changed, 22 insertions(+), 27 deletions(-) diff --git a/R/vsc.R b/R/vsc.R index bc7c71e15..3e8e9c39a 100644 --- a/R/vsc.R +++ b/R/vsc.R @@ -15,18 +15,18 @@ load_settings <- function() { return(FALSE) } - mapping <- c( - "plot.useHttpgd" = "vsc.use_httpgd", - "workspaceViewer.showObjectSize" = "vsc.show_object_size", - "session.emulateRStudioAPI" = "vsc.rstudioapi", - "session.levelOfObjectDetail" = "vsc.str.max.level", - "session.watchGlobalEnvironment" = "vsc.globalenv", - "session.viewers.viewColumn.plot" = "vsc.plot", - "session.viewers.viewColumn.browser" = "vsc.browser", - "session.viewers.viewColumn.viewer" = "vsc.viewer", - "session.viewers.viewColumn.pageViewer" = "vsc.page_viewer", - "session.viewers.viewColumn.view" = "vsc.view", - "session.viewers.viewColumn.helpPanel" = "vsc.helpPanel" + mapping <- alist( + vsc.use_httpgd = plot$useHttpgd, + vsc.show_object_size = workspaceViewer$showObjectSize, + vsc.rstudioapi = session$emulateRStudioAPI, + vsc.str.max.level = session$levelOfObjectDetail, + vsc.globalenv = session$watchGlobalEnvironment, + vsc.plot = session$viewers$viewColumn$plot, + vsc.browser = session$viewers$viewColumn$browser, + vsc.viewer = session$viewers$viewColumn$viewer, + vsc.page_viewer = session$viewers$viewColumn$pageViewer, + vsc.view = session$viewers$viewColumn$view, + vsc.helpPanel = session$viewers$viewColumn$helpPanel ) vsc_settings <- tryCatch(jsonlite::read_json(settings_file), error = function(e) { @@ -37,28 +37,23 @@ load_settings <- function() { return(FALSE) } - vsc_settings <- unlist(vsc_settings) - ops <- vsc_settings[names(vsc_settings) %in% names(mapping)] - - # map VS Code settings to R options - names(ops) <- mapping[names(ops)] + ops <- lapply(mapping, eval, vsc_settings) # exclude options set by user on startup ops <- ops[!(names(ops) %in% user_options)] # translate VS Code setting values to R option values r_options <- lapply(ops, function(x) { - switch(EXPR = x, - "Two" = "Two", - "Active" = "Active", - "Beside" = "Beside", - "Disable" = FALSE, - "FALSE" = FALSE, - "TRUE" = TRUE, - "Minimal" = 0, - "Detailed" = 2, + if (is.character(x) && length(x) == 1) { + switch(EXPR = x, + "Disable" = FALSE, + "Minimal" = 0, + "Detailed" = 2, + x + ) + } else { x - ) + } }) options(r_options) From 675b4d4090f23f8dfb5f304fee1cad7dfc0164d5 Mon Sep 17 00:00:00 2001 From: Kun Ren Date: Wed, 11 Aug 2021 19:27:36 +0800 Subject: [PATCH 17/17] Use quote list --- R/vsc.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/R/vsc.R b/R/vsc.R index 3e8e9c39a..b759959e6 100644 --- a/R/vsc.R +++ b/R/vsc.R @@ -15,7 +15,7 @@ load_settings <- function() { return(FALSE) } - mapping <- alist( + mapping <- quote(list( vsc.use_httpgd = plot$useHttpgd, vsc.show_object_size = workspaceViewer$showObjectSize, vsc.rstudioapi = session$emulateRStudioAPI, @@ -27,7 +27,7 @@ load_settings <- function() { vsc.page_viewer = session$viewers$viewColumn$pageViewer, vsc.view = session$viewers$viewColumn$view, vsc.helpPanel = session$viewers$viewColumn$helpPanel - ) + )) vsc_settings <- tryCatch(jsonlite::read_json(settings_file), error = function(e) { message("Error occurs when reading VS Code settings: ", conditionMessage(e)) @@ -37,7 +37,7 @@ load_settings <- function() { return(FALSE) } - ops <- lapply(mapping, eval, vsc_settings) + ops <- eval(mapping, vsc_settings) # exclude options set by user on startup ops <- ops[!(names(ops) %in% user_options)]