Support astgrep (#4975)
CI / Build (push) Canceled after 0s
CI / Neovim 0.10 Windows (push) Canceled after 0s
CI / Neovim 0.12 Windows (push) Canceled after 0s
CI / Vim 8.2 Windows (push) Canceled after 0s
CI / Vim 9.2 Windows (push) Canceled after 0s
CI / Lint (push) Canceled after 0s
CI / Lua (push) Canceled after 0s
CI / Neovim 0.10 Linux (push) Canceled after 0s
CI / Neovim 0.12 Linux (push) Canceled after 0s
CI / Vim 8.2 Linux (push) Canceled after 0s
CI / Vim 9.2 Linux (push) Canceled after 0s

* astgrep: support its LSP

Fixes: #4974

* astgrep: add a fixer
This commit is contained in:
Ben Boeckel
2026-07-25 23:08:59 +09:00
committed by GitHub
parent 40cbe2121b
commit 9e2efaa4d3
83 changed files with 678 additions and 0 deletions
+5
View File
@@ -22,6 +22,11 @@ let s:default_registry = {
\ 'suggested_filetypes': ['apkbuild'],
\ 'description': 'Fix policy violations found by apkbuild-lint in APKBUILDs',
\ },
\ 'ast-grep': {
\ 'function': 'ale#fixers#astgrep#Fix',
\ 'suggested_filetypes': ['c', 'cpp', 'cs', 'css', 'elixer', 'go', 'haskell', 'html', 'java', 'javascript', 'json', 'kotlin', 'lua', 'nix', 'php', 'python', 'ruby', 'rust', 'scala', 'sh', 'solidity', 'swift', 'tsx', 'typescript', 'yaml'],
\ 'description': 'Apply ast-grep rules.',
\ },
\ 'autoimport': {
\ 'function': 'ale#fixers#autoimport#Fix',
\ 'suggested_filetypes': ['python'],
+18
View File
@@ -0,0 +1,18 @@
" Author: Ben Boeckel <github@me.benboeckel.net>
" Description: Fix files with `ast-grep`.
call ale#Set('astgrep_executable', 'ast-grep')
call ale#Set('astgrep_scan_options', '--update-all')
function! ale#fixers#astgrep#Fix(buffer) abort
let l:executable = ale#Var(a:buffer, 'astgrep_executable')
let l:options = ale#Var(a:buffer, 'astgrep_scan_options')
return {
\ 'command': ale#Escape(l:executable)
\ . ' scan'
\ . (empty(l:options) ? '' : ' ' . l:options)
\ . ' %t',
\ 'read_temporary_file': 1,
\}
endfunction
+29
View File
@@ -0,0 +1,29 @@
" Author: Ben Boeckel <github@me.benboeckel.net>
" Description: A CLI tool for code structural search, lint and rewriting
call ale#Set('astgrep_executable', 'ast-grep')
function! ale#handlers#astgrep#GetCommand(buffer) abort
return '%e lsp'
endfunction
function! ale#handlers#astgrep#GetProjectRoot(buffer) abort
" Try to find nearest sgconfig.yml
let l:sgconfig_file = ale#path#FindNearestFile(a:buffer, 'sgconfig.yml')
if !empty(l:sgconfig_file)
return fnamemodify(l:sgconfig_file . '/', ':p:h:h')
endif
return ''
endfunction
function! ale#handlers#astgrep#Define(lang) abort
call ale#linter#Define(a:lang, {
\ 'name': 'astgrep',
\ 'lsp': 'stdio',
\ 'executable': {b -> ale#Var(b, 'astgrep_executable')},
\ 'command': function('ale#handlers#astgrep#GetCommand'),
\ 'project_root': function('ale#handlers#astgrep#GetProjectRoot'),
\})
endfunction