From 1b24bd3f5fc37a8c30d9be9d9dc8576aea53657b Mon Sep 17 00:00:00 2001 From: Jonathan Palardy Date: Mon, 5 Feb 2024 17:16:25 -0800 Subject: [PATCH] Support 'gleam format' as Gleam fixer (#4710) --- autoload/ale/fix/registry.vim | 5 ++++ autoload/ale/fixers/gleam_format.vim | 19 +++++++++++++ doc/ale-gleam.txt | 13 +++++++-- doc/ale-supported-languages-and-tools.txt | 1 + doc/ale.txt | 1 + supported-tools.md | 1 + .../test_gleam_format_fixer_callback.vader | 28 +++++++++++++++++++ test/test-files/gleam/testfile.gleam | 0 8 files changed, 65 insertions(+), 3 deletions(-) create mode 100644 autoload/ale/fixers/gleam_format.vim create mode 100644 test/fixers/test_gleam_format_fixer_callback.vader create mode 100644 test/test-files/gleam/testfile.gleam 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 - Currently, the only supported linter for gleam is gleamlsp. +=============================================================================== +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'` + + 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