From 663a26c901a9929287a2f6eb704c0aa52b7e204e Mon Sep 17 00:00:00 2001 From: Katzmann1983 Date: Tue, 10 Mar 2020 20:31:34 +0100 Subject: [PATCH 01/11] Update SessionSource.R # Filter empty string (a symbol) https://github.com/rstudio/rstudio/issues/5285 --- src/cpp/session/modules/SessionSource.R | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/cpp/session/modules/SessionSource.R b/src/cpp/session/modules/SessionSource.R index 71da6934cc7..1b0ce0da9fd 100644 --- a/src/cpp/session/modules/SessionSource.R +++ b/src/cpp/session/modules/SessionSource.R @@ -184,6 +184,8 @@ if (length(args) > 0) { + # Filter empty string https://github.com/rstudio/rstudio/issues/5285 + args <- args[sapply(args, function(x) nchar(as.character(as.expression(x))) > 0 )] for (ee in args) freeVars <- c(freeVars, codetools:::walkCode(ee, w)) } From 63b6ac6980fa4052d75000f46eb78d6016db7efd Mon Sep 17 00:00:00 2001 From: Katzmann1983 Date: Thu, 12 Mar 2020 11:57:35 +0100 Subject: [PATCH 02/11] Update SessionSource.R Resolving comments --- src/cpp/session/modules/SessionSource.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cpp/session/modules/SessionSource.R b/src/cpp/session/modules/SessionSource.R index 1b0ce0da9fd..303a76e8720 100644 --- a/src/cpp/session/modules/SessionSource.R +++ b/src/cpp/session/modules/SessionSource.R @@ -184,10 +184,10 @@ if (length(args) > 0) { - # Filter empty string https://github.com/rstudio/rstudio/issues/5285 - args <- args[sapply(args, function(x) nchar(as.character(as.expression(x))) > 0 )] for (ee in args) - freeVars <- c(freeVars, codetools:::walkCode(ee, w)) + # Filter empty string https://github.com/rstudio/rstudio/issues/5285 + if (!identical(args[[i]], expression())) + freeVars <- c(freeVars, codetools:::walkCode(ee, w)) } return(unique(freeVars)) }) From c0e9e7fce436a4bce00ec286c5b26b823374af7c Mon Sep 17 00:00:00 2001 From: Katzmann1983 Date: Thu, 12 Mar 2020 15:53:48 +0100 Subject: [PATCH 03/11] Update SessionSource.R --- src/cpp/session/modules/SessionSource.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cpp/session/modules/SessionSource.R b/src/cpp/session/modules/SessionSource.R index 303a76e8720..eedd394b92e 100644 --- a/src/cpp/session/modules/SessionSource.R +++ b/src/cpp/session/modules/SessionSource.R @@ -184,10 +184,10 @@ if (length(args) > 0) { - for (ee in args) + for (i in seq_along(args)) # Filter empty string https://github.com/rstudio/rstudio/issues/5285 if (!identical(args[[i]], expression())) - freeVars <- c(freeVars, codetools:::walkCode(ee, w)) + freeVars <- c(freeVars, codetools:::walkCode(args[[i]], w)) } return(unique(freeVars)) }) From b0eaf59ba71868f34ebfe589b46bdb35269af0f1 Mon Sep 17 00:00:00 2001 From: Katzmann1983 Date: Mon, 16 Mar 2020 10:31:18 +0100 Subject: [PATCH 04/11] It's legal to access an R NA within a list --- src/cpp/session/modules/SessionSource.R | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/cpp/session/modules/SessionSource.R b/src/cpp/session/modules/SessionSource.R index eedd394b92e..7adf83cdbe6 100644 --- a/src/cpp/session/modules/SessionSource.R +++ b/src/cpp/session/modules/SessionSource.R @@ -184,10 +184,9 @@ if (length(args) > 0) { + # Needs to access the list via index in case of empty strings https://github.com/rstudio/rstudio/issues/5285 for (i in seq_along(args)) - # Filter empty string https://github.com/rstudio/rstudio/issues/5285 - if (!identical(args[[i]], expression())) - freeVars <- c(freeVars, codetools:::walkCode(args[[i]], w)) + freeVars <- c(freeVars, codetools:::walkCode(args[[i]], w)) } return(unique(freeVars)) }) From 8ddf0e62e15fc35c98b0f2ad52fba999fd0e428c Mon Sep 17 00:00:00 2001 From: Katzmann1983 Date: Mon, 16 Mar 2020 10:32:09 +0100 Subject: [PATCH 05/11] Update SessionSource.R --- src/cpp/session/modules/SessionSource.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cpp/session/modules/SessionSource.R b/src/cpp/session/modules/SessionSource.R index 7adf83cdbe6..213f1eeb18c 100644 --- a/src/cpp/session/modules/SessionSource.R +++ b/src/cpp/session/modules/SessionSource.R @@ -184,7 +184,8 @@ if (length(args) > 0) { - # Needs to access the list via index in case of empty strings https://github.com/rstudio/rstudio/issues/5285 + # Needs to access the list via index in case of empty strings + # see https://github.com/rstudio/rstudio/issues/5285 for (i in seq_along(args)) freeVars <- c(freeVars, codetools:::walkCode(args[[i]], w)) } From df87fe45c137fe7db0a257cf888d833c346590dd Mon Sep 17 00:00:00 2001 From: Jonathan McPherson Date: Tue, 24 Mar 2020 09:27:15 -0700 Subject: [PATCH 06/11] only use user pref for default working dir if defined --- src/cpp/session/SessionDirs.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/cpp/session/SessionDirs.cpp b/src/cpp/session/SessionDirs.cpp index 89f1fa2d313..c1080c4ad26 100644 --- a/src/cpp/session/SessionDirs.cpp +++ b/src/cpp/session/SessionDirs.cpp @@ -29,14 +29,21 @@ namespace dirs { FilePath getDefaultWorkingDirectory() { - // calculate using user settings - FilePath defaultWorkingDir = module_context::resolveAliasedPath( - prefs::userPrefs().initialWorkingDirectory()); + // see if the user has defined a default working directory in preferences + FilePath defaultWorkingDir; + std::string initialWorkingDir = prefs::userPrefs().initialWorkingDirectory(); + if (!initialWorkingDir.empty()) + { + // the user has defined a default; resolve the path + defaultWorkingDir = module_context::resolveAliasedPath(initialWorkingDir); + } + + // see if there's a working directory defined in the R session options (set by + // session-default-working-dir) FilePath sessionDefaultWorkingDir = FilePath(session::options().defaultWorkingDir()); - // return it if it exists, otherwise use the - // session specified value if it exists - // otherwise, use the default user home path + // return the first of these directories that is defined and exists, or the user home directory + // in the case that neither exists if (defaultWorkingDir.exists() && defaultWorkingDir.isDirectory()) return defaultWorkingDir; else if (sessionDefaultWorkingDir.exists() && sessionDefaultWorkingDir.isDirectory()) From 174742afa11beec35c4954a2c42600cf12f0c3b7 Mon Sep 17 00:00:00 2001 From: Kevin Ushey Date: Fri, 20 Mar 2020 15:08:11 -0700 Subject: [PATCH 07/11] make global VCS commands rebindable --- src/gwt/.gitignore | 1 + .../studio/client/workbench/commands/Commands.cmd.xml | 6 ------ 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/src/gwt/.gitignore b/src/gwt/.gitignore index 744cf0fef03..79a839dd73c 100644 --- a/src/gwt/.gitignore +++ b/src/gwt/.gitignore @@ -1,6 +1,7 @@ bin/ extras/ gen/ +log/ sdk/ war/ diff --git a/src/gwt/src/org/rstudio/studio/client/workbench/commands/Commands.cmd.xml b/src/gwt/src/org/rstudio/studio/client/workbench/commands/Commands.cmd.xml index 60163a6ae23..7722e2f4bed 100644 --- a/src/gwt/src/org/rstudio/studio/client/workbench/commands/Commands.cmd.xml +++ b/src/gwt/src/org/rstudio/studio/client/workbench/commands/Commands.cmd.xml @@ -2265,14 +2265,12 @@ well as menu structures (for main menu and popup menus). buttonLabel="Diff" menuLabel="Diff" desc="Diff selected file(s)" - rebindable="false" context="vcs"/> @@ -2293,7 +2291,6 @@ well as menu structures (for main menu and popup menus). From 484818f155c4b8bd589bbff9d5e7e8fd4ecb7421 Mon Sep 17 00:00:00 2001 From: Jonathan McPherson Date: Tue, 24 Mar 2020 17:13:41 -0700 Subject: [PATCH 08/11] update NEWS --- NEWS-1.3.md | 1 + 1 file changed, 1 insertion(+) diff --git a/NEWS-1.3.md b/NEWS-1.3.md index 5a0aae54e0c..42cfb23855b 100644 --- a/NEWS-1.3.md +++ b/NEWS-1.3.md @@ -128,6 +128,7 @@ * Enable wrap-around for previous/next source tab by default (#6139) * Provide full SHA in detail of Git commits (#6155) * File monitor now ignores Packrat, renv library folders (#3267) +* Make global source control commands rebindable (#6503) ### Bugfixes From 8e3e4d536b4135dedf33069d4798c21ca790a10a Mon Sep 17 00:00:00 2001 From: melissa-barca Date: Tue, 24 Mar 2020 14:57:17 -0700 Subject: [PATCH 09/11] fix bug where errors did not appear with the correct file --- src/cpp/session/modules/SessionFind.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/cpp/session/modules/SessionFind.cpp b/src/cpp/session/modules/SessionFind.cpp index e8efb90b955..f3f9ab1da76 100644 --- a/src/cpp/session/modules/SessionFind.cpp +++ b/src/cpp/session/modules/SessionFind.cpp @@ -1002,17 +1002,27 @@ class GrepOperation : public boost::enable_shared_from_this matchOffs.push_back(matchOff); replaceMatchOns.push_back(replaceMatchOn); replaceMatchOffs.push_back(replaceMatchOff); - for (std::string newError : errorMessage) - errors.push_back(json::Value(newError)); + json::Array combinedErrors = json::toJsonArray(errorMessage); + errors.push_back(combinedErrors); recordsToProcess--; } } + // when doing a replace, we haven't completed the replace for the last file here if (findResults().replace() && !currentFile_.empty() && !findResults().preview()) { std::set errorMessage; completeFileReplace(&errorMessage); - for (std::string newError : errorMessage) - errors.push_back(json::Value(newError)); + + // it is unlikely there will be any errors if we've made it this far, + // but if so we must add them to the last array in errors + // if there is an error, there will only be one + if (!errorMessage.empty()) + { + json::Array lastErrors = errors.getBack().getArray(); + errors.erase(errors.end()); + lastErrors.push_back(json::Value(*errorMessage.begin())); + errors.push_back(lastErrors); + } } if (nextLineStart) From e9906601225d68288991566b855d91101b9148f8 Mon Sep 17 00:00:00 2001 From: Kevin Ushey Date: Wed, 25 Mar 2020 10:31:38 -0700 Subject: [PATCH 10/11] invoke renv::init() in subproc --- src/cpp/session/modules/SessionRenv.R | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/cpp/session/modules/SessionRenv.R b/src/cpp/session/modules/SessionRenv.R index b07b978f402..bf896836c50 100644 --- a/src/cpp/session/modules/SessionRenv.R +++ b/src/cpp/session/modules/SessionRenv.R @@ -17,9 +17,25 @@ .rs.addJsonRpcHandler("renv_init", function(project) { - # ask renv not to restart since we'll do it ourselves - .rs.ensureDirectory(project) - renv::init(project = project, restart = FALSE) + # the project directory should already exist, but be extra careful + # and create it if necessary + dir.create(project, showWarnings = FALSE, recursive = TRUE) + owd <- setwd(project) + on.exit(setwd(owd), add = TRUE) + + # set library paths to be inherited by child process + libs <- paste(.libPaths(), collapse = .Platform$path.sep) + renv:::renv_scope_envvars(R_LIBS = libs) + + # form path to R + exe <- if (Sys.info()[["sysname"]] == "Windows") "R.exe" else "R" + r <- file.path(R.home("bin"), exe) + + # form command line arguments + args <- c("--vanilla", "--slave", "-e", shQuote("renv::init()")) + + # invoke R + system2(r, args) }) .rs.addJsonRpcHandler("renv_actions", function(action) From 4e0b594b34d4783e10864f6903088951896d5c5c Mon Sep 17 00:00:00 2001 From: Kevin Ushey Date: Wed, 25 Mar 2020 10:31:38 -0700 Subject: [PATCH 11/11] invoke renv::init() in subproc --- src/cpp/session/modules/SessionRenv.R | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/cpp/session/modules/SessionRenv.R b/src/cpp/session/modules/SessionRenv.R index b07b978f402..bf896836c50 100644 --- a/src/cpp/session/modules/SessionRenv.R +++ b/src/cpp/session/modules/SessionRenv.R @@ -17,9 +17,25 @@ .rs.addJsonRpcHandler("renv_init", function(project) { - # ask renv not to restart since we'll do it ourselves - .rs.ensureDirectory(project) - renv::init(project = project, restart = FALSE) + # the project directory should already exist, but be extra careful + # and create it if necessary + dir.create(project, showWarnings = FALSE, recursive = TRUE) + owd <- setwd(project) + on.exit(setwd(owd), add = TRUE) + + # set library paths to be inherited by child process + libs <- paste(.libPaths(), collapse = .Platform$path.sep) + renv:::renv_scope_envvars(R_LIBS = libs) + + # form path to R + exe <- if (Sys.info()[["sysname"]] == "Windows") "R.exe" else "R" + r <- file.path(R.home("bin"), exe) + + # form command line arguments + args <- c("--vanilla", "--slave", "-e", shQuote("renv::init()")) + + # invoke R + system2(r, args) }) .rs.addJsonRpcHandler("renv_actions", function(action)