summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Palardy <jonathan.palardy@gmail.com>2024-02-05 17:16:25 -0800
committerGitHub <noreply@github.com>2024-02-06 10:16:25 +0900
commit1b24bd3f5fc37a8c30d9be9d9dc8576aea53657b (patch)
tree609e0a31ffa05a1ef29caed23d83980026aefc61
parent8922478a83cd06bfe5b82eb45279649adc4ec046 (diff)
downloadale-1b24bd3f5fc37a8c30d9be9d9dc8576aea53657b.zip
Support 'gleam format' as Gleam fixer (#4710)
-rw-r--r--autoload/ale/fix/registry.vim5
-rw-r--r--autoload/ale/fixers/gleam_format.vim19
-rw-r--r--doc/ale-gleam.txt11
-rw-r--r--doc/ale-supported-languages-and-tools.txt1
-rw-r--r--doc/ale.txt1
-rw-r--r--supported-tools.md1
-rw-r--r--test/fixers/test_gleam_format_fixer_callback.vader28
-rw-r--r--test/test-files/gleam/testfile.gleam0
8 files changed, 64 insertions, 2 deletions
diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim
index 044a14d5..e7b48b45 100644
--- a/autoload/ale/fix/registry.vim
+++ b/autoload/ale/fix/registry.vim
@@ -291,6 +291,11 @@ let s:default_registry = {
\ 'suggested_filetypes': ['solidity'],
\ 'description': 'Fix Solidity files with forge fmt.',
\ },
+\ 'gleam_format': {
+\ 'function': 'ale#fixers#gleam_format#Fix',
+\ 'suggested_filetypes': ['gleam'],
+\ 'description': 'Fix Gleam files with gleam format.',
+\ },
\ 'gofmt': {
\ 'function': 'ale#fixers#gofmt#Fix',
\ 'suggested_filetypes': ['go'],
diff --git a/autoload/ale/fixers/gleam_format.vim b/autoload/ale/fixers/gleam_format.vim
new file mode 100644
index 00000000..00c366f5
--- /dev/null
+++ b/autoload/ale/fixers/gleam_format.vim
@@ -0,0 +1,19 @@
+" Author: Jonathan Palardt https://github.com/jpalardy
+" Description: Integration of 'gleam format' with ALE.
+
+call ale#Set('gleam_format_executable', 'gleam')
+
+function! ale#fixers#gleam_format#GetExecutable(buffer) abort
+ let l:executable = ale#Var(a:buffer, 'gleam_format_executable')
+
+ return ale#Escape(l:executable)
+endfunction
+
+function! ale#fixers#gleam_format#Fix(buffer) abort
+ let l:executable = ale#fixers#gleam_format#GetExecutable(a:buffer)
+
+ return {
+ \ 'command': l:executable . ' format %t',
+ \ 'read_temporary_file': 1,
+ \}
+endfunction
diff --git a/doc/ale-gleam.txt b/doc/ale-gleam.txt
index 3ca199b6..9b870a58 100644
--- a/doc/ale-gleam.txt
+++ b/doc/ale-gleam.txt
@@ -2,10 +2,17 @@
ALE Gleam Integration *ale-gleam-options*
*ale-integration-gleam*
+
===============================================================================
-Integration Information
+gleam_format *ale-gleam-gleam_format*
+
+g:ale_gleam_gleam_format_executable *g:ale_gleam_gleam_format_executable*
+ *b:ale_gleam_gleam_format_executable*
+ Type: |String|
+ Default: `'gleam'`
- Currently, the only supported linter for gleam is gleamlsp.
+ This variable can be modified to change the executable path for
+ `gleam format`.
===============================================================================
diff --git a/doc/ale-supported-languages-and-tools.txt b/doc/ale-supported-languages-and-tools.txt
index 403aa842..4b583d56 100644
--- a/doc/ale-supported-languages-and-tools.txt
+++ b/doc/ale-supported-languages-and-tools.txt
@@ -203,6 +203,7 @@ Notes:
* Git Commit Messages
* `gitlint`
* Gleam
+ * `gleam_format`
* `gleamlsp`
* GLSL
* `glslang`
diff --git a/doc/ale.txt b/doc/ale.txt
index 756735f7..5254b9d6 100644
--- a/doc/ale.txt
+++ b/doc/ale.txt
@@ -3032,6 +3032,7 @@ documented in additional help files.
git commit..............................|ale-gitcommit-options|
gitlint...............................|ale-gitcommit-gitlint|
gleam...................................|ale-gleam-options|
+ gleam_format..........................|ale-gleam-gleam_format|
gleamlsp..............................|ale-gleam-gleamlsp|
glsl....................................|ale-glsl-options|
glslang...............................|ale-glsl-glslang|
diff --git a/supported-tools.md b/supported-tools.md
index 785b1b27..aa6f65dd 100644
--- a/supported-tools.md
+++ b/supported-tools.md
@@ -212,6 +212,7 @@ formatting.
* Git Commit Messages
* [gitlint](https://github.com/jorisroovers/gitlint)
* Gleam
+ * [gleam_format](https://github.com/gleam-lang/gleam)
* [gleamlsp](https://github.com/gleam-lang/gleam)
* GLSL
* [glslang](https://github.com/KhronosGroup/glslang)
diff --git a/test/fixers/test_gleam_format_fixer_callback.vader b/test/fixers/test_gleam_format_fixer_callback.vader
new file mode 100644
index 00000000..2adf9a24
--- /dev/null
+++ b/test/fixers/test_gleam_format_fixer_callback.vader
@@ -0,0 +1,28 @@
+Before:
+ call ale#test#SetDirectory('/testplugin/test/fixers')
+
+After:
+ Restore
+
+ call ale#test#RestoreDirectory()
+
+Execute(The gleam_format command should have default values):
+ call ale#test#SetFilename('../test-files/elixir/testfile.gleam')
+
+ AssertEqual
+ \ {
+ \ 'read_temporary_file': 1,
+ \ 'command': ale#Escape('gleam') . ' format %t',
+ \ },
+ \ ale#fixers#gleam_format#Fix(bufnr(''))
+
+Execute(The gleam_format executable should be configurable):
+ let g:ale_gleam_format_executable = 'xxxinvalid'
+ call ale#test#SetFilename('../test-files/elixir/testfile.gleam')
+
+ AssertEqual
+ \ {
+ \ 'read_temporary_file': 1,
+ \ 'command': ale#Escape('xxxinvalid') . ' format %t',
+ \ },
+ \ ale#fixers#gleam_format#Fix(bufnr(''))
diff --git a/test/test-files/gleam/testfile.gleam b/test/test-files/gleam/testfile.gleam
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/test/test-files/gleam/testfile.gleam