Git Product home page Git Product logo

languageserver's Introduction

languageserver: An implementation of the Language Server Protocol for R

R-CMD-check codecov CRAN_Status_Badge CRAN Downloads r-universe

languageserver is an implementation of the Microsoft's Language Server Protocol for the language of R.

Installation

A few dependencies are required beforehand:

# On Debian, Ubuntu, etc.
apt install --assume-yes --no-install-recommends build-essential libcurl4-openssl-dev libssl-dev libxml2-dev r-base

# On Fedora, Centos, etc.
dnf install --assumeyes --setopt=install_weak_deps=False @development-tools libcurl-devel libxml2-devel openssl-devel R

# On Alpine
apk add --no-cache curl-dev g++ gcc libxml2-dev linux-headers make R R-dev

languageserver is released on CRAN and can be easily installed by

install.packages("languageserver")

To try the latest features, install the daily development build from our r-universe repository:

install.packages("languageserver", repos = c(
    reditorsupport = "https://reditorsupport.r-universe.dev",
    getOption("repos")
))

Or install the latest development version from our GitHub repository:

# install.packages("remotes")
remotes::install_github("REditorSupport/languageserver")

Language Clients

The following editors are supported by installing the corresponding extensions:

  • VS Code: vscode-R

  • Atom: atom-ide-r

  • Sublime Text: R-IDE

  • Vim/NeoVim: LanguageClient-neovim with settings

    let g:LanguageClient_serverCommands = {
        \ 'r': ['R', '--slave', '-e', 'languageserver::run()'],
        \ }

    or, if you use coc.nvim, you can do one of two things:

    • Install coc-r-lsp with:

      :CocInstall coc-r-lsp
    • or install the languageserver package in R

      install.packages("languageserver")
      # or install the developement version
      # remotes::install_github("REditorSupport/languageserver")

      Then add the following to your Coc config:

      "languageserver": {
          "R": {
              "command": "/usr/bin/R",
              "args" : [ "--slave", "-e", "languageserver::run()"],
              "filetypes" : ["r"]
          }
      }
  • Emacs: lsp-mode

  • JupyterLab: jupyterlab-lsp

  • BBEdit: preconfigured in version 14.0 and later; see the BBEdit LSP support page for complete details.

  • Nova: R-Nova

Services Implemented

languageserver is still under active development, the following services have been implemented:

Settings

languageserver exposes the following settings via LSP configuration.

settings default description
r.lsp.debug false increase verbosity for debug purpose
r.lsp.log_file null file to log debug messages, fallback to stderr if empty
r.lsp.diagnostics true enable file diagnostics via lintr
r.lsp.rich_documentation true rich documentation with enhanced markdown features
r.lsp.snippet_support true enable snippets in auto completion
r.lsp.max_completions 200 maximum number of completion items
r.lsp.lint_cache false toggle caching of lint results
r.lsp.server_capabilities {} override server capabilities defined in capabilities.R. See FAQ below.
r.lsp.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,

options(languageserver.snippet_support = FALSE)

will turn off snippet support globally. LSP configuration settings are always overriden by options().

FAQ

Linters

With lintr v2.0.0, the linters can be specified by creating the .lintr file at the project or home directory. Details can be found at lintr documentation.

Customizing server capabilities

Server capabilities are defined in 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

"r": {
    "lsp": {
        "server_capabilities": {
            "definitionProvider": false
        }
    }
}

or R options

options(
    languageserver.server_capabilities = list(
        definitionProvider = FALSE
    )
)

Customizing formatting style

The language server uses styler to perform code formatting. It uses styler::tidyverse_style(indent_by = options$tabSize) as the default style where options is the formatting options.

The formatting style can be customized by specifying languageserver.formatting_style option which is supposed to be a function that accepts an options argument mentioned above. You could consider to put the code in .Rprofile.

styler::tidyverse_style provides numerous arguments to customize the formatting behavior. For example, to make it only work at indention scope:

options(languageserver.formatting_style = function(options) {
    styler::tidyverse_style(scope = "indention", indent_by = options$tabSize)
})

To disable assignment operator fix (replacing = with <-):

options(languageserver.formatting_style = function(options) {
    style <- styler::tidyverse_style(indent_by = options$tabSize)
    style$token$force_assignment_op <- NULL
    style
})

To further customize the formatting style, please refer to Customizing styler.

languageserver's People

Contributors

andycraig avatar andyquinterom avatar atusy avatar badouralix avatar chemzqm avatar dependabot[bot] avatar dgkf avatar dpprdan avatar eitsupi avatar heavywatal avatar ikuyadeu avatar izahn avatar jonclayden avatar jozefhajnala avatar krassowski avatar kylebutts avatar lorenzwalthert avatar manuelhentschel avatar mattn avatar michaelchirico avatar otherdoug avatar qinwf avatar randy3k avatar renkun-ken avatar sei40kr avatar she3o avatar shrektan avatar siegel avatar tutuchan avatar yunuuuu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

languageserver's Issues

Connection to server is erroring

With latest dev installed, languageserver stops working in vscode at startup:

[Error - 12:51:45 AM] Connection to server is erroring. Shutting down server.
[Error - 12:51:45 AM] Connection to server is erroring. Shutting down server.
[Error - 12:51:45 AM] Connection to server is erroring. Shutting down server.
[Error - 12:51:45 AM] Connection to server is erroring. Shutting down server.
[Error - 12:51:45 AM] Connection to server is erroring. Shutting down server.
Language server exited with exit code 1

I enabled debugging, but this is the whole log I get.

I tried directly calling languageserver::run() and the connection failed anyway:

> languageserver::run(debug = TRUE, host = "127.0.0.1", port = 13567)                                                                                                                                                                
connection type: tcp at  13567
Error in socketConnection(host = host, port = port, open = "r+") : 
  cannot open the connection
In addition: Warning message:
In socketConnection(host = host, port = port, open = "r+") :
  127.0.0.1:13567 cannot be opened

Provide symbols in local scope in auto-completion

For the following cases, I'm wondering if it is possible to provide local symbols in the function body of test0 and the expression of test1.

test0 <- function(x, y, z) {
  x + y + z
}

test1 <- local({
  p <- 1
  q <- 2
  if (q >= p) {
    cat("hello!\n")
  }
})

Bug/possible syntax error in new languageserver 0.3.0

With the new version of languageserver 0.3.0 there appears to be a bug that causes linting to not work anymore. When I try to lint files I get this:

