Skip to content

A TCP client for the R languageserver

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md
Notifications You must be signed in to change notification settings

MilesMcBain/tcplspclient

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tcplspclient

A TCP client for corresponding with R’s language server enabling interactive debugging.

Installation

pak::pkg_install("milesmcbain/tcplspclient")

Usage

In R session 1 (client):

  1. Start the client. (It’s technically the server. Good one Microsoft.)
library(tcplspclient)
client <- TCPLanguageClient$new(host = "localhost", port = 8888)

In R session 2 (server):

  1. devtools::load_all()
  2. Add browser() statements or use debugonce()/debug() etc to languageserver functions.
  3. Connect the language server to the client:
run(port = 8888)

In R session 1 (client)

  1. Do handshake.
# TCP client connected to localhost:8888
server_capabilities <- client$handshake()

server_capabilities
# $textDocumentSync
# $textDocumentSync$openClose
# [1] TRUE

# $textDocumentSync$change
# [1] 1

# $textDocumentSync$willSave
# [1] FALSE

# ...
  1. Send messages to trigger server actions to debug in session 2.
  • note see this file for protocol wrapper functions.
doc_path <- "~/code/r/blogdown_test/content/post/test2.R"

client$send_notification(
        method = "textDocument/didSave",
        params  = list(textDocument = list(
          uri = languageserver:::path_to_uri(doc_path)), 
          text = paste0(stringi::stri_read_lines(doc_path), collapse = "\n")
        )
)

response <- client$send_message(
        method = "textDocument/documentSymbol",
        params = list(
            textDocument = list(uri = 
                languageserver:::path_to_uri("~/code/r/blogdown_test/content/post/test2.R"))
        )
    )

Now debug interactively in R session 1. Eventually get the response you expected:

response

# response
# [[1]]
# [[1]]$name
# [1] "f"

# [[1]]$kind
# [1] 12

# [[1]]$location
# [[1]]$location$uri
# [1] "file:///home/miles/code/r/blogdown_test/content/post/test2.R"

# [[1]]$location$range
# [[1]]$location$range$start
# [[1]]$location$range$start$line
# [1] 0

# [[1]]$location$range$start$character
# [1] 0

Licenses

Code in this project is substantially copied from the {languageserver}. Code files carry approriate licenses and attribution in header comments.

About

A TCP client for the R languageserver

Resources

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages