Skip to content

Commit c301fbb

Browse files
committed
refactor: rename default fallback workspace key to '_default_'
1 parent d86eb84 commit c301fbb

1 file changed

Lines changed: 17 additions & 14 deletions

File tree

R/languageserver.R

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ LanguageServer <- R6::R6Class("LanguageServer",
6868

6969
self$pending_replies <- collections::dict()
7070
self$workspaces <- collections::dict()
71-
self$workspaces$set("", Workspace$new(NULL))
71+
self$workspaces$set("_default_", Workspace$new(NULL))
7272

7373
super$initialize()
7474
},
@@ -84,15 +84,15 @@ LanguageServer <- R6::R6Class("LanguageServer",
8484
}
8585
},
8686
add_workspace = function(uri) {
87-
key <- if (length(uri) == 0) "" else uri
87+
key <- if (length(uri) == 0) "_default_" else uri
8888
if (!self$workspaces$has(key)) {
8989
path <- if (length(uri) == 0) NULL else path_from_uri(uri)
9090
new_workspace <- Workspace$new(path)
9191
self$workspaces$set(key, new_workspace)
92-
92+
9393
# Remove documents from the fallback workspace if they belong here
9494
if (!is.null(path)) {
95-
fallback <- self$workspaces$get("")
95+
fallback <- self$workspaces$get("_default_")
9696
for (doc_uri in fallback$documents$keys()) {
9797
doc_path <- path_from_uri(doc_uri)
9898
if (path_has_parent(doc_path, path)) {
@@ -103,15 +103,17 @@ LanguageServer <- R6::R6Class("LanguageServer",
103103
}
104104
},
105105
remove_workspace = function(uri) {
106-
key <- if (length(uri) == 0) "" else uri
107-
if (key == "") return(invisible(NULL))
106+
key <- if (length(uri) == 0) "_default_" else uri
107+
if (key == "_default_") {
108+
return(invisible(NULL))
109+
}
108110
if (self$workspaces$has(key)) {
109111
workspace <- self$workspaces$get(key)
110112
for (doc_uri in workspace$documents$keys()) {
111113
diagnostics_callback(self, doc_uri, NULL, list())
112114
doc <- workspace$documents$get(doc_uri)
113115
if (isTRUE(doc$is_open)) {
114-
self$workspaces$get("")$documents$set(doc_uri, doc)
116+
self$workspaces$get("_default_")$documents$set(doc_uri, doc)
115117
}
116118
}
117119
self$workspaces$remove(key)
@@ -120,15 +122,17 @@ LanguageServer <- R6::R6Class("LanguageServer",
120122
get_workspace = function(uri) {
121123
workspaces_list <- self$workspaces$values()
122124

123-
default_key <- if (length(self$rootUri) == 0) "" else self$rootUri
124-
default_workspace <- self$workspaces$get(default_key, self$workspaces$get(""))
125+
default_key <- if (length(self$rootUri) == 0) "_default_" else self$rootUri
126+
default_workspace <- self$workspaces$get(default_key, self$workspaces$get("_default_"))
125127

126-
if (length(uri) == 0) return(default_workspace)
128+
if (length(uri) == 0) {
129+
return(default_workspace)
130+
}
127131

128132
path <- path_from_uri(uri)
129133
best_match <- NULL
130134
max_len <- -1
131-
135+
132136
for (workspace in workspaces_list) {
133137
root <- workspace$root
134138
if (length(root) > 0 && path_has_parent(path, root)) {
@@ -138,7 +142,7 @@ LanguageServer <- R6::R6Class("LanguageServer",
138142
}
139143
}
140144
}
141-
145+
142146
best_match %||% default_workspace
143147
},
144148
load_workspace = function(workspace) {
@@ -163,8 +167,7 @@ LanguageServer <- R6::R6Class("LanguageServer",
163167
self$load_workspace(workspace)
164168
}
165169
},
166-
text_sync = function(
167-
uri, document, run_lintr = FALSE, parse = FALSE, delay = 0) {
170+
text_sync = function(uri, document, run_lintr = FALSE, parse = FALSE, delay = 0) {
168171
if (!self$pending_replies$has(uri)) {
169172
self$pending_replies$set(uri, list(
170173
`textDocument/documentSymbol` = collections::queue(),

0 commit comments

Comments
 (0)