diff options
author | AlvinRolling <alvinrolling@gmail.com> | 2024-02-22 10:18:04 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-22 11:18:04 +0900 |
commit | 52c6146751cda840fc6df66efe6a7c4ab3409223 (patch) | |
tree | ce57710737dddc60bf99ac08a2a2c1acda89d044 /ale_linters/verilog | |
parent | 1c5b84f375a5d0ea4eb11d64b333119245ec5605 (diff) | |
download | ale-52c6146751cda840fc6df66efe6a7c4ab3409223.zip |
Slang linter for Verilog. (#4713)
Diffstat (limited to 'ale_linters/verilog')
-rw-r--r-- | ale_linters/verilog/slang.vim | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/ale_linters/verilog/slang.vim b/ale_linters/verilog/slang.vim new file mode 100644 index 00000000..40299a34 --- /dev/null +++ b/ale_linters/verilog/slang.vim @@ -0,0 +1,53 @@ +" Author: Alvin Rolling <alvinrolling@gmail.com> +" Description: slang for verilog files + +" Set this option to change Slang lint options +if !exists('g:ale_verilog_slang_options') + let g:ale_verilog_slang_options = '' +endif + +" --lint-only +function! ale_linters#verilog#slang#GetCommand(buffer) abort + return 'slang -Weverything ' + \ . '-I%s:h ' + \ . ale#Var(a:buffer, 'verilog_slang_options') .' ' + \ . '%t' +endfunction + +function! s:RemoveUnicodeQuotes(text) abort + let l:text = a:text + let l:text = substitute(l:text, '[`´‘’]', '''', 'g') + let l:text = substitute(l:text, '[“”]', '"', 'g') + + return l:text +endfunction + +function! ale_linters#verilog#slang#Handle(buffer, lines) abort + let l:pattern = '\v^([a-zA-Z]?:?[^:]+):(\d+)?:?(\d+)?:? ([^:]+): (.+)$' + let l:output = [] + + for l:match in ale#util#GetMatches(a:lines, l:pattern) + let l:item = { + \ 'lnum': str2nr(l:match[2]), + \ 'type': (l:match[4] is# 'error') ? 'E' : 'W', + \ 'text': s:RemoveUnicodeQuotes(l:match[5]), + \} + + if !empty(l:match[3]) + let l:item.col = str2nr(l:match[3]) + endif + + call add(l:output, l:item) + endfor + + return l:output +endfunction + +call ale#linter#Define('verilog', { +\ 'name': 'slang', +\ 'output_stream': 'stderr', +\ 'executable': 'slang', +\ 'command': function('ale_linters#verilog#slang#GetCommand'), +\ 'callback': 'ale_linters#verilog#slang#Handle', +\ 'read_buffer': 0, +\}) |