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:
87
sources_non_forked/ale/ale_linters/thrift/thrift.vim
Normal file
87
sources_non_forked/ale/ale_linters/thrift/thrift.vim
Normal file
@ -0,0 +1,87 @@
|
||||
" Author: Jon Parise <jon@indelible.org>
|
||||
|
||||
call ale#Set('thrift_thrift_executable', 'thrift')
|
||||
call ale#Set('thrift_thrift_generators', ['cpp'])
|
||||
call ale#Set('thrift_thrift_includes', ['.'])
|
||||
call ale#Set('thrift_thrift_options', '-strict')
|
||||
|
||||
function! ale_linters#thrift#thrift#GetCommand(buffer) abort
|
||||
let l:generators = ale#Var(a:buffer, 'thrift_thrift_generators')
|
||||
let l:includes = ale#Var(a:buffer, 'thrift_thrift_includes')
|
||||
|
||||
" The thrift compiler requires at least one generator. If none are set,
|
||||
" fall back to our default value to avoid silently failing. We could also
|
||||
" `throw` here, but that seems even less helpful.
|
||||
if empty(l:generators)
|
||||
let l:generators = ['cpp']
|
||||
endif
|
||||
|
||||
let l:output_dir = ale#command#CreateDirectory(a:buffer)
|
||||
|
||||
return '%e'
|
||||
\ . ale#Pad(join(map(copy(l:generators), "'--gen ' . v:val")))
|
||||
\ . ale#Pad(join(map(copy(l:includes), "'-I ' . v:val")))
|
||||
\ . ale#Pad(ale#Var(a:buffer, 'thrift_thrift_options'))
|
||||
\ . ' -out ' . ale#Escape(l:output_dir)
|
||||
\ . ' %t'
|
||||
endfunction
|
||||
|
||||
function! ale_linters#thrift#thrift#Handle(buffer, lines) abort
|
||||
" Matches lines like the following:
|
||||
"
|
||||
" [SEVERITY:/path/filename.thrift:31] Message text
|
||||
" [ERROR:/path/filename.thrift:31] (last token was ';')
|
||||
let l:pattern = '\v^\[(\u+):(.*):(\d+)\] (.*)$'
|
||||
|
||||
let l:index = 0
|
||||
let l:output = []
|
||||
|
||||
" Roll our own output-matching loop instead of using ale#util#GetMatches
|
||||
" because we need to support error messages that span multiple lines.
|
||||
while l:index < len(a:lines)
|
||||
let l:line = a:lines[l:index]
|
||||
|
||||
let l:match = matchlist(l:line, l:pattern)
|
||||
|
||||
if empty(l:match)
|
||||
let l:index += 1
|
||||
continue
|
||||
endif
|
||||
|
||||
let l:severity = l:match[1]
|
||||
|
||||
if l:severity is# 'WARNING'
|
||||
let l:type = 'W'
|
||||
else
|
||||
let l:type = 'E'
|
||||
endif
|
||||
|
||||
" If our text looks like "(last token was ';')", the *next* line
|
||||
" should contain a more descriptive error message.
|
||||
let l:text = l:match[4]
|
||||
|
||||
if l:text =~# '\(last token was .*\)'
|
||||
let l:index += 1
|
||||
let l:text = get(a:lines, l:index, 'Unknown error ' . l:text)
|
||||
endif
|
||||
|
||||
call add(l:output, {
|
||||
\ 'lnum': l:match[3] + 0,
|
||||
\ 'col': 0,
|
||||
\ 'type': l:type,
|
||||
\ 'text': l:text,
|
||||
\})
|
||||
|
||||
let l:index += 1
|
||||
endwhile
|
||||
|
||||
return l:output
|
||||
endfunction
|
||||
|
||||
call ale#linter#Define('thrift', {
|
||||
\ 'name': 'thrift',
|
||||
\ 'output_stream': 'both',
|
||||
\ 'executable': {b -> ale#Var(b, 'thrift_thrift_executable')},
|
||||
\ 'command': function('ale_linters#thrift#thrift#GetCommand'),
|
||||
\ 'callback': 'ale_linters#thrift#thrift#Handle',
|
||||
\})
|
46
sources_non_forked/ale/ale_linters/thrift/thriftcheck.vim
Normal file
46
sources_non_forked/ale/ale_linters/thrift/thriftcheck.vim
Normal file
@ -0,0 +1,46 @@
|
||||
" Author: Jon Parise <jon@indelible.org>
|
||||
|
||||
call ale#Set('thrift_thriftcheck_executable', 'thriftcheck')
|
||||
call ale#Set('thrift_thriftcheck_options', '')
|
||||
|
||||
function! ale_linters#thrift#thriftcheck#GetCommand(buffer) abort
|
||||
return '%e'
|
||||
\ . ale#Pad(ale#Var(a:buffer, 'thrift_thriftcheck_options'))
|
||||
\ . ' --stdin-filename %s'
|
||||
\ . ' %t'
|
||||
endfunction
|
||||
|
||||
function! ale_linters#thrift#thriftcheck#Handle(buffer, lines) abort
|
||||
" Matches lines like the following:
|
||||
"
|
||||
" file.thrift:1:1: error: "py" namespace must match "^idl\\." (namespace.pattern)
|
||||
" file.thrift:3:5: warning: 64-bit integer constant -2147483649 may not work in all languages (int.64bit)
|
||||
let l:pattern = '\v^[a-zA-Z]?:?[^:]+:(\d+):(\d+): ?([^:]+): (.+) \(([^\)]+)\)$'
|
||||
|
||||
let l:output = []
|
||||
|
||||
for l:match in ale#util#GetMatches(a:lines, l:pattern)
|
||||
if l:match[3] is# 'warning'
|
||||
let l:type = 'W'
|
||||
else
|
||||
let l:type = 'E'
|
||||
endif
|
||||
|
||||
call add(l:output, {
|
||||
\ 'lnum': l:match[1] + 0,
|
||||
\ 'col': l:match[2] + 0,
|
||||
\ 'type': l:type,
|
||||
\ 'text': l:match[4],
|
||||
\ 'code': l:match[5],
|
||||
\})
|
||||
endfor
|
||||
|
||||
return l:output
|
||||
endfunction
|
||||
|
||||
call ale#linter#Define('thrift', {
|
||||
\ 'name': 'thriftcheck',
|
||||
\ 'executable': {b -> ale#Var(b, 'thrift_thriftcheck_executable')},
|
||||
\ 'command': function('ale_linters#thrift#thriftcheck#GetCommand'),
|
||||
\ 'callback': 'ale_linters#thrift#thriftcheck#Handle',
|
||||
\})
|
Reference in New Issue
Block a user