mirror of
https://github.com/amix/vimrc
synced 2025-07-09 18:55:01 +08:00
gitignore sources_non_forked_cache
This commit is contained in:
97
sources_non_forked/ale/ale_linters/erlang/dialyzer.vim
Normal file
97
sources_non_forked/ale/ale_linters/erlang/dialyzer.vim
Normal file
@ -0,0 +1,97 @@
|
||||
" Author: Autoine Gagne - https://github.com/AntoineGagne
|
||||
" Description: Define a checker that runs dialyzer on Erlang files.
|
||||
|
||||
let g:ale_erlang_dialyzer_executable =
|
||||
\ get(g:, 'ale_erlang_dialyzer_executable', 'dialyzer')
|
||||
let g:ale_erlang_dialyzer_options =
|
||||
\ get(g:, 'ale_erlang_dialyzer_options', '-Wunmatched_returns'
|
||||
\ . ' -Werror_handling'
|
||||
\ . ' -Wrace_conditions'
|
||||
\ . ' -Wunderspecs')
|
||||
let g:ale_erlang_dialyzer_plt_file =
|
||||
\ get(g:, 'ale_erlang_dialyzer_plt_file', '')
|
||||
let g:ale_erlang_dialyzer_rebar3_profile =
|
||||
\ get(g:, 'ale_erlang_dialyzer_rebar3_profile', 'default')
|
||||
|
||||
function! ale_linters#erlang#dialyzer#GetRebar3Profile(buffer) abort
|
||||
return ale#Var(a:buffer, 'erlang_dialyzer_rebar3_profile')
|
||||
endfunction
|
||||
|
||||
function! ale_linters#erlang#dialyzer#FindPlt(buffer) abort
|
||||
let l:plt_file = ''
|
||||
let l:rebar3_profile = ale_linters#erlang#dialyzer#GetRebar3Profile(a:buffer)
|
||||
let l:plt_file_directory = ale#path#FindNearestDirectory(a:buffer, '_build/' . l:rebar3_profile)
|
||||
|
||||
if !empty(l:plt_file_directory)
|
||||
let l:plt_file = globpath(l:plt_file_directory, '*_plt', 0, 1)
|
||||
endif
|
||||
|
||||
if !empty(l:plt_file)
|
||||
return l:plt_file[0]
|
||||
endif
|
||||
|
||||
if !empty($REBAR_PLT_DIR)
|
||||
return expand('$REBAR_PLT_DIR/dialyzer/plt')
|
||||
endif
|
||||
|
||||
return expand('$HOME/.dialyzer_plt')
|
||||
endfunction
|
||||
|
||||
function! ale_linters#erlang#dialyzer#GetPlt(buffer) abort
|
||||
let l:plt_file = ale#Var(a:buffer, 'erlang_dialyzer_plt_file')
|
||||
|
||||
if !empty(l:plt_file)
|
||||
return l:plt_file
|
||||
endif
|
||||
|
||||
return ale_linters#erlang#dialyzer#FindPlt(a:buffer)
|
||||
endfunction
|
||||
|
||||
function! ale_linters#erlang#dialyzer#GetExecutable(buffer) abort
|
||||
return ale#Var(a:buffer, 'erlang_dialyzer_executable')
|
||||
endfunction
|
||||
|
||||
function! ale_linters#erlang#dialyzer#GetCommand(buffer) abort
|
||||
let l:options = ale#Var(a:buffer, 'erlang_dialyzer_options')
|
||||
|
||||
let l:command = ale#Escape(ale_linters#erlang#dialyzer#GetExecutable(a:buffer))
|
||||
\ . ' -n'
|
||||
\ . ' --plt ' . ale#Escape(ale_linters#erlang#dialyzer#GetPlt(a:buffer))
|
||||
\ . ' ' . l:options
|
||||
\ . ' %s'
|
||||
|
||||
return l:command
|
||||
endfunction
|
||||
|
||||
function! ale_linters#erlang#dialyzer#Handle(buffer, lines) abort
|
||||
" Match patterns like the following:
|
||||
"
|
||||
" erl_tidy_prv_fmt.erl:3: Callback info about the provider behaviour is not available
|
||||
let l:pattern = '^\S\+:\(\d\+\): \(.\+\)$'
|
||||
let l:output = []
|
||||
|
||||
for l:line in a:lines
|
||||
let l:match = matchlist(l:line, l:pattern)
|
||||
|
||||
if len(l:match) != 0
|
||||
let l:code = l:match[2]
|
||||
|
||||
call add(l:output, {
|
||||
\ 'lnum': str2nr(l:match[1]),
|
||||
\ 'lcol': 0,
|
||||
\ 'text': l:code,
|
||||
\ 'type': 'W'
|
||||
\})
|
||||
endif
|
||||
endfor
|
||||
|
||||
return l:output
|
||||
endfunction
|
||||
|
||||
call ale#linter#Define('erlang', {
|
||||
\ 'name': 'dialyzer',
|
||||
\ 'executable': function('ale_linters#erlang#dialyzer#GetExecutable'),
|
||||
\ 'command': function('ale_linters#erlang#dialyzer#GetCommand'),
|
||||
\ 'callback': function('ale_linters#erlang#dialyzer#Handle'),
|
||||
\ 'lint_file': 1
|
||||
\})
|
40
sources_non_forked/ale/ale_linters/erlang/elvis.vim
Normal file
40
sources_non_forked/ale/ale_linters/erlang/elvis.vim
Normal file
@ -0,0 +1,40 @@
|
||||
" Author: Dmitri Vereshchagin <dmitri.vereshchagin@gmail.com>
|
||||
" Description: Elvis linter for Erlang files
|
||||
|
||||
call ale#Set('erlang_elvis_executable', 'elvis')
|
||||
|
||||
function! ale_linters#erlang#elvis#Handle(buffer, lines) abort
|
||||
let l:pattern = '\v:(\d+):[^:]+:(.+)'
|
||||
let l:loclist = []
|
||||
|
||||
for l:match in ale#util#GetMatches(a:lines, l:pattern)
|
||||
call add(l:loclist, {
|
||||
\ 'lnum': str2nr(l:match[1]),
|
||||
\ 'text': s:AbbreviateMessage(l:match[2]),
|
||||
\ 'type': 'W',
|
||||
\ 'sub_type': 'style',
|
||||
\})
|
||||
endfor
|
||||
|
||||
return l:loclist
|
||||
endfunction
|
||||
|
||||
function! s:AbbreviateMessage(text) abort
|
||||
let l:pattern = '\v\c^(line \d+ is too long):.*$'
|
||||
|
||||
return substitute(a:text, l:pattern, '\1.', '')
|
||||
endfunction
|
||||
|
||||
function! s:GetCommand(buffer) abort
|
||||
let l:file = ale#Escape(expand('#' . a:buffer . ':.'))
|
||||
|
||||
return '%e rock --output-format=parsable ' . l:file
|
||||
endfunction
|
||||
|
||||
call ale#linter#Define('erlang', {
|
||||
\ 'name': 'elvis',
|
||||
\ 'callback': 'ale_linters#erlang#elvis#Handle',
|
||||
\ 'executable': {b -> ale#Var(b, 'erlang_elvis_executable')},
|
||||
\ 'command': function('s:GetCommand'),
|
||||
\ 'lint_file': 1,
|
||||
\})
|
49
sources_non_forked/ale/ale_linters/erlang/erlang_ls.vim
Normal file
49
sources_non_forked/ale/ale_linters/erlang/erlang_ls.vim
Normal file
@ -0,0 +1,49 @@
|
||||
" Author: Dmitri Vereshchagin <dmitri.vereshchagin@gmail.com>
|
||||
" Description: LSP linter for Erlang files
|
||||
|
||||
call ale#Set('erlang_erlang_ls_executable', 'erlang_ls')
|
||||
call ale#Set('erlang_erlang_ls_log_dir', '')
|
||||
call ale#Set('erlang_erlang_ls_log_level', 'info')
|
||||
|
||||
function! s:GetCommand(buffer) abort
|
||||
let l:log_dir = ale#Var(a:buffer, 'erlang_erlang_ls_log_dir')
|
||||
let l:log_level = ale#Var(a:buffer, 'erlang_erlang_ls_log_level')
|
||||
|
||||
let l:command = '%e'
|
||||
|
||||
if !empty(l:log_dir)
|
||||
let l:command .= ' --log-dir=' . ale#Escape(l:log_dir)
|
||||
endif
|
||||
|
||||
let l:command .= ' --log-level=' . ale#Escape(l:log_level)
|
||||
|
||||
return l:command
|
||||
endfunction
|
||||
|
||||
function! s:FindProjectRoot(buffer) abort
|
||||
let l:markers = ['_build/', 'erlang_ls.config', 'rebar.lock']
|
||||
|
||||
" This is a way to find Erlang/OTP root (the one that is managed
|
||||
" by kerl or asdf). Useful if :ALEGoToDefinition takes us there.
|
||||
let l:markers += ['.kerl_config']
|
||||
|
||||
for l:marker in l:markers
|
||||
let l:path = l:marker[-1:] is# '/'
|
||||
\ ? ale#path#FindNearestDirectory(a:buffer, l:marker)
|
||||
\ : ale#path#FindNearestFile(a:buffer, l:marker)
|
||||
|
||||
if !empty(l:path)
|
||||
return ale#path#Dirname(l:path)
|
||||
endif
|
||||
endfor
|
||||
|
||||
return ''
|
||||
endfunction
|
||||
|
||||
call ale#linter#Define('erlang', {
|
||||
\ 'name': 'erlang_ls',
|
||||
\ 'executable': {b -> ale#Var(b, 'erlang_erlang_ls_executable')},
|
||||
\ 'command': function('s:GetCommand'),
|
||||
\ 'lsp': 'stdio',
|
||||
\ 'project_root': function('s:FindProjectRoot'),
|
||||
\})
|
104
sources_non_forked/ale/ale_linters/erlang/erlc.vim
Normal file
104
sources_non_forked/ale/ale_linters/erlang/erlc.vim
Normal file
@ -0,0 +1,104 @@
|
||||
" Author: Magnus Ottenklinger - https://github.com/evnu
|
||||
|
||||
let g:ale_erlang_erlc_executable = get(g:, 'ale_erlang_erlc_executable', 'erlc')
|
||||
let g:ale_erlang_erlc_options = get(g:, 'ale_erlang_erlc_options', '')
|
||||
|
||||
function! ale_linters#erlang#erlc#GetExecutable(buffer) abort
|
||||
return ale#Var(a:buffer, 'erlang_erlc_executable')
|
||||
endfunction
|
||||
|
||||
function! ale_linters#erlang#erlc#GetCommand(buffer) abort
|
||||
let l:output_file = ale#util#Tempname()
|
||||
call ale#command#ManageFile(a:buffer, l:output_file)
|
||||
|
||||
let l:command = ale#Escape(ale_linters#erlang#erlc#GetExecutable(a:buffer))
|
||||
\ . ' -o ' . ale#Escape(l:output_file)
|
||||
\ . ' ' . ale#Var(a:buffer, 'erlang_erlc_options')
|
||||
\ . ' %t'
|
||||
|
||||
return l:command
|
||||
endfunction
|
||||
|
||||
function! ale_linters#erlang#erlc#Handle(buffer, lines) abort
|
||||
" Matches patterns like the following:
|
||||
"
|
||||
" error.erl:4: variable 'B' is unbound
|
||||
" error.erl:3: Warning: function main/0 is unused
|
||||
" error.erl:4: Warning: variable 'A' is unused
|
||||
let l:pattern = '\v^([a-zA-Z]?:?[^:]+):(\d+):(\d+:)? (Warning: )?(.+)$'
|
||||
|
||||
" parse_transforms are a special case. The error message does not indicate a location:
|
||||
" error.erl: undefined parse transform 'some_parse_transform'
|
||||
let l:pattern_parse_transform = '\v(undefined parse transform .*)$'
|
||||
let l:output = []
|
||||
|
||||
let l:pattern_no_module_definition = '\v(no module definition)$'
|
||||
let l:pattern_unused = '\v(.* is unused)$'
|
||||
|
||||
let l:is_hrl = fnamemodify(bufname(a:buffer), ':e') is# 'hrl'
|
||||
|
||||
for l:line in a:lines
|
||||
let l:match = matchlist(l:line, l:pattern)
|
||||
|
||||
" Determine if the output indicates an error. We distinguish between two cases:
|
||||
"
|
||||
" 1) normal errors match l:pattern
|
||||
" 2) parse_transform errors match l:pattern_parse_transform
|
||||
"
|
||||
" If none of the patterns above match, the line can be ignored
|
||||
if len(l:match) == 0 " not a 'normal' warning or error
|
||||
let l:match_parse_transform = matchlist(l:line, l:pattern_parse_transform)
|
||||
|
||||
if len(l:match_parse_transform) == 0 " also not a parse_transform error
|
||||
continue
|
||||
endif
|
||||
|
||||
call add(l:output, {
|
||||
\ 'bufnr': a:buffer,
|
||||
\ 'lnum': 0,
|
||||
\ 'col': 0,
|
||||
\ 'type': 'E',
|
||||
\ 'text': l:match_parse_transform[0],
|
||||
\})
|
||||
|
||||
continue
|
||||
endif
|
||||
|
||||
let l:line = l:match[2]
|
||||
let l:warning_or_text = l:match[4]
|
||||
let l:text = l:match[5]
|
||||
|
||||
" If this file is a header .hrl, ignore the following expected messages:
|
||||
" - 'no module definition'
|
||||
" - 'X is unused'
|
||||
if l:is_hrl && (
|
||||
\ match(l:text, l:pattern_no_module_definition) != -1
|
||||
\ || match(l:text, l:pattern_unused) != -1
|
||||
\)
|
||||
continue
|
||||
endif
|
||||
|
||||
if !empty(l:warning_or_text)
|
||||
let l:type = 'W'
|
||||
else
|
||||
let l:type = 'E'
|
||||
endif
|
||||
|
||||
call add(l:output, {
|
||||
\ 'bufnr': a:buffer,
|
||||
\ 'lnum': l:line,
|
||||
\ 'col': 0,
|
||||
\ 'type': l:type,
|
||||
\ 'text': l:text,
|
||||
\})
|
||||
endfor
|
||||
|
||||
return l:output
|
||||
endfunction
|
||||
|
||||
call ale#linter#Define('erlang', {
|
||||
\ 'name': 'erlc',
|
||||
\ 'executable': function('ale_linters#erlang#erlc#GetExecutable'),
|
||||
\ 'command': function('ale_linters#erlang#erlc#GetCommand'),
|
||||
\ 'callback': 'ale_linters#erlang#erlc#Handle',
|
||||
\})
|
42
sources_non_forked/ale/ale_linters/erlang/syntaxerl.vim
Normal file
42
sources_non_forked/ale/ale_linters/erlang/syntaxerl.vim
Normal file
@ -0,0 +1,42 @@
|
||||
" Author: Dmitri Vereshchagin <dmitri.vereshchagin@gmail.com>
|
||||
" Description: SyntaxErl linter for Erlang files
|
||||
|
||||
call ale#Set('erlang_syntaxerl_executable', 'syntaxerl')
|
||||
|
||||
function! ale_linters#erlang#syntaxerl#RunHelpCommand(buffer) abort
|
||||
let l:executable = ale#Var(a:buffer, 'erlang_syntaxerl_executable')
|
||||
|
||||
return ale#command#Run(
|
||||
\ a:buffer,
|
||||
\ ale#Escape(l:executable) . ' -h',
|
||||
\ function('ale_linters#erlang#syntaxerl#GetCommand'),
|
||||
\)
|
||||
endfunction
|
||||
|
||||
function! ale_linters#erlang#syntaxerl#GetCommand(buffer, output, meta) abort
|
||||
let l:use_b_option = match(a:output, '\C\V-b, --base\>') > -1
|
||||
|
||||
return '%e' . (l:use_b_option ? ' -b %s %t' : ' %t')
|
||||
endfunction
|
||||
|
||||
function! ale_linters#erlang#syntaxerl#Handle(buffer, lines) abort
|
||||
let l:pattern = '\v\C:(\d+):( warning:)? (.+)'
|
||||
let l:loclist = []
|
||||
|
||||
for l:match in ale#util#GetMatches(a:lines, l:pattern)
|
||||
call add(l:loclist, {
|
||||
\ 'lnum': l:match[1] + 0,
|
||||
\ 'text': l:match[3],
|
||||
\ 'type': empty(l:match[2]) ? 'E' : 'W',
|
||||
\})
|
||||
endfor
|
||||
|
||||
return l:loclist
|
||||
endfunction
|
||||
|
||||
call ale#linter#Define('erlang', {
|
||||
\ 'name': 'syntaxerl',
|
||||
\ 'executable': {b -> ale#Var(b, 'erlang_syntaxerl_executable')},
|
||||
\ 'command': {b -> ale_linters#erlang#syntaxerl#RunHelpCommand(b)},
|
||||
\ 'callback': 'ale_linters#erlang#syntaxerl#Handle',
|
||||
\})
|
Reference in New Issue
Block a user