Skip to content

Commit 164b0db

Browse files
authored
Merge pull request #326 from renkun-ken/token-completion
Exclude existing completion items in token_completion
2 parents 0951151 + fd6cbc4 commit 164b0db

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

R/completion.R

+4-2
Original file line numberDiff line numberDiff line change
@@ -336,14 +336,15 @@ scope_completion <- function(uri, workspace, token, point, snippet_support = NUL
336336
completions
337337
}
338338

339-
token_completion <- function(uri, workspace, token) {
339+
token_completion <- function(uri, workspace, token, exclude = NULL) {
340340
xdoc <- workspace$get_parse_data(uri)$xml_doc
341341
if (is.null(xdoc)) {
342342
return(list())
343343
}
344344

345345
symbols <- unique(xml_text(xml_find_all(xdoc, "//SYMBOL | //SYMBOL_SUB | //SYMBOL_FUNCTION_CALL")))
346346
symbols <- symbols[startsWith(symbols, token)]
347+
symbols <- setdiff(symbols, exclude)
347348
token_completions <- lapply(symbols, function(symbol) {
348349
list(
349350
label = symbol,
@@ -399,9 +400,10 @@ completion_reply <- function(id, uri, workspace, document, point, capabilities)
399400
}
400401

401402
if (is.null(token_result$package)) {
403+
existing_symbols <- vapply(completions, "[[", character(1), "label")
402404
completions <- c(
403405
completions,
404-
token_completion(uri, workspace, token)
406+
token_completion(uri, workspace, token, existing_symbols)
405407
)
406408
}
407409

0 commit comments

Comments
 (0)