From dc980e40d8ca0de4a3d65a5ed51c2ced6c463411 Mon Sep 17 00:00:00 2001 From: Jakson Alves de Aquino Date: Thu, 4 Jun 2026 13:47:01 -0300 Subject: [PATCH 1/3] New option: `compl_data.max_list_len` Close #586 --- doc/R.nvim.txt | 18 ++++++++++------- lua/r/config.lua | 3 ++- lua/r/run.lua | 3 +++ nvimcom/DESCRIPTION | 4 ++-- nvimcom/R/nvimcom.R | 2 ++ nvimcom/src/nvimcom.c | 45 ++++++++++++++++++++++++------------------- 6 files changed, 45 insertions(+), 30 deletions(-) diff --git a/doc/R.nvim.txt b/doc/R.nvim.txt index 331917a3..efe29631 100644 --- a/doc/R.nvim.txt +++ b/doc/R.nvim.txt @@ -1332,18 +1332,22 @@ in the Lua table `compl_data` in your `R.nvim` config. Below are the default values: >lua compl_data = { + max_list_len = 10000, max_depth = 3, max_size = 1000000, max_time = 100, }, < -You should increase the value of `max_depth` if you want to complete or see in -the Object Browser more than 3 list levels. You should increase either -`max_size` or `max_time` if `nvimcom` needs more space or more time to build -the completion data with the desired list depth. You should decrease the -values if you notice any delay when R is running commands. In this case, -please, put `options(nvimcom.verbose = 1)` in your `~/.Rprofile` and use the -information output by `nvimcom` to decide what parameter to change. +You should increase the value of `max_list_len` if want to be able to open in +the Object Browser and do completion of list and S4 objects with more than +10000 elements. You should increase the value of `max_depth` if you want to +complete or see in the Object Browser more than 3 list levels. You should +increase either `max_size` or `max_time` if `nvimcom` needs more space or more +time to build the completion data with the desired list depth. You should +decrease the values if you notice any delay when R is running commands. In +this case, please, put `options(nvimcom.verbose = 1)` in your `~/.Rprofile` +and use the information output by `nvimcom` to decide what parameter to +change. It is possible to add a custom keymap through `objbr_mappings` table. The keymap defined in this table will be available in the object browser only. diff --git a/lua/r/config.lua b/lua/r/config.lua index ee837a5c..41e431ad 100644 --- a/lua/r/config.lua +++ b/lua/r/config.lua @@ -166,7 +166,7 @@ local hooks = require("r.hooks") --- ---Options for fine-grained control of the object browser. Do `:help compl_data` ---for more information. ----@field compl_data? { max_depth: integer, max_size: integer, max_time: integer } +---@field compl_data? { max_list_len: integer, max_depth: integer, max_size: integer, max_time: integer } --- ---Options for the r_ls (R.nvim's built-in language server) ---@field r_ls? RLSConfigOpts @@ -496,6 +496,7 @@ local config = { convert_range_int = false, compldir = "", compl_data = { + max_list_len = 10000, max_depth = 3, max_size = 1000000, max_time = 100, diff --git a/lua/r/run.lua b/lua/r/run.lua index 5064c9b1..cbb19c35 100644 --- a/lua/r/run.lua +++ b/lua/r/run.lua @@ -69,6 +69,9 @@ start_R2 = function() 'Sys.setenv(RNVIM_ID= "' .. vim.env.RNVIM_ID .. '")', 'Sys.setenv(RNVIM_SECRET = "' .. vim.env.RNVIM_SECRET .. '")', 'Sys.setenv(RNVIM_PORT = "' .. vim.env.RNVIM_PORT .. '")', + "options(nvimcom.max_list_len = " + .. tostring(config.compl_data.max_list_len) + .. ")", "options(nvimcom.max_depth = " .. tostring(config.compl_data.max_depth) .. ")", "options(nvimcom.max_size = " .. tostring(config.compl_data.max_size) .. ")", "options(nvimcom.max_time = " .. tostring(config.compl_data.max_time) .. ")", diff --git a/nvimcom/DESCRIPTION b/nvimcom/DESCRIPTION index 8268e751..7738f891 100644 --- a/nvimcom/DESCRIPTION +++ b/nvimcom/DESCRIPTION @@ -1,6 +1,6 @@ Package: nvimcom -Version: 0.9.94 -Date: 2026-04-27 +Version: 0.9.95 +Date: 2026-06-04 Title: Intermediate the Communication Between R and Neovim Authors@R: c( person("Jakson", "Aquino", email = "jalvesaq@gmail.com", diff --git a/nvimcom/R/nvimcom.R b/nvimcom/R/nvimcom.R index 0f71871c..d2aa2b16 100644 --- a/nvimcom/R/nvimcom.R +++ b/nvimcom/R/nvimcom.R @@ -31,6 +31,7 @@ NvimcomEnv$tcb <- FALSE options(nvimcom.setwidth = TRUE) options(nvimcom.debug_r = TRUE) options(nvimcom.nvimpager = TRUE) + options(nvimcom.max_list_len = 10000) options(nvimcom.max_depth = 12) options(nvimcom.max_size = 1000000) options(nvimcom.max_time = 100) @@ -65,6 +66,7 @@ NvimcomEnv$tcb <- FALSE as.integer(getOption("nvimcom.verbose")), as.integer(getOption("nvimcom.allnames")), as.integer(getOption("nvimcom.setwidth")), + as.integer(getOption("nvimcom.max_list_len")), as.integer(getOption("nvimcom.max_depth")), as.integer(getOption("nvimcom.max_size")), as.integer(getOption("nvimcom.max_time")), diff --git a/nvimcom/src/nvimcom.c b/nvimcom/src/nvimcom.c index d58860f0..4179138e 100644 --- a/nvimcom/src/nvimcom.c +++ b/nvimcom/src/nvimcom.c @@ -93,6 +93,7 @@ static double timelimit = 100.0; // Maximum acceptable time to build list of .GlobalEnv objects static int sizelimit = 1000000; // Maximum acceptable size of string // representing .GlobalEnv (list of objects) +static int maxlslen = 10000; // Maximum acceptable list length static int maxdepth = 12; // How many levels to parse in lists and S4 objects // when building list of objects for auto-completion. The value decreases if // the listing is too slow. @@ -609,7 +610,7 @@ static char *nvimcom_glbnv_line(SEXP *x, const char *xname, const char *curenv, if (xgroup == 4 || xgroup == 7) { snprintf(newenv, 575, "%s%s@", curenv, xname); - if (len > 0) { + if (len > 0 && len < maxlslen) { for (int i = 0; i < len; i++) { ename = CHAR(STRING_ELT(sn, i)); if (R_has_slot(*x, Rf_install(ename)) == 1) { @@ -627,7 +628,7 @@ static char *nvimcom_glbnv_line(SEXP *x, const char *xname, const char *curenv, len = length(listNames); if (len == 0) { /* Empty list? */ int len1 = length(*x); - if (len1 > 0) { /* List without names */ + if (len1 > 0 && len1 < maxlslen) { /* List without names */ len1 -= 1; if (newenv[strlen(newenv) - 1] == '$') newenv[strlen(newenv) - 1] = 0; // Delete trailing '$' @@ -643,28 +644,31 @@ static char *nvimcom_glbnv_line(SEXP *x, const char *xname, const char *curenv, UNPROTECT(1); } } else { /* Named list */ - SEXP eexp; - len -= 1; - for (int i = 0; i < len; i++) { - PROTECT(eexp = STRING_ELT(listNames, i)); - ename = CHAR(eexp); - UNPROTECT(1); + if (len < maxlslen) { + SEXP eexp; + len -= 1; + for (int i = 0; i < len; i++) { + PROTECT(eexp = STRING_ELT(listNames, i)); + ename = CHAR(eexp); + UNPROTECT(1); + if (ename[0] == 0) { + snprintf(ebuf, 63, "[[%d]]", i + 1); + ename = ebuf; + } + PROTECT(elmt = VECTOR_ELT(*x, i)); + p = nvimcom_glbnv_line(&elmt, ename, newenv, p, + depth + 1); + UNPROTECT(1); + } + ename = CHAR(STRING_ELT(listNames, len)); if (ename[0] == 0) { - snprintf(ebuf, 63, "[[%d]]", i + 1); + snprintf(ebuf, 63, "[[%d]]", len + 1); ename = ebuf; } - PROTECT(elmt = VECTOR_ELT(*x, i)); + PROTECT(elmt = VECTOR_ELT(*x, len)); p = nvimcom_glbnv_line(&elmt, ename, newenv, p, depth + 1); UNPROTECT(1); } - ename = CHAR(STRING_ELT(listNames, len)); - if (ename[0] == 0) { - snprintf(ebuf, 63, "[[%d]]", len + 1); - ename = ebuf; - } - PROTECT(elmt = VECTOR_ELT(*x, len)); - p = nvimcom_glbnv_line(&elmt, ename, newenv, p, depth + 1); - UNPROTECT(1); } UNPROTECT(1); /* listNames */ } @@ -1272,11 +1276,12 @@ static void *client_loop_thread(__attribute__((unused)) void *arg) * * @param rinfo Information on R to be passed to nvim. */ -SEXP nvimcom_Start(SEXP vrb, SEXP anm, SEXP swd, SEXP imd, SEXP szl, SEXP tml, - SEXP dbg, SEXP nvv, SEXP rinfo) { +SEXP nvimcom_Start(SEXP vrb, SEXP anm, SEXP swd, SEXP imd, SEXP lsl, SEXP szl, + SEXP tml, SEXP dbg, SEXP nvv, SEXP rinfo) { verbose = *INTEGER(vrb); allnames = *INTEGER(anm); setwidth = *INTEGER(swd); + maxlslen = *INTEGER(lsl); maxdepth = *INTEGER(imd); sizelimit = *INTEGER(szl); timelimit = (double)*INTEGER(tml); From b5fdeffae927fe729870415240fe8ba72eed4591 Mon Sep 17 00:00:00 2001 From: Jakson Alves de Aquino Date: Fri, 5 Jun 2026 09:08:50 -0300 Subject: [PATCH 2/3] Update doc/R.nvim.txt Co-authored-by: Philippe Massicotte --- doc/R.nvim.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/R.nvim.txt b/doc/R.nvim.txt index efe29631..de402de1 100644 --- a/doc/R.nvim.txt +++ b/doc/R.nvim.txt @@ -1338,7 +1338,7 @@ values: max_time = 100, }, < -You should increase the value of `max_list_len` if want to be able to open in +You should increase the value of `max_list_len` if you want to be able to open in the Object Browser and do completion of list and S4 objects with more than 10000 elements. You should increase the value of `max_depth` if you want to complete or see in the Object Browser more than 3 list levels. You should From d49f77a9a178d186b6f49dc1f6696f935e98af8b Mon Sep 17 00:00:00 2001 From: Jakson Alves de Aquino Date: Fri, 5 Jun 2026 09:12:24 -0300 Subject: [PATCH 3/3] Fix order of parameters --- nvimcom/src/nvimcom.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nvimcom/src/nvimcom.c b/nvimcom/src/nvimcom.c index 4179138e..4708b44f 100644 --- a/nvimcom/src/nvimcom.c +++ b/nvimcom/src/nvimcom.c @@ -1276,7 +1276,7 @@ static void *client_loop_thread(__attribute__((unused)) void *arg) * * @param rinfo Information on R to be passed to nvim. */ -SEXP nvimcom_Start(SEXP vrb, SEXP anm, SEXP swd, SEXP imd, SEXP lsl, SEXP szl, +SEXP nvimcom_Start(SEXP vrb, SEXP anm, SEXP swd, SEXP lsl, SEXP imd, SEXP szl, SEXP tml, SEXP dbg, SEXP nvv, SEXP rinfo) { verbose = *INTEGER(vrb); allnames = *INTEGER(anm);