mirror of
https://github.com/dense-analysis/ale.git
synced 2026-02-07 10:21:05 +08:00
Add ReScript support (#5072)
This adds support for both rescript format and rescript-language-server. Closes https://github.com/dense-analysis/ale/issues/3335
This commit is contained in:
@@ -672,6 +672,11 @@ let s:default_registry = {
|
||||
\ 'suggested_filetypes': ['racket'],
|
||||
\ 'description': 'Fix Racket files with raco fmt.',
|
||||
\ },
|
||||
\ 'rescript_format': {
|
||||
\ 'function': 'ale#fixers#rescript_format#Fix',
|
||||
\ 'suggested_filetypes': ['rescript'],
|
||||
\ 'description': 'Official formatter for ReScript.',
|
||||
\ },
|
||||
\ 'ruff': {
|
||||
\ 'function': 'ale#fixers#ruff#Fix',
|
||||
\ 'suggested_filetypes': ['python'],
|
||||
|
||||
33
autoload/ale/fixers/rescript_format.vim
Normal file
33
autoload/ale/fixers/rescript_format.vim
Normal file
@@ -0,0 +1,33 @@
|
||||
" Author: John Jackson <john@johnridesa.bike>
|
||||
" Description: Fix ReScript files with the ReScript formatter.
|
||||
|
||||
call ale#Set('rescript_format_executable', 'rescript')
|
||||
call ale#Set(
|
||||
\ 'rescript_format_use_global',
|
||||
\ get(g:, 'ale_use_global_executables', v:false)
|
||||
\ )
|
||||
|
||||
function! s:GetExecutable(buffer) abort
|
||||
return ale#path#FindExecutable(a:buffer, 'rescript_format', [
|
||||
\ 'node_modules/.bin/rescript',
|
||||
\])
|
||||
endfunction
|
||||
|
||||
function! s:FixWithVersion(buffer, version) abort
|
||||
let l:exe = ale#Escape(s:GetExecutable(a:buffer))
|
||||
let l:stdin = ale#semver#GTE(a:version, [12, 0, 0]) ? ' --stdin' : ' -stdin'
|
||||
let l:ext = fnamemodify(bufname(a:buffer), ':e') is? 'resi'
|
||||
\ ? ' .resi'
|
||||
\ : ' .res'
|
||||
|
||||
return {'command': l:exe . ' format' . l:stdin . l:ext}
|
||||
endfunction
|
||||
|
||||
function! ale#fixers#rescript_format#Fix(buffer) abort
|
||||
return ale#semver#RunWithVersionCheck(
|
||||
\ a:buffer,
|
||||
\ s:GetExecutable(a:buffer),
|
||||
\ '%e --version',
|
||||
\ function('s:FixWithVersion'),
|
||||
\)
|
||||
endfunction
|
||||
Reference in New Issue
Block a user