Add GLSL linter using glslang (#914)

* Add a glslang linter for GLSL
This commit is contained in:
Sven-Hendrik Haase 2017-09-08 19:06:47 +09:00 committed by w0rp
parent 73d031d7ea
commit ff28836616
6 changed files with 150 additions and 1 deletions

View File

@ -92,9 +92,10 @@ formatting.
| Erlang | [erlc](http://erlang.org/doc/man/erlc.html), [SyntaxErl](https://github.com/ten0s/syntaxerl) |
| Fortran | [gcc](https://gcc.gnu.org/) |
| FusionScript | [fusion-lint](https://github.com/RyanSquared/fusionscript) |
| GLSL | [glslang](https://github.com/KhronosGroup/glslang) |
| Go | [gofmt](https://golang.org/cmd/gofmt/), [go vet](https://golang.org/cmd/vet/), [golint](https://godoc.org/github.com/golang/lint), [gometalinter](https://github.com/alecthomas/gometalinter) !!, [go build](https://golang.org/cmd/go/) !!, [gosimple](https://github.com/dominikh/go-tools/tree/master/cmd/gosimple), [staticcheck](https://github.com/dominikh/go-tools/tree/master/cmd/staticcheck) |
| GraphQL | [gqlint](https://github.com/happylinks/gqlint) |
| Haml | [haml-lint](https://github.com/brigade/haml-lint)
| Haml | [haml-lint](https://github.com/brigade/haml-lint) |
| Handlebars | [ember-template-lint](https://github.com/rwjblue/ember-template-lint) |
| Haskell | [ghc](https://www.haskell.org/ghc/), [stack-ghc](https://haskellstack.org/), [stack-build](https://haskellstack.org/) !!, [ghc-mod](https://github.com/DanielG/ghc-mod), [stack-ghc-mod](https://github.com/DanielG/ghc-mod), [hlint](https://hackage.haskell.org/package/hlint), [hdevtools](https://hackage.haskell.org/package/hdevtools) |
| HTML | [HTMLHint](http://htmlhint.com/), [proselint](http://proselint.com/), [tidy](http://www.html-tidy.org/) |

View File

@ -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',
\})

36
doc/ale-glsl.txt Normal file
View File

@ -0,0 +1,36 @@
===============================================================================
ALE GLSL Integration *ale-glsl-options*
*ale-integration-glsl*
===============================================================================
Integration Information
Since Vim does not detect the glsl file types out-of-the-box, you need the
runtime files for glsl from here: https://github.com/tikhomirov/vim-glsl
Note that the current glslang-based linter expects glslangValidator in
standard paths. If it's not installed system-wide you can set
|g:ale_glsl_glslang_executable| to a specific path.
===============================================================================
glslang *ale-glsl-glslang*
g:ale_glsl_glslang_executable *g:ale_glsl_glslang_executable*
*b:ale_glsl_glslang_executable*
Type: |String|
Default: `'glslangValidator'`
This variable can be changed to change the path to glslangValidator.
g:ale_glsl_glslang_options *g:ale_glsl_glslang_options*
*b:ale_glsl_glslang_options*
Type: |String|
Default: `''`
This variable can be set to pass additional options to glslangValidator.
===============================================================================
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:

View File

@ -49,6 +49,8 @@ CONTENTS *ale-contents*
gcc.................................|ale-fortran-gcc|
fusionscript..........................|ale-fuse-options|
fusion-lint.........................|ale-fuse-fusionlint|
glsl..................................|ale-glsl-options|
glslang.............................|ale-glsl-glslang|
go....................................|ale-go-options|
gometalinter........................|ale-go-gometalinter|
graphql...............................|ale-graphql-options|
@ -220,6 +222,7 @@ Notes:
* Erlang: `erlc`, `SyntaxErl`
* Fortran: `gcc`
* FusionScript: `fusion-lint`
* GLSL: glslang
* Go: `gofmt`, `go vet`, `golint`, `gometalinter`!!, `go build`!!, `gosimple`, `staticcheck`
* GraphQL: `gqlint`
* Haml: `haml-lint`

View File

@ -0,0 +1,42 @@
Before:
Save g:ale_glsl_glslang_executable
Save g:ale_glsl_glslang_options
unlet! g:ale_glsl_glslang_executable
unlet! g:ale_glsl_glslang_options
runtime ale_linters/glsl/glslang.vim
call ale#test#SetDirectory('/testplugin/test/command_callback')
After:
Restore
unlet! g:ale_cuda_nvcc_executable
unlet! g:ale_cuda_nvcc_options
call ale#linter#Reset()
Execute(Executable should default to glslangValidator):
AssertEqual
\ 'glslangValidator',
\ ale_linters#glsl#glslang#GetExecutable(bufnr(''))
Execute(Executable should be configurable):
let g:ale_glsl_glslang_executable = 'foobar'
AssertEqual
\ 'foobar',
\ ale_linters#glsl#glslang#GetExecutable(bufnr(''))
Execute(Command should use executable):
AssertEqual
\ 'glslangValidator -C %t',
\ ale_linters#glsl#glslang#GetCommand(bufnr(''))
let g:ale_glsl_glslang_executable = 'foobar'
AssertEqual
\ 'foobar -C %t',
\ ale_linters#glsl#glslang#GetCommand(bufnr(''))
Execute(Options should work):
let g:ale_glsl_glslang_options = '--test'
AssertEqual
\ 'glslangValidator --test -C %t',
\ ale_linters#glsl#glslang#GetCommand(bufnr(''))

View File

@ -0,0 +1,21 @@
Execute(The glsl glslang handler should parse lines correctly):
AssertEqual
\ [
\ {
\ 'lnum': 4,
\ 'col': 0,
\ 'type': 'E',
\ 'text': '''gl_ModelViewProjectionMatrix'' : undeclared identifier',
\ },
\ {
\ 'lnum': 121,
\ 'col': 0,
\ 'type': 'W',
\ 'text': '''switch'' : last case/default label not followed by statements',
\ },
\ ],
\ ale_linters#glsl#glslang#Handle(bufnr(''), [
\ 'ERROR: 0:4: ''gl_ModelViewProjectionMatrix'' : undeclared identifier',
\ 'WARNING: 0:121: ''switch'' : last case/default label not followed by statements',
\ 'ERROR: 2 compilation errors. No code generated.',
\ ])