1
0
mirror of https://github.com/amix/vimrc synced 2025-06-16 01:25:00 +08:00

Updated plugins

This commit is contained in:
Amir Salihefendic
2018-09-24 21:40:17 -03:00
parent 6bd9eda8c3
commit a6b64938eb
199 changed files with 2897 additions and 980 deletions

View File

@ -27,7 +27,7 @@ let s:getcmdwintype_exists = exists('*getcmdwintype')
function! ale#ShouldDoNothing(buffer) abort
" The checks are split into separate if statements to make it possible to
" profile each check individually with Vim's profiling tools.
"
" Do nothing if ALE is disabled.
if !getbufvar(a:buffer, 'ale_enabled', get(g:, 'ale_enabled', 0))
return 1
@ -62,6 +62,11 @@ function! ale#ShouldDoNothing(buffer) abort
return 1
endif
" Don't start linting and so on when an operator is pending.
if ale#util#Mode(1) is# 'no'
return 1
endif
" Do nothing if running in the sandbox.
if ale#util#InSandbox()
return 1

View File

@ -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

View File

@ -54,7 +54,8 @@ function! ale#c#ParseCFlags(path_prefix, cflag_line) abort
call add(l:previous_options, l:option)
" Check if cflag contained a '-' and should not have been splitted
let l:option_list = split(l:option, '\zs')
if l:option_list[-1] isnot# ' '
if len(l:option_list) > 0 && l:option_list[-1] isnot# ' '
continue
endif

View File

@ -39,10 +39,14 @@ let s:LSP_COMPLETION_COLOR_KIND = 16
let s:LSP_COMPLETION_FILE_KIND = 17
let s:LSP_COMPLETION_REFERENCE_KIND = 18
let s:lisp_regex = '\v[a-zA-Z_\-][a-zA-Z_\-0-9]*$'
" Regular expressions for checking the characters in the line before where
" the insert cursor is. If one of these matches, we'll check for completions.
let s:should_complete_map = {
\ '<default>': '\v[a-zA-Z$_][a-zA-Z$_0-9]*$|\.$',
\ 'clojure': s:lisp_regex,
\ 'lisp': s:lisp_regex,
\ 'typescript': '\v[a-zA-Z$_][a-zA-Z$_0-9]*$|\.$|''$|"$',
\ 'rust': '\v[a-zA-Z$_][a-zA-Z$_0-9]*$|\.$|::$',
\}
@ -75,6 +79,7 @@ endfunction
" Check if we should look for completions for a language.
function! ale#completion#GetPrefix(filetype, line, column) abort
let l:regex = s:GetFiletypeValue(s:should_complete_map, a:filetype)
" The column we're using completions for is where we are inserting text,
" like so:
" abc
@ -93,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 = []
@ -259,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'
@ -354,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
@ -385,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]

View File

@ -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,42 +57,55 @@ 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
" Only echo the warnings in normal mode, otherwise we will get problems.
if mode() isnot# 'n'
if mode(1) isnot# 'n'
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 !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_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 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
" Only echo the warnings in normal mode, otherwise we will get problems.
if mode() isnot# 'n'
if mode(1) isnot# 'n'
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

View File

@ -49,7 +49,7 @@ function! ale#definition#HandleLSPResponse(conn_id, response) abort
for l:item in l:result
let l:filename = ale#path#FromURI(l:item.uri)
let l:line = l:item.range.start.line + 1
let l:column = l:item.range.start.character
let l:column = l:item.range.start.character + 1
call ale#util#Open(l:filename, l:line, l:column, l:options)
break

View File

