@@ -455,6 +455,8 @@ completion_reply <- function(id, uri, workspace, document, point, capabilities)
455455 items = list ()
456456 )))
457457 }
458+
459+ t0 <- Sys.time()
458460 snippet_support <- isTRUE(capabilities $ completionItem $ snippetSupport ) &&
459461 getOption(" languageserver.snippet_support" , TRUE )
460462
@@ -499,10 +501,32 @@ completion_reply <- function(id, uri, workspace, document, point, capabilities)
499501 )
500502 }
501503
504+ init_count <- length(completions )
505+ nmax <- getOption(" languageserver.max_completions" , 200 )
506+
507+ if (init_count > nmax ) {
508+ isIncomplete <- TRUE
509+ label_text <- vapply(completions , " [[" , character (1 ), " label" )
510+ sort_text <- vapply(completions , " [[" , character (1 ), " sortText" )
511+ order <- order(! startsWith(label_text , token ), sort_text )
512+ completions <- completions [order ][seq_len(nmax )]
513+ } else {
514+ isIncomplete <- FALSE
515+ }
516+
517+ t1 <- Sys.time()
518+
519+ logger $ info(" completions: " , list (
520+ init_count = init_count ,
521+ final_count = length(completions ),
522+ time = as.numeric(t1 - t0 ),
523+ isIncomplete = isIncomplete
524+ ))
525+
502526 Response $ new(
503527 id ,
504528 result = list (
505- isIncomplete = FALSE ,
529+ isIncomplete = isIncomplete ,
506530 items = completions
507531 )
508532 )
0 commit comments