summaryrefslogtreecommitdiff
path: root/ale_linters/glsl
diff options
context:
space:
mode:
authorSven-Hendrik Haase <svenstaro@gmail.com>2017-09-08 19:06:47 +0900
committerw0rp <w0rp@users.noreply.github.com>2017-09-08 11:06:47 +0100
commitff288366165804e8956013cca8c1291536cf9707 (patch)
tree1e8957d04b4b3da3680f6b77478acab39018782b /ale_linters/glsl
parent73d031d7eacba95c68287eddb52fb0b73947ba05 (diff)
downloadale-ff288366165804e8956013cca8c1291536cf9707.zip
Add GLSL linter using glslang (#914)
* Add a glslang linter for GLSL
Diffstat (limited to 'ale_linters/glsl')
-rw-r--r--ale_linters/glsl/glslang.vim46
1 files changed, 46 insertions, 0 deletions
diff --git a/ale_linters/glsl/glslang.vim b/ale_linters/glsl/glslang.vim
new file mode 100644
index 00000000..21a03ee2
--- /dev/null
+++ b/ale_linters/glsl/glslang.vim
@@ -0,0 +1,46 @@
+" Author: Sven-Hendrik Haase <svenstaro@gmail.com>
+" Description: glslang-based linter for glsl files
+"
+" TODO: Once https://github.com/KhronosGroup/glslang/pull/1047 is accepted,
+" we can use stdin.
+
+let g:ale_glsl_glslang_executable =
+\ get(g:, 'ale_glsl_glslang_executable', 'glslangValidator')
+
+let g:ale_glsl_glslang_options = get(g:, 'ale_glsl_glslang_options', '')
+
+function! ale_linters#glsl#glslang#GetExecutable(buffer) abort
+ return ale#Var(a:buffer, 'glsl_glslang_executable')
+endfunction
+
+function! ale_linters#glsl#glslang#GetCommand(buffer) abort
+ return ale_linters#glsl#glslang#GetExecutable(a:buffer)
+ \ . ' ' . ale#Var(a:buffer, 'glsl_glslang_options')
+ \ . ' ' . '-C %t'
+endfunction
+
+function! ale_linters#glsl#glslang#Handle(buffer, lines) abort
+ " Matches patterns like the following:
+ "
+ " ERROR: 0:5: 'foo' : undeclared identifier
+ let l:pattern = '^\(.\+\): \(\d\+\):\(\d\+\): \(.\+\)'
+ let l:output = []
+
+ for l:match in ale#util#GetMatches(a:lines, l:pattern)
+ call add(l:output, {
+ \ 'lnum': str2nr(l:match[3]),
+ \ 'col': str2nr(l:match[2]),
+ \ 'text': l:match[4],
+ \ 'type': l:match[1] is# 'ERROR' ? 'E' : 'W',
+ \})
+ endfor
+
+ return l:output
+endfunction
+
+call ale#linter#Define('glsl', {
+\ 'name': 'glslang',
+\ 'executable_callback': 'ale_linters#glsl#glslang#GetExecutable',
+\ 'command_callback': 'ale_linters#glsl#glslang#GetCommand',
+\ 'callback': 'ale_linters#glsl#glslang#Handle',
+\})