@ -18,6 +18,22 @@ if !has_key(s:, 'executable_cache_map')
let s:executable_cache_map = {}
endif
function! ale#engine#CleanupEveryBuffer() abort
for l:key in keys(g:ale_buffer_info)
" The key could be a filename or a buffer number, so try and
" convert it to a number. We need a number for the other
" functions.
let l:buffer = str2nr(l:key)
if l:buffer > 0
" Stop all jobs and clear the results for everything, and delete
" all of the data we stored for the buffer.
call ale#engine#Cleanup(l:buffer)
endif
endfor
endfunction
function! ale#engine#ResetExecutableCache() abort
let s:executable_cache_map = {}
endfunction
@ -231,6 +247,7 @@ function! s:HandleExit(job_id, exit_code) abort
if l:next_chain_index < len(get(l:linter, 'command_chain', []))
call s:InvokeChain(l:buffer, l:executable, l:linter, l:next_chain_index, l:output)
return
endif
@ -595,9 +612,8 @@ function! ale#engine#ProcessChain(buffer, linter, chain_index, input) abort
\)
endif
" If we have a command to run, execute that.
if !empty(l:command)
" We hit a command to run, so we'll execute that
" The chain item can override the output_stream option.
if has_key(l:chain_item, 'output_stream')
let l:output_stream = l:chain_item.output_stream

View File

@ -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

View File

@ -30,7 +30,14 @@ function! ale#fix#ApplyQueuedFixes() abort
call winrestview(l:save)
endif
call setline(1, l:data.output)
" If the file is in DOS mode, we have to remove carriage returns from
" the ends of lines before calling setline(), or we will see them
" twice.
let l:lines_to_set = getbufvar(l:buffer, '&fileformat') is# 'dos'
\ ? map(copy(l:data.output), 'substitute(v:val, ''\r\+$'', '''', '''')')
\ : l:data.output
call setline(1, l:lines_to_set)
if l:data.should_save
if empty(&buftype)
@ -71,6 +78,7 @@ function! ale#fix#ApplyFixes(buffer, output) abort
if l:data.lines_before != l:lines
call remove(g:ale_fix_buffer_data, a:buffer)
execute 'echoerr ''The file was changed before fixing finished'''
return
endif
endif

View File

