summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorw0rp <w0rp@users.noreply.github.com>2018-08-28 21:52:18 +0100
committerGitHub <noreply@github.com>2018-08-28 21:52:18 +0100
commit09e43ab16bc8fe7d5ddc72e904b05682587fd335 (patch)
tree74c11f647694c42f7f7d81a995f9bc7e49c3930b
parent339930ad68a16e8298b8b84ef0ab428bf7061c5f (diff)
parent1980245b94d7b997c6ba376d8a2644397afe02d6 (diff)
downloadale-09e43ab16bc8fe7d5ddc72e904b05682587fd335.zip
Merge pull request #1847 from hsanson/1846-support-solargraph-lsp
1846 support solargraph lsp
-rw-r--r--README.md2
-rw-r--r--ale_linters/ruby/solargraph.vim19
-rw-r--r--autoload/ale/assert.vim13
-rw-r--r--autoload/ale/ruby.vim22
-rw-r--r--doc/ale-development.txt1
-rw-r--r--doc/ale-ruby.txt18
-rw-r--r--doc/ale.txt3
-rw-r--r--test/command_callback/test_ruby_solargraph.vader29
-rw-r--r--test/ruby_fixtures/valid_ruby_app1/Rakefile0
-rw-r--r--test/ruby_fixtures/valid_ruby_app1/lib/file.rb0
-rw-r--r--test/ruby_fixtures/valid_ruby_app2/Gemfile0
-rw-r--r--test/ruby_fixtures/valid_ruby_app2/lib/file.rb0
12 files changed, 105 insertions, 2 deletions
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(<args>)
command! -nargs=+ AssertLSPLanguage :call ale#assert#LSPLanguage(<args>)
command! -nargs=+ AssertLSPProject :call ale#assert#LSPProject(<args>)
+ command! -nargs=+ AssertLSPAddress :call ale#assert#LSPAddress(<args>)
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
@@ -99,4 +99,22 @@ g:ale_ruby_rufo_executable *g:ale_ruby_rufo_executable*
===============================================================================
+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 <https://github.com/hsanson>
+" 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
--- /dev/null
+++ b/test/ruby_fixtures/valid_ruby_app1/Rakefile
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
--- /dev/null
+++ b/test/ruby_fixtures/valid_ruby_app1/lib/file.rb
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
--- /dev/null
+++ b/test/ruby_fixtures/valid_ruby_app2/Gemfile
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
--- /dev/null
+++ b/test/ruby_fixtures/valid_ruby_app2/lib/file.rb