-
Notifications
You must be signed in to change notification settings - Fork 99
Improve handling configuration settings #439
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
3f3296d
01ddd25
cd4cbe5
3d717c6
c7b6a28
2a8e4c4
4724e42
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
protocol_set_trace <- function(self, id, params) { | ||
value <- params$value | ||
if (value == "off") { | ||
logger$disable_debug() | ||
lsp_settings$set("debug", FALSE) | ||
} else { | ||
logger$enable_debug() | ||
lsp_settings$set("debug", TRUE) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
Settings <- R6::R6Class("Settings", | ||
private = list( | ||
renkun-ken marked this conversation as resolved.
Show resolved
Hide resolved
|
||
settings = list( | ||
debug = FALSE, | ||
log_file = NULL, | ||
diagnostics = TRUE, | ||
rich_documentation = TRUE, | ||
snippet_support = TRUE, | ||
max_completions = 200, | ||
lint_cache = TRUE, | ||
server_capabilities = list(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps we should have an individual switch for each provider rather than to expose the capabilities. |
||
link_file_size_limit = 16L * 1024L^2 | ||
) | ||
), | ||
public = list( | ||
update_from_options = function() { | ||
# update default settings | ||
for (key in names(private$settings)) { | ||
prefixed_key <- paste0("languageserver.", key) | ||
if (hasName(options(), prefixed_key)) { | ||
value <- getOption(prefixed_key) | ||
logger$info("Update setting", key, "to", value) | ||
self$set(key, value) | ||
} | ||
} | ||
}, | ||
update_from_workspace = function(settings) { | ||
setting_keys <- names(settings) | ||
for (key in setting_keys) { | ||
prefixed_key <- paste0("languageserver.", key) | ||
if (hasName(options(), prefixed_key)) { | ||
logger$info("Setting", key, "is masked by options(...).") | ||
} else { | ||
self$set(key, settings[[key]]) | ||
} | ||
} | ||
}, | ||
get = function(key) { | ||
return(private$settings[[key]]) | ||
}, | ||
set = function(key, value) { | ||
private$settings[[key]] <- value | ||
return(self) | ||
} | ||
) | ||
) | ||
|
||
|
||
# create the settings object | ||
lsp_settings <- Settings$new() |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -109,22 +109,27 @@ These editors are supported by installing the corresponding package. | |
|
||
## Settings | ||
|
||
`languageserver` exposes the following settings via `workspace/didChangeConfiguration` | ||
`languageserver` exposes the following settings via LSP configuration. | ||
|
||
settings | default | description | ||
---- | ----- | ----- | ||
`debug` | `false` | increase verbosity for debug purpose | ||
`log_file` | `nil` | file to log debug messages, fallback to stderr if empty | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it is nil, not null? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are right. Too much golang this week. |
||
`diagnostics` | `true` | enable file diagnostics via [lintr](https://github.com/jimhester/lintr) | ||
`rich_documentation` | `true` | rich documentation with enhanced markdown features | ||
`snippet_support` | `true` | enable snippets in auto completion | ||
`max_completions` | 200 | maximum number of completion items | ||
`lint_cache` | `true` | toggle caching of lint results | ||
`server_capabilities` | `{}` | override server capabilities defined in [capabilities.R](https://github.com/REditorSupport/languageserver/blob/master/R/capabilities.R). See FAQ below. | ||
`link_file_size_limit` | 16384 | maximum file size (in bytes) that supports document links | ||
|
||
These settings could also specified in `.Rprofile` file via `options(languageserver.<SETTING_NAME> = <VALUE>)`. For example, | ||
|
||
```json | ||
{ | ||
"r.lsp.debug": { | ||
"type": "boolean", | ||
"default": false, | ||
"description": "Debug R Language Server" | ||
}, | ||
"r.lsp.diagnostics": { | ||
"type": "boolean", | ||
"default": true, | ||
"description": "Enable Diagnostics" | ||
} | ||
} | ||
```r | ||
options(languageserver.snippet_support = FALSE) | ||
``` | ||
will turn off snippet support globally. LSP configuration settings are always overriden by `options()`. | ||
|
||
|
||
## FAQ | ||
|
||
|
@@ -134,9 +139,17 @@ With [lintr](https://github.com/jimhester/lintr) v2.0.0, the linters can be spec | |
|
||
### Customizing server capbabilities | ||
|
||
Server capabilities are defined in [capabilities.R](https://github.com/REditorSupport/languageserver/blob/master/R/capabilities.R). Users could override the settings by specifiying `languageserver.server_capabilities` option in `.Rprofile`. For example, | ||
the following code will turn off `definitionProvider`, | ||
|
||
Server capabilities are defined in | ||
[capabilities.R](https://github.com/REditorSupport/languageserver/blob/master/R/capabilities.R). | ||
Users could override the capabilities by specifying the LSP configuration setting | ||
`server_capabilities` or | ||
`options(languageserver.server_capabilities)` in `.Rprofile`. For example, to turn off `definitionProvider`, one could either use LSP configuration | ||
```json | ||
"server_capabilities": { | ||
"definitionProvider": false | ||
} | ||
``` | ||
or R options | ||
```r | ||
options( | ||
languageserver.server_capabilities = list( | ||
|
@@ -145,8 +158,6 @@ options( | |
) | ||
``` | ||
|
||
Please only use this option to disable providers and do not enable any providers that have not been implemented. Changing any other entries may cause unexpected behaviors on the server. | ||
|
||
### Customizing formatting style | ||
|
||
The language server uses [`styler`](https://github.com/r-lib/styler) to perform code formatting. It uses `styler::tidyverse_style(indent_by = options$tabSize)` as the default style where `options` is the [formatting | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.