summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ale_linters/wgsl/naga.vim12
-rw-r--r--autoload/ale/handlers/naga.vim30
-rw-r--r--doc/ale-supported-languages-and-tools.txt2
-rw-r--r--doc/ale-wgsl.txt17
-rw-r--r--doc/ale.txt2
-rw-r--r--supported-tools.md2
-rw-r--r--test/handler/test_naga_handler.vader23
-rw-r--r--test/linter/test_naga.vader10
8 files changed, 98 insertions, 0 deletions
diff --git a/ale_linters/wgsl/naga.vim b/ale_linters/wgsl/naga.vim
new file mode 100644
index 00000000..2816751b
--- /dev/null
+++ b/ale_linters/wgsl/naga.vim
@@ -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',
+\})
diff --git a/autoload/ale/handlers/naga.vim b/autoload/ale/handlers/naga.vim
new file mode 100644
index 00000000..6480aba6
--- /dev/null
+++ b/autoload/ale/handlers/naga.vim
@@ -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
+
diff --git a/doc/ale-supported-languages-and-tools.txt b/doc/ale-supported-languages-and-tools.txt
index ed1d1d5e..7b722d06 100644
--- a/doc/ale-supported-languages-and-tools.txt
+++ b/doc/ale-supported-languages-and-tools.txt
@@ -628,6 +628,8 @@ Notes:
* `prettier`
* `vls`
* `volar`
+* WGSL
+ * `naga`
* XHTML
* `alex`
* `cspell`
diff --git a/doc/ale-wgsl.txt b/doc/ale-wgsl.txt
new file mode 100644
index 00000000..5254f43b
--- /dev/null
+++ b/doc/ale-wgsl.txt
@@ -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:
diff --git a/doc/ale.txt b/doc/ale.txt
index 4e576284..c7c1e81b 100644
--- a/doc/ale.txt
+++ b/doc/ale.txt
@@ -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|
diff --git a/supported-tools.md b/supported-tools.md
index 75b22d94..170a118b 100644
--- a/supported-tools.md
+++ b/supported-tools.md
@@ -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)
diff --git a/test/handler/test_naga_handler.vader b/test/handler/test_naga_handler.vader
new file mode 100644
index 00000000..48b8c281
--- /dev/null
+++ b/test/handler/test_naga_handler.vader
@@ -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
diff --git a/test/linter/test_naga.vader b/test/linter/test_naga.vader
new file mode 100644
index 00000000..bf91604b
--- /dev/null
+++ b/test/linter/test_naga.vader
@@ -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'