@ -145,6 +145,11 @@ let s:default_registry = {
\ 'suggested_filetypes': ['go'],
\ 'description': 'Fix Go files imports with goimports.',
\ },
\ 'gomod': {
\ 'function': 'ale#fixers#gomod#Fix',
\ 'suggested_filetypes': ['gomod'],
\ 'description': 'Fix Go module files with go mod edit -fmt.',
\ },
\ 'tslint': {
\ 'function': 'ale#fixers#tslint#Fix',
\ 'suggested_filetypes': ['typescript'],
@ -180,6 +185,11 @@ let s:default_registry = {
\ 'suggested_filetypes': ['haskell'],
\ 'description': 'Refactor Haskell files with stylish-haskell.',
\ },
\ 'ocamlformat': {
\ 'function': 'ale#fixers#ocamlformat#Fix',
\ 'suggested_filetypes': ['ocaml'],
\ 'description': 'Fix OCaml files with ocamlformat.',
\ },
\ 'refmt': {
\ 'function': 'ale#fixers#refmt#Fix',
\ 'suggested_filetypes': ['reason'],
@ -190,6 +200,11 @@ let s:default_registry = {
\ 'suggested_filetypes': ['sh'],
\ 'description': 'Fix sh files with shfmt.',
\ },
\ 'sqlfmt': {
\ 'function': 'ale#fixers#sqlfmt#Fix',
\ 'suggested_filetypes': ['sql'],
\ 'description': 'Fix SQL files with sqlfmt.',
\ },
\ 'google_java_format': {
\ 'function': 'ale#fixers#google_java_format#Fix',
\ 'suggested_filetypes': ['java'],
@ -225,6 +240,16 @@ let s:default_registry = {
\ 'suggested_filetypes': ['dart'],
\ 'description': 'Fix Dart files with dartfmt.',
\ },
\ 'xmllint': {
\ 'function': 'ale#fixers#xmllint#Fix',
\ 'suggested_filetypes': ['xml'],
\ 'description': 'Fix XML files with xmllint.',
\ },
\ 'uncrustify': {
\ 'function': 'ale#fixers#uncrustify#Fix',
\ 'suggested_filetypes': ['c', 'cpp', 'cs', 'objc', 'objcpp', 'd', 'java', 'p', 'vala' ],
\ 'description': 'Fix C, C++, C#, ObjectiveC, ObjectiveC++, D, Java, Pawn, and VALA files with uncrustify.',
\ },
\}
" Reset the function registry to the default entries.

View File

@ -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

View File

@ -17,6 +17,7 @@ function! ale#fixers#fixjson#Fix(buffer) abort
let l:command = l:executable . ' --stdin-filename ' . l:filename
let l:options = ale#Var(a:buffer, 'json_fixjson_options')
if l:options isnot# ''
let l:command .= ' ' . l:options
endif

View File

@ -0,0 +1,10 @@
call ale#Set('go_go_executable', 'go')
function! ale#fixers#gomod#Fix(buffer) abort
let l:executable = ale#Var(a:buffer, 'go_go_executable')
return {
\ 'command': ale#Escape(l:executable) . ' mod edit -fmt %t',
\ 'read_temporary_file': 1,
\}
endfunction

View File

@ -5,6 +5,7 @@ call ale#Set('javascript_importjs_executable', 'importjs')
function! ale#fixers#importjs#ProcessOutput(buffer, output) abort
let l:result = ale#util#FuzzyJSONDecode(a:output, [])
return split(get(l:result, 'fileContent', ''), "\n")
endfunction

View File

@ -0,0 +1,18 @@
" Author: Stephen Lumenta <@sbl>
" Description: Integration of ocamlformat with ALE.
call ale#Set('ocaml_ocamlformat_executable', 'ocamlformat')
call ale#Set('ocaml_ocamlformat_options', '')
function! ale#fixers#ocamlformat#Fix(buffer) abort
let l:executable = ale#Var(a:buffer, 'ocaml_ocamlformat_executable')
let l:options = ale#Var(a:buffer, 'ocaml_ocamlformat_options')
return {
\ 'command': ale#Escape(l:executable)
\ . (empty(l:options) ? '' : ' ' . l:options)
\ . ' --inplace'
\ . ' %t',
\ 'read_temporary_file': 1,
\}
endfunction

View File

@ -14,6 +14,7 @@ endfunction
function! ale#fixers#php_cs_fixer#Fix(buffer) abort
let l:executable = ale#fixers#php_cs_fixer#GetExecutable(a:buffer)
return {
\ 'command': ale#Escape(l:executable)
\ . ' ' . ale#Var(a:buffer, 'php_cs_fixer_options')

View File

@ -18,6 +18,7 @@ function! ale#fixers#phpcbf#Fix(buffer) abort
let l:standard_option = !empty(l:standard)
\ ? '--standard=' . l:standard
\ : ''
return {
\ 'command': ale#Escape(l:executable) . ' --stdin-path=%s ' . l:standard_option . ' -'
\}

View File

@ -4,6 +4,7 @@
if !exists('g:ale_puppet_puppetlint_executable')
let g:ale_puppet_puppetlint_executable = 'puppet-lint'
endif
if !exists('g:ale_puppet_puppetlint_options')
let g:ale_puppet_puppetlint_options = ''
endif

View File

@ -1,16 +1,15 @@
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'
endfunction
function! ale#fixers#rubocop#Fix(buffer) abort

View File

@ -15,7 +15,6 @@ function! ale#fixers#scalafmt#GetCommand(buffer) abort
return ale#Escape(l:executable) . l:exec_args
\ . (empty(l:options) ? '' : ' ' . l:options)
\ . ' %t'
endfunction
function! ale#fixers#scalafmt#Fix(buffer) abort

View File

@ -5,13 +5,27 @@ scriptencoding utf-8
call ale#Set('sh_shfmt_executable', 'shfmt')
call ale#Set('sh_shfmt_options', '')
function! s:DefaultOption(buffer) abort
if getbufvar(a:buffer, '&expandtab') == 0
" Tab is used by default
return ''
endif
let l:tabsize = getbufvar(a:buffer, '&shiftwidth')
if l:tabsize == 0
let l:tabsize = getbufvar(a:buffer, '&tabstop')
endif
return ' -i ' . l:tabsize
endfunction
function! ale#fixers#shfmt#Fix(buffer) abort
let l:executable = ale#Var(a:buffer, 'sh_shfmt_executable')
let l:options = ale#Var(a:buffer, 'sh_shfmt_options')
return {
\ 'command': ale#Escape(l:executable)
\ . (empty(l:options) ? '' : ' ' . l:options)
\ . (empty(l:options) ? s:DefaultOption(a:buffer) : ' ' . l:options)
\}
endfunction

View File

@ -0,0 +1,13 @@
call ale#Set('sql_sqlfmt_executable', 'sqlfmt')
call ale#Set('sql_sqlfmt_options', '')
function! ale#fixers#sqlfmt#Fix(buffer) abort
let l:executable = ale#Var(a:buffer, 'sql_sqlfmt_executable')
let l:options = ale#Var(a:buffer, 'sql_sqlfmt_options')
return {
\ 'command': ale#Escape(l:executable)
\ . ' -w'
\ . (empty(l:options) ? '' : ' ' . l:options),
\}
endfunction

View File

@ -0,0 +1,16 @@
" Author: Derek P Sifford <dereksifford@gmail.com>
" Description: Fixer for C, C++, C#, ObjectiveC, D, Java, Pawn, and VALA.
call ale#Set('c_uncrustify_executable', 'uncrustify')
call ale#Set('c_uncrustify_options', '')
function! ale#fixers#uncrustify#Fix(buffer) abort
let l:executable = ale#Var(a:buffer, 'c_uncrustify_executable')
let l:options = ale#Var(a:buffer, 'c_uncrustify_options')
return {
\ 'command': ale#Escape(l:executable)
\ . ' --no-backup'
\ . (empty(l:options) ? '' : ' ' . l:options)
\}
endfunction

View File

@ -0,0 +1,29 @@
" Author: Cyril Roelandt <tipecaml@gmail.com>
" Description: Integration of xmllint with ALE.
call ale#Set('xml_xmllint_executable', 'xmllint')
call ale#Set('xml_xmllint_options', '')
call ale#Set('xml_xmllint_indentsize', 2)
function! ale#fixers#xmllint#Fix(buffer) abort
let l:executable = ale#Escape(ale#Var(a:buffer, 'xml_xmllint_executable'))
let l:filename = ale#Escape(bufname(a:buffer))
let l:command = l:executable . ' --format ' . l:filename
let l:indent = ale#Var(a:buffer, 'xml_xmllint_indentsize')
if l:indent isnot# ''
let l:env = ale#Env('XMLLINT_INDENT', repeat(' ', l:indent))
let l:command = l:env . l:command
endif
let l:options = ale#Var(a:buffer, 'xml_xmllint_options')
if l:options isnot# ''
let l:command .= ' ' . l:options
endif
return {
\ 'command': l:command
\}
endfunction

View File

@ -0,0 +1,27 @@
" Author: Horacio Sanson https://github.com/hsanson
" Description: Functions for integrating with Go tools
" Find the nearest dir listed in GOPATH and assume it the root of the go
" project.
function! ale#go#FindProjectRoot(buffer) abort
let l:sep = has('win32') ? ';' : ':'
let l:filename = ale#path#Simplify(expand('#' . a:buffer . ':p'))
for l:name in split($GOPATH, l:sep)
let l:path_dir = ale#path#Simplify(l:name)
" Use the directory from GOPATH if the current filename starts with it.
if l:filename[: len(l:path_dir) - 1] is? l:path_dir
return l:path_dir
endif
endfor
let l:default_go_path = ale#path#Simplify(expand('~/go'))
if isdirectory(l:default_go_path)
return l:default_go_path
endif
return ''
endfunction

View File

@ -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]

View File

@ -9,9 +9,11 @@ function! ale#handlers#gawk#HandleGawkFormat(buffer, lines) abort
for l:match in ale#util#GetMatches(a:lines, l:pattern)
let l:ecode = 'E'
if l:match[2] is? 'warning:'
let l:ecode = 'W'
endif
call add(l:output, {
\ 'lnum': l:match[1] + 0,
\ 'col': 0,

View File

@ -21,5 +21,6 @@ function! ale#handlers#go#Handler(buffer, lines) abort
\ 'type': 'E',
\})
endfor
return l:output
endfunction

View File

@ -3,6 +3,7 @@
function! ale#handlers#ols#GetExecutable(buffer) abort
let l:ols_setting = ale#handlers#ols#GetLanguage(a:buffer) . '_ols'
return ale#node#FindExecutable(a:buffer, l:ols_setting, [
\ 'node_modules/.bin/ocaml-language-server',
\])

