]> git.madduck.net Git - etc/vim.git/blob - autoload/ale/handlers/openscad.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:

Squashed '.vim/bundle/ale/' content from commit 22185c4c
[etc/vim.git] / autoload / ale / handlers / openscad.vim
1 scriptencoding utf-8LE
2 " Description: This file defines a handler function for linting OpenSCAD files
3 " with SCA2D
4
5 function! ale#handlers#openscad#SCA2D_callback(buffer, lines) abort
6     " Example output::
7     " foo.scad:3:1: W2001: Variable `unused` overwritten within scope.
8     " foo.scad:1:1: F0001: Cannot read file due to syntax error:
9     "    - No terminal matches '}' in the current parser context, at line 1 col 36
10     let l:filename_re = '^\([^:]*\):'
11     let l:linenum_re = '\([0-9]*\):'
12     let l:colnum_re = '\([0-9]*\):'
13     let l:err_id = '\([IWEFU][0-9]\+\):'
14     let l:err_msg = '\(.*\)'
15     let l:pattern =  filename_re .
16     \ linenum_re .
17     \ colnum_re .
18     \ ' ' .
19     \ err_id .
20     \ ' ' .
21     \ err_msg
22
23     let l:result = []
24     let l:idx = 0
25
26     for l:line in a:lines
27         let l:matches = matchlist(line, pattern)
28
29         if len(matches) > 0
30             " option: Info, Warning, Error, Fatal, Unknown
31             if index(['I', 'W'], matches[4][0]) >= 0
32                 let l:type = 'W'
33             else
34                 let l:type = 'E'
35             endif
36
37             let l:lnum = matches[2]
38             let l:col = matches[3]
39             let l:text = matches[5]
40
41             " Better locations for some syntax errors
42             if matches[4][0] is# 'F'
43                 let l:syntax_error_re = '^\(.*\), at line \([0-9]\+\) col \([0-9]\+\)$'
44                 let l:next_line = a:lines[idx+1]
45                 let l:syn_err_matches = matchlist(l:next_line, l:syntax_error_re)
46
47                 if len(syn_err_matches) > 0
48                     let l:text = l:text . l:syn_err_matches[1]
49                     let l:lnum = l:syn_err_matches[2]
50                     let l:col = l:syn_err_matches[3]
51                 else
52                     let l:text = l:next_line
53                 endif
54             endif
55
56             let l:element = {
57             \ 'lnum': str2nr(l:lnum),
58             \ 'col': str2nr(l:col),
59             \ 'text': l:text,
60             \ 'detail': l:matches[4] . ': ' . l:text,
61             \ 'filename': fnamemodify(matches[1], ':p'),
62             \ 'type': l:type
63             \ }
64
65             call add(l:result, l:element)
66         endif
67
68         let l:idx += 1
69     endfor
70
71     return result
72
73 endfun