diff --git a/README.md b/README.md index 10a5433..e808d82 100644 --- a/README.md +++ b/README.md @@ -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/) | diff --git a/ale_linters/glsl/glslang.vim b/ale_linters/glsl/glslang.vim new file mode 100644 index 0000000..21a03ee --- /dev/null +++ b/ale_linters/glsl/glslang.vim @@ -0,0 +1,46 @@ +" Author: Sven-Hendrik Haase +" 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', +\}) diff --git a/doc/ale-glsl.txt b/doc/ale-glsl.txt new file mode 100644 index 0000000..fbadf03 --- /dev/null +++ b/doc/ale-glsl.txt @@ -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: diff --git a/doc/ale.txt b/doc/ale.txt index 44d9e0f..319c109 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -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` diff --git a/test/command_callback/test_glslang_command_callback.vader b/test/command_callback/test_glslang_command_callback.vader new file mode 100644 index 0000000..9d40683 --- /dev/null +++ b/test/command_callback/test_glslang_command_callback.vader @@ -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('')) diff --git a/test/handler/test_glslang_handler.vader b/test/handler/test_glslang_handler.vader new file mode 100644 index 0000000..d51c985 --- /dev/null +++ b/test/handler/test_glslang_handler.vader @@ -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.', + \ ])