View File

@ -14,7 +14,6 @@ endfunction
function! ale#handlers#pony#HandlePonycFormat(buffer, lines) abort
" Look for lines like the following.
" /home/code/pony/classes/Wombat.pony:22:30: can't lookup private fields from outside the type
let l:pattern = '\v^([^:]+):(\d+):(\d+)?:? (.+)$'
let l:output = []

View File

@ -6,15 +6,18 @@ function! ale#handlers#redpen#HandleRedpenOutput(buffer, lines) abort
" element.
let l:res = json_decode(join(a:lines))[0]
let l:output = []
for l:err in l:res.errors
let l:item = {
\ 'text': l:err.message,
\ 'type': 'W',
\ 'code': l:err.validator,
\}
if has_key(l:err, 'startPosition')
let l:item.lnum = l:err.startPosition.lineNum
let l:item.col = l:err.startPosition.offset + 1
if has_key(l:err, 'endPosition')
let l:item.end_lnum = l:err.endPosition.lineNum
let l:item.end_col = l:err.endPosition.offset
@ -28,29 +31,35 @@ function! ale#handlers#redpen#HandleRedpenOutput(buffer, lines) abort
" Adjust column number for multibyte string
let l:line = getline(l:item.lnum)
if l:line is# ''
let l:line = l:err.sentence
endif
let l:line = split(l:line, '\zs')
if l:item.col >= 2
let l:col = 0
for l:strlen in map(l:line[0:(l:item.col - 2)], 'strlen(v:val)')
let l:col = l:col + l:strlen
endfor
let l:item.col = l:col + 1
endif
if has_key(l:item, 'end_col')
let l:col = 0
for l:strlen in map(l:line[0:(l:item.end_col - 1)], 'strlen(v:val)')
let l:col = l:col + l:strlen
endfor
let l:item.end_col = l:col
endif
call add(l:output, l:item)
endfor
return l:output
endfunction

