]> git.madduck.net Git - etc/vim.git/blob - .vim/bundle/ale/ale_linters/cs/csc.vim

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Merge commit '56df844d3c39ec494dacc69eae34272b27db185a' as '.vim/bundle/asyncomplete'
[etc/vim.git] / .vim / bundle / ale / ale_linters / cs / csc.vim
1 call ale#Set('cs_csc_options', '')
2 call ale#Set('cs_csc_source', '')
3 call ale#Set('cs_csc_assembly_path', [])
4 call ale#Set('cs_csc_assemblies', [])
5
6 function! ale_linters#cs#csc#GetCwd(buffer) abort
7     let l:cwd = ale#Var(a:buffer, 'cs_csc_source')
8
9     return !empty(l:cwd) ? l:cwd : expand('#' . a:buffer . ':p:h')
10 endfunction
11
12 function! ale_linters#cs#csc#GetCommand(buffer) abort
13     " Pass assembly paths via the -lib: parameter.
14     let l:path_list = ale#Var(a:buffer, 'cs_csc_assembly_path')
15
16     let l:lib_option = !empty(l:path_list)
17     \   ? '/lib:' . join(map(copy(l:path_list), 'ale#Escape(v:val)'), ',')
18     \   : ''
19
20     " Pass paths to DLL files via the -r: parameter.
21     let l:assembly_list = ale#Var(a:buffer, 'cs_csc_assemblies')
22
23     let l:r_option = !empty(l:assembly_list)
24     \   ? '/r:' . join(map(copy(l:assembly_list), 'ale#Escape(v:val)'), ',')
25     \   : ''
26
27     " register temporary module target file with ale
28     " register temporary module target file with ALE.
29     let l:out = ale#command#CreateFile(a:buffer)
30
31     " The code is compiled as a module and the output is redirected to a
32     " temporary file.
33     return 'csc /unsafe'
34     \    . ale#Pad(ale#Var(a:buffer, 'cs_csc_options'))
35     \    . ale#Pad(l:lib_option)
36     \    . ale#Pad(l:r_option)
37     \    . ' /out:' . l:out
38     \    . ' /t:module'
39     \    . ' /recurse:' . ale#Escape('*.cs')
40 endfunction
41
42 function! ale_linters#cs#csc#Handle(buffer, lines) abort
43     " Look for lines like the following.
44     "
45     " Tests.cs(12,29): error CSXXXX: ; expected
46     "
47     " NOTE: pattern also captures file name as linter compiles all
48     " files within the source tree rooted at the specified source
49     " path and not just the file loaded in the buffer
50     let l:patterns = [
51     \    '^\v(.+\.cs)\((\d+),(\d+)\)\:\s+([^ ]+)\s+([cC][sS][^ ]+):\s(.+)$',
52     \    '^\v([^ ]+)\s+([Cc][sS][^ ]+):\s+(.+)$',
53     \]
54     let l:output = []
55     let l:dir = ale_linters#cs#csc#GetCwd(a:buffer)
56
57     for l:match in ale#util#GetMatches(a:lines, l:patterns)
58         if len(l:match) > 6 && strlen(l:match[5]) > 2 && l:match[5][:1] is? 'CS'
59             call add(l:output, {
60             \   'filename': ale#path#GetAbsPath(l:dir, l:match[1]),
61             \   'lnum': l:match[2] + 0,
62             \   'col': l:match[3] + 0,
63             \   'type': l:match[4] is# 'error' ? 'E' : 'W',
64             \   'code': l:match[5],
65             \   'text': l:match[6] ,
66             \})
67         elseif strlen(l:match[2]) > 2 && l:match[2][:1] is? 'CS'
68             call add(l:output, {
69             \   'filename':'<csc>',
70             \   'lnum': -1,
71             \   'col': -1,
72             \   'type': l:match[1] is# 'error' ? 'E' : 'W',
73             \   'code': l:match[2],
74             \   'text': l:match[3],
75             \})
76         endif
77     endfor
78
79     return l:output
80 endfunction
81
82 call ale#linter#Define('cs',{
83 \   'name': 'csc',
84 \   'output_stream': 'stdout',
85 \   'executable': 'csc',
86 \   'cwd': function('ale_linters#cs#csc#GetCwd'),
87 \   'command': function('ale_linters#cs#csc#GetCommand'),
88 \   'callback': 'ale_linters#cs#csc#Handle',
89 \   'lint_file': 1
90 \})