2017-12-19 17:34:34 +00:00
|
|
|
call ale#Set('cs_mcsc_options', '')
|
|
|
|
call ale#Set('cs_mcsc_source', '')
|
|
|
|
call ale#Set('cs_mcsc_assembly_path', [])
|
|
|
|
call ale#Set('cs_mcsc_assemblies', [])
|
2017-09-26 07:19:53 +00:00
|
|
|
|
2017-12-19 17:34:34 +00:00
|
|
|
function! s:GetWorkingDirectory(buffer) abort
|
|
|
|
let l:working_directory = ale#Var(a:buffer, 'cs_mcsc_source')
|
2017-09-26 07:19:53 +00:00
|
|
|
|
2017-12-19 17:34:34 +00:00
|
|
|
if !empty(l:working_directory)
|
|
|
|
return l:working_directory
|
|
|
|
endif
|
2017-09-26 07:19:53 +00:00
|
|
|
|
2017-12-19 17:34:34 +00:00
|
|
|
return fnamemodify(bufname(a:buffer), ':p:h')
|
|
|
|
endfunction
|
2017-09-26 07:19:53 +00:00
|
|
|
|
2017-12-19 17:34:34 +00:00
|
|
|
function! ale_linters#cs#mcsc#GetCommand(buffer) abort
|
|
|
|
" Pass assembly paths via the -lib: parameter.
|
|
|
|
let l:path_list = ale#Var(a:buffer, 'cs_mcsc_assembly_path')
|
2017-09-26 07:19:53 +00:00
|
|
|
|
2017-12-19 17:34:34 +00:00
|
|
|
let l:lib_option = !empty(l:path_list)
|
|
|
|
\ ? '-lib:' . join(map(copy(l:path_list), 'ale#Escape(v:val)'), ',')
|
|
|
|
\ : ''
|
2017-09-26 07:19:53 +00:00
|
|
|
|
2017-12-19 17:34:34 +00:00
|
|
|
" Pass paths to DLL files via the -r: parameter.
|
|
|
|
let l:assembly_list = ale#Var(a:buffer, 'cs_mcsc_assemblies')
|
2017-09-26 07:19:53 +00:00
|
|
|
|
2017-12-19 17:34:34 +00:00
|
|
|
let l:r_option = !empty(l:assembly_list)
|
|
|
|
\ ? '-r:' . join(map(copy(l:assembly_list), 'ale#Escape(v:val)'), ',')
|
|
|
|
\ : ''
|
2017-09-26 07:19:53 +00:00
|
|
|
|
|
|
|
" register temporary module target file with ale
|
|
|
|
let l:out = tempname()
|
|
|
|
call ale#engine#ManageFile(a:buffer, l:out)
|
|
|
|
|
2017-12-19 17:34:34 +00:00
|
|
|
" The code is compiled as a module and the output is redirected to a
|
|
|
|
" temporary file.
|
|
|
|
return ale#path#CdString(s:GetWorkingDirectory(a:buffer))
|
2017-09-26 07:19:53 +00:00
|
|
|
\ . 'mcs -unsafe'
|
2017-09-25 10:54:50 +00:00
|
|
|
\ . ' ' . ale#Var(a:buffer, 'cs_mcsc_options')
|
2017-12-19 17:34:34 +00:00
|
|
|
\ . ' ' . l:lib_option
|
|
|
|
\ . ' ' . l:r_option
|
2017-09-26 07:19:53 +00:00
|
|
|
\ . ' -out:' . l:out
|
2017-09-25 10:54:50 +00:00
|
|
|
\ . ' -t:module'
|
2017-12-19 17:34:34 +00:00
|
|
|
\ . ' -recurse:' . ale#Escape('*.cs')
|
2017-09-25 10:54:50 +00:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! ale_linters#cs#mcsc#Handle(buffer, lines) abort
|
|
|
|
" Look for lines like the following.
|
|
|
|
"
|
|
|
|
" Tests.cs(12,29): error CSXXXX: ; expected
|
2017-09-26 07:19:53 +00:00
|
|
|
"
|
|
|
|
" NOTE: pattern also captures file name as linter compiles all
|
|
|
|
" files within the source tree rooted at the specified source
|
|
|
|
" path and not just the file loaded in the buffer
|
2017-11-19 00:19:09 +00:00
|
|
|
let l:pattern = '^\v(.+\.cs)\((\d+),(\d+)\)\: ([^ ]+) ([^ ]+): (.+)$'
|
2017-09-25 10:54:50 +00:00
|
|
|
let l:output = []
|
2017-12-19 17:34:34 +00:00
|
|
|
|
|
|
|
let l:dir = s:GetWorkingDirectory(a:buffer)
|
2017-09-25 10:54:50 +00:00
|
|
|
|
|
|
|
for l:match in ale#util#GetMatches(a:lines, l:pattern)
|
|
|
|
call add(l:output, {
|
2017-12-19 17:34:34 +00:00
|
|
|
\ 'filename': ale#path#GetAbsPath(l:dir, l:match[1]),
|
2017-09-25 10:54:50 +00:00
|
|
|
\ 'lnum': l:match[2] + 0,
|
|
|
|
\ 'col': l:match[3] + 0,
|
2017-11-19 00:19:09 +00:00
|
|
|
\ 'type': l:match[4] is# 'error' ? 'E' : 'W',
|
|
|
|
\ 'code': l:match[5],
|
|
|
|
\ 'text': l:match[6],
|
2017-09-25 10:54:50 +00:00
|
|
|
\})
|
|
|
|
endfor
|
|
|
|
|
|
|
|
return l:output
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
call ale#linter#Define('cs',{
|
|
|
|
\ 'name': 'mcsc',
|
|
|
|
\ 'output_stream': 'stderr',
|
|
|
|
\ 'executable': 'mcs',
|
|
|
|
\ 'command_callback': 'ale_linters#cs#mcsc#GetCommand',
|
|
|
|
\ 'callback': 'ale_linters#cs#mcsc#Handle',
|
2017-09-26 07:19:53 +00:00
|
|
|
\ 'lint_file': 1
|
2017-09-25 10:54:50 +00:00
|
|
|
\})
|