2017-09-26 03:19:53 -04:00
|
|
|
" general mcs options which are likely to stay constant across
|
|
|
|
" source trees like -pkg:dotnet
|
2017-09-25 06:54:50 -04:00
|
|
|
let g:ale_cs_mcsc_options = get(g:, 'ale_cs_mcsc_options', '')
|
2017-09-26 03:19:53 -04:00
|
|
|
|
|
|
|
" path string pointing the linter to the base path of the
|
|
|
|
" source tree to check
|
|
|
|
let g:ale_cs_mcsc_source = get(g:, 'ale_cs_mcsc_source','.')
|
|
|
|
|
|
|
|
" list of search paths for additional assemblies to consider
|
|
|
|
let g:ale_cs_mcsc_assembly_path = get(g:, 'ale_cs_mcsc_assembly_path',[])
|
|
|
|
|
|
|
|
" list of assemblies to consider
|
|
|
|
let g:ale_cs_mcsc_assemblies = get(g:, 'ale_cs_mcsc_assemblies',[])
|
2017-09-25 06:54:50 -04:00
|
|
|
function! ale_linters#cs#mcsc#GetCommand(buffer) abort
|
2017-09-26 03:19:53 -04:00
|
|
|
|
|
|
|
" if list of assembly search paths is not empty convert it to
|
|
|
|
" appropriate -lib: parameter of mcs
|
|
|
|
let l:path = ale#Var(a:buffer, 'cs_mcsc_assembly_path')
|
|
|
|
|
|
|
|
if !empty(l:path)
|
|
|
|
let l:path = '-lib:"' . join(l:path, '","') .'"'
|
|
|
|
else
|
2017-09-25 06:54:50 -04:00
|
|
|
let l:path =''
|
|
|
|
endif
|
2017-09-26 03:19:53 -04:00
|
|
|
|
|
|
|
" if list of assemblies to link is not empty convert it to the
|
|
|
|
" appropriate -r: parameter of mcs
|
|
|
|
let l:assemblies = ale#Var(a:buffer, 'cs_mcsc_assemblies')
|
|
|
|
|
|
|
|
if !empty(l:assemblies)
|
|
|
|
let l:assemblies = '-r:"' . join(l:assemblies, '","') . '"'
|
|
|
|
else
|
2017-09-25 06:54:50 -04:00
|
|
|
let l:assemblies =''
|
|
|
|
endif
|
2017-09-26 03:19:53 -04:00
|
|
|
|
|
|
|
" register temporary module target file with ale
|
|
|
|
let l:out = tempname()
|
|
|
|
call ale#engine#ManageFile(a:buffer, l:out)
|
|
|
|
|
|
|
|
" assemble linter command string to be executed by ale
|
|
|
|
" implicitly set -unsafe mcs flag set compilation
|
|
|
|
" target to module (-t:module), direct mcs output to
|
|
|
|
" temporary file (-out)
|
|
|
|
"
|
|
|
|
return 'cd "' . ale#Var(a:buffer, 'cs_mcsc_source') . '";'
|
|
|
|
\ . 'mcs -unsafe'
|
2017-09-25 06:54:50 -04:00
|
|
|
\ . ' ' . ale#Var(a:buffer, 'cs_mcsc_options')
|
|
|
|
\ . ' ' . l:path
|
|
|
|
\ . ' ' . l:assemblies
|
2017-09-26 03:19:53 -04:00
|
|
|
\ . ' -out:' . l:out
|
2017-09-25 06:54:50 -04:00
|
|
|
\ . ' -t:module'
|
2017-09-26 03:19:53 -04:00
|
|
|
\ . ' -recurse:"*.cs"'
|
2017-09-25 06:54:50 -04: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 03:19:53 -04: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-09-25 06:54:50 -04:00
|
|
|
let l:pattern = '^\(.\+\.cs\)(\(\d\+\),\(\d\+\)): \(.\+\): \(.\+\)'
|
|
|
|
let l:output = []
|
2017-09-26 03:19:53 -04:00
|
|
|
let l:source = ale#Var(a:buffer, 'cs_mcsc_source')
|
2017-09-25 06:54:50 -04:00
|
|
|
|
|
|
|
for l:match in ale#util#GetMatches(a:lines, l:pattern)
|
|
|
|
call add(l:output, {
|
2017-09-26 03:19:53 -04:00
|
|
|
\ 'filename': fnamemodify(l:source . '/' . l:match[1], ':p'),
|
2017-09-25 06:54:50 -04:00
|
|
|
\ 'lnum': l:match[2] + 0,
|
|
|
|
\ 'col': l:match[3] + 0,
|
|
|
|
\ 'text': l:match[4] . ': ' . l:match[5],
|
|
|
|
\ 'type': l:match[4] =~# '^error' ? 'E' : 'W',
|
|
|
|
\})
|
|
|
|
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 03:19:53 -04:00
|
|
|
\ 'lint_file': 1
|
2017-09-25 06:54:50 -04:00
|
|
|
\})
|