Skip to content

Commit

Permalink
Support Positron >= 2024.11
Browse files Browse the repository at this point in the history
  • Loading branch information
olivroy committed Oct 22, 2024
1 parent bfd3c75 commit 0f3addf
Show file tree
Hide file tree
Showing 8 changed files with 414 additions and 406 deletions.
15 changes: 12 additions & 3 deletions R/open.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ active_rs_doc <- function() {
if (!interactive() && !is_rstudio()) {
return("Non-existing doc")
}
if (!is_rstudio(f = "documentPath")) {
cli::cli_abort("Not in RStudio.")
}

if (is_rstudio(f = "documentPath")) {
# Not yet supported in Positron
unsaved_doc <- tryCatch(rstudioapi::documentPath(), error = function(e) TRUE)
if (isTRUE(unsaved_doc)) {
return(NULL)
Expand All @@ -68,6 +68,15 @@ active_rs_doc <- function() {
cli::cli_abort("Either RStudio is not available or you are trying to map an unsaved file")
})
path <- fs::path_expand_r(path)
} else if (is_rstudio(f = "getSourceEditorContext")) {
# Will work for Positron >= 2024.11
# https://github.com/posit-dev/positron/issues/5112
path <- rstudioapi::getSourceEditorContext()$path
} else {
cli::cli_abort("Not in RStudio or Positron. rstudioapi problem.")
}


active_proj <- proj_get2()
if (is.null(active_proj)) {
return(invisible(path))
Expand Down
Loading

0 comments on commit 0f3addf

Please sign in to comment.