summaryrefslogtreecommitdiff
path: root/autoload
diff options
context:
space:
mode:
Diffstat (limited to 'autoload')
-rw-r--r--autoload/ale/fix/registry.vim5
-rw-r--r--autoload/ale/fixers/standardrb.vim23
-rw-r--r--autoload/ale/hover.vim38
-rw-r--r--autoload/ale/ruby.vim32
-rw-r--r--autoload/ale/test.vim10
5 files changed, 107 insertions, 1 deletions
diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim
index 75fd1508..6a8fd382 100644
--- a/autoload/ale/fix/registry.vim
+++ b/autoload/ale/fix/registry.vim
@@ -115,6 +115,11 @@ let s:default_registry = {
\ 'suggested_filetypes': ['javascript'],
\ 'description': 'Fix JavaScript files using standard --fix',
\ },
+\ 'standardrb': {
+\ 'function': 'ale#fixers#standardrb#Fix',
+\ 'suggested_filetypes': ['ruby'],
+\ 'description': 'Fix ruby files with standardrb --fix',
+\ },
\ 'stylelint': {
\ 'function': 'ale#fixers#stylelint#Fix',
\ 'suggested_filetypes': ['css', 'sass', 'scss', 'stylus'],
diff --git a/autoload/ale/fixers/standardrb.vim b/autoload/ale/fixers/standardrb.vim
new file mode 100644
index 00000000..fab1e2bc
--- /dev/null
+++ b/autoload/ale/fixers/standardrb.vim
@@ -0,0 +1,23 @@
+" Author: Justin Searls - https://github.com/searls
+" Description: Fix Ruby files with StandardRB.
+
+call ale#Set('ruby_standardrb_options', '')
+call ale#Set('ruby_standardrb_executable', 'standardrb')
+
+function! ale#fixers#standardrb#GetCommand(buffer) abort
+ let l:executable = ale#Var(a:buffer, 'ruby_standardrb_executable')
+ let l:config = ale#path#FindNearestFile(a:buffer, '.standard.yml')
+ let l:options = ale#Var(a:buffer, 'ruby_standardrb_options')
+
+ return ale#handlers#ruby#EscapeExecutable(l:executable, 'standardrb')
+ \ . (!empty(l:config) ? ' --config ' . ale#Escape(l:config) : '')
+ \ . (!empty(l:options) ? ' ' . l:options : '')
+ \ . ' --fix --force-exclusion %t'
+endfunction
+
+function! ale#fixers#standardrb#Fix(buffer) abort
+ return {
+ \ 'command': ale#fixers#standardrb#GetCommand(a:buffer),
+ \ 'read_temporary_file': 1,
+ \}
+endfunction
diff --git a/autoload/ale/hover.vim b/autoload/ale/hover.vim
index 69db276e..490cc406 100644
--- a/autoload/ale/hover.vim
+++ b/autoload/ale/hover.vim
@@ -24,7 +24,21 @@ function! ale#hover#HandleTSServerResponse(conn_id, response) abort
if get(a:response, 'success', v:false) is v:true
\&& get(a:response, 'body', v:null) isnot v:null
- if get(l:options, 'hover_from_balloonexpr', 0)
+ " If we pass the show_documentation flag, we should show the full
+ " documentation, and always in the preview window.
+ if get(l:options, 'show_documentation', 0)
+ let l:documentation = get(a:response.body, 'documentation', '')
+
+ " displayString is not included here, because it can be very
+ " noisy and run on for many lines for complex types. A less
+ " verbose alternative may be nice in future.
+ if !empty(l:documentation)
+ call ale#preview#Show(split(l:documentation, "\n"), {
+ \ 'filetype': 'ale-preview.message',
+ \ 'stay_here': 1,
+ \})
+ endif
+ elseif get(l:options, 'hover_from_balloonexpr', 0)
\&& exists('*balloon_show')
\&& ale#Var(l:options.buffer, 'set_balloons')
call balloon_show(a:response.body.displayString)
@@ -126,6 +140,7 @@ function! s:OnReady(linter, lsp_details, line, column, opt, ...) abort
\ 'line': a:line,
\ 'column': l:column,
\ 'hover_from_balloonexpr': get(a:opt, 'called_from_balloonexpr', 0),
+ \ 'show_documentation': get(a:opt, 'show_documentation', 0),
\}
endfunction
@@ -153,9 +168,30 @@ endfunction
" - in the balloon if opt.called_from_balloonexpr and balloon_show is detected
" - as status message otherwise
function! ale#hover#Show(buffer, line, col, opt) abort
+ let l:show_documentation = get(a:opt, 'show_documentation', 0)
+
for l:linter in ale#linter#Get(getbufvar(a:buffer, '&filetype'))
+ " Only tsserver supports documentation requests at the moment.
if !empty(l:linter.lsp)
+ \&& (!l:show_documentation || l:linter.lsp is# 'tsserver')
call s:ShowDetails(l:linter, a:buffer, a:line, a:col, a:opt)
endif
endfor
endfunction
+
+" This function implements the :ALEHover command.
+function! ale#hover#ShowAtCursor() abort
+ let l:buffer = bufnr('')
+ let l:pos = getcurpos()
+
+ call ale#hover#Show(l:buffer, l:pos[1], l:pos[2], {})
+endfunction
+
+" This function implements the :ALEDocumentation command.
+function! ale#hover#ShowDocumentationAtCursor() abort
+ let l:buffer = bufnr('')
+ let l:pos = getcurpos()
+ let l:options = {'show_documentation': 1}
+
+ call ale#hover#Show(l:buffer, l:pos[1], l:pos[2], l:options)
+endfunction
diff --git a/autoload/ale/ruby.vim b/autoload/ale/ruby.vim
index 5f0aa50d..3d9c5a51 100644
--- a/autoload/ale/ruby.vim
+++ b/autoload/ale/ruby.vim
@@ -42,3 +42,35 @@ function! ale#ruby#FindProjectRoot(buffer) abort
return ''
endfunction
+
+" Handle output from rubocop and linters that depend on it (e.b. standardrb)
+function! ale#ruby#HandleRubocopOutput(buffer, lines) abort
+ try
+ let l:errors = json_decode(a:lines[0])
+ catch
+ return []
+ endtry
+
+ if !has_key(l:errors, 'summary')
+ \|| l:errors['summary']['offense_count'] == 0
+ \|| empty(l:errors['files'])
+ return []
+ endif
+
+ let l:output = []
+
+ for l:error in l:errors['files'][0]['offenses']
+ let l:start_col = l:error['location']['column'] + 0
+ call add(l:output, {
+ \ 'lnum': l:error['location']['line'] + 0,
+ \ 'col': l:start_col,
+ \ 'end_col': l:start_col + l:error['location']['length'] - 1,
+ \ 'code': l:error['cop_name'],
+ \ 'text': l:error['message'],
+ \ 'type': ale_linters#ruby#rubocop#GetType(l:error['severity']),
+ \})
+ endfor
+
+ return l:output
+endfunction
+
diff --git a/autoload/ale/test.vim b/autoload/ale/test.vim
index 083b546f..e6ec70dc 100644
--- a/autoload/ale/test.vim
+++ b/autoload/ale/test.vim
@@ -75,3 +75,13 @@ function! ale#test#GetQflistWithoutModule() abort
return l:results
endfunction
+
+function! ale#test#GetPreviewWindowText() abort
+ for l:window in range(1, winnr('$'))
+ if getwinvar(l:window, '&previewwindow', 0)
+ let l:buffer = winbufnr(l:window)
+
+ return getbufline(l:buffer, 1, '$')
+ endif
+ endfor
+endfunction