mirror of
https://github.com/dense-analysis/ale.git
synced 2026-02-25 02:57:20 +08:00
fix(biome): find root when using biome.jsonc (#4774)
Since biome supports either `biome.json` or `biome.jsonc` config files, we need to look for both when searching for the LSP project root. We can also look for a package.json or .git folder to use. This uses mostly the same logic as deno.
This commit is contained in:
@@ -5,6 +5,7 @@ call ale#Set('biome_executable', 'biome')
|
||||
call ale#Set('biome_use_global', get(g:, 'ale_use_global_executables', 0))
|
||||
call ale#Set('biome_options', '')
|
||||
call ale#Set('biome_fixer_apply_unsafe', 0)
|
||||
call ale#Set('biome_lsp_project_root', '')
|
||||
|
||||
function! ale#handlers#biome#GetExecutable(buffer) abort
|
||||
return ale#path#FindExecutable(a:buffer, 'biome', [
|
||||
@@ -30,7 +31,35 @@ function! ale#handlers#biome#GetLanguage(buffer) abort
|
||||
endfunction
|
||||
|
||||
function! ale#handlers#biome#GetProjectRoot(buffer) abort
|
||||
let l:biome_file = ale#path#FindNearestFile(a:buffer, 'biome.json')
|
||||
let l:project_root = ale#Var(a:buffer, 'biome_lsp_project_root')
|
||||
|
||||
return !empty(l:biome_file) ? fnamemodify(l:biome_file, ':h') : ''
|
||||
if !empty(l:project_root)
|
||||
return l:project_root
|
||||
endif
|
||||
|
||||
let l:possible_project_roots = [
|
||||
\ 'biome.json',
|
||||
\ 'biome.jsonc',
|
||||
\ 'package.json',
|
||||
\ '.git',
|
||||
\ bufname(a:buffer),
|
||||
\]
|
||||
|
||||
for l:possible_root in l:possible_project_roots
|
||||
let l:project_root = ale#path#FindNearestFile(a:buffer, l:possible_root)
|
||||
|
||||
if empty(l:project_root)
|
||||
let l:project_root = ale#path#FindNearestDirectory(a:buffer, l:possible_root)
|
||||
endif
|
||||
|
||||
if !empty(l:project_root)
|
||||
" dir:p expands to /full/path/to/dir/ whereas
|
||||
" file:p expands to /full/path/to/file (no trailing slash)
|
||||
" Appending '/' ensures that :h:h removes the path's last segment
|
||||
" regardless of whether it is a directory or not.
|
||||
return fnamemodify(l:project_root . '/', ':p:h:h')
|
||||
endif
|
||||
endfor
|
||||
|
||||
return ''
|
||||
endfunction
|
||||
|
||||
Reference in New Issue
Block a user