mirror of
https://github.com/dense-analysis/ale
synced 2024-12-17 20:05:31 +00:00
Add naga
linter for WGSL support (#4047)
* Add WGSL support using `naga` command * Add documents for wgsl * Add test for `naga` linter * Separate naga handler callback to hanlder/naga.vim
This commit is contained in:
parent
d1e2aaf85d
commit
0d529d9b94
12
ale_linters/wgsl/naga.vim
Normal file
12
ale_linters/wgsl/naga.vim
Normal file
@ -0,0 +1,12 @@
|
||||
" Author: rhysd <https://github.com/rhysd>
|
||||
" Description: naga-cli linter for WGSL syntax.
|
||||
|
||||
call ale#Set('wgsl_naga_executable', 'naga')
|
||||
|
||||
call ale#linter#Define('wgsl', {
|
||||
\ 'name': 'naga',
|
||||
\ 'executable': {b -> ale#Var(b, 'wgsl_naga_executable')},
|
||||
\ 'output_stream': 'stderr',
|
||||
\ 'command': {b -> '%e --stdin-file-path %s'},
|
||||
\ 'callback': 'ale#handlers#naga#Handle',
|
||||
\})
|
30
autoload/ale/handlers/naga.vim
Normal file
30
autoload/ale/handlers/naga.vim
Normal file
@ -0,0 +1,30 @@
|
||||
" Author: rhysd <https://github.com/rhysd>
|
||||
" Description: Handle errors for naga-cli.
|
||||
|
||||
function! ale#handlers#naga#Handle(buffer, lines) abort
|
||||
let l:errors = []
|
||||
let l:current_error = v:null
|
||||
|
||||
for l:line in a:lines
|
||||
if l:line =~# '^error: '
|
||||
let l:text = l:line[7:]
|
||||
let l:current_error = { 'text': l:text, 'type': 'E' }
|
||||
continue
|
||||
endif
|
||||
|
||||
if l:current_error isnot v:null
|
||||
let l:matches = matchlist(l:line, '\v:(\d+):(\d+)$')
|
||||
|
||||
if !empty(l:matches)
|
||||
let l:current_error.lnum = str2nr(l:matches[1])
|
||||
let l:current_error.col = str2nr(l:matches[2])
|
||||
call add(l:errors, l:current_error)
|
||||
let l:current_error = v:null
|
||||
continue
|
||||
endif
|
||||
endif
|
||||
endfor
|
||||
|
||||
return l:errors
|
||||
endfunction
|
||||
|
@ -628,6 +628,8 @@ Notes:
|
||||
* `prettier`
|
||||
* `vls`
|
||||
* `volar`
|
||||
* WGSL
|
||||
* `naga`
|
||||
* XHTML
|
||||
* `alex`
|
||||
* `cspell`
|
||||
|
17
doc/ale-wgsl.txt
Normal file
17
doc/ale-wgsl.txt
Normal file
@ -0,0 +1,17 @@
|
||||
===============================================================================
|
||||
ALE WGSL Integration *ale-wgsl-options*
|
||||
|
||||
|
||||
===============================================================================
|
||||
naga *ale-wgsl-naga*
|
||||
|
||||
g:ale_wgsl_naga_executable *g:ale_wgsl_naga_executable*
|
||||
*b:ale_wgsl_naga_executable*
|
||||
Type: |String|
|
||||
Default: `'naga'`
|
||||
|
||||
The executable that will be run for the `naga` linter.
|
||||
|
||||
|
||||
===============================================================================
|
||||
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:
|
@ -3222,6 +3222,8 @@ documented in additional help files.
|
||||
prettier..............................|ale-vue-prettier|
|
||||
vls...................................|ale-vue-vls|
|
||||
volar.................................|ale-vue-volar|
|
||||
wgsl....................................|ale-wgsl-options|
|
||||
naga..................................|ale-wgsl-naga|
|
||||
xhtml...................................|ale-xhtml-options|
|
||||
cspell................................|ale-xhtml-cspell|
|
||||
write-good............................|ale-xhtml-write-good|
|
||||
|
@ -637,6 +637,8 @@ formatting.
|
||||
* [prettier](https://github.com/prettier/prettier)
|
||||
* [vls](https://github.com/vuejs/vetur/tree/master/server)
|
||||
* [volar](https://github.com/johnsoncodehk/volar)
|
||||
* WGSL
|
||||
* [naga](https://github.com/gfx-rs/naga)
|
||||
* XHTML
|
||||
* [alex](https://github.com/get-alex/alex)
|
||||
* [cspell](https://github.com/streetsidesoftware/cspell/tree/main/packages/cspell)
|
||||
|
23
test/handler/test_naga_handler.vader
Normal file
23
test/handler/test_naga_handler.vader
Normal file
@ -0,0 +1,23 @@
|
||||
Before:
|
||||
runtime ale_linters/wgsl/naga.vim
|
||||
|
||||
After:
|
||||
call ale#linter#Reset()
|
||||
|
||||
Execute(Error handler should parse error message and position from input):
|
||||
let example_output = [
|
||||
\ "error: expected global item ('struct', 'let', 'var', 'type', ';', 'fn') or the end of the file, found '['",
|
||||
\ " ┌─ wgsl:5:1",
|
||||
\ " │",
|
||||
\ "5 │ [[group(1), binding(0)]]",
|
||||
\ " │ ^ expected global item ('struct', 'let', 'var', 'type', ';', 'fn') or the end of the file",
|
||||
\ "Could not parse WGSL",
|
||||
\ ]
|
||||
let actual = ale#handlers#naga#Handle(0, example_output)
|
||||
let expected = [{
|
||||
\ "text": "expected global item ('struct', 'let', 'var', 'type', ';', 'fn') or the end of the file, found '['",
|
||||
\ "lnum": 5,
|
||||
\ "col": 1,
|
||||
\ "type": "E",
|
||||
\ }]
|
||||
AssertEqual actual, expected
|
10
test/linter/test_naga.vader
Normal file
10
test/linter/test_naga.vader
Normal file
@ -0,0 +1,10 @@
|
||||
Before:
|
||||
call ale#assert#SetUpLinterTest('wgsl', 'naga')
|
||||
|
||||
After:
|
||||
call ale#assert#TearDownLinterTest()
|
||||
|
||||
Execute(The naga command should be customizable):
|
||||
let g:ale_wgsl_naga_executable = '/path/to/naga'
|
||||
AssertLinter '/path/to/naga',
|
||||
\ ale#Escape('/path/to/naga') . ' --stdin-file-path %s'
|
Loading…
Reference in New Issue
Block a user