View File

@ -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

View File

@ -13,8 +13,10 @@ function! s:HandleSyntaxError(buffer, lines) abort
for l:line in a:lines
let l:match = matchlist(l:line, l:pattern)
if len(l:match) == 0
let l:match = matchlist(l:line, l:column)
if len(l:match) != 0
let l:output[len(l:output) - 1]['col'] = len(l:match[1])
endif
@ -35,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

View File

@ -11,8 +11,10 @@ function! ale#handlers#sml#GetCmFile(buffer) abort
let l:as_list = 1
let l:cmfile = ''
for l:path in ale#path#Upwards(expand('#' . a:buffer . ':p:h'))
let l:results = glob(l:path . '/' . l:pattern, 0, l:as_list)
if len(l:results) > 0
" If there is more than one CM file, we take the first one
" See :help ale-sml-smlnj for how to configure this.
@ -46,6 +48,7 @@ endfunction
function! ale#handlers#sml#GetExecutableSmlnjCm(buffer) abort
return s:GetExecutable(a:buffer, 'smlnj-cm')
endfunction
function! ale#handlers#sml#GetExecutableSmlnjFile(buffer) abort
return s:GetExecutable(a:buffer, 'smlnj-file')
endfunction
@ -53,7 +56,6 @@ endfunction
function! ale#handlers#sml#Handle(buffer, lines) abort
" Try to match basic sml errors
" TODO(jez) We can get better errorfmt strings from Syntastic
let l:out = []
let l:pattern = '^.*\:\([0-9\.]\+\)\ \(\w\+\)\:\ \(.*\)'
let l:pattern2 = '^.*\:\([0-9]\+\)\.\?\([0-9]\+\).* \(\(Warning\|Error\): .*\)'
@ -83,7 +85,6 @@ function! ale#handlers#sml#Handle(buffer, lines) abort
\})
continue
endif
endfor
return l:out

