diff --git a/R/handlers-textsync.R b/R/handlers-textsync.R index 0f2dd98a..7378e809 100644 --- a/R/handlers-textsync.R +++ b/R/handlers-textsync.R @@ -66,6 +66,13 @@ text_document_did_save <- function(self, params) { text <- params[["text"]] uri <- uri_escape_unicode(textDocument[["uri"]]) logger$info("did save:", list(uri = uri)) + + # https://github.com/microsoft/language-server-protocol/issues/2110 + # follow dbaeumer's take on not handling files that weren't claimed before didSave + if (!self$workspace$documents$has(uri)) { + return(NULL) + } + path <- path_from_uri(uri) if (!is.null(text)) { content <- stringi::stri_split_lines(text)[[1]] @@ -74,14 +81,9 @@ text_document_did_save <- function(self, params) { } else { content <- NULL } - if (self$workspace$documents$has(uri)) { - doc <- self$workspace$documents$get(uri) - doc$set_content(doc$version, content) - } else { - doc <- Document$new(uri, language = NULL, version = NULL, content = content) - self$workspace$documents$set(uri, doc) - } - doc$did_open() + + doc <- self$workspace$documents$get(uri) + doc$set_content(doc$version, content) self$text_sync(uri, document = doc, run_lintr = TRUE, parse = TRUE) } diff --git a/tests/testthat/test-call-hierarchy.R b/tests/testthat/test-call-hierarchy.R index c722e5a7..65991e57 100644 --- a/tests/testthat/test-call-hierarchy.R +++ b/tests/testthat/test-call-hierarchy.R @@ -9,7 +9,7 @@ test_that("Call hierarchy works in single file", { "fun <- function(x) { foo(x) + bar(x) + 1 }" ), single_file) - client %>% did_save(single_file) + client %>% did_open(single_file) result <- client %>% respond_prepare_call_hierarchy( single_file, c(0, 1), retry_when = function(result) length(result) == 0) @@ -74,8 +74,8 @@ test_that("Call hierarchy works in multiple files", { "fun <- function(x) { foo(x) + bar(x) + 1 }" ), file2) - client %>% did_save(file1) - client %>% did_save(file2) + client %>% did_open(file1) + client %>% did_open(file2) result <- client %>% respond_prepare_call_hierarchy( file2, c(0, 22), retry_when = function(result) length(result) == 0) @@ -120,7 +120,7 @@ test_that("Call hierarchy incoming calls works", { "fun <- function(x) { foo(x) + bar(x) + foo(bar(x)) }" ), single_file) - client %>% did_save(single_file) + client %>% did_open(single_file) items <- client %>% respond_prepare_call_hierarchy( single_file, c(0, 1), retry_when = function(result) length(result) == 0) @@ -183,7 +183,7 @@ test_that("Call hierarchy outgoing calls works", { "fun <- function(x) { foo(x) + bar(x) + foo(bar(x)) }" ), single_file) - client %>% did_save(single_file) + client %>% did_open(single_file) items <- client %>% respond_prepare_call_hierarchy( single_file, c(2, 1), retry_when = function(result) length(result) == 0) diff --git a/tests/testthat/test-color.R b/tests/testthat/test-color.R index bd06d64b..6a094de9 100644 --- a/tests/testthat/test-color.R +++ b/tests/testthat/test-color.R @@ -18,7 +18,7 @@ test_that("Document color works", { temp_file ) - client %>% did_save(temp_file) + client %>% did_open(temp_file) result <- client %>% respond_document_color(temp_file) expect_length(result, 5) @@ -65,7 +65,7 @@ test_that("Document color works in Rmarkdown", { temp_file ) - client %>% did_save(temp_file) + client %>% did_open(temp_file) result <- client %>% respond_document_color(temp_file) expect_length(result, 5) diff --git a/tests/testthat/test-completion.R b/tests/testthat/test-completion.R index 8176609f..c7510cfd 100644 --- a/tests/testthat/test-completion.R +++ b/tests/testthat/test-completion.R @@ -19,7 +19,7 @@ test_that("Simple completion works", { ), temp_file) - client %>% did_save(temp_file) + client %>% did_open(temp_file) result <- client %>% respond_completion(temp_file, c(0, 3)) @@ -79,7 +79,7 @@ test_that("Simple completion is case insensitive", { ), temp_file) - client %>% did_save(temp_file) + client %>% did_open(temp_file) result <- client %>% respond_completion(temp_file, c(0, 3)) @@ -132,7 +132,7 @@ test_that("Completion of attached package functions works", { ), temp_file) - client %>% did_save(temp_file) + client %>% did_open(temp_file) result <- client %>% respond_completion(temp_file, c(2, 6), retry_when = function(result) result$items %>% keep(~ .$label == "fromJSON") %>% length() == 0) @@ -151,7 +151,7 @@ test_that("Completion of attached package functions works", { ), temp_file) - client %>% did_save(temp_file) + client %>% did_open(temp_file) result <- client %>% respond_completion(temp_file, c(1, 6), retry_when = function(result) result$items %>% keep(~ .$label == "fromJSON") %>% length() == 0) @@ -174,7 +174,7 @@ test_that("Completion of package functions attached in unscoped functions works" ), temp_file) - client %>% did_save(temp_file) + client %>% did_open(temp_file) result <- client %>% respond_completion(temp_file, c(1, 6), retry_when = function(result) result$items %>% keep(~ .$label == "fromJSON") %>% length() == 0) @@ -191,7 +191,7 @@ test_that("Completion of package functions attached in unscoped functions works" ), temp_file) - client %>% did_save(temp_file) + client %>% did_open(temp_file) result <- client %>% respond_completion(temp_file, c(4, 6), retry_when = function(result) result$items %>% keep(~ .$label == "fromJSON") %>% length() == 0) @@ -218,7 +218,7 @@ test_that("Completion is robust to invalid source", { ), temp_file) - client %>% did_save(temp_file) + client %>% did_open(temp_file) result <- client %>% respond_completion(temp_file, c(4, 6), retry_when = function(result) result$items %>% keep(~ .$label == "fromJSON") %>% length() == 0) @@ -243,7 +243,7 @@ test_that("Completion of function arguments works", { ), temp_file) - client %>% did_save(temp_file) + client %>% did_open(temp_file) result <- client %>% respond_completion(temp_file, c(0, 6)) arg_items <- result$items %>% keep(~.$label == "object") @@ -275,7 +275,7 @@ test_that("Completion of function arguments is case insensitive", { ), temp_file) - client %>% did_save(temp_file) + client %>% did_open(temp_file) result <- client %>% respond_completion(temp_file, c(0, 6)) arg_items <- result$items %>% keep(~ .$label == "object") @@ -302,7 +302,7 @@ test_that("Completion of options works", { ), temp_file) - client %>% did_save(temp_file) + client %>% did_open(temp_file) result <- client %>% respond_completion(temp_file, c(0, 11)) arg_items <- result$items %>% @@ -331,7 +331,7 @@ test_that("Completion of function arguments preserves the order of arguments", { ), temp_file) - client %>% did_save(temp_file) + client %>% did_open(temp_file) result <- client %>% respond_completion(temp_file, c(0, 5)) arg_items <- result$items %>% @@ -375,7 +375,7 @@ test_that("Completion of local function arguments works", { ), temp_file) - client %>% did_save(temp_file) + client %>% did_open(temp_file) result <- client %>% respond_completion( temp_file, c(4, 13), @@ -430,7 +430,7 @@ test_that("Completion of user function arguments preserves the order of argument ), temp_file) - client %>% did_save(temp_file) + client %>% did_open(temp_file) result <- client %>% respond_completion( temp_file, c(3, 5), @@ -455,7 +455,7 @@ test_that("Completion of user function works", { ), temp_file) - client %>% did_save(temp_file) + client %>% did_open(temp_file) result <- client %>% respond_completion( temp_file, c(1, 4), @@ -480,7 +480,7 @@ test_that("Completion of user function contains no duplicate symbols", { ), temp_file) - client %>% did_save(temp_file) + client %>% did_open(temp_file) result <- client %>% respond_completion( temp_file, c(2, 4), @@ -511,7 +511,7 @@ test_that("Completion of symbols in scope works", { temp_file ) - client %>% did_save(temp_file) + client %>% did_open(temp_file) result <- client %>% respond_completion( temp_file, c(5, 12), @@ -555,7 +555,7 @@ test_that("Completion of symbols in scope works with semi-colons", { temp_file ) - client %>% did_save(temp_file) + client %>% did_open(temp_file) result <- client %>% respond_completion( temp_file, c(5, 12), @@ -588,8 +588,8 @@ test_that("Completion inside a package works", { temp_file <- withr::local_tempfile(fileext = ".R") writeLines(c("noth"), temp_file) - # client %>% did_save(path(wd, "R", "mypackage.R")) - client %>% did_save(temp_file) + # client %>% did_open(path(wd, "R", "mypackage.R")) + client %>% did_open(temp_file) result <- client %>% respond_completion( temp_file, c(0, 4), retry_when = function(result) length(result) == 0 || length(result$items) == 0) @@ -605,8 +605,8 @@ test_that("Completion of imported objects works inside a package", { temp_file <- withr::local_tempfile(fileext = ".R") writeLines(c("dic"), temp_file) - # client %>% did_save(path(wd, "R", "mypackage.R")) - client %>% did_save(temp_file) + # client %>% did_open(path(wd, "R", "mypackage.R")) + client %>% did_open(temp_file) result <- client %>% respond_completion( temp_file, c(0, 3), retry_when = function(result) length(result) == 0 || length(result$items) == 0) @@ -616,8 +616,8 @@ test_that("Completion of imported objects works inside a package", { temp_file <- withr::local_tempfile(fileext = ".R") writeLines(c("lint_p"), temp_file) - # client %>% did_save(path(wd, "R", "mypackage.R")) - client %>% did_save(temp_file) + # client %>% did_open(path(wd, "R", "mypackage.R")) + client %>% did_open(temp_file) result <- client %>% respond_completion( temp_file, c(0, 6), retry_when = function(result) length(result) == 0 || length(result$items) == 0) @@ -636,7 +636,7 @@ test_that("Completion of re-exported objects works", { ), temp_file) - client %>% did_save(temp_file) + client %>% did_open(temp_file) result <- client %>% respond_completion(temp_file, c(0, 16)) @@ -657,7 +657,7 @@ test_that("Completion of tokens in document works", { temp_file ) - client %>% did_save(temp_file) + client %>% did_open(temp_file) result <- client %>% respond_completion( temp_file, c(2, 7), @@ -684,7 +684,7 @@ test_that("Completion item resolve works", { ), temp_file) - client %>% did_save(temp_file) + client %>% did_open(temp_file) result <- client %>% respond_completion(temp_file, c(0, 2)) items <- result$items %>% keep(~.$label == "base") @@ -742,7 +742,7 @@ test_that("Completion item resolve extracts symbol documentation", { ), temp_file) - client %>% did_save(temp_file) + client %>% did_open(temp_file) result <- client %>% respond_completion( temp_file, c(2, 6), @@ -773,7 +773,7 @@ test_that("Completion item resolve extracts function documentation", { ), temp_file) - client %>% did_save(temp_file) + client %>% did_open(temp_file) result <- client %>% respond_completion( temp_file, c(5, 6), @@ -817,7 +817,7 @@ test_that("Completion item resolve extracts local function documentation", { ), temp_file) - client %>% did_save(temp_file) + client %>% did_open(temp_file) result <- client %>% respond_completion( temp_file, c(6, 8), @@ -865,7 +865,7 @@ test_that("Completion in Rmarkdown works", { temp_file ) - client %>% did_save(temp_file) + client %>% did_open(temp_file) result <- client %>% respond_completion(temp_file, c(3, 3)) diff --git a/tests/testthat/test-definition.R b/tests/testthat/test-definition.R index cefb492e..2de9275c 100644 --- a/tests/testthat/test-definition.R +++ b/tests/testthat/test-definition.R @@ -8,8 +8,8 @@ test_that("Go to Definition works for functions in files", { writeLines(c("my_fn <- function(x) {", " x + 1", "}"), defn_file) writeLines(c("my_fn"), query_file) - client %>% did_save(defn_file) - client %>% did_save(query_file) + client %>% did_open(defn_file) + client %>% did_open(query_file) # query at the beginning of token result <- client %>% respond_definition(query_file, c(0, 0)) @@ -31,7 +31,7 @@ test_that("Go to Definition works for functions in files", { # remove definition writeLines("", defn_file) - client %>% did_save(defn_file) + client %>% did_open(defn_file) result <- client %>% respond_definition(query_file, c(0, 0), retry_when = function(result) { @@ -42,7 +42,7 @@ test_that("Go to Definition works for functions in files", { # move function into different file writeLines(c("my_fn <- function(x) {", " x + 1", "}"), defn2_file) - client %>% did_save(defn2_file) + client %>% did_open(defn2_file) result <- client %>% respond_definition(query_file, c(0, 0)) @@ -56,7 +56,7 @@ test_that("Go to Definition works for functions in packages", { query_file <- withr::local_tempfile(fileext = ".R") writeLines(c("print"), query_file) - client %>% did_save(query_file) + client %>% did_open(query_file) result <- client %>% respond_definition(query_file, c(0, 0)) @@ -72,7 +72,7 @@ test_that("Go to Definition works in single file", { c("my_fn <- function(x) {x + 1}", "my_fn", ".nonexistent"), single_file) - client %>% did_save(single_file) + client %>% did_open(single_file) # first query a known function to make sure the file is processed result <- client %>% respond_definition(single_file, c(1, 0)) @@ -127,7 +127,7 @@ test_that("Go to Definition works in scope with different assignment operators", "my_fn(1)" ), single_file) - client %>% did_save(single_file) + client %>% did_open(single_file) # first query a known function to make sure the file is processed result <- client %>% respond_definition(single_file, c(8, 0)) @@ -178,7 +178,7 @@ test_that("Go to Definition works in scope with semi-colons", { "my_fn(1)" ), single_file) - client %>% did_save(single_file) + client %>% did_open(single_file) # first query a known function to make sure the file is processed result <- client %>% respond_definition(single_file, c(8, 0)) @@ -226,7 +226,7 @@ test_that("Go to Definition works on both sides of assignment", { "var3 + 3 -> var3" ), single_file) - client %>% did_save(single_file) + client %>% did_open(single_file) result <- client %>% respond_definition(single_file, c(0, 1)) @@ -287,8 +287,8 @@ test_that("Go to Definition works when package is specified", { writeLines(c("print <- function(x) {", "# Not base::print", "}"), defn_file) writeLines(c("print", "base::print"), query_file) - client %>% did_save(defn_file) - client %>% did_save(query_file) + client %>% did_open(defn_file) + client %>% did_open(query_file) result <- client %>% respond_definition(query_file, c(0, 0), retry_when = function(result) { @@ -322,7 +322,7 @@ test_that("Go to Definition in Rmarkdown works", { single_file ) - client %>% did_save(single_file) + client %>% did_open(single_file) # first query a known function to make sure the file is processed result <- client %>% respond_definition(single_file, c(5, 0)) @@ -354,8 +354,8 @@ test_that("Go to Definition works for file paths", { sprintf("source('%s')", basename(defn_file)) ), query_file) - client %>% did_save(defn_file) - client %>% did_save(query_file) + client %>% did_open(defn_file) + client %>% did_open(query_file) result <- client %>% respond_definition(query_file, c(0, 9)) expect_equal(result$uri, path_to_uri(defn_file)) diff --git a/tests/testthat/test-folding.R b/tests/testthat/test-folding.R index 63f8ecb2..caa9e96f 100644 --- a/tests/testthat/test-folding.R +++ b/tests/testthat/test-folding.R @@ -10,7 +10,7 @@ test_that("Expression folding rage works", { "g <- function(x) { x - 1 }" ), defn_file) - client %>% did_save(defn_file) + client %>% did_open(defn_file) result <- client %>% respond_document_folding_range(defn_file) result <- result[order(sapply(result, "[[", "startLine"))] @@ -36,7 +36,7 @@ test_that("Section folding range works", { "g <- function(x) { x - 1 }" ), defn_file) - client %>% did_save(defn_file) + client %>% did_open(defn_file) result <- client %>% respond_document_folding_range(defn_file) %>% keep(~ .$kind == FoldingRangeKind$Region) @@ -73,7 +73,7 @@ test_that("Comment folding range works", { "g <- function(x) { x - 1 }" ), defn_file) - client %>% did_save(defn_file) + client %>% did_open(defn_file) result <- client %>% respond_document_folding_range(defn_file) %>% keep(~ .$kind == FoldingRangeKind$Comment) @@ -106,7 +106,7 @@ test_that("Multiple-level Folding range works", { "two_c <- 1:2" ), defn_file) - client %>% did_save(defn_file) + client %>% did_open(defn_file) result <- client %>% respond_document_folding_range(defn_file) result <- result[order(sapply(result, "[[", "startLine"))] @@ -149,7 +149,7 @@ test_that("Multiple-level Folding range nested in blocks works well", { " }} # end of both f1 and f4" ), defn_file) - client %>% did_save(defn_file) + client %>% did_open(defn_file) result <- client %>% respond_document_folding_range(defn_file) result <- result[order(sapply(result, "[[", "startLine"))] @@ -196,7 +196,7 @@ test_that("two or more blank lines breaking section succession works well", { "d <- 1:2" ), defn_file) - client %>% did_save(defn_file) + client %>% did_open(defn_file) result <- client %>% respond_document_folding_range(defn_file) result <- result[order(sapply(result, "[[", "startLine"))] @@ -233,7 +233,7 @@ test_that("Folding range of binary opts works well", { "1" ), defn_file) - client %>% did_save(defn_file) + client %>% did_open(defn_file) result <- client %>% respond_document_folding_range(defn_file) result <- result[order(sapply(result, "[[", "startLine"))] @@ -273,7 +273,7 @@ test_that("Folding range works in Rmarkdown", { "```" ), defn_file) - client %>% did_save(defn_file) + client %>% did_open(defn_file) result <- client %>% respond_document_folding_range(defn_file) result <- result[order(sapply(result, "[[", "startLine"))] diff --git a/tests/testthat/test-formatting.R b/tests/testthat/test-formatting.R index 424f9571..94edce10 100644 --- a/tests/testthat/test-formatting.R +++ b/tests/testthat/test-formatting.R @@ -9,7 +9,7 @@ test_that("Formatting document works", { "}" ), temp_file) - client %>% did_save(temp_file) + client %>% did_open(temp_file) result <- client %>% respond_formatting(temp_file) @@ -36,7 +36,7 @@ test_that("Formatting selection works for complete line", { "}" ), temp_file) - client %>% did_save(temp_file) + client %>% did_open(temp_file) result <- client %>% respond_range_formatting(temp_file, c(1, 0), c(2, 7)) @@ -59,7 +59,7 @@ test_that("Formatting selection works for partial line", { "}" ), temp_file) - client %>% did_save(temp_file) + client %>% did_open(temp_file) result <- client %>% respond_range_formatting(temp_file, c(1, 4), c(2, 7)) @@ -81,7 +81,7 @@ test_that("Formatting selection preserves initial indentation", { " }" ), temp_file) - client %>% did_save(temp_file) + client %>% did_open(temp_file) result <- client %>% respond_range_formatting(temp_file, c(0, 0), c(3, 3)) @@ -106,7 +106,7 @@ test_that("Formatting selection does not add indentation to multi-line string", "}" ), temp_file) - client %>% did_save(temp_file) + client %>% did_open(temp_file) result <- client %>% respond_range_formatting(temp_file, c(1, 0), c(3, 23)) @@ -134,7 +134,7 @@ test_that("On type formatting works", { "select(a,b)" ), temp_file) - client %>% did_save(temp_file) + client %>% did_open(temp_file) result <- client %>% respond_on_type_formatting(temp_file, c(1, 10), ")") expect_length(result, 1) @@ -192,7 +192,7 @@ test_that("Formatting in Rmarkdown works", { single_file ) - client %>% did_save(single_file) + client %>% did_open(single_file) # first query a known function to make sure the file is processed result <- client %>% respond_formatting(single_file) @@ -223,7 +223,7 @@ test_that("On type formatting works in Rmarkdown", { "```" ), temp_file) - client %>% did_save(temp_file) + client %>% did_open(temp_file) result <- client %>% respond_on_type_formatting(temp_file, c(1, 10), ")", retry = FALSE) expect_length(result, 0) diff --git a/tests/testthat/test-highlight.R b/tests/testthat/test-highlight.R index ac7f3677..67ab11c5 100644 --- a/tests/testthat/test-highlight.R +++ b/tests/testthat/test-highlight.R @@ -12,7 +12,7 @@ test_that("Document highlight works", { ), temp_file) - client %>% did_save(temp_file) + client %>% did_open(temp_file) # query at the beginning of token result <- client %>% respond_document_highlight(temp_file, c(1, 0)) @@ -73,7 +73,7 @@ test_that("Document highlight works in Rmarkdown", { temp_file ) - client %>% did_save(temp_file) + client %>% did_open(temp_file) result <- client %>% respond_document_highlight(temp_file, c(6, 0)) diff --git a/tests/testthat/test-hover.R b/tests/testthat/test-hover.R index 60353b02..729852ad 100644 --- a/tests/testthat/test-hover.R +++ b/tests/testthat/test-hover.R @@ -11,7 +11,7 @@ test_that("Simple hover works", { temp_file ) - client %>% did_save(temp_file) + client %>% did_open(temp_file) result <- client %>% respond_hover(temp_file, c(0, 7)) expect_length(result$contents, 1) @@ -39,7 +39,7 @@ test_that("Hover on user function works", { temp_file ) - client %>% did_save(temp_file) + client %>% did_open(temp_file) result <- client %>% respond_hover(temp_file, c(1, 3)) expect_length(result$contents, 1) @@ -77,7 +77,7 @@ test_that("Hover on user function with multi-lined arguments works", { temp_file ) - client %>% did_save(temp_file) + client %>% did_open(temp_file) result <- client %>% respond_hover(temp_file, c(6, 3)) expect_length(result$contents, 1) @@ -109,7 +109,7 @@ test_that("Hover on variable works", { temp_file ) - client %>% did_save(temp_file) + client %>% did_open(temp_file) result <- client %>% respond_hover(temp_file, c(0, 1)) expect_equal(result$range$start, list(line = 0, character = 0)) @@ -151,7 +151,7 @@ test_that("Hover on variable with leading tabs works", { temp_file ) - client %>% did_save(temp_file) + client %>% did_open(temp_file) result <- client %>% respond_hover(temp_file, c(0, 1)) expect_equal(result$range$start, list(line = 0, character = 0)) @@ -188,7 +188,7 @@ test_that("Hover on variable works with semi-colons", { temp_file ) - client %>% did_save(temp_file) + client %>% did_open(temp_file) result <- client %>% respond_hover(temp_file, c(0, 1)) expect_equal(result$range$start, list(line = 0, character = 0)) @@ -233,7 +233,7 @@ test_that("Hover works in scope with different assignment operators", { "my_fn(1)" ), temp_file) - client %>% did_save(temp_file) + client %>% did_open(temp_file) result <- client %>% respond_hover(temp_file, c(8, 0)) expect_equal(result$range$start, list(line = 8, character = 0)) @@ -280,7 +280,7 @@ test_that("Hover works on both sides of assignment", { "var3 + 3 -> var3" ), single_file) - client %>% did_save(single_file) + client %>% did_open(single_file) result <- client %>% respond_hover(single_file, c(0, 1)) expect_equal(result$range$start, list(line = 0, character = 0)) @@ -341,7 +341,7 @@ test_that("Hover on function argument works", { temp_file ) - client %>% did_save(temp_file) + client %>% did_open(temp_file) result <- client %>% respond_hover(temp_file, c(0, 30)) expect_equal(result$range$start, list(line = 0, character = 27)) @@ -375,7 +375,7 @@ test_that("Hover on user function with function argument works", { temp_file ) - client %>% did_save(temp_file) + client %>% did_open(temp_file) result <- client %>% respond_hover(temp_file, c(1, 3)) expect_length(result$contents, 1) @@ -408,7 +408,7 @@ test_that("Hover works with local function", { ), temp_file) - client %>% did_save(temp_file) + client %>% did_open(temp_file) result <- client %>% respond_hover(temp_file, c(3, 20)) expect_equal(result$range$start, list(line = 3, character = 19)) @@ -447,7 +447,7 @@ test_that("Hover on operator is ignored", { temp_file ) - client %>% did_save(temp_file) + client %>% did_open(temp_file) result <- client %>% respond_hover(temp_file, c(2, 22), retry_when = function(result) length(result) > 0) @@ -468,8 +468,8 @@ test_that("Hover works across multiple files", { writeLines(c("test <- 1"), defn_file) writeLines(c("test + 1"), query_file) - client %>% did_save(defn_file) - client %>% did_save(query_file) + client %>% did_open(defn_file) + client %>% did_open(query_file) result <- client %>% respond_hover(query_file, c(0, 0)) @@ -497,7 +497,7 @@ test_that("Simple hover works in Rmarkdown", { temp_file ) - client %>% did_save(temp_file) + client %>% did_open(temp_file) result <- client %>% respond_hover(temp_file, c(5, 7)) expect_length(result$contents, 1) @@ -529,7 +529,7 @@ test_that("Hover on user function works in Rmarkdown", { temp_file ) - client %>% did_save(temp_file) + client %>% did_open(temp_file) result <- client %>% respond_hover(temp_file, c(6, 3)) expect_length(result$contents, 1) @@ -562,7 +562,7 @@ test_that("Hover on variable works in Rmarkdown", { temp_file ) - client %>% did_save(temp_file) + client %>% did_open(temp_file) result <- client %>% respond_hover(temp_file, c(5, 1)) expect_equal(result$range$start, list(line = 5, character = 0)) @@ -609,7 +609,7 @@ test_that("Hover on function argument works in Rmarkdown", { temp_file ) - client %>% did_save(temp_file) + client %>% did_open(temp_file) result <- client %>% respond_hover(temp_file, c(5, 30)) expect_equal(result$range$start, list(line = 5, character = 27)) diff --git a/tests/testthat/test-link.R b/tests/testthat/test-link.R index 567352a6..43df482a 100644 --- a/tests/testthat/test-link.R +++ b/tests/testthat/test-link.R @@ -35,7 +35,7 @@ test_that("Document link works", { temp_file ) - client %>% did_save(temp_file) + client %>% did_open(temp_file) result <- client %>% respond_document_link(temp_file) @@ -107,7 +107,7 @@ test_that("Document link works with raw strings", { temp_file ) - client %>% did_save(temp_file) + client %>% did_open(temp_file) result <- client %>% respond_document_link(temp_file) @@ -184,7 +184,7 @@ test_that("Document link works in Rmarkdown", { temp_file ) - client %>% did_save(temp_file) + client %>% did_open(temp_file) result <- client %>% respond_document_link(temp_file) @@ -252,7 +252,7 @@ test_that("Document link works with null workspace folder", { "source('non_exist_file.R')" ), temp_file) - client %>% did_save(temp_file) + client %>% did_open(temp_file) result <- client %>% respond_document_link(temp_file) @@ -314,7 +314,7 @@ test_that("Document link works with untitled document", { uri <- "untitled:Untitled-1" - client %>% did_save(uri = uri, text = c( + client %>% did_open(uri = uri, text = c( sprintf("source('%s')", src_file1), sprintf("source('%s')", basename(src_file1)), sprintf("source('%s')", src_file2), diff --git a/tests/testthat/test-references.R b/tests/testthat/test-references.R index 3982b1ec..22662269 100644 --- a/tests/testthat/test-references.R +++ b/tests/testthat/test-references.R @@ -8,8 +8,8 @@ test_that("Find References works for functions in files", { writeLines(c("my_fn <- function(x) {", " x + 1", "}"), defn_file) writeLines(c("my_fn"), query_file) - client %>% did_save(defn_file) - client %>% did_save(query_file) + client %>% did_open(defn_file) + client %>% did_open(query_file) # query at the beginning of token result <- client %>% respond_references( @@ -56,7 +56,7 @@ test_that("Find References works for functions in files", { # remove definition writeLines("", defn_file) - client %>% did_save(defn_file) + client %>% did_open(defn_file) result <- client %>% respond_references(query_file, c(0, 0), retry_when = function(result) { @@ -67,7 +67,7 @@ test_that("Find References works for functions in files", { # move function into different file writeLines(c("my_fn <- function(x) {", " x + 1", "}"), defn2_file) - client %>% did_save(defn2_file) + client %>% did_open(defn2_file) result <- client %>% respond_references(query_file, c(0, 0)) expect_length(result, 2) @@ -92,7 +92,7 @@ test_that("Find References works in single file", { c("my_fn <- function(x) {x + 1}", "my_fn", ".nonexistent"), single_file) - client %>% did_save(single_file) + client %>% did_open(single_file) # first query a known function to make sure the file is processed result <- client %>% respond_references( @@ -128,7 +128,7 @@ test_that("Find References works in scope with different assignment operators", "my_fn(1)" ), single_file) - client %>% did_save(single_file) + client %>% did_open(single_file) # first query a known function to make sure the file is processed result <- client %>% respond_references( @@ -208,7 +208,7 @@ test_that("Find References in Rmarkdown works", { single_file ) - client %>% did_save(single_file) + client %>% did_open(single_file) # first query a known function to make sure the file is processed result <- client %>% respond_references(single_file, c(5, 0)) diff --git a/tests/testthat/test-rename.R b/tests/testthat/test-rename.R index 7f7eac0c..b6867901 100644 --- a/tests/testthat/test-rename.R +++ b/tests/testthat/test-rename.R @@ -8,8 +8,8 @@ test_that("Rename works for functions in files", { writeLines(c("my_fn <- function(x) {", " x + 1", "}"), defn_file) writeLines(c("my_fn"), query_file) - client %>% did_save(defn_file) - client %>% did_save(query_file) + client %>% did_open(defn_file) + client %>% did_open(query_file) # query at the beginning of token result <- client %>% respond_rename( @@ -62,7 +62,7 @@ test_that("Rename works for functions in files", { # remove definition writeLines("", defn_file) - client %>% did_save(defn_file) + client %>% did_open(defn_file) result <- client %>% respond_rename(query_file, c(0, 0), "new_fn", retry_when = function(result) { @@ -73,7 +73,7 @@ test_that("Rename works for functions in files", { # move function into different file writeLines(c("my_fn <- function(x) {", " x + 1", "}"), defn2_file) - client %>% did_save(defn2_file) + client %>% did_open(defn2_file) result <- client %>% respond_rename(query_file, c(0, 0), "new_fn") expect_length(result$changes, 2) @@ -100,7 +100,7 @@ test_that("Rename works in single file", { c("my_fn <- function(x) {x + 1}", "my_fn", ".nonexistent"), single_file) - client %>% did_save(single_file) + client %>% did_open(single_file) # first query a known function to make sure the file is processed result <- client %>% respond_rename(single_file, c(1, 0), "new_fn") @@ -140,7 +140,7 @@ test_that("Rename works in scope with different assignment operators", { "my_fn(1)" ), single_file) - client %>% did_save(single_file) + client %>% did_open(single_file) # first query a known function to make sure the file is processed result <- client %>% respond_rename( @@ -250,7 +250,7 @@ test_that("Rename in Rmarkdown works", { single_file ) - client %>% did_save(single_file) + client %>% did_open(single_file) # first query a known function to make sure the file is processed result <- client %>% respond_rename(single_file, c(5, 0), "new_fn") @@ -281,7 +281,7 @@ test_that("Prepare rename works in single file", { c("my_fn <- function(x) {x + 123}", "my_fn", "new_fn"), single_file) - client %>% did_save(single_file) + client %>% did_open(single_file) # first make sure the file is processed result <- client %>% respond_references( diff --git a/tests/testthat/test-selection.R b/tests/testthat/test-selection.R index 66ac1ce8..9766e491 100644 --- a/tests/testthat/test-selection.R +++ b/tests/testthat/test-selection.R @@ -9,7 +9,7 @@ test_that("Selection range works with single position", { "}" ), defn_file) - client %>% did_save(defn_file) + client %>% did_open(defn_file) result <- client %>% respond_selection_range(defn_file, list( list( line = 1, @@ -59,7 +59,7 @@ test_that("Selection range works with multiple positions", { "}" ), defn_file) - client %>% did_save(defn_file) + client %>% did_open(defn_file) result <- client %>% respond_selection_range(defn_file, list( list( line = 0, @@ -138,7 +138,7 @@ test_that("Selection range works in Rmarkdown", { "```" ), defn_file) - client %>% did_save(defn_file) + client %>% did_open(defn_file) result <- client %>% respond_selection_range(defn_file, list( list( diff --git a/tests/testthat/test-signature.R b/tests/testthat/test-signature.R index 21fb9e25..d74c8928 100644 --- a/tests/testthat/test-signature.R +++ b/tests/testthat/test-signature.R @@ -10,7 +10,7 @@ test_that("Simple signature works", { ), temp_file) - client %>% did_save(temp_file) + client %>% did_open(temp_file) result <- client %>% respond_signature(temp_file, c(0, 10)) expect_length(result$signatures, 1) @@ -37,7 +37,7 @@ test_that("Signature of user function works", { writeLines(c("foo <- function(x, y = 3) { x + y }"), defn_file) writeLines(c("foo(3, "), temp_file) - client %>% did_save(defn_file) %>% did_save(temp_file) + client %>% did_open(defn_file) %>% did_open(temp_file) result <- client %>% respond_signature( temp_file, c(0, 7), @@ -56,7 +56,7 @@ test_that("Signature of user function works with semi-colon", { writeLines(c("foo <- function(x, y = 3) { x + y };"), defn_file) writeLines(c("foo(3, "), temp_file) - client %>% did_save(defn_file) %>% did_save(temp_file) + client %>% did_open(defn_file) %>% did_open(temp_file) result <- client %>% respond_signature( temp_file, c(0, 7), @@ -83,7 +83,7 @@ test_that("Signature in Rmarkdown works", { temp_file ) - client %>% did_save(temp_file) + client %>% did_open(temp_file) result <- client %>% respond_signature(temp_file, c(3, 10)) expect_length(result$signatures, 1) diff --git a/tests/testthat/test-symbol.R b/tests/testthat/test-symbol.R index 71e87bef..5bd6b631 100644 --- a/tests/testthat/test-symbol.R +++ b/tests/testthat/test-symbol.R @@ -14,7 +14,7 @@ test_that("Document Symbol works", { ")" ), defn_file) - client %>% did_save(defn_file) + client %>% did_open(defn_file) result <- client %>% respond_document_symbol(defn_file) expect_setequal(result %>% map_chr(~ .$name), c("f", "g", "p", "m")) @@ -64,7 +64,7 @@ test_that("Recognize symbols created by delayedAssign/assign/makeActiveBinding", "assign('assign4', 4, pos = new.env())" ), defn_file) - client %>% did_save(defn_file) + client %>% did_open(defn_file) result <- client %>% respond_document_symbol(defn_file) expect_setequal( @@ -90,7 +90,7 @@ test_that("Document symbols are robust to invalid source", { "d1 <- 1" ), defn_file) - client %>% did_save(defn_file) + client %>% did_open(defn_file) result <- client %>% respond_document_symbol(defn_file) expect_setequal( @@ -126,7 +126,7 @@ test_that("Document section symbol works", { ")" ), defn_file) - client %>% did_save(defn_file) + client %>% did_open(defn_file) result <- client %>% respond_document_symbol(defn_file) expect_setequal( @@ -193,8 +193,8 @@ test_that("Workspace Symbol works", { ")" ), defn2_file) - client %>% did_save(defn_file) - client %>% did_save(defn2_file) + client %>% did_open(defn_file) + client %>% did_open(defn2_file) expected_names <- c("f1", "f2") result <- client %>% respond_workspace_symbol( @@ -277,7 +277,7 @@ test_that("Document section symbol works in Rmarkdown", { "```" ), defn_file) - client %>% did_save(defn_file) + client %>% did_open(defn_file) result <- client %>% respond_document_symbol(defn_file) expect_setequal( diff --git a/tests/testthat/test-unicode-path.R b/tests/testthat/test-unicode-path.R index 85f4e916..414d342f 100644 --- a/tests/testthat/test-unicode-path.R +++ b/tests/testthat/test-unicode-path.R @@ -19,8 +19,8 @@ test_that("Works with unicode path", { writeLines(c("my_fn <- function(x) {", " x + 1", "}"), defn_file) writeLines(c("my_fn"), query_file) - client %>% did_save(defn_file) - client %>% did_save(query_file) + client %>% did_open(defn_file) + client %>% did_open(query_file) result <- client %>% respond_definition(query_file, c(0, 0)) @@ -29,7 +29,7 @@ test_that("Works with unicode path", { # remove definition writeLines("", defn_file) - client %>% did_save(defn_file) + client %>% did_open(defn_file) result <- client %>% respond_definition(query_file, c(0, 0), retry_when = function(result) { @@ -40,7 +40,7 @@ test_that("Works with unicode path", { # move function into different file writeLines(c("my_fn <- function(x) {", " x + 1", "}"), defn2_file) - client %>% did_save(defn2_file) + client %>% did_open(defn2_file) result <- client %>% respond_definition(query_file, c(0, 0)) diff --git a/tests/testthat/test-workspace.R b/tests/testthat/test-workspace.R index 259abbdd..80180833 100644 --- a/tests/testthat/test-workspace.R +++ b/tests/testthat/test-workspace.R @@ -9,7 +9,7 @@ test_that("Null workspace folder works", { ), temp_file) - client %>% did_save(temp_file) + client %>% did_open(temp_file) result <- client %>% respond_signature(temp_file, c(0, 10)) expect_length(result$signatures, 1)