From b84983a4e59324cbea21171133b3370988d2e208 Mon Sep 17 00:00:00 2001 From: Kun Ren Date: Thu, 27 May 2021 12:43:50 +0800 Subject: [PATCH] Use a function call as the completer in on-type-formatting --- R/formatting.R | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/R/formatting.R b/R/formatting.R index 2a936b37..ab19a65f 100644 --- a/R/formatting.R +++ b/R/formatting.R @@ -126,17 +126,17 @@ range_formatting_reply <- function(id, uri, document, range, options) { on_type_formatting_reply <- function(id, uri, document, point, ch, options) { content <- document$content end_line <- point$row + 1 - use_zero <- FALSE + use_completer <- FALSE if (ch == "\n") { start_line <- end_line - 1 if (grepl("^\\s*(#.*)?$", content[[start_line]])) { return(Response$new(id)) } if (grepl("^\\s*(#.*)?$", content[[end_line]])) { - # use "0" to complete the potentially incomplete expression + # use completer to complete the potentially incomplete expression last_line <- content[end_line] - content[end_line] <- "0" - use_zero <- TRUE + content[end_line] <- "f()" + use_completer <- TRUE } } else { start_line <- end_line @@ -203,8 +203,9 @@ on_type_formatting_reply <- function(id, uri, document, point, ch, options) { error = function(e) logger$info("on_type_formatting_reply:styler:", e) ) if (!is.null(new_text)) { - if (use_zero) { - new_text <- substr(new_text, 1, nchar(new_text) - 1) + if (use_completer) { + # remove completer from formatted text + new_text <- substr(new_text, 1, nchar(new_text) - 3) new_text <- paste0(new_text, trimws(last_line)) } range <- range(