Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions R/handlers-textsync.R
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Expand All @@ -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)
}

Expand Down
10 changes: 5 additions & 5 deletions tests/testthat/test-call-hierarchy.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-color.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
60 changes: 30 additions & 30 deletions tests/testthat/test-completion.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down Expand Up @@ -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))

Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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")
Expand Down Expand Up @@ -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")
Expand All @@ -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 %>%
Expand Down Expand Up @@ -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 %>%
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand All @@ -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),
Expand All @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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))

Expand All @@ -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),
Expand All @@ -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")
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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))

Expand Down
Loading
Loading