diff --git a/README.md b/README.md index 4fd109ff..bd2ef92a 100644 --- a/README.md +++ b/README.md @@ -167,7 +167,7 @@ formatting. | reStructuredText | [alex](https://github.com/wooorm/alex) !!, [proselint](http://proselint.com/), [redpen](http://redpen.cc/), [rstcheck](https://github.com/myint/rstcheck), [vale](https://github.com/ValeLint/vale), [write-good](https://github.com/btford/write-good) | | Re:VIEW | [redpen](http://redpen.cc/) | | RPM spec | [rpmlint](https://github.com/rpm-software-management/rpmlint) (disabled by default; see `:help ale-integration-spec`) | -| Ruby | [brakeman](http://brakemanscanner.org/) !!, [rails_best_practices](https://github.com/flyerhzm/rails_best_practices) !!, [reek](https://github.com/troessner/reek), [rubocop](https://github.com/bbatsov/rubocop), [ruby](https://www.ruby-lang.org), [rufo](https://github.com/ruby-formatter/rufo) | +| Ruby | [brakeman](http://brakemanscanner.org/) !!, [rails_best_practices](https://github.com/flyerhzm/rails_best_practices) !!, [reek](https://github.com/troessner/reek), [rubocop](https://github.com/bbatsov/rubocop), [ruby](https://www.ruby-lang.org), [rufo](https://github.com/ruby-formatter/rufo), [solargraph]([solargraph](https://solargraph.org) | | Rust | cargo !! (see `:help ale-integration-rust` for configuration instructions), [rls](https://github.com/rust-lang-nursery/rls), [rustc](https://www.rust-lang.org/), [rustfmt](https://github.com/rust-lang-nursery/rustfmt) | | SASS | [sass-lint](https://www.npmjs.com/package/sass-lint), [stylelint](https://github.com/stylelint/stylelint) | | SCSS | [prettier](https://github.com/prettier/prettier), [sass-lint](https://www.npmjs.com/package/sass-lint), [scss-lint](https://github.com/brigade/scss-lint), [stylelint](https://github.com/stylelint/stylelint) | diff --git a/ale_linters/ruby/solargraph.vim b/ale_linters/ruby/solargraph.vim new file mode 100644 index 00000000..a53bcaa3 --- /dev/null +++ b/ale_linters/ruby/solargraph.vim @@ -0,0 +1,19 @@ +" Author: Horacio Sanson - https://github.com/hsanson +" Description: Solargraph Language Server https://solargraph.org/ + +call ale#Set('ruby_solargraph_host', '127.0.0.1') +call ale#Set('ruby_solargraph_port', '7658') + +function! ale_linters#ruby#solargraph#GetAddress(buffer) abort + let l:host = ale#Var(a:buffer, 'ruby_solargraph_host') + let l:port = ale#Var(a:buffer, 'ruby_solargraph_port') + return l:host . ':' . l:port +endfunction + +call ale#linter#Define('ruby', { +\ 'name': 'solargraph', +\ 'lsp': 'socket', +\ 'address_callback': 'ale_linters#ruby#solargraph#GetAddress', +\ 'language': 'ruby', +\ 'project_root_callback': 'ale#ruby#FindProjectRoot' +\}) diff --git a/autoload/ale/assert.vim b/autoload/ale/assert.vim index 87798520..a1bfd0b7 100644 --- a/autoload/ale/assert.vim +++ b/autoload/ale/assert.vim @@ -101,6 +101,14 @@ function! ale#assert#LSPProject(expected_root) abort AssertEqual a:expected_root, l:root endfunction +function! ale#assert#LSPAddress(expected_address) abort + let l:buffer = bufnr('') + let l:linter = s:GetLinter() + let l:address = ale#util#GetFunction(l:linter.address_callback)(l:buffer) + + AssertEqual a:expected_address, l:address +endfunction + " A dummy function for making sure this module is loaded. function! ale#assert#SetUpLinterTest(filetype, name) abort " Set up a marker so ALE doesn't create real random temporary filenames. @@ -141,6 +149,7 @@ function! ale#assert#SetUpLinterTest(filetype, name) abort command! -nargs=+ AssertLSPOptions :call ale#assert#LSPOptions() command! -nargs=+ AssertLSPLanguage :call ale#assert#LSPLanguage() command! -nargs=+ AssertLSPProject :call ale#assert#LSPProject() + command! -nargs=+ AssertLSPAddress :call ale#assert#LSPAddress() endfunction function! ale#assert#TearDownLinterTest() abort @@ -171,6 +180,10 @@ function! ale#assert#TearDownLinterTest() abort delcommand AssertLSPProject endif + if exists(':AssertLSPAddress') + delcommand AssertLSPAddress + endif + if exists('g:dir') call ale#test#RestoreDirectory() endif diff --git a/autoload/ale/ruby.vim b/autoload/ale/ruby.vim index b981ded6..f0d84296 100644 --- a/autoload/ale/ruby.vim +++ b/autoload/ale/ruby.vim @@ -20,3 +20,25 @@ function! ale#ruby#FindRailsRoot(buffer) abort return '' endfunction + +" Find the nearest dir containing a potential ruby project. +function! ale#ruby#FindProjectRoot(buffer) abort + let l:dir = ale#ruby#FindRailsRoot(a:buffer) + + if isdirectory(l:dir) + return l:dir + endif + + for l:name in ['Rakefile', 'Gemfile'] + let l:dir = fnamemodify( + \ ale#path#FindNearestFile(a:buffer, l:name), + \ ':h' + \) + + if l:dir isnot# '.' && isdirectory(l:dir) + return l:dir + endif + endfor + + return '' +endfunction diff --git a/doc/ale-development.txt b/doc/ale-development.txt index d83c98f2..ac72d615 100644 --- a/doc/ale-development.txt +++ b/doc/ale-development.txt @@ -307,6 +307,7 @@ given the above setup are as follows. `AssertLSPLanguage language` - Check the language given to an LSP server. `AssertLSPOptions options_dict` - Check the options given to an LSP server. `AssertLSPProject project_root` - Check the root given to an LSP server. +`AssertLSPAddress address` - Check the address to an LSP server. =============================================================================== vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl: diff --git a/doc/ale-ruby.txt b/doc/ale-ruby.txt index 85a3e137..ec7b07cf 100644 --- a/doc/ale-ruby.txt +++ b/doc/ale-ruby.txt @@ -98,5 +98,23 @@ g:ale_ruby_rufo_executable *g:ale_ruby_rufo_executable* binstubs or a bundle. +=============================================================================== +solargraph *ale-ruby-solargraph* + +g:ale_ruby_solargraph_host *g:ale_ruby_solargraph_host* + *b:ale_ruby_solargraph_host* + Type: String + Default: `'127.0.0.1'` + + The host/ip where the solargraph language server is running. + +g:ale_ruby_solargraph_port *g:ale_ruby_solargraph_port* + *b:ale_ruby_solargraph_port* + Type: String + Default: `'7658'` + + The listening port where the solargraph language server is running. + + =============================================================================== vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl: diff --git a/doc/ale.txt b/doc/ale.txt index 8e38f92a..8e126938 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -237,6 +237,7 @@ CONTENTS *ale-contents* rubocop.............................|ale-ruby-rubocop| ruby................................|ale-ruby-ruby| rufo................................|ale-ruby-rufo| + solargraph..........................|ale-ruby-solargraph| rust..................................|ale-rust-options| cargo...............................|ale-rust-cargo| rls.................................|ale-rust-rls| @@ -422,7 +423,7 @@ Notes: * reStructuredText: `alex`!!, `proselint`, `redpen`, `rstcheck`, `vale`, `write-good` * Re:VIEW: `redpen` * RPM spec: `rpmlint` -* Ruby: `brakeman`, `rails_best_practices`!!, `reek`, `rubocop`, `ruby`, `rufo` +* Ruby: `brakeman`, `rails_best_practices`!!, `reek`, `rubocop`, `ruby`, `rufo`, `solargraph` * Rust: `cargo`!!, `rls`, `rustc` (see |ale-integration-rust|), `rustfmt` * SASS: `sass-lint`, `stylelint` * SCSS: `prettier`, `sass-lint`, `scss-lint`, `stylelint` diff --git a/test/command_callback/test_ruby_solargraph.vader b/test/command_callback/test_ruby_solargraph.vader new file mode 100644 index 00000000..a27cb62d --- /dev/null +++ b/test/command_callback/test_ruby_solargraph.vader @@ -0,0 +1,29 @@ +" Author: Horacio Sanson +" Description: Tests for solargraph lsp linter. + +Before: + call ale#assert#SetUpLinterTest('ruby', 'solargraph') + +After: + call ale#assert#TearDownLinterTest() + +Execute(should set solargraph for rails app): + call ale#test#SetFilename('../ruby_fixtures/valid_rails_app/app/models/thing.rb') + AssertLSPLanguage 'ruby' + AssertLSPOptions {} + AssertLSPProject ale#path#Simplify(g:dir . 'command_callback/../ruby_fixtures/valid_rails_app') + AssertLSPAddress '127.0.0.1:7658' + +Execute(should set solargraph for ruby app1): + call ale#test#SetFilename('../ruby_fixtures/valid_ruby_app1/lib/file.rb') + AssertLSPLanguage 'ruby' + AssertLSPOptions {} + AssertLSPProject ale#path#Simplify(g:dir . 'command_callback/../ruby_fixtures/valid_ruby_app1') + AssertLSPAddress '127.0.0.1:7658' + +Execute(should set solargraph for ruby app2): + call ale#test#SetFilename('../ruby_fixtures/valid_ruby_app2/lib/file.rb') + AssertLSPLanguage 'ruby' + AssertLSPOptions {} + AssertLSPProject ale#path#Simplify(g:dir . 'command_callback/../ruby_fixtures/valid_ruby_app2') + AssertLSPAddress '127.0.0.1:7658' diff --git a/test/ruby_fixtures/valid_ruby_app1/Rakefile b/test/ruby_fixtures/valid_ruby_app1/Rakefile new file mode 100644 index 00000000..e69de29b diff --git a/test/ruby_fixtures/valid_ruby_app1/lib/file.rb b/test/ruby_fixtures/valid_ruby_app1/lib/file.rb new file mode 100644 index 00000000..e69de29b diff --git a/test/ruby_fixtures/valid_ruby_app2/Gemfile b/test/ruby_fixtures/valid_ruby_app2/Gemfile new file mode 100644 index 00000000..e69de29b diff --git a/test/ruby_fixtures/valid_ruby_app2/lib/file.rb b/test/ruby_fixtures/valid_ruby_app2/lib/file.rb new file mode 100644 index 00000000..e69de29b