mirror of
https://github.com/dense-analysis/ale.git
synced 2026-03-05 22:54:24 +08:00
Add support for R languageserver (#3370)
This commit is contained in:
26
ale_linters/r/languageserver.vim
Normal file
26
ale_linters/r/languageserver.vim
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
" Author: Eric Zhao <21zhaoe@protonmail.com>
|
||||||
|
" Description: Implementation of the Language Server Protocol for R.
|
||||||
|
|
||||||
|
call ale#Set('r_languageserver_cmd', 'languageserver::run()')
|
||||||
|
call ale#Set('r_languageserver_options', {})
|
||||||
|
|
||||||
|
function! ale_linters#r#languageserver#GetCommand(buffer) abort
|
||||||
|
let l:cmd_string = ale#Var(a:buffer, 'r_languageserver_cmd')
|
||||||
|
|
||||||
|
return 'Rscript --vanilla -e ' . ale#Escape(l:cmd_string)
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! ale_linters#r#languageserver#GetProjectRoot(buffer) abort
|
||||||
|
let l:project_root = ale#path#FindNearestFile(a:buffer, '.Rprofile')
|
||||||
|
|
||||||
|
return !empty(l:project_root) ? fnamemodify(l:project_root, ':h') : fnamemodify(a:buffer, ':h')
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
call ale#linter#Define('r', {
|
||||||
|
\ 'name': 'languageserver',
|
||||||
|
\ 'lsp': 'stdio',
|
||||||
|
\ 'lsp_config': {b -> ale#Var(b, 'r_languageserver_options')},
|
||||||
|
\ 'executable': 'Rscript',
|
||||||
|
\ 'command': function('ale_linters#r#languageserver#GetCommand'),
|
||||||
|
\ 'project_root': function('ale_linters#r#languageserver#GetProjectRoot')
|
||||||
|
\})
|
||||||
@@ -2,6 +2,29 @@
|
|||||||
ALE R Integration *ale-r-options*
|
ALE R Integration *ale-r-options*
|
||||||
|
|
||||||
|
|
||||||
|
===============================================================================
|
||||||
|
languageserver *ale-r-languageserver*
|
||||||
|
|
||||||
|
g:ale_r_languageserver_cmd *g:ale_r_languageserver_cmd*
|
||||||
|
*b:ale_r_languageserver_cmd*
|
||||||
|
Type: |String|
|
||||||
|
Default: `'languageserver::run()'`
|
||||||
|
|
||||||
|
This option can be configured to change the execution command for
|
||||||
|
languageserver.
|
||||||
|
|
||||||
|
See the languageserver documentation for more options.
|
||||||
|
|
||||||
|
|
||||||
|
g:ale_r_languageserver_options *g:ale_r_languageserver_options*
|
||||||
|
*b:ale_r_languageserver_options*
|
||||||
|
Type: |Dictionary|
|
||||||
|
Default: `{}`
|
||||||
|
|
||||||
|
This option can be configured to change settings for languageserver. See the
|
||||||
|
languageserver documentation for more information.
|
||||||
|
|
||||||
|
|
||||||
===============================================================================
|
===============================================================================
|
||||||
lintr *ale-r-lintr*
|
lintr *ale-r-lintr*
|
||||||
|
|
||||||
|
|||||||
@@ -389,6 +389,7 @@ Notes:
|
|||||||
* `qmlfmt`
|
* `qmlfmt`
|
||||||
* `qmllint`
|
* `qmllint`
|
||||||
* R
|
* R
|
||||||
|
* `languageserver`
|
||||||
* `lintr`
|
* `lintr`
|
||||||
* `styler`
|
* `styler`
|
||||||
* Racket
|
* Racket
|
||||||
|
|||||||
@@ -2854,6 +2854,7 @@ documented in additional help files.
|
|||||||
qml.....................................|ale-qml-options|
|
qml.....................................|ale-qml-options|
|
||||||
qmlfmt................................|ale-qml-qmlfmt|
|
qmlfmt................................|ale-qml-qmlfmt|
|
||||||
r.......................................|ale-r-options|
|
r.......................................|ale-r-options|
|
||||||
|
languageserver........................|ale-r-languageserver|
|
||||||
lintr.................................|ale-r-lintr|
|
lintr.................................|ale-r-lintr|
|
||||||
styler................................|ale-r-styler|
|
styler................................|ale-r-styler|
|
||||||
reasonml................................|ale-reasonml-options|
|
reasonml................................|ale-reasonml-options|
|
||||||
|
|||||||
@@ -398,6 +398,7 @@ formatting.
|
|||||||
* [qmlfmt](https://github.com/jesperhh/qmlfmt)
|
* [qmlfmt](https://github.com/jesperhh/qmlfmt)
|
||||||
* [qmllint](https://github.com/qt/qtdeclarative/tree/5.11/tools/qmllint)
|
* [qmllint](https://github.com/qt/qtdeclarative/tree/5.11/tools/qmllint)
|
||||||
* R
|
* R
|
||||||
|
* [languageserver](https://github.com/REditorSupport/languageserver)
|
||||||
* [lintr](https://github.com/jimhester/lintr)
|
* [lintr](https://github.com/jimhester/lintr)
|
||||||
* [styler](https://github.com/r-lib/styler)
|
* [styler](https://github.com/r-lib/styler)
|
||||||
* Racket
|
* Racket
|
||||||
|
|||||||
0
test/command_callback/r_paths/.Rprofile
Normal file
0
test/command_callback/r_paths/.Rprofile
Normal file
22
test/command_callback/test_r_languageserver_callbacks.vader
Normal file
22
test/command_callback/test_r_languageserver_callbacks.vader
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
Before:
|
||||||
|
call ale#assert#SetUpLinterTest('r', 'languageserver')
|
||||||
|
|
||||||
|
After:
|
||||||
|
call ale#assert#TearDownLinterTest()
|
||||||
|
|
||||||
|
Execute(The default executable path should be correct):
|
||||||
|
AssertLinter 'Rscript', 'Rscript --vanilla -e ' . ale#Escape('languageserver::run()')
|
||||||
|
|
||||||
|
Execute(The project root should be detected correctly):
|
||||||
|
AssertLSPProject '.'
|
||||||
|
|
||||||
|
call ale#test#SetFilename('r_paths/dummy/test.R')
|
||||||
|
|
||||||
|
AssertLSPProject ale#path#Simplify(g:dir . '/r_paths')
|
||||||
|
|
||||||
|
Execute(Should accept configuration settings):
|
||||||
|
AssertLSPConfig {}
|
||||||
|
|
||||||
|
let b:ale_r_languageserver_options = {'r': {'lsp': {'debug': 'true', 'diagnostics': 'true'}}}
|
||||||
|
|
||||||
|
AssertLSPConfig {'r': {'lsp': {'debug': 'true', 'diagnostics': 'true'}}}
|
||||||
Reference in New Issue
Block a user