Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions R/handlers-general.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
#'
#' @keywords internal
on_initialize <- function(self, id, params) {
trace <- params$trace
if (!is.null(trace) && trace %in% c("messages", "verbose")) {
logger$enable_debug()
}

logger$info("session: ", list(
system = as.list(Sys.info()),
pid = Sys.getpid(),
Expand Down
8 changes: 8 additions & 0 deletions R/handlers-protocol.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
protocol_set_trace <- function(self, id, params) {
value <- params$value
if (value == "off") {
logger$disable_debug()
} else {
logger$enable_debug()
}
}
8 changes: 6 additions & 2 deletions R/handlers-workspace.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ workspace_did_change_configuration <- function(self, params) {
settings <- if (is.null(vscode_setting)) settings else vscode_setting

logger$info("settings ", settings)
logger$debug_mode(settings$debug)
logger$info(settings)

debug <- settings$debug
if (isTRUE(debug) || is.character(debug)) {
log_file <- if (is.character(debug)) debug else NULL
logger$enable_debug(file = log_file)
}

if (!is.null(settings$diagnostics) && !isTRUE(settings$diagnostics)) {
logger$info("disable diagnostics")
Expand Down
8 changes: 6 additions & 2 deletions R/languageserver.R
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,8 @@ LanguageServer$set("public", "register_handlers", function() {
`textDocument/didChange` = text_document_did_change,
`textDocument/didSave` = text_document_did_save,
`textDocument/didClose` = text_document_did_close,
`workspace/didChangeConfiguration` = workspace_did_change_configuration
`workspace/didChangeConfiguration` = workspace_did_change_configuration,
`$/setTrace` = protocol_set_trace
)
})

Expand All @@ -250,7 +251,10 @@ LanguageServer$set("public", "register_handlers", function() {
run <- function(debug = FALSE, host = "localhost", port = NULL) {
tools::Rd2txt_options(underline_titles = FALSE)
tools::Rd2txt_options(itemBullet = "* ")
logger$debug_mode(debug)
if (isTRUE(debug) || is.character(debug)) {
log_file <- if (is.character(debug)) debug else NULL
logger$enable_debug(file = log_file)
}
langserver <- LanguageServer$new(host, port)
langserver$run()
}
13 changes: 7 additions & 6 deletions R/log.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,15 @@ Logger <- R6::R6Class("Logger",
file = stderr()
),
public = list(
debug_mode = function(debug) {
if (isTRUE(debug) || is.character(debug)) {
private$debug <- TRUE
if (is.character(debug)) {
private$file <- debug
}
enable_debug = function(file = NULL) {
private$debug <- TRUE
if (!is.null(file)) {
private$file <- file
}
},
disable_debug = function() {
private$debug <- FALSE
},
error = function(...) {
log_write(..., file = private$file)
},
Expand Down