From 651038b6017c2d2bd7027076ff2838e7cc4a078e Mon Sep 17 00:00:00 2001 From: "D. Ben Knoble" Date: Mon, 19 Jul 2021 21:02:23 -0400 Subject: [PATCH] racket: support racket-langserver lsp (#3808) * racket: support racket-langserver lsp * racket-langserver: find highest dir with init.rkt * autoload/ale/racket: re-indent to 4 spaces * racket: lint: sort supported tools * racket: lint: function! This is _not_ needed anymore, but the lint wants it. See :help E127 * racket-langserver: do not use new dict format * racket: lint: use snake_case * add tests for racket-langserver * racket-langserver tests: correct result values --- ale_linters/racket/langserver.vim | 7 +++ autoload/ale/racket.vim | 12 +++++ doc/ale-supported-languages-and-tools.txt | 1 + supported-tools.md | 1 + test/linter/test_racket_langserver.vader | 45 +++++++++++++++++++ .../racket/many-inits/a/b/c/foo.rkt | 3 ++ .../racket/many-inits/a/b/c/init.rkt | 1 + test/test-files/racket/many-inits/a/b/foo.rkt | 3 ++ .../test-files/racket/many-inits/a/b/init.rkt | 1 + test/test-files/racket/many-inits/a/foo.rkt | 3 ++ test/test-files/racket/many-inits/a/init.rkt | 1 + test/test-files/racket/many-inits/foo.rkt | 3 ++ test/test-files/racket/many-inits/init.rkt | 1 + test/test-files/racket/simple-script/foo.rkt | 3 ++ 14 files changed, 85 insertions(+) create mode 100644 ale_linters/racket/langserver.vim create mode 100644 autoload/ale/racket.vim create mode 100644 test/linter/test_racket_langserver.vader create mode 100644 test/test-files/racket/many-inits/a/b/c/foo.rkt create mode 100644 test/test-files/racket/many-inits/a/b/c/init.rkt create mode 100644 test/test-files/racket/many-inits/a/b/foo.rkt create mode 100644 test/test-files/racket/many-inits/a/b/init.rkt create mode 100644 test/test-files/racket/many-inits/a/foo.rkt create mode 100644 test/test-files/racket/many-inits/a/init.rkt create mode 100644 test/test-files/racket/many-inits/foo.rkt create mode 100644 test/test-files/racket/many-inits/init.rkt create mode 100644 test/test-files/racket/simple-script/foo.rkt diff --git a/ale_linters/racket/langserver.vim b/ale_linters/racket/langserver.vim new file mode 100644 index 00000000..ec80ed7b --- /dev/null +++ b/ale_linters/racket/langserver.vim @@ -0,0 +1,7 @@ +call ale#linter#Define('racket', { +\ 'name': 'racket_langserver', +\ 'lsp': 'stdio', +\ 'executable': 'racket', +\ 'command': '%e -l racket-langserver', +\ 'project_root': function('ale#racket#FindProjectRoot'), +\}) diff --git a/autoload/ale/racket.vim b/autoload/ale/racket.vim new file mode 100644 index 00000000..ff896108 --- /dev/null +++ b/autoload/ale/racket.vim @@ -0,0 +1,12 @@ +function! ale#racket#FindProjectRoot(buffer) abort + let l:cwd = expand('#' . a:buffer . ':p:h') + let l:highest_init = l:cwd + + for l:path in ale#path#Upwards(l:cwd) + if filereadable(l:path.'/init.rkt') + let l:highest_init = l:path + endif + endfor + + return l:highest_init +endfunction diff --git a/doc/ale-supported-languages-and-tools.txt b/doc/ale-supported-languages-and-tools.txt index 638cee7d..27c50efa 100644 --- a/doc/ale-supported-languages-and-tools.txt +++ b/doc/ale-supported-languages-and-tools.txt @@ -428,6 +428,7 @@ Notes: * `lintr` * `styler` * Racket + * `racket-langserver` * `raco` * Re:VIEW * `redpen` diff --git a/supported-tools.md b/supported-tools.md index 1b7b1de4..2a60b6d6 100644 --- a/supported-tools.md +++ b/supported-tools.md @@ -437,6 +437,7 @@ formatting. * [lintr](https://github.com/jimhester/lintr) * [styler](https://github.com/r-lib/styler) * Racket + * [racket-langserver](https://github.com/jeapostrophe/racket-langserver/tree/master) * [raco](https://docs.racket-lang.org/raco/) * Re:VIEW * [redpen](http://redpen.cc/) diff --git a/test/linter/test_racket_langserver.vader b/test/linter/test_racket_langserver.vader new file mode 100644 index 00000000..021eb565 --- /dev/null +++ b/test/linter/test_racket_langserver.vader @@ -0,0 +1,45 @@ +" Author: D. Ben Knoble +" Description: Tests for racket-langserver lsp linter. +Before: + call ale#assert#SetUpLinterTest('racket', 'langserver') + +After: + call ale#assert#TearDownLinterTest() + +Execute(command callback should return default string): + AssertLinter 'racket', ale#Escape('racket').' -l racket-langserver' + +Execute(should set racket-langserver for deep module 3): + call ale#test#SetFilename('../test-files/racket/many-inits/a/b/c/foo.rkt') + AssertLSPLanguage 'racket' + AssertLSPOptions {} + AssertLSPConfig {} + AssertLSPProject ale#test#GetFilename('../test-files/racket/many-inits') + +Execute(should set racket-langserver for deep module 2): + call ale#test#SetFilename('../test-files/racket/many-inits/a/b/foo.rkt') + AssertLSPLanguage 'racket' + AssertLSPOptions {} + AssertLSPConfig {} + AssertLSPProject ale#test#GetFilename('../test-files/racket/many-inits') + +Execute(should set racket-langserver for deep module 1): + call ale#test#SetFilename('../test-files/racket/many-inits/a/foo.rkt') + AssertLSPLanguage 'racket' + AssertLSPOptions {} + AssertLSPConfig {} + AssertLSPProject ale#test#GetFilename('../test-files/racket/many-inits') + +Execute(should set racket-langserver for top-level module): + call ale#test#SetFilename('../test-files/racket/many-inits/foo.rkt') + AssertLSPLanguage 'racket' + AssertLSPOptions {} + AssertLSPConfig {} + AssertLSPProject ale#test#GetFilename('../test-files/racket/many-inits') + +Execute(should set racket-langserver for non-package module or script): + call ale#test#SetFilename('../test-files/racket/simple-script/foo.rkt') + AssertLSPLanguage 'racket' + AssertLSPOptions {} + AssertLSPConfig {} + AssertLSPProject ale#test#GetFilename('../test-files/racket/simple-script') diff --git a/test/test-files/racket/many-inits/a/b/c/foo.rkt b/test/test-files/racket/many-inits/a/b/c/foo.rkt new file mode 100644 index 00000000..622f3eea --- /dev/null +++ b/test/test-files/racket/many-inits/a/b/c/foo.rkt @@ -0,0 +1,3 @@ +#lang racket/base + +(displayln "foo") diff --git a/test/test-files/racket/many-inits/a/b/c/init.rkt b/test/test-files/racket/many-inits/a/b/c/init.rkt new file mode 100644 index 00000000..e0c94f27 --- /dev/null +++ b/test/test-files/racket/many-inits/a/b/c/init.rkt @@ -0,0 +1 @@ +#lang info diff --git a/test/test-files/racket/many-inits/a/b/foo.rkt b/test/test-files/racket/many-inits/a/b/foo.rkt new file mode 100644 index 00000000..622f3eea --- /dev/null +++ b/test/test-files/racket/many-inits/a/b/foo.rkt @@ -0,0 +1,3 @@ +#lang racket/base + +(displayln "foo") diff --git a/test/test-files/racket/many-inits/a/b/init.rkt b/test/test-files/racket/many-inits/a/b/init.rkt new file mode 100644 index 00000000..e0c94f27 --- /dev/null +++ b/test/test-files/racket/many-inits/a/b/init.rkt @@ -0,0 +1 @@ +#lang info diff --git a/test/test-files/racket/many-inits/a/foo.rkt b/test/test-files/racket/many-inits/a/foo.rkt new file mode 100644 index 00000000..622f3eea --- /dev/null +++ b/test/test-files/racket/many-inits/a/foo.rkt @@ -0,0 +1,3 @@ +#lang racket/base + +(displayln "foo") diff --git a/test/test-files/racket/many-inits/a/init.rkt b/test/test-files/racket/many-inits/a/init.rkt new file mode 100644 index 00000000..e0c94f27 --- /dev/null +++ b/test/test-files/racket/many-inits/a/init.rkt @@ -0,0 +1 @@ +#lang info diff --git a/test/test-files/racket/many-inits/foo.rkt b/test/test-files/racket/many-inits/foo.rkt new file mode 100644 index 00000000..622f3eea --- /dev/null +++ b/test/test-files/racket/many-inits/foo.rkt @@ -0,0 +1,3 @@ +#lang racket/base + +(displayln "foo") diff --git a/test/test-files/racket/many-inits/init.rkt b/test/test-files/racket/many-inits/init.rkt new file mode 100644 index 00000000..e0c94f27 --- /dev/null +++ b/test/test-files/racket/many-inits/init.rkt @@ -0,0 +1 @@ +#lang info diff --git a/test/test-files/racket/simple-script/foo.rkt b/test/test-files/racket/simple-script/foo.rkt new file mode 100644 index 00000000..622f3eea --- /dev/null +++ b/test/test-files/racket/simple-script/foo.rkt @@ -0,0 +1,3 @@ +#lang racket/base + +(displayln "foo")