> library(languageserver)
> languageserver:::diagnose_file("test.R")
Error in range(start = list(line = line, character = result$ranges[[1]][1] -  : 
  `range` requires 'position' parameters!

Where in 0.2.9 it would work with same files.

Installation failed on mac osx High Sierra

make: /usr/local/opt/llvm/bin/clang: No such file or directory
make: *** [document.o] Error 1
ERROR: compilation failed for package ‘languageserver’

I don't have a /usr/local/opt/llvm/ directory. I have /usr/bin/clang and /usr/local/Homebrew/Library/Homebrew/shims/super/clang.
Hope that's help

Parse document and capture function and symbol definitions

At the moment, this package is not designed for providing completions from attached R session (like RStudio), local symbol/function completion for currently editing file is missing.

One simple approach to implement this is to parse the file or document being edited and extract all expressions like

fun <- function(a, b, c)
fun = function(a, b, c)
x <- list(1, 2, 3)

that is, top-level expression with an assignment operator (<- or =), and LHS is a symbol. If RHS is function, then function completion will be provided, or otherwise it is regarded as a variable.

Symbols

I realised that the machinery for Go to Definition can also be used to provide symbol information (e.g., for outlines and Go to Symbol).

I have a working implementation for textDocument/documentSymbol, although it still needs cleaning up. I should be able to put together a PR in the next week or so.

All text disappears after being formatted on save

I'm using vscode and the latest languageserver.

When formatOnSave is enabled, as I save a document, the R code formatter will sometimes make all text disappear.

The following is the log as I type x <- 1 and save the document and everything disappears:

R binary: R
connection type: tcp at  43461

connected

received:  Content-Length: 2476

received payload.

handling request:  initialize

initialization config:  {"processId":8939,"rootPath":"/home/renkun/test","rootUri":"file:///home/renkun/test","capabilities":{"workspace":{"applyEdit":true,"workspaceEdit":{"documentChanges":true,"resourceOperations":["create","rename","delete"],"failureHandling":"textOnlyTransactional"},"didChangeConfiguration":{"dynamicRegistration":true},"didChangeWatchedFiles":{"dynamicRegistration":true},"symbol":{"dynamicRegistration":true,"symbolKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26]}},"executeCommand":{"dynamicRegistration":true},"configuration":true,"workspaceFolders":true},"textDocument":{"publishDiagnostics":{"relatedInformation":true},"synchronization":{"dynamicRegistration":true,"willSave":true,"willSaveWaitUntil":true,"didSave":true},"completion":{"dynamicRegistration":true,"contextSupport":true,"completionItem":{"snippetSupport":true,"commitCharactersSupport":true,"documentationFormat":["markdown","plaintext"],"deprecatedSupport":true,"preselectSupport":true},"completionItemKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25]}},"hover":{"dynamicRegistration":true,"contentFormat":["markdown","plaintext"]},"signatureHelp":{"dynamicRegistration":true,"signatureInformation":{"documentationFormat":["markdown","plaintext"]}},"definition":{"dynamicRegistration":true},"references":{"dynamicRegistration":true},"documentHighlight":{"dynamicRegistration":true},"documentSymbol":{"dynamicRegistration":true,"symbolKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26]},"hierarchicalDocumentSymbolSupport":true},"codeAction":{"dynamicRegistration":true,"codeActionLiteralSupport":{"codeActionKind":{"valueSet":["","quickfix","refactor","refactor.extract","refactor.inline","refactor.rewrite","source","source.organizeImports"]}}},"codeLens":{"dynamicRegistration":true},"formatting":{"dynamicRegistration":true},"rangeFormatting":{"dynamicRegistration":true},"onTypeFormatting":{"dynamicRegistration":true},"rename":{"dynamicRegistration":true,"prepareSupport":true},"documentLink":{"dynamicRegistration":true},"typeDefinition":{"dynamicRegistration":true},"implementation":{"dynamicRegistration":true},"colorProvider":{"dynamicRegistration":true},"foldingRange":{"dynamicRegistration":true,"rangeLimit":5000,"lineFoldingOnly":true}}},"trace":"off","workspaceFolders":[{"uri":"file:///home/renkun/test","name":"test"}]}

deliver:  ["Response","Message","R6"]

received:  Content-Length: 52

received payload.

handling notification:  initialized
on_initialized

received:  Content-Length: 142

received payload.

handling notification:  workspace/didChangeConfiguration

settings  {"path":"","debug":true,"diagnostics":false}

{"path":"","debug":true,"diagnostics":false}

disable diagnostics

received:  Content-Length: 156

received payload.

handling notification:  textDocument/didOpen

received:  Content-Length: 131

received payload.

handling request:  textDocument/documentSymbol

document symbols found:  0

deliver:  ["Response","Message","R6"]

received:  Content-Length: 163

received payload.

handling notification:  textDocument/didChange
did change:  file:///home/renkun/test/test.R

received:  Content-Length: 191

received payload.

handling request:  textDocument/completion

token:  x

closure:  list()

completions:  29

deliver:  ["Response","Message","R6"]

received:  Content-Length: 166

received payload.

handling notification:  textDocument/didChange
did change:  file:///home/renkun/test/test.R

received:  Content-Length: 191

received payload.

handling request:  textDocument/completion

token:  

closure:  list()

completions:  0

deliver:  ["Response","Message","R6"]

received:  Content-Length: 170

received payload.

handling notification:  textDocument/didChange
did change:  file:///home/renkun/test/test.R

received:  Content-Length: 171

received payload.

handling request:  textDocument/formatting

deliver:  ["Response","Message","R6"]

received:  Content-Length: 131

received payload.

handling request:  textDocument/documentSymbol
document symbols found:  0

deliver:  ["Response","Message","R6"]

received:  Content-Length: 164

received payload.

handling notification:  textDocument/didChange
did change:  file:///home/renkun/test/test.R

received:  Content-Length: 129

received payload.

handling notification:  textDocument/didSave
did save: file:///home/renkun/test/test.R

received:  Content-Length: 131

received payload.

handling request:  textDocument/documentSymbol
document symbols found:  0

deliver:  ["Response","Message","R6"]

Autocompletion per document or for the whole workspace

The current implementation of symbol provider is workspace-wide, i.e., if you open and edit 10 R script files, then all documents are parsed and all symbols are shared in the completion list when I edit one file.

This can sometimes be annoying if I need to edit a simple script and a very long script that defines a lot of symbols at the same time.

I'm wondering if it makes sense to provide symbols per document, or according to referenced documents (as mentioned in #20).

Package object completion should not include non-package objects

Currently, if I type foo::, the completion list includes not only the exported objects of package foo, but also objects from global_env. For example,

x1 <- 0
x2 <- 0
ggplot2::x|

At ggplot2::, global objects still appear in the completion list, which I think does not make sense because if I choose any of them, e.g. ggplot2::x1 does not exist. The better behavior should be only to provide package objects under such circumstances (:: only shows package exports and ::: only shows package exports and non-exports).

test_that: DefinitionCache and Notification not found in windows 10 + r 3.6.1

Windows 10 + R 3.6.1,
When I run the test_that manually, it reports DefinitionCache and Notification not found.
The reason I did the test is wanting to find out why the lsp doesn't work in Emacs (stdio? R --slave -e languageserver::run()) while works fine in vscode (tcp?).

Details Error:

Error: Test failed: 'DefinitionCache works'
* object 'DefinitionCache' not found
1: .handleSimpleError(function (e) 
   {
       handled <<- TRUE
       test_error <<- e
       options(expressions = expressions_opt_new)
       on.exit(options(expressions = expressions_opt), add = TRUE)
       e$expectation_calls <- frame_calls(11, 2)
       test_error <<- e
       register_expectation(e)
       e$handled <- TRUE
       test_error <<- e
   }, "object 'DefinitionCache' not found", base::quote(eval(code, test_env))) at :2
2: eval(code, test_env)
Error: Test failed: 'Go to Definition works when package is specified'
* object 'Notification' not found
1: client$deliver(Notification$new("textDocument/didSave", list(textDocument = list(uri = path_to_uri(defn_file))))) at :15

For your further information about Emacs:
eglot has outputs:

{"jsonrpc":"2.0","id":1,"result":{"capabilities":{"textDocumentSync":{"openClose":true,"change":1,"willSave":false,"willSaveWaitUntil":false,"save":{"includeText":false}},"hoverProvider":true,"completionProvider":{"resolveProvider":false,"triggerCharacters":["."]},"signatureHelpProvider":{"triggerCharacters":["(",","]},"definitionProvider":true,"documentFormattingProvider":true,"documentRangeFormattingProvider":true}}}

and events:

client-request (id:1) Sat Jul 13 17:05:06 2019:
(:jsonrpc "2.0" :id 1 :method "initialize" :params
          (:processId 164788 :rootPath "c:/Users/username/Documents/base/test/R/" :rootUri "file:///c:/Users/username/Documents/base/test/R/" :initializationOptions nil :capabilities
                      (:workspace
                       (:applyEdit t :executeCommand
                                   (:dynamicRegistration :json-false)
                                   :workspaceEdit
                                   (:documentChanges :json-false)
                                   :didChangeWatchedFiles
                                   (:dynamicRegistration t)
                                   :symbol
                                   (:dynamicRegistration :json-false))
                       :textDocument
                       (:synchronization
                        (:dynamicRegistration :json-false :willSave t :willSaveWaitUntil t :didSave t)
                        :completion
                        (:dynamicRegistration :json-false :completionItem
                                              (:snippetSupport t)
                                              :contextSupport t)
                        :hover
                        (:dynamicRegistration :json-false)
                        :signatureHelp
                        (:dynamicRegistration :json-false :signatureInformation
                                              (:parameterInformation
                                               (:labelOffsetSupport t)))
                        :references
                        (:dynamicRegistration :json-false)
                        :definition
                        (:dynamicRegistration :json-false)
                        :documentSymbol
                        (:dynamicRegistration :json-false :symbolKind
                                              (:valueSet
                                               [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26]))
                        :documentHighlight
                        (:dynamicRegistration :json-false)
                        :codeAction
                        (:dynamicRegistration :json-false :codeActionLiteralSupport
                                              (:codeActionKind
                                               (:valueSet
                                                ["quickfix" "refactor" "refactor.extract" "refactor.inline" "refactor.rewrite" "source" "source.organizeImports"])))
                        :formatting
                        (:dynamicRegistration :json-false)
                        :rangeFormatting
                        (:dynamicRegistration :json-false)
                        :rename
                        (:dynamicRegistration :json-false)
                        :publishDiagnostics
                        (:relatedInformation :json-false))
                       :experimental nil)))

internal Sat Jul 13 17:07:06 2019:
(:message "Connection state changed" :change "unknown signal\n")


----------b---y---e---b---y---e----------

Formatting empty document causes internal error

Formatting an empty document will cause an internal error:

internal error:  list(message = "attempt to select less than one element in integerOneIndex", call = document[[ndoc]])

[Error - 10:51:54 AM] Request textDocument/formatting failed.
  Message: attempt to select less than one element in integerOneIndex document[[ndoc]]

  Code: -32603 

It's caused by formatting_reply where document length is assumed to be non-zero. I'll file a PR quickly for this.

Recursive parsing for symbols in global scope

I'm trying to implement recursive parsing for symbols in global scope. For example, in the following script:

x0 <- 0

if (x0 > 0) {
  x1 <- 1
  if (x1 < 0) {
    x2 <- 2
  } else {
    x3 <- 3
  }
}

for (i in 1:10) {
  x4 <- 4
  if (i >= 5) {
    x5 <- 5
  }
}

while (i < 100) {
  x6 <- 6
  if (x6 < 10) {
    x7 <- 7
    {
      x8 <- 8
    }
  }
}

All expressions are evaluated in the global scope so x1 .. x8 would be in the same scope if defined.

Extend completion with source by recursive parsing

It is tricky to provide completion without attaching to the R session being used by user. One simplified approach that I believe can serve most of the purposes is parse the currently editing document and find top-level source functions, and parse those files recursively.

For example, the following code is from several R scripts:

main.R:

library(data.table)
library(glmnet)
source("my_plot.R")
source("data/utils.R")

my_plot.R:

library(ggplot2)

data/utils.R:

library(DBI)
requireNamespace("RMariaDB")

When main.R is being edited, those library expressions are captured. If those source expressions are captured and my_plot.R and data/utils.R are analyzed, where library and source expressions in these files are also captured, the completion will be much better and no less accurate, especially when #19 is implemented.

Also those top-level library(), require(), loadNamespace(), requireNamespace() calls can be used to provide diagnostics when required package is not installed.

definition does not exclude `::` in strings

In the following code

xml_find_all(x, "descendant::expr")

when I hold Command button in VSCode, it sends a definition request. When I move my cursor to "descendant::expr", the request results in an error:

[Error - 2:31:59 PM] Request textDocument/definition failed.
  Message: {"message":"there is no package called ‘descendant’","call":{},"package":"descendant","lib.loc":{}}

  Code: -32603 

It seems that hover definition does not exclude :: in string literals.

Compilation failed on Ubuntu 16.04.03

> R -e 'devtools::install_github("REditorSupport/languageserver")'

R version 3.4.3 (2017-11-30) -- "Kite-Eating Tree"
Copyright (C) 2017 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> devtools::install_github("REditorSupport/languageserver")
g++  -I/usr/share/R/include -DNDEBUG      -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c document.cpp -o document.o
/usr/lib/R/etc/Makeconf:168: recipe for target 'document.o' failed

vscode with rtichoke

Hey,

Thanks for your work here. I'm currently having a problem with vscode when attempting to use rtichoke as the R terminal instead of the default R.exe. When using rtichoke hover-help and code completion both quit working:

rtichoke-vscode-bug

Sorry if the gif is a bit hard to see. I'm just showing it working with R.exe and then I switch to rtichoke and am showing it no longer working. This is on Windows 10 by the way.

Any advice on debugging this would be appreciated. Thanks.

Specifying default linters in .Rprofile doesn't work anymore

My default linters specification in .Rprofile doesn't work anymore. Not sure what upgrade or otherwise caused it to stop working. I do not have a .lintr file. I set a longer line length and suppressing infix spaces warning:

setHook(
    packageEvent("languageserver", "onLoad"),
    function(...) {
        options(languageserver.default_linters = lintr::with_defaults(
            line_length_linter=lintr::line_length_linter(120),
            object_usage_linter=NULL,
            object_length_linter=NULL,
            object_name_linter=NULL,
            commented_code_linter=NULL,
            infix_spaces_linter=NULL
        ))
    }
)

I'm using R 3.4.3, languageserver 0.2.5, Atom 1.33.1 with ide-r 0.1.8. When I have files open in Atom it gives me line length and infix spaces warnings. It used to work not sure why it stopped.

Completion only works for packages loaded by default

I use languageserver via coc-r-lsp and in combination with nvim-r. Completion works fine for packages that R loads at startup: base, utils, ...

I expected getting completion for the functions provided by a package after loading it, e.g. being offered left_join as a completion option after running library(dplyr), but that doesn't work.

range formatting ignores current indentation

The following code is a minimal example to demonstrate that range formatting ignores the current indentation.

When editing the function body of f, the cursor has two-space indentation initially, copy-paste the code from x <- rnorm(n) to coef(m) with indentation included to the cursor and I find the code removes its indentation after formatting (triggered by formatOnPaste in vscode). Formatting the whole document will fix this indentation issue.

Similar behavior occurs when I copy the whole t expression and paste it inside the function body of g at the cursor of two-space indentation.

n <- 1000
t <- system.time({
  x <- rnorm(n)
  y <- 3 + 2 * x + rnorm(n)
  m <- lm(y ~ x)
  coef(m)
})

f <- function(n) {
  ## paste here and the two-space indentaion is lost
x <- rnorm(n)
y <- 3 + 2 * x + rnorm(n)
m <- lm(y ~ x)
coef(m)
}

g <- function(x) {
  ## paste here and the two-space indentation is lost
t <- system.time({
  x <- rnorm(n)
  y <- 3 + 2 * x + rnorm(n)
  m <- lm(y ~ x)
  coef(m)
})
}

I guess it's because range_formatting_reply ignores the indentation of the current cursor.

Stuck at initialization with Monaco.

I am trying to Monaco editor to connect to a node.js process on Ubuntu 16.04, which in turn connects to the R language server via stdio.

Now I am stuck at the initialize step: the client sends the request to the server, but the server never sends any response, and the client errs because it fails to initialize the server.

The request sent from the client looks like this:

{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"rootPath":null,"rootUri":"/home","capabilities":{"workspace":{"applyEdit":true,"workspaceEdit":{"documentChanges":true},"didChangeConfiguration":{"dynamicRegistration":false},"didChangeWatchedFiles":{"dynamicRegistration":false},"symbol":{"dynamicRegistration":true},"executeCommand":{"dynamicRegistration":true}},"textDocument":{"synchronization":{"dynamicRegistration":true},"completion":{"completionItem":{"snippetSupport":true},"dynamicRegistration":true},"hover":{"dynamicRegistration":true},"signatureHelp":{"dynamicRegistration":true},"references":{"dynamicRegistration":true},"documentHighlight":{"dynamicRegistration":true},"documentSymbol":{"dynamicRegistration":true},"formatting":{"dynamicRegistration":true},"rangeFormatting":{"dynamicRegistration":true},"onTypeFormatting":{"dynamicRegistration":true},"definition":{"dynamicRegistration":true},"codeAction":{"dynamicRegistration":true},"codeLens":{"dynamicRegistration":true},"documentLink":{"dynamicRegistration":true},"rename":{"dynamicRegistration":true}}},"initializationOptions":{"storagePath":"/"},"trace":"off"}}

The settings used to start the R language server look like this:

{
        "uri": "/home/model.r",
        "rootUri": "/home",
        "command": "R",
        "args": [
            '--quiet',
            '--slave',
            '-e',
            "'languageserver::run()'"
        ]
}

I have looked into the server console, but I am unable to find any info/error message I can use to go further.

Any help on this issue would be appreciated!

Crash on creating empty file in vscode

When I create an empty file in vscode, the language server crashes.

Error in vapply(dots, function(x) { : values must be length 1,
 but FUN(X[[1]]) result is length 0
Calls: <Anonymous> ... <Anonymous> -> log_write -> cat -> to_string -> vapply
In addition: Warning messages:
1: In readChar(self$inputcon, n, useBytes = TRUE) :
  text connection used with readChar(), results may be incorrect
2: In readChar(self$inputcon, n, useBytes = TRUE) :
  text connection used with readChar(), results may be incorrect
3: In readChar(self$inputcon, n, useBytes = TRUE) :
  text connection used with readChar(), results may be incorrect
4: In readChar(self$inputcon, n, useBytes = TRUE) :
  text connection used with readChar(), results may be incorrect
5: In readChar(self$inputcon, n, useBytes = TRUE) :
  text connection used with readChar(), results may be incorrect
Execution halted

[Error - 1:04:27 PM] Connection to server got closed. Server will not be restarted.
[Error - 1:04:27 PM] Request textDocument/documentSymbol failed.
Error: Connection got disposed.
	at Object.dispose (/home/ken/.vscode-server/extensions/reditorsupport.r-lsp-0.1.1/node_modules/vscode-jsonrpc/lib/main.js:876:25)
	at Object.dispose (/home/ken/.vscode-server/extensions/reditorsupport.r-lsp-0.1.1/node_modules/vscode-languageclient/lib/client.js:71:35)
	at LanguageClient.handleConnectionClosed (/home/ken/.vscode-server/extensions/reditorsupport.r-lsp-0.1.1/node_modules/vscode-languageclient/lib/client.js:2153:42)
	at LanguageClient.handleConnectionClosed (/home/ken/.vscode-server/extensions/reditorsupport.r-lsp-0.1.1/node_modules/vscode-languageclient/lib/main.js:151:15)
	at closeHandler (/home/ken/.vscode-server/extensions/reditorsupport.r-lsp-0.1.1/node_modules/vscode-languageclient/lib/client.js:2140:18)
	at CallbackList.invoke (/home/ken/.vscode-server/extensions/reditorsupport.r-lsp-0.1.1/node_modules/vscode-jsonrpc/lib/events.js:62:39)
	at Emitter.fire (/home/ken/.vscode-server/extensions/reditorsupport.r-lsp-0.1.1/node_modules/vscode-jsonrpc/lib/events.js:120:36)
	at closeHandler (/home/ken/.vscode-server/extensions/reditorsupport.r-lsp-0.1.1/node_modules/vscode-jsonrpc/lib/main.js:226:26)
	at CallbackList.invoke (/home/ken/.vscode-server/extensions/reditorsupport.r-lsp-0.1.1/node_modules/vscode-jsonrpc/lib/events.js:62:39)
	at Emitter.fire (/home/ken/.vscode-server/extensions/reditorsupport.r-lsp-0.1.1/node_modules/vscode-jsonrpc/lib/events.js:120:36)
	at StreamMessageWriter.fireClose (/home/ken/.vscode-server/extensions/reditorsupport.r-lsp-0.1.1/node_modules/vscode-jsonrpc/lib/messageWriter.js:39:27)
	at Socket.StreamMessageWriter.writable.on (/home/ken/.vscode-server/extensions/reditorsupport.r-lsp-0.1.1/node_modules/vscode-jsonrpc/lib/messageWriter.js:58:46)
	at Socket.emit (events.js:187:15)
	at TCP._handle.close (net.js:606:12)
Language server exited with exit code 1

It's caused by to_string() not considering length(x) == 0 case. I'll file a PR to fix this soon.

Error: cannot open the connection.

When trying to initialize the R language server with Monaco editor, I am seeing:

R Server: received: Content-Length: 52

R Server: received payload.

R Server: handling notification: initialized
on_initialized

R Server: received: Content-Length: 944

R Server: received payload.

R Server: handling notification: textDocument/didOpen

R Server: internal error: list(message = "cannot open the connection", call = file(con, "r"))

The settings used to start the R language server look like this:

{
        "uri": "/home/model.r",
        "rootUri": "/home",
        "command": "R",
        "args": [
            '--quiet',
            '--slave',
            '-e',
            "'languageserver::run()'"
        ]
}

Handle encoding headers?

We tried using python-jsonrpc-server multiplexer for jupyterlab-lsp, however it failed with R languageserver, while most other LSP servers work ok. Would you be willing to accept a PR allowing to parse encoding and other headers, such as this:

Content-Type: application/vscode-jsonrpc; charset=utf8\r\n

Currently, I get Error in self$read_content(nbytes) : Unexpected non-empty line when this is present - it seems that only Content-Length is supported. It would be good enough if the server did not error on the additional header (the header/contents separation is defined by an empty line, so there should be no problem with detecting variable length headers).

Some relevant discussion: https://github.com/krassowski/jupyterlab-lsp/pull/50 (we also struggle with the compilation time of the languageserver and its dependencies and are looking to conda - e.g. https://anaconda.org/gwerbin/r-languageserver, to get precompiled binaries - would you be interested in us setting up a conda package for your project? Or maybe you know another solution to the slow compilation process?)

Go to Definition

It seems like there is some interest in Go to Definition lately (e.g., REditorSupport/vscode-R#105) so I thought I'd open an Issue for it.

To me it looks like the way you'd go about implementing it would be to have workspace_sync grab the function definitions in the documents and store their locations. This would be done either by modifying parse_document or creating a similar function. To look up the location of a requested definition, you'd use a function that would be structured like get_signature.

Functions with the same name can be declared more than once in R; in these cases, I think provided Go to Definition goes to one of the definitions it would be okay.

Conceivably you could have Go to Definition work for variables as well as functions but since they're more likely to be mutated I don't think it's worth including them at this point.

@randy3k How does the above sound to you? I thought I might have a try at implementing it if no-one else is working on it. (@minkir014 @Tutuchan If you're working on this already let me know - I'd be happy to leave it to someone else!)

Auto-completion for R6 object

Thanks for this amazing package. It works brilliant for Vim on Linux. It seems like that auto-completion on R6 object methods is not supported. Is there any plan to add support for R6 object? Thanks!

Unit tests hang when using devtools

This only affects development, not the end user.

To duplicate:

With languageserver not installed:

devtools::load_all("languageserver")
devtools::test("languageserver")

Output is:

Loading languageserver
Loading required package: testthat
Testing languageserver
✔ | OK F W S | Context

Then is no progress beyond that.

When languageserver is installed, unit tests complete as expected.

@kforner says (#37):

I think this is because the R process run by https://github.com/REditorSupport/languageserver/blob/master/R/languageclient.R#L18 does not find the package, since it is not installed. But there is not any error check at this point.
I propose to add a sleep, then a check that the process is still alive, otherwise raise an execption with the error stream content.

Not working on Windows

Windows does not read from STDIN non-blocking-ly. We might need to use PEEKNAMEDPIPE to check that STDIN is ready.

Request textDocument/rangeFormatting failed

Create a document like the following:

cols <- c("a", "b", "c", "d", "e",
  "f", "g", "h", "i", "j", "k", "l",
  "m", "n", "o", "p")

cols_new <- test("file1",
  names = c(1:10, 15:20),
  colnames = c())

And then copy the elements of cols (from "a" to "p" without c()) and paste them into the parentheses in colnames = c() and an internal error of languageserver occurs:

internal error:  <text>:3:22: unexpected ')'
2:   "f", "g", "h", "i", "j", "k", "l",
3:   "m", "n", "o", "p"))
                        ^

[Error - 4:14:43 PM] Request textDocument/rangeFormatting failed.
  Message: <text>:3:22: unexpected ')'
2:   "f", "g", "h", "i", "j", "k", "l",
3:   "m", "n", "o", "p"))
                        ^

  Code: -32603 

Problem when multiple functions are removed from file

There is unfortunately a problem with some of the Go to Definition code I added, which means that the DefinitionCache class does not update correctly when multiple functions are removed from a file at the same time. This means that Go to Definition can send the user to a location in a file where a function previously existed but now does not. In some cases I think it can crash the Language Server with an error like:

Error in `[[<-`(`*tmp*`, removed_functs, value = NULL) : 
  no such index at level 1

I haven't been able to reproduce this error reliably though.

It's possible this is solely a result of using [[]] rather than [] at https://github.com/REditorSupport/languageserver/blob/master/R/definition.R#L18

I will have some free time to look into this properly in a couple of weeks.

Emacs config

The lsp-mode configuration might have changed recently. The current configuration as stated in the README results for me in a "Symbol's function definition is void: lsp-define-stdio-client".

The README for lsp-mode states another snippet for setting up a language support, which would for R be then like this:

    (lsp-register-client
     (make-lsp-client :new-connection
                      (lsp-stdio-connection '("R" "--slave" "-e"
                                              "languageserver::run()"))
                      :major-modes '(ess-r-mode inferior-ess-r-mode)
                      :server-id 'lsp-R))

I've tested this, works fine for me

LS exits on startup within a Docker container

After I have installed successfully the R language server, I run the following command:

R --quiet --slave -e 'languageserver::run()'

This, I think, is supposed to start the language server. However, it exits in about 1 second without printing any message.

How do I start the language server and keep it alive and accepting input from stdin, like most other language servers do?

My env: Ubuntu 16.04.

Thanks!

Provide roxygen entries in auto-completion

For package developer, it would be great to provide roxygen entries in auto-completion.
For example, entries like @param, @export in lines starting with #' can be provided to facilitate documentation writing.

#' Test function
#' @param x an object
#' @param check a function
#' @export
#' @examples
#' test(NULL, is.null)
#' test(0, is.null)
test <- function(x, check) {
  if (check(x)) {
    x
  } else {
    stop("Check failed")
  }
}

Another related issue is that writing a line of roxygen comment and starting a new line should make the new line automatically start with #'. I'm not sure if it is a LSP thing (maybe onTypeFormatter?) or I should go to vscode-R extension (since I'm using vscode) for this feature?

compleitionProvider.triggerCharacters is string, should be array of strings

Hello, I am trying to use your language server with my client, but I'm running into this issue:

Your language server responds to the initialize request with the following:

{
...
    "completionProvider": {
      ...
      "triggerCharacters": "."
    },
    "signatureHelpProvider": {
      "triggerCharacters": [
        "(",
        ","
      ]
    },
...
}

completionProvider.triggerCharacters's return in this response is a string. However, the type the should be string[] according to the LSP spec. This issue causes my client to be unable to connect to this language server.

I dug into this a little bit, and noticed the following code:

CompletionOptions <- list(
resolveProvider = FALSE,
triggerCharacters = c(".")
)
SignatureHelpOptions <- list(
triggerCharacters = c("(", ",")
)

signatureHelpProvider.triggerCharacters's type in the above response is actually string[]. The only difference between the two that I can see in your code is that completionProvider.triggerCharacters is a sequence containing a single string ".", while signatureHelpProvider.triggerCharactersis a sequence containing multiple strings "(", "," .

I don't know enough about R to know if this is an issue with this language server, or the underlying jsonlite library that you use.

language server should be able to fufill requests even without textdocument/didOpen Notifications

The LSP Spec says the following:

... Note that a server’s ability to fulfill requests is independent of whether a text document is open or closed.

For example, I see no hover when I hover over length in this file: https://github.com/gluc/data.tree/blob/HEAD/R/node_methods_traversal.R#L93, unless I manually send this didOpen notification with the file contents. The spec says that language servers should still be able to hovers, etc. even without this notification.

License

Hey,
I find this project really useful and interesting.
I'd like to contribute, but the licensing terms are unclear to me, there's just a copyright mention.
Could you please clarify it ?

Thanks,
Karl

Completion on user-defined functions doesn't work.

While completion on built-in functions like paste seems to work, completion on user-defined functions doesn't seem so.

For example, if I define a function like addcustom, and later I enter 'addcu' expecting addcustom to be in the completion candidate list, it's not.

LSP client crash for non-ascii characters

When I'm typing non-ascii characters (e.g. Chinese) in the editor like the following:

x <- "你好"

and I start a new line and types anything that triggers the auto-completion, the LSP crashes instantly with the following log:

{"path":"","debug":true,"diagnostics":false}
disable diagnostics

received:  Content-Length: 187

error handling json:  list(message = "parse error: trailing garbage\n          text\":\"x <- \\\"你好\\\"\\nx\"}}}Cont\n                     (right here) ------^\n", call = NULL)

received:  ent-Length: 143

Error in self$read_header() : Unexpected input: ent-Length: 143


list()
exiting
Warning messages:
1: In readChar(self$inputcon, n) :
  text connection used with readChar(), results may be incorrect
2: In readChar(self$inputcon, n) :
  text connection used with readChar(), results may be incorrect
3: In readChar(self$inputcon, n) :
  text connection used with readChar(), results may be incorrect
4: In readChar(self$inputcon, n) :
  text connection used with readChar(), results may be incorrect

[Info  - 9:14:54 PM] Connection to server got closed. Server will restart.
[Error - 9:14:54 PM] Request textDocument/documentSymbol failed.
Error: Connection got disposed.
	at Object.dispose (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-jsonrpc/lib/main.js:876:25)
	at Object.dispose (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-languageclient/lib/client.js:71:35)
	at LanguageClient.handleConnectionClosed (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-languageclient/lib/client.js:2150:42)
	at LanguageClient.handleConnectionClosed (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-languageclient/lib/main.js:150:15)
	at closeHandler (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-languageclient/lib/client.js:2137:18)
	at CallbackList.invoke (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-jsonrpc/lib/events.js:62:39)
	at Emitter.fire (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-jsonrpc/lib/events.js:120:36)
	at closeHandler (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-jsonrpc/lib/main.js:226:26)
	at CallbackList.invoke (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-jsonrpc/lib/events.js:62:39)
	at Emitter.fire (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-jsonrpc/lib/events.js:120:36)
	at StreamMessageWriter.fireClose (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-jsonrpc/lib/messageWriter.js:39:27)
	at Socket.constructor.writable.on (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-jsonrpc/lib/messageWriter.js:58:46)
	at Socket.emit (events.js:187:15)
	at TCP.Socket._destroy._handle.close (net.js:606:12)
[Error - 9:14:54 PM] Request textDocument/completion failed.
Error: Connection got disposed.
	at Object.dispose (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-jsonrpc/lib/main.js:876:25)
	at Object.dispose (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-languageclient/lib/client.js:71:35)
	at LanguageClient.handleConnectionClosed (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-languageclient/lib/client.js:2150:42)
	at LanguageClient.handleConnectionClosed (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-languageclient/lib/main.js:150:15)
	at closeHandler (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-languageclient/lib/client.js:2137:18)
	at CallbackList.invoke (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-jsonrpc/lib/events.js:62:39)
	at Emitter.fire (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-jsonrpc/lib/events.js:120:36)
	at closeHandler (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-jsonrpc/lib/main.js:226:26)
	at CallbackList.invoke (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-jsonrpc/lib/events.js:62:39)
	at Emitter.fire (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-jsonrpc/lib/events.js:120:36)
	at StreamMessageWriter.fireClose (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-jsonrpc/lib/messageWriter.js:39:27)
	at Socket.constructor.writable.on (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-jsonrpc/lib/messageWriter.js:58:46)
	at Socket.emit (events.js:187:15)
	at TCP.Socket._destroy._handle.close (net.js:606:12)
R binary: R
Language server exited with exit code 0
connection type: tcp at  58921

connected

received:  Content-Length: 2506

received payload.

handling request:  initialize

initialization config:  {"processId":59325,"rootPath":"/Users/ken/data/comp-data","rootUri":"file:///Users/ken/data/comp-data","capabilities":{"workspace":{"applyEdit":true,"workspaceEdit":{"documentChanges":true,"resourceOperations":["create","rename","delete"],"failureHandling":"textOnlyTransactional"},"didChangeConfiguration":{"dynamicRegistration":true},"didChangeWatchedFiles":{"dynamicRegistration":true},"symbol":{"dynamicRegistration":true,"symbolKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26]}},"executeCommand":{"dynamicRegistration":true},"configuration":true,"workspaceFolders":true},"textDocument":{"publishDiagnostics":{"relatedInformation":true},"synchronization":{"dynamicRegistration":true,"willSave":true,"willSaveWaitUntil":true,"didSave":true},"completion":{"dynamicRegistration":true,"contextSupport":true,"completionItem":{"snippetSupport":true,"commitCharactersSupport":true,"documentationFormat":["markdown","plaintext"],"deprecatedSupport":true,"preselectSupport":true},"completionItemKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25]}},"hover":{"dynamicRegistration":true,"contentFormat":["markdown","plaintext"]},"signatureHelp":{"dynamicRegistration":true,"signatureInformation":{"documentationFormat":["markdown","plaintext"]}},"definition":{"dynamicRegistration":true},"references":{"dynamicRegistration":true},"documentHighlight":{"dynamicRegistration":true},"documentSymbol":{"dynamicRegistration":true,"symbolKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26]},"hierarchicalDocumentSymbolSupport":true},"codeAction":{"dynamicRegistration":true,"codeActionLiteralSupport":{"codeActionKind":{"valueSet":["","quickfix","refactor","refactor.extract","refactor.inline","refactor.rewrite","source","source.organizeImports"]}}},"codeLens":{"dynamicRegistration":true},"formatting":{"dynamicRegistration":true},"rangeFormatting":{"dynamicRegistration":true},"onTypeFormatting":{"dynamicRegistration":true},"rename":{"dynamicRegistration":true,"prepareSupport":true},"documentLink":{"dynamicRegistration":true},"typeDefinition":{"dynamicRegistration":true},"implementation":{"dynamicRegistration":true},"colorProvider":{"dynamicRegistration":true},"foldingRange":{"dynamicRegistration":true,"rangeLimit":5000,"lineFoldingOnly":true}}},"trace":"off","workspaceFolders":[{"uri":"file:///Users/ken/data/comp-data","name":"comp-data"}]}

deliver:  ["Response","Message","R6"]

received:  Content-Length: 52

received payload.

handling notification:  initialized
on_initialized

received:  Content-Length: 142

received payload.

handling notification:  workspace/didChangeConfiguration

settings  {"path":"","debug":true,"diagnostics":false}

{"path":"","debug":true,"diagnostics":false}

disable diagnostics

received:  Content-Length: 187

error handling json:  list(message = "parse error: trailing garbage\n          text\":\"x <- \\\"你好\\\"\\nx\"}}}Cont\n                     (right here) ------^\n", call = NULL)

received:  ent-Length: 143

Error in self$read_header() : Unexpected input: ent-Length: 143


list()
exiting
Warning messages:

1: In readChar(self$inputcon, n) :
  text connection used with readChar(), results may be incorrect
2: In readChar(self$inputcon, n) :
  text connection used with readChar(), results may be incorrect
3: In readChar(self$inputcon, n) :
  text connection used with readChar(), results may be incorrect
4: In readChar(self$inputcon, n) :
  text connection used with readChar(), results may be incorrect

[Info  - 9:14:55 PM] Connection to server got closed. Server will restart.
[Error - 9:14:55 PM] Request textDocument/documentSymbol failed.
Error: Connection got disposed.
	at Object.dispose (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-jsonrpc/lib/main.js:876:25)
	at Object.dispose (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-languageclient/lib/client.js:71:35)
	at LanguageClient.handleConnectionClosed (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-languageclient/lib/client.js:2150:42)
	at LanguageClient.handleConnectionClosed (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-languageclient/lib/main.js:150:15)
	at closeHandler (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-languageclient/lib/client.js:2137:18)
	at CallbackList.invoke (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-jsonrpc/lib/events.js:62:39)
	at Emitter.fire (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-jsonrpc/lib/events.js:120:36)
	at closeHandler (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-jsonrpc/lib/main.js:226:26)
	at CallbackList.invoke (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-jsonrpc/lib/events.js:62:39)
	at Emitter.fire (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-jsonrpc/lib/events.js:120:36)
	at StreamMessageWriter.fireClose (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-jsonrpc/lib/messageWriter.js:39:27)
	at Socket.constructor.writable.on (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-jsonrpc/lib/messageWriter.js:58:46)
	at Socket.emit (events.js:187:15)
	at TCP.Socket._destroy._handle.close (net.js:606:12)
[Error - 9:14:55 PM] Request textDocument/completion failed.
Error: Connection got disposed.
	at Object.dispose (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-jsonrpc/lib/main.js:876:25)
	at Object.dispose (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-languageclient/lib/client.js:71:35)
	at LanguageClient.handleConnectionClosed (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-languageclient/lib/client.js:2150:42)
	at LanguageClient.handleConnectionClosed (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-languageclient/lib/main.js:150:15)
	at closeHandler (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-languageclient/lib/client.js:2137:18)
	at CallbackList.invoke (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-jsonrpc/lib/events.js:62:39)
	at Emitter.fire (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-jsonrpc/lib/events.js:120:36)
	at closeHandler (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-jsonrpc/lib/main.js:226:26)
	at CallbackList.invoke (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-jsonrpc/lib/events.js:62:39)
	at Emitter.fire (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-jsonrpc/lib/events.js:120:36)
	at StreamMessageWriter.fireClose (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-jsonrpc/lib/messageWriter.js:39:27)
	at Socket.constructor.writable.on (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-jsonrpc/lib/messageWriter.js:58:46)
	at Socket.emit (events.js:187:15)
	at TCP.Socket._destroy._handle.close (net.js:606:12)
R binary: R
Language server exited with exit code 0
connection type: tcp at  58923

connected

received:  Content-Length: 2506

received payload.

handling request:  initialize

initialization config:  {"processId":59325,"rootPath":"/Users/ken/data/comp-data","rootUri":"file:///Users/ken/data/comp-data","capabilities":{"workspace":{"applyEdit":true,"workspaceEdit":{"documentChanges":true,"resourceOperations":["create","rename","delete"],"failureHandling":"textOnlyTransactional"},"didChangeConfiguration":{"dynamicRegistration":true},"didChangeWatchedFiles":{"dynamicRegistration":true},"symbol":{"dynamicRegistration":true,"symbolKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26]}},"executeCommand":{"dynamicRegistration":true},"configuration":true,"workspaceFolders":true},"textDocument":{"publishDiagnostics":{"relatedInformation":true},"synchronization":{"dynamicRegistration":true,"willSave":true,"willSaveWaitUntil":true,"didSave":true},"completion":{"dynamicRegistration":true,"contextSupport":true,"completionItem":{"snippetSupport":true,"commitCharactersSupport":true,"documentationFormat":["markdown","plaintext"],"deprecatedSupport":true,"preselectSupport":true},"completionItemKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25]}},"hover":{"dynamicRegistration":true,"contentFormat":["markdown","plaintext"]},"signatureHelp":{"dynamicRegistration":true,"signatureInformation":{"documentationFormat":["markdown","plaintext"]}},"definition":{"dynamicRegistration":true},"references":{"dynamicRegistration":true},"documentHighlight":{"dynamicRegistration":true},"documentSymbol":{"dynamicRegistration":true,"symbolKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26]},"hierarchicalDocumentSymbolSupport":true},"codeAction":{"dynamicRegistration":true,"codeActionLiteralSupport":{"codeActionKind":{"valueSet":["","quickfix","refactor","refactor.extract","refactor.inline","refactor.rewrite","source","source.organizeImports"]}}},"codeLens":{"dynamicRegistration":true},"formatting":{"dynamicRegistration":true},"rangeFormatting":{"dynamicRegistration":true},"onTypeFormatting":{"dynamicRegistration":true},"rename":{"dynamicRegistration":true,"prepareSupport":true},"documentLink":{"dynamicRegistration":true},"typeDefinition":{"dynamicRegistration":true},"implementation":{"dynamicRegistration":true},"colorProvider":{"dynamicRegistration":true},"foldingRange":{"dynamicRegistration":true,"rangeLimit":5000,"lineFoldingOnly":true}}},"trace":"off","workspaceFolders":[{"uri":"file:///Users/ken/data/comp-data","name":"comp-data"}]}

deliver:  ["Response","Message","R6"]

received:  Content-Length: 52

received payload.

handling notification:  initialized
on_initialized

received:  Content-Length: 142

received payload.

handling notification:  workspace/didChangeConfiguration

settings  {"path":"","debug":true,"diagnostics":false}

{"path":"","debug":true,"diagnostics":false}

disable diagnostics

received:  Content-Length: 187

error handling json:  list(message = "parse error: trailing garbage\n          text\":\"x <- \\\"你好\\\"\\nx\"}}}Cont\n                     (right here) ------^\n", call = NULL)

received:  ent-Length: 143

Error in self$read_header() : Unexpected input: ent-Length: 143


list()
exiting
Warning messages:
1: In readChar(self$inputcon, n) :
  text connection used with readChar(), results may be incorrect
2: In readChar(self$inputcon, n) :
  text connection used with readChar(), results may be incorrect
3: 
In readChar(self$inputcon, n) :
  text connection used with readChar(), results may be incorrect
4: In readChar(self$inputcon, n) :
  text connection used with readChar(), results may be incorrect

[Info  - 9:14:56 PM] Connection to server got closed. Server will restart.
[Error - 9:14:56 PM] Request textDocument/documentSymbol failed.
Error: Connection got disposed.
	at Object.dispose (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-jsonrpc/lib/main.js:876:25)
	at Object.dispose (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-languageclient/lib/client.js:71:35)
	at LanguageClient.handleConnectionClosed (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-languageclient/lib/client.js:2150:42)
	at LanguageClient.handleConnectionClosed (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-languageclient/lib/main.js:150:15)
	at closeHandler (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-languageclient/lib/client.js:2137:18)
	at CallbackList.invoke (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-jsonrpc/lib/events.js:62:39)
	at Emitter.fire (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-jsonrpc/lib/events.js:120:36)
	at closeHandler (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-jsonrpc/lib/main.js:226:26)
	at CallbackList.invoke (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-jsonrpc/lib/events.js:62:39)
	at Emitter.fire (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-jsonrpc/lib/events.js:120:36)
	at StreamMessageWriter.fireClose (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-jsonrpc/lib/messageWriter.js:39:27)
	at Socket.constructor.writable.on (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-jsonrpc/lib/messageWriter.js:58:46)
	at Socket.emit (events.js:187:15)
	at TCP.Socket._destroy._handle.close (net.js:606:12)
[Error - 9:14:56 PM] Request textDocument/completion failed.
Error: Connection got disposed.
	at Object.dispose (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-jsonrpc/lib/main.js:876:25)
	at Object.dispose (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-languageclient/lib/client.js:71:35)
	at LanguageClient.handleConnectionClosed (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-languageclient/lib/client.js:2150:42)
	at LanguageClient.handleConnectionClosed (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-languageclient/lib/main.js:150:15)
	at closeHandler (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-languageclient/lib/client.js:2137:18)
	at CallbackList.invoke (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-jsonrpc/lib/events.js:62:39)
	at Emitter.fire (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-jsonrpc/lib/events.js:120:36)
	at closeHandler (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-jsonrpc/lib/main.js:226:26)
	at CallbackList.invoke (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-jsonrpc/lib/events.js:62:39)
	at Emitter.fire (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-jsonrpc/lib/events.js:120:36)
	at StreamMessageWriter.fireClose (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-jsonrpc/lib/messageWriter.js:39:27)
	at Socket.constructor.writable.on (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-jsonrpc/lib/messageWriter.js:58:46)
	at Socket.emit (events.js:187:15)
	at TCP.Socket._destroy._handle.close (net.js:606:12)
R binary: R
Language server exited with exit code 0
connection type: tcp at  58925

connected

received:  Content-Length: 2506

received payload.

handling request:  initialize

initialization config:  {"processId":59325,"rootPath":"/Users/ken/data/comp-data","rootUri":"file:///Users/ken/data/comp-data","capabilities":{"workspace":{"applyEdit":true,"workspaceEdit":{"documentChanges":true,"resourceOperations":["create","rename","delete"],"failureHandling":"textOnlyTransactional"},"didChangeConfiguration":{"dynamicRegistration":true},"didChangeWatchedFiles":{"dynamicRegistration":true},"symbol":{"dynamicRegistration":true,"symbolKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26]}},"executeCommand":{"dynamicRegistration":true},"configuration":true,"workspaceFolders":true},"textDocument":{"publishDiagnostics":{"relatedInformation":true},"synchronization":{"dynamicRegistration":true,"willSave":true,"willSaveWaitUntil":true,"didSave":true},"completion":{"dynamicRegistration":true,"contextSupport":true,"completionItem":{"snippetSupport":true,"commitCharactersSupport":true,"documentationFormat":["markdown","plaintext"],"deprecatedSupport":true,"preselectSupport":true},"completionItemKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25]}},"hover":{"dynamicRegistration":true,"contentFormat":["markdown","plaintext"]},"signatureHelp":{"dynamicRegistration":true,"signatureInformation":{"documentationFormat":["markdown","plaintext"]}},"definition":{"dynamicRegistration":true},"references":{"dynamicRegistration":true},"documentHighlight":{"dynamicRegistration":true},"documentSymbol":{"dynamicRegistration":true,"symbolKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26]},"hierarchicalDocumentSymbolSupport":true},"codeAction":{"dynamicRegistration":true,"codeActionLiteralSupport":{"codeActionKind":{"valueSet":["","quickfix","refactor","refactor.extract","refactor.inline","refactor.rewrite","source","source.organizeImports"]}}},"codeLens":{"dynamicRegistration":true},"formatting":{"dynamicRegistration":true},"rangeFormatting":{"dynamicRegistration":true},"onTypeFormatting":{"dynamicRegistration":true},"rename":{"dynamicRegistration":true,"prepareSupport":true},"documentLink":{"dynamicRegistration":true},"typeDefinition":{"dynamicRegistration":true},"implementation":{"dynamicRegistration":true},"colorProvider":{"dynamicRegistration":true},"foldingRange":{"dynamicRegistration":true,"rangeLimit":5000,"lineFoldingOnly":true}}},"trace":"off","workspaceFolders":[{"uri":"file:///Users/ken/data/comp-data","name":"comp-data"}]}

deliver:  ["Response","Message","R6"]

received:  Content-Length: 52

received payload.

handling notification:  initialized
on_initialized

received:  Content-Length: 142

received payload.

handling notification:  workspace/didChangeConfiguration

settings  {"path":"","debug":true,"diagnostics":false}

{"path":"","debug":true,"diagnostics":false}

disable diagnostics

received:  Content-Length: 187

error handling json:  list(message = "parse error: trailing garbage\n          text\":\"x <- \\\"你好\\\"\\nx\"}}}Cont\n                     (right here) ------^\n", call = NULL)

received:  ent-Length: 143

Error in self$read_header() : Unexpected input: ent-Length: 143


list()
exiting
Warning messages:
1: In readChar(self$inputcon, n) :
  text connection used with readChar(), results may be incorrect
2: In readChar(self$inputcon, n) :
  text connection used with readChar(), results may be incorrect
3: In readChar(self$inputcon, n) :
  text connection used with readChar(), results may be incorrect
4: In readChar(self$inputcon, n) :
  text connection used with readChar(), results may be incorrect

[Error - 9:14:56 PM] Connection to server got closed. Server will not be restarted.
[Error - 9:14:56 PM] Request textDocument/documentSymbol failed.
Error: Connection got disposed.
	at Object.dispose (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-jsonrpc/lib/main.js:876:25)
	at Object.dispose (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-languageclient/lib/client.js:71:35)
	at LanguageClient.handleConnectionClosed (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-languageclient/lib/client.js:2150:42)
	at LanguageClient.handleConnectionClosed (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-languageclient/lib/main.js:150:15)
	at closeHandler (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-languageclient/lib/client.js:2137:18)
	at CallbackList.invoke (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-jsonrpc/lib/events.js:62:39)
	at Emitter.fire (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-jsonrpc/lib/events.js:120:36)
	at closeHandler (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-jsonrpc/lib/main.js:226:26)
	at CallbackList.invoke (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-jsonrpc/lib/events.js:62:39)
	at Emitter.fire (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-jsonrpc/lib/events.js:120:36)
	at StreamMessageWriter.fireClose (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-jsonrpc/lib/messageWriter.js:39:27)
	at Socket.constructor.writable.on (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-jsonrpc/lib/messageWriter.js:58:46)
	at Socket.emit (events.js:187:15)
	at TCP.Socket._destroy._handle.close (net.js:606:12)
[Error - 9:14:56 PM] Request textDocument/completion failed.
Error: Connection got disposed.
	at Object.dispose (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-jsonrpc/lib/main.js:876:25)
	at Object.dispose (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-languageclient/lib/client.js:71:35)
	at LanguageClient.handleConnectionClosed (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-languageclient/lib/client.js:2150:42)
	at LanguageClient.handleConnectionClosed (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-languageclient/lib/main.js:150:15)
	at closeHandler (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-languageclient/lib/client.js:2137:18)
	at CallbackList.invoke (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-jsonrpc/lib/events.js:62:39)
	at Emitter.fire (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-jsonrpc/lib/events.js:120:36)
	at closeHandler (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-jsonrpc/lib/main.js:226:26)
	at CallbackList.invoke (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-jsonrpc/lib/events.js:62:39)
	at Emitter.fire (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-jsonrpc/lib/events.js:120:36)
	at StreamMessageWriter.fireClose (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-jsonrpc/lib/messageWriter.js:39:27)
	at Socket.constructor.writable.on (/Users/ken/.vscode/extensions/reditorsupport.r-lsp-0.1.0/node_modules/vscode-jsonrpc/lib/messageWriter.js:58:46)
	at Socket.emit (events.js:187:15)
	at TCP.Socket._destroy._handle.close (net.js:606:12)
Language server exited with exit code 0

Auto-complete with full list of package objects on `::` and `:::`

Currently, typing pkg:: does not trigger auto-completion to show the full list of exported objects of pkg. Neither does pkg::: show the full list of exported and non-exported objects of pkg.

It would be convinient to trigger auto-completion on both :: and ::: so that user could easily explorer the functions in a package without knowing in advance the exact starting letters of the function the user wants.

Provide diagnostics on non-installed packages

The current diagnotics use lintr which is mainly focused on style diagnostics. However, code correctness is largely not diagnosed. An obvious one is to check if there is any library(pkg) call that points to non-installed package. Similar calls include require(pkg), loadNamespace("pkg"), requireNamespace("pkg"), pkg::foo, pkg:::bar.

The recently released lintr v2.0.0 supports customized lintr. I'm not sure if it is better to use this or separate correctness checks from linting.

Language server should load package under development at startup

Currently, the packages to load on startup of languageserver are those basic packages an fresh R session would attach.

If the project is a package (when NAMESPACE or DESCRIPTION is detected), the package should be loaded on startup too, to provide completion.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.