Skip to content

Commit

Permalink
Merge pull request #413 from renkun-ken/faster-completion
Browse files Browse the repository at this point in the history
Faster completion
  • Loading branch information
renkun-ken authored Apr 9, 2021
2 parents f9b218c + 6155b1d commit 2564649
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
26 changes: 25 additions & 1 deletion R/completion.R
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,8 @@ completion_reply <- function(id, uri, workspace, document, point, capabilities)
items = list()
)))
}

t0 <- Sys.time()
snippet_support <- isTRUE(capabilities$completionItem$snippetSupport) &&
getOption("languageserver.snippet_support", TRUE)

Expand Down Expand Up @@ -499,10 +501,32 @@ completion_reply <- function(id, uri, workspace, document, point, capabilities)
)
}

init_count <- length(completions)
nmax <- getOption("languageserver.max_completions", 200)

if (init_count > nmax) {
isIncomplete <- TRUE
label_text <- vapply(completions, "[[", character(1), "label")
sort_text <- vapply(completions, "[[", character(1), "sortText")
order <- order(!startsWith(label_text, token), sort_text)
completions <- completions[order][seq_len(nmax)]
} else {
isIncomplete <- FALSE
}

t1 <- Sys.time()

logger$info("completions: ", list(
init_count = init_count,
final_count = length(completions),
time = as.numeric(t1 - t0),
isIncomplete = isIncomplete
))

Response$new(
id,
result = list(
isIncomplete = FALSE,
isIncomplete = isIncomplete,
items = completions
)
)
Expand Down
3 changes: 2 additions & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ check_scope <- function(uri, document, point) {
}
}

match_with <- function(x, pattern) {
match_with <- function(x, token) {
pattern <- gsub(".", "\\.", token, fixed = TRUE)
grepl(pattern, x, ignore.case = TRUE)
}

Expand Down

0 comments on commit 2564649

Please sign in to comment.