diff options
Diffstat (limited to 'autoload')
-rw-r--r-- | autoload/ale/completion.vim | 18 | ||||
-rw-r--r-- | autoload/ale/cursor.vim | 79 | ||||
-rw-r--r-- | autoload/ale/events.vim | 6 | ||||
-rw-r--r-- | autoload/ale/fixers/eslint.vim | 2 | ||||
-rw-r--r-- | autoload/ale/fixers/rubocop.vim | 10 | ||||
-rw-r--r-- | autoload/ale/handlers/eslint.vim | 7 | ||||
-rw-r--r-- | autoload/ale/handlers/rubocop.vim | 6 | ||||
-rw-r--r-- | autoload/ale/handlers/ruby.vim | 7 | ||||
-rw-r--r-- | autoload/ale/julia.vim | 19 | ||||
-rw-r--r-- | autoload/ale/lsp_linter.vim | 16 | ||||
-rw-r--r-- | autoload/ale/preview.vim | 2 |
11 files changed, 126 insertions, 46 deletions
diff --git a/autoload/ale/completion.vim b/autoload/ale/completion.vim index bded12b1..9dd913f5 100644 --- a/autoload/ale/completion.vim +++ b/autoload/ale/completion.vim @@ -98,14 +98,15 @@ function! ale#completion#GetTriggerCharacter(filetype, prefix) abort return '' endfunction -function! ale#completion#Filter(buffer, suggestions, prefix) abort +function! ale#completion#Filter(buffer, filetype, suggestions, prefix) abort let l:excluded_words = ale#Var(a:buffer, 'completion_excluded_words') + let l:triggers = s:GetFiletypeValue(s:trigger_character_map, a:filetype) " For completing... " foo. " ^ " We need to include all of the given suggestions. - if a:prefix is# '.' + if index(l:triggers, a:prefix) >= 0 let l:filtered_suggestions = a:suggestions else let l:filtered_suggestions = [] @@ -264,7 +265,7 @@ function! ale#completion#ParseTSServerCompletionEntryDetails(response) abort call add(l:documentationParts, l:part.text) endfor - if l:suggestion.kind is# 'clasName' + if l:suggestion.kind is# 'className' let l:kind = 'f' elseif l:suggestion.kind is# 'parameterName' let l:kind = 'f' @@ -359,17 +360,23 @@ function! ale#completion#ParseLSPCompletions(response) abort let l:kind = 'v' endif + let l:doc = get(l:item, 'documentation', '') + + if type(l:doc) is v:t_dict && has_key(l:doc, 'value') + let l:doc = l:doc.value + endif + call add(l:results, { \ 'word': l:word, \ 'kind': l:kind, \ 'icase': 1, \ 'menu': get(l:item, 'detail', ''), - \ 'info': get(l:item, 'documentation', ''), + \ 'info': (type(l:doc) is v:t_string ? l:doc : ''), \}) endfor if has_key(l:info, 'prefix') - return ale#completion#Filter(l:buffer, l:results, l:info.prefix) + return ale#completion#Filter(l:buffer, &filetype, l:results, l:info.prefix) endif return l:results @@ -390,6 +397,7 @@ function! ale#completion#HandleTSServerResponse(conn_id, response) abort if l:command is# 'completions' let l:names = ale#completion#Filter( \ l:buffer, + \ &filetype, \ ale#completion#ParseTSServerCompletions(a:response), \ b:ale_completion_info.prefix, \)[: g:ale_completion_max_suggestions - 1] diff --git a/autoload/ale/cursor.vim b/autoload/ale/cursor.vim index 3fa4e5ba..c3b48ca3 100644 --- a/autoload/ale/cursor.vim +++ b/autoload/ale/cursor.vim @@ -1,4 +1,6 @@ +scriptencoding utf-8 " Author: w0rp <devw0rp@gmail.com> +" Author: João Paulo S. de Souza <joao.paulo.silvasouza@hotmail.com> " Description: Echoes lint message for the current line, if any " Controls the milliseconds delay before echoing a message. @@ -37,12 +39,11 @@ function! ale#cursor#TruncatedEcho(original_message) abort endtry endfunction -function! s:FindItemAtCursor() abort - let l:buf = bufnr('') - let l:info = get(g:ale_buffer_info, l:buf, {}) +function! s:FindItemAtCursor(buffer) abort + let l:info = get(g:ale_buffer_info, a:buffer, {}) let l:loclist = get(l:info, 'loclist', []) let l:pos = getcurpos() - let l:index = ale#util#BinarySearch(l:loclist, l:buf, l:pos[1], l:pos[2]) + let l:index = ale#util#BinarySearch(l:loclist, a:buffer, l:pos[1], l:pos[2]) let l:loc = l:index >= 0 ? l:loclist[l:index] : {} return [l:info, l:loc] @@ -56,7 +57,9 @@ function! s:StopCursorTimer() abort endfunction function! ale#cursor#EchoCursorWarning(...) abort - if !g:ale_echo_cursor + let l:buffer = bufnr('') + + if !g:ale_echo_cursor && !g:ale_cursor_detail return endif @@ -65,28 +68,39 @@ function! ale#cursor#EchoCursorWarning(...) abort return endif - if ale#ShouldDoNothing(bufnr('')) + if ale#ShouldDoNothing(l:buffer) return endif - let l:buffer = bufnr('') - let [l:info, l:loc] = s:FindItemAtCursor() + let [l:info, l:loc] = s:FindItemAtCursor(l:buffer) + + if g:ale_echo_cursor + if !empty(l:loc) + let l:format = ale#Var(l:buffer, 'echo_msg_format') + let l:msg = ale#GetLocItemMessage(l:loc, l:format) + call ale#cursor#TruncatedEcho(l:msg) + let l:info.echoed = 1 + elseif get(l:info, 'echoed') + " We'll only clear the echoed message when moving off errors once, + " so we don't continually clear the echo line. + execute 'echo' + let l:info.echoed = 0 + endif + endif - if !empty(l:loc) - let l:format = ale#Var(l:buffer, 'echo_msg_format') - let l:msg = ale#GetLocItemMessage(l:loc, l:format) - call ale#cursor#TruncatedEcho(l:msg) - let l:info.echoed = 1 - elseif get(l:info, 'echoed') - " We'll only clear the echoed message when moving off errors once, - " so we don't continually clear the echo line. - execute 'echo' - let l:info.echoed = 0 + if g:ale_cursor_detail + if !empty(l:loc) + call s:ShowCursorDetailForItem(l:loc, {'stay_here': 1}) + else + call ale#preview#CloseIfTypeMatches('ale-preview') + endif endif endfunction function! ale#cursor#EchoCursorWarningWithDelay() abort - if !g:ale_echo_cursor + let l:buffer = bufnr('') + + if !g:ale_echo_cursor && !g:ale_cursor_detail return endif @@ -104,7 +118,7 @@ function! ale#cursor#EchoCursorWarningWithDelay() abort " we should echo something. Otherwise we can end up doing processing " the echo message far too frequently. if l:pos != s:last_pos - let l:delay = ale#Var(bufnr(''), 'echo_delay') + let l:delay = ale#Var(l:buffer, 'echo_delay') let s:last_pos = l:pos let s:cursor_timer = timer_start( @@ -114,24 +128,37 @@ function! ale#cursor#EchoCursorWarningWithDelay() abort endif endfunction +function! s:ShowCursorDetailForItem(loc, options) abort + let l:stay_here = get(a:options, 'stay_here', 0) + + let s:last_detailed_line = line('.') + let l:message = get(a:loc, 'detail', a:loc.text) + let l:lines = split(l:message, "\n") + call ale#preview#Show(l:lines, {'stay_here': l:stay_here}) + + " Clear the echo message if we manually displayed details. + if !l:stay_here + execute 'echo' + endif +endfunction + function! ale#cursor#ShowCursorDetail() abort + let l:buffer = bufnr('') + " Only echo the warnings in normal mode, otherwise we will get problems. if mode() isnot# 'n' return endif - if ale#ShouldDoNothing(bufnr('')) + if ale#ShouldDoNothing(l:buffer) return endif call s:StopCursorTimer() - let [l:info, l:loc] = s:FindItemAtCursor() + let [l:info, l:loc] = s:FindItemAtCursor(l:buffer) if !empty(l:loc) - let l:message = get(l:loc, 'detail', l:loc.text) - - call ale#preview#Show(split(l:message, "\n")) - execute 'echo' + call s:ShowCursorDetailForItem(l:loc, {'stay_here': 0}) endif endfunction diff --git a/autoload/ale/events.vim b/autoload/ale/events.vim index 300aefcc..e48ad488 100644 --- a/autoload/ale/events.vim +++ b/autoload/ale/events.vim @@ -131,13 +131,17 @@ function! ale#events#Init() abort autocmd InsertLeave * call ale#Queue(0) endif - if g:ale_echo_cursor + if g:ale_echo_cursor || g:ale_cursor_detail autocmd CursorMoved,CursorHold * if exists('*ale#engine#Cleanup') | call ale#cursor#EchoCursorWarningWithDelay() | endif " Look for a warning to echo as soon as we leave Insert mode. " The script's position variable used when moving the cursor will " not be changed here. autocmd InsertLeave * if exists('*ale#engine#Cleanup') | call ale#cursor#EchoCursorWarning() | endif endif + + if g:ale_close_preview_on_insert + autocmd InsertEnter * if exists('*ale#preview#CloseIfTypeMatches') | call ale#preview#CloseIfTypeMatches('ale-preview') | endif + endif endif augroup END endfunction diff --git a/autoload/ale/fixers/eslint.vim b/autoload/ale/fixers/eslint.vim index 36f47510..ea5b2a63 100644 --- a/autoload/ale/fixers/eslint.vim +++ b/autoload/ale/fixers/eslint.vim @@ -25,7 +25,7 @@ endfunction function! ale#fixers#eslint#ProcessEslintDOutput(buffer, output) abort " If the output is an error message, don't use it. for l:line in a:output[:10] - if l:line =~# '^Error:' + if l:line =~# '\v^Error:|^Could not connect' return [] endif endfor diff --git a/autoload/ale/fixers/rubocop.vim b/autoload/ale/fixers/rubocop.vim index 0a39ef62..a4613817 100644 --- a/autoload/ale/fixers/rubocop.vim +++ b/autoload/ale/fixers/rubocop.vim @@ -1,12 +1,12 @@ +call ale#Set('ruby_rubocop_options', '') +call ale#Set('ruby_rubocop_executable', 'rubocop') + function! ale#fixers#rubocop#GetCommand(buffer) abort - let l:executable = ale#handlers#rubocop#GetExecutable(a:buffer) - let l:exec_args = l:executable =~? 'bundle$' - \ ? ' exec rubocop' - \ : '' + let l:executable = ale#Var(a:buffer, 'ruby_rubocop_executable') let l:config = ale#path#FindNearestFile(a:buffer, '.rubocop.yml') let l:options = ale#Var(a:buffer, 'ruby_rubocop_options') - return ale#Escape(l:executable) . l:exec_args + return ale#handlers#ruby#EscapeExecutable(l:executable, 'rubocop') \ . (!empty(l:config) ? ' --config ' . ale#Escape(l:config) : '') \ . (!empty(l:options) ? ' ' . l:options : '') \ . ' --auto-correct %t' diff --git a/autoload/ale/handlers/eslint.vim b/autoload/ale/handlers/eslint.vim index bc10ec21..eda033e4 100644 --- a/autoload/ale/handlers/eslint.vim +++ b/autoload/ale/handlers/eslint.vim @@ -99,6 +99,13 @@ function! ale#handlers#eslint#Handle(buffer, lines) abort \}] endif + if a:lines == ['Could not connect'] + return [{ + \ 'lnum': 1, + \ 'text': 'Could not connect to eslint_d. Try updating eslint_d or killing it.', + \}] + endif + " Matches patterns line the following: " " /path/to/some-filename.js:47:14: Missing trailing comma. [Warning/comma-dangle] diff --git a/autoload/ale/handlers/rubocop.vim b/autoload/ale/handlers/rubocop.vim deleted file mode 100644 index f6367cf5..00000000 --- a/autoload/ale/handlers/rubocop.vim +++ /dev/null @@ -1,6 +0,0 @@ -call ale#Set('ruby_rubocop_options', '') -call ale#Set('ruby_rubocop_executable', 'rubocop') - -function! ale#handlers#rubocop#GetExecutable(buffer) abort - return ale#Var(a:buffer, 'ruby_rubocop_executable') -endfunction diff --git a/autoload/ale/handlers/ruby.vim b/autoload/ale/handlers/ruby.vim index 110fe156..c28b8b75 100644 --- a/autoload/ale/handlers/ruby.vim +++ b/autoload/ale/handlers/ruby.vim @@ -37,3 +37,10 @@ function! ale#handlers#ruby#HandleSyntaxErrors(buffer, lines) abort return s:HandleSyntaxError(a:buffer, a:lines) endfunction +function! ale#handlers#ruby#EscapeExecutable(executable, bundle_exec) abort + let l:exec_args = a:executable =~? 'bundle' + \ ? ' exec ' . a:bundle_exec + \ : '' + + return ale#Escape(a:executable) . l:exec_args +endfunction diff --git a/autoload/ale/julia.vim b/autoload/ale/julia.vim new file mode 100644 index 00000000..18dd9ad7 --- /dev/null +++ b/autoload/ale/julia.vim @@ -0,0 +1,19 @@ +" Author: Bartolomeo Stellato bartolomeo.stellato@gmail.com +" Description: Functions for integrating with Julia tools + +" Find the nearest dir containing a julia project +let s:__ale_julia_project_filenames = ['REQUIRE', 'Manifest.toml', 'Project.toml'] + +function! ale#julia#FindProjectRoot(buffer) abort + for l:project_filename in s:__ale_julia_project_filenames + let l:full_path = ale#path#FindNearestFile(a:buffer, l:project_filename) + + if !empty(l:full_path) + let l:path = fnamemodify(l:full_path, ':p:h') + + return l:path + endif + endfor + + return '' +endfunction diff --git a/autoload/ale/lsp_linter.vim b/autoload/ale/lsp_linter.vim index 8fbad12f..a11c76bc 100644 --- a/autoload/ale/lsp_linter.vim +++ b/autoload/ale/lsp_linter.vim @@ -55,16 +55,29 @@ function! s:HandleTSServerDiagnostics(response, error_type) abort endif let l:thislist = ale#lsp#response#ReadTSServerDiagnostics(a:response) + let l:no_changes = 0 " tsserver sends syntax and semantic errors in separate messages, so we " have to collect the messages separately for each buffer and join them " back together again. if a:error_type is# 'syntax' + if len(l:thislist) is 0 && len(get(l:info, 'syntax_loclist', [])) is 0 + let l:no_changes = 1 + endif + let l:info.syntax_loclist = l:thislist else + if len(l:thislist) is 0 && len(get(l:info, 'semantic_loclist', [])) is 0 + let l:no_changes = 1 + endif + let l:info.semantic_loclist = l:thislist endif + if l:no_changes + return + endif + let l:loclist = get(l:info, 'semantic_loclist', []) \ + get(l:info, 'syntax_loclist', []) @@ -99,9 +112,10 @@ endfunction function! ale#lsp_linter#HandleLSPResponse(conn_id, response) abort let l:method = get(a:response, 'method', '') - let l:linter_name = get(s:lsp_linter_map, a:conn_id, '') if get(a:response, 'jsonrpc', '') is# '2.0' && has_key(a:response, 'error') + let l:linter_name = get(s:lsp_linter_map, a:conn_id, '') + call s:HandleLSPErrorMessage(l:linter_name, a:response) elseif l:method is# 'textDocument/publishDiagnostics' call s:HandleLSPDiagnostics(a:conn_id, a:response) diff --git a/autoload/ale/preview.vim b/autoload/ale/preview.vim index aefbb691..180a37d0 100644 --- a/autoload/ale/preview.vim +++ b/autoload/ale/preview.vim @@ -15,13 +15,13 @@ function! ale#preview#Show(lines, ...) abort setlocal modifiable setlocal noreadonly setlocal nobuflisted - let &l:filetype = get(l:options, 'filetype', 'ale-preview') setlocal buftype=nofile setlocal bufhidden=wipe :%d call setline(1, a:lines) setlocal nomodifiable setlocal readonly + let &l:filetype = get(l:options, 'filetype', 'ale-preview') if get(l:options, 'stay_here') wincmd p |