Skip to content

Commit 36c721a

Browse files
authored
Merge pull request #714 from REditorSupport/ignore-didSave-without-didOpen
Ignore did save without did open
2 parents 2df33df + e12b0e7 commit 36c721a

22 files changed

+168
-166
lines changed

R/handlers-textsync.R

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ text_document_did_save <- function(self, params) {
6767
text <- params[["text"]]
6868
uri <- uri_escape_unicode(textDocument[["uri"]])
6969
logger$info("did save:", list(uri = uri))
70+
71+
# https://github.com/microsoft/language-server-protocol/issues/2110
72+
# follow dbaeumer's take on not handling files that weren't claimed before didSave
73+
if (!self$workspace$documents$has(uri)) {
74+
return(NULL)
75+
}
76+
7077
path <- path_from_uri(uri)
7178
if (!is.null(text)) {
7279
content <- stringi::stri_split_lines(text)[[1]]
@@ -75,13 +82,8 @@ text_document_did_save <- function(self, params) {
7582
} else {
7683
content <- NULL
7784
}
78-
if (self$workspace$documents$has(uri)) {
79-
doc <- self$workspace$documents$get(uri)
80-
doc$set_content(doc$version, content)
81-
} else {
82-
doc <- Document$new(uri, language = NULL, version = NULL, content = content)
83-
self$workspace$documents$set(uri, doc)
84-
}
85+
doc <- self$workspace$documents$get(uri)
86+
doc$set_content(doc$version, content)
8587
doc$did_open()
8688
self$text_sync(uri, document = doc, run_lintr = TRUE, parse = TRUE)
8789
}

tests/testthat/test-call-hierarchy.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ test_that("Call hierarchy works in single file", {
99
"fun <- function(x) { foo(x) + bar(x) + 1 }"
1010
), single_file)
1111

12-
client %>% did_save(single_file)
12+
client %>% did_open(single_file)
1313

1414
result <- client %>% respond_prepare_call_hierarchy(
1515
single_file, c(0, 1), retry_when = function(result) length(result) == 0)
@@ -74,8 +74,8 @@ test_that("Call hierarchy works in multiple files", {
7474
"fun <- function(x) { foo(x) + bar(x) + 1 }"
7575
), file2)
7676

77-
client %>% did_save(file1)
78-
client %>% did_save(file2)
77+
client %>% did_open(file1)
78+
client %>% did_open(file2)
7979

8080
result <- client %>% respond_prepare_call_hierarchy(
8181
file2, c(0, 22), retry_when = function(result) length(result) == 0)
@@ -120,7 +120,7 @@ test_that("Call hierarchy incoming calls works", {
120120
"fun <- function(x) { foo(x) + bar(x) + foo(bar(x)) }"
121121
), single_file)
122122

123-
client %>% did_save(single_file)
123+
client %>% did_open(single_file)
124124

125125
items <- client %>% respond_prepare_call_hierarchy(
126126
single_file, c(0, 1), retry_when = function(result) length(result) == 0)
@@ -183,7 +183,7 @@ test_that("Call hierarchy outgoing calls works", {
183183
"fun <- function(x) { foo(x) + bar(x) + foo(bar(x)) }"
184184
), single_file)
185185

186-
client %>% did_save(single_file)
186+
client %>% did_open(single_file)
187187

188188
items <- client %>% respond_prepare_call_hierarchy(
189189
single_file, c(2, 1), retry_when = function(result) length(result) == 0)

tests/testthat/test-color.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ test_that("Document color works", {
1818
temp_file
1919
)
2020

21-
client %>% did_save(temp_file)
21+
client %>% did_open(temp_file)
2222

2323
result <- client %>% respond_document_color(temp_file)
2424
expect_length(result, 5)
@@ -65,7 +65,7 @@ test_that("Document color works in Rmarkdown", {
6565
temp_file
6666
)
6767

68-
client %>% did_save(temp_file)
68+
client %>% did_open(temp_file)
6969

7070
result <- client %>% respond_document_color(temp_file)
7171
expect_length(result, 5)

0 commit comments

Comments
 (0)