@@ -456,8 +456,6 @@ completion_reply <- function(id, uri, workspace, document, point, capabilities)
456456 )))
457457 }
458458
459- nmax <- getOption(" languageserver.max_completions" , 100 )
460-
461459 t0 <- Sys.time()
462460 snippet_support <- isTRUE(capabilities $ completionItem $ snippetSupport ) &&
463461 getOption(" languageserver.snippet_support" , TRUE )
@@ -470,7 +468,7 @@ completion_reply <- function(id, uri, workspace, document, point, capabilities)
470468
471469 completions <- list ()
472470
473- if (length( completions ) < nmax && token_result $ accessor == " " ) {
471+ if (token_result $ accessor == " " ) {
474472 call_result <- document $ detect_call(point )
475473 if (nzchar(call_result $ token )) {
476474 completions <- c(
@@ -483,55 +481,45 @@ completion_reply <- function(id, uri, workspace, document, point, capabilities)
483481
484482 if (nzchar(full_token )) {
485483 if (is.null(package )) {
486- if (length(completions ) < nmax ) {
487- completions <- c(completions ,
488- constant_completion(token ))
489- }
490-
491- if (length(completions ) < nmax ) {
492- completions <- c(completions ,
493- package_completion(token ))
494- }
495-
496- if (length(completions ) < nmax ) {
497- completions <- c(completions ,
498- scope_completion(uri , workspace , token , point , snippet_support ))
499- }
484+ completions <- c(completions ,
485+ constant_completion(token ),
486+ package_completion(token ),
487+ scope_completion(uri , workspace , token , point , snippet_support )
488+ )
500489 }
501490
502- if (length(completions ) < nmax ) {
503- completions <- c(
504- completions ,
505- workspace_completion(
506- workspace , token , package , token_result $ accessor == " ::" , snippet_support ))
507- }
491+ completions <- c(
492+ completions ,
493+ workspace_completion(
494+ workspace , token , package , token_result $ accessor == " ::" , snippet_support ))
508495 }
509496
510- if (length( completions ) < nmax && is.null(token_result $ package )) {
497+ if (is.null(token_result $ package )) {
511498 existing_symbols <- vapply(completions , " [[" , character (1 ), " label" )
512499 completions <- c(
513500 completions ,
514501 token_completion(uri , workspace , token , existing_symbols )
515502 )
516503 }
517504
518- t1 <- Sys.time( )
519- count <- length( completions )
505+ init_count <- length( completions )
506+ nmax <- getOption( " languageserver.max_completions " , 200 )
520507
521508 if (length(completions ) > = nmax ) {
522509 isIncomplete <- TRUE
523510 label_text <- vapply(completions , " [[" , character (1 ), " label" )
524- completions <- completions [startsWith(label_text , token )]
525- if (length(completions ) > = nmax ) {
526- sort_text <- vapply(completions , " [[" , character (1 ), " sortText" )
527- completions <- completions [order(sort_text )][seq_len(nmax )]
528- }
511+ sort_text <- vapply(completions , " [[" , character (1 ), " sortText" )
512+ order <- order(! startsWith(label_text , token ), sort_text )
513+ completions <- completions [order ][seq_len(nmax )]
529514 } else {
530515 isIncomplete <- FALSE
531516 }
532517
518+ t1 <- Sys.time()
519+
533520 logger $ info(" completions: " , list (
534- count = count ,
521+ init_count = init_count ,
522+ final_count = length(completions ),
535523 time = as.numeric(t1 - t0 ),
536524 isIncomplete = isIncomplete
537525 ))
0 commit comments