View File

@ -23,6 +23,7 @@ function! ale#handlers#vale#Handle(buffer, lines) abort
endif
let l:output = []
for l:error in l:errors[keys(l:errors)[0]]
call add(l:output, {
\ 'lnum': l:error['Line'],

View File

@ -0,0 +1,20 @@
" Author: Horacio Sanson https://github.com/hsanson
" Description: Functions for integrating with Java tools
" Find the nearest dir contining a gradle or pom file and asume it
" the root of a java app.
function! ale#java#FindProjectRoot(buffer) abort
let l:gradle_root = ale#gradle#FindProjectRoot(a:buffer)
if !empty(l:gradle_root)
return l:gradle_root
endif
let l:maven_pom_file = ale#path#FindNearestFile(a:buffer, 'pom.xml')
if !empty(l:maven_pom_file)
return fnamemodify(l:maven_pom_file, ':h')
endif
return ''
endfunction

View File

@ -249,6 +249,11 @@ function! ale#job#Start(command, options) abort
let l:job_options.exit_cb = function('s:VimExitCallback')
endif
" Use non-blocking writes for Vim versions that support the option.
if has('patch-8.1.350')
let l:job_options.noblock = 1
endif
" Vim 8 will read the stdin from the file's buffer.
let l:job_info.job = job_start(a:command, l:job_options)
let l:job_id = ale#job#ParseVim8ProcessID(string(l:job_info.job))
@ -278,11 +283,13 @@ function! ale#job#IsRunning(job_id) abort
try
" In NeoVim, if the job isn't running, jobpid() will throw.
call jobpid(a:job_id)
return 1
catch
endtry
elseif has_key(s:job_map, a:job_id)
let l:job = s:job_map[a:job_id].job
return job_status(l:job) is# 'run'
endif

View File

@ -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

View File

@ -99,7 +99,7 @@ function! ale#linter#PreProcess(filetype, linter) abort
endif
if index(['', 'socket', 'stdio', 'tsserver'], l:obj.lsp) < 0
throw '`lsp` must be either `''lsp''` or `''tsserver''` if defined'
throw '`lsp` must be either `''lsp''`, `''stdio''`, `''socket''` or `''tsserver''` if defined'
endif
if !l:needs_executable

View File

@ -25,6 +25,7 @@ function! ale#list#IsQuickfixOpen() abort
return 1
endif
endfor
return 0
endfunction
@ -112,9 +113,11 @@ function! s:SetListsImpl(timer_id, buffer, loclist) abort
" open windows vertically instead of default horizontally
let l:open_type = ''
if ale#Var(a:buffer, 'list_vertical') == 1
let l:open_type = 'vert '
endif
if g:ale_set_quickfix
if !ale#list#IsQuickfixOpen()
silent! execute l:open_type . 'copen ' . str2nr(ale#Var(a:buffer, 'list_window_size'))

View File

@ -24,6 +24,7 @@ function! ale#lsp#Register(executable_or_address, project, init_options) abort
" capabilities_queue: The list of callbacks to call with capabilities.
" capabilities: Features the server supports.
let s:connections[l:conn_id] = {
\ 'id': l:conn_id,
\ 'is_tsserver': 0,
\ 'data': '',
\ 'root': a:project,
@ -98,6 +99,7 @@ function! s:CreateTSServerMessageData(message) abort
endif
let l:data = json_encode(l:obj) . "\n"
return [l:is_notification ? 0 : l:obj.seq, l:data]
endfunction

View File

@ -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)

View File

@ -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

View File

@ -1,6 +1,8 @@
" Author: w0rp <devw0rp@gmail.com>
" Description: Functions for integrating with Python linters.
call ale#Set('python_auto_pipenv', '0')
let s:sep = has('win32') ? '\' : '/'
" bin is used for Unix virtualenv directories, and Scripts is for Windows.
let s:bin_dir = has('unix') ? 'bin' : 'Scripts'
@ -107,3 +109,8 @@ function! ale#python#FindExecutable(buffer, base_var_name, path_list) abort
return ale#Var(a:buffer, a:base_var_name . '_executable')
endfunction
" Detects whether a pipenv environment is present.
function! ale#python#PipenvPresent(buffer) abort
return findfile('Pipfile.lock', expand('#' . a:buffer . ':p:h') . ';') isnot# ''
endfunction

View File

@ -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 ['.solargraph.yml', '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

View File

@ -55,11 +55,18 @@ function! ale#socket#Open(address, options) abort
if !has('nvim')
" Vim
let l:channel_info.channel = ch_open(a:address, {
let l:channel_options = {
\ 'mode': l:mode,
\ 'waittime': 0,
\ 'callback': function('s:VimOutputCallback'),
\})
\}
" Use non-blocking writes for Vim versions that support the option.
if has('patch-8.1.350')
let l:channel_options.noblock = 1
endif
let l:channel_info.channel = ch_open(a:address, l:channel_options)
let l:vim_info = ch_info(l:channel_info.channel)
let l:channel_id = !empty(l:vim_info) ? l:vim_info.id : -1
elseif exists('*chansend') && exists('*sockconnect')
@ -104,6 +111,7 @@ function! ale#socket#IsOpen(channel_id) abort
endif
let l:channel = s:channel_map[a:channel_id].channel
return ch_status(l:channel) is# 'open'
endfunction

View File

@ -15,21 +15,6 @@ function! s:DisablePostamble() abort
endif
endfunction
function! s:CleanupEveryBuffer() abort
for l:key in keys(g:ale_buffer_info)
" The key could be a filename or a buffer number, so try and
" convert it to a number. We need a number for the other
" functions.
let l:buffer = str2nr(l:key)
if l:buffer > 0
" Stop all jobs and clear the results for everything, and delete
" all of the data we stored for the buffer.
call ale#engine#Cleanup(l:buffer)
endif
endfor
endfunction
function! ale#toggle#Toggle() abort
let g:ale_enabled = !get(g:, 'ale_enabled')
@ -40,7 +25,7 @@ function! ale#toggle#Toggle() abort
call ale#balloon#Enable()
endif
else
call s:CleanupEveryBuffer()
call ale#engine#CleanupEveryBuffer()
call s:DisablePostamble()
if exists('*ale#balloon#Disable')
@ -64,7 +49,7 @@ function! ale#toggle#Disable() abort
endfunction
function! ale#toggle#Reset() abort
call s:CleanupEveryBuffer()
call ale#engine#CleanupEveryBuffer()
call ale#highlight#UpdateHighlights()
endfunction
@ -76,6 +61,7 @@ function! ale#toggle#ToggleBuffer(buffer) abort
" linting locally when linting is disabled globally
if l:enabled && !g:ale_enabled
execute 'echom ''ALE cannot be enabled locally when disabled globally'''
return
endif

View File

@ -54,6 +54,7 @@ endif
function! ale#util#JoinNeovimOutput(job, last_line, data, mode, callback) abort
if a:mode is# 'raw'
call a:callback(a:job, join(a:data, "\n"))
return ''
endif
@ -404,7 +405,7 @@ endfunction
" the buffer.
function! ale#util#Writefile(buffer, lines, filename) abort
let l:corrected_lines = getbufvar(a:buffer, '&fileformat') is# 'dos'
\ ? map(copy(a:lines), 'v:val . "\r"')
\ ? map(copy(a:lines), 'substitute(v:val, ''\r*$'', ''\r'', '''')')
\ : a:lines
call writefile(l:corrected_lines, a:filename) " no-custom-checks