mirror of
https://github.com/dense-analysis/ale
synced 2024-12-11 17:06:52 +00: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:
parent
e09520e2d7
commit
ed0b036220
@ -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
|
||||
|
@ -35,6 +35,22 @@ g:ale_biome_fixer_apply_unsafe *g:ale_biome_fixer_apply_unsafe*
|
||||
If set to `1`, biome will apply unsafe fixes along with safe fixes.
|
||||
|
||||
|
||||
g:ale_biome_lsp_project_root *g:ale_biome_lsp_project_root*
|
||||
*b:ale_biome_lsp_project_root*
|
||||
Type: |String|
|
||||
Default: `''`
|
||||
|
||||
If this variable is left unset, ALE will try to find the project root by
|
||||
executing the following steps in the given order:
|
||||
|
||||
1. Find an ancestor directory containing a biome.json.
|
||||
2. Find an ancestor directory containing a biome.jsonc.
|
||||
3. Find an ancestor directory containing a package.json.
|
||||
4. Find an ancestor directory containing a .git folder.
|
||||
5. Use the directory of the current buffer (if the buffer was opened from
|
||||
a file).
|
||||
|
||||
|
||||
===============================================================================
|
||||
cspell *ale-typescript-cspell*
|
||||
|
||||
|
@ -1,7 +1,9 @@
|
||||
Before:
|
||||
Save g:ale_biome_options
|
||||
Save g:ale_biome_lsp_project_root
|
||||
|
||||
let g:ale_biome_options = ''
|
||||
let g:ale_biome_lsp_project_root = ''
|
||||
|
||||
call ale#assert#SetUpLinterTest('typescript', 'biome')
|
||||
call ale#test#SetFilename('test.ts')
|
||||
@ -33,3 +35,20 @@ Execute(Uses the filetype as the language):
|
||||
call ale#test#SetFilename('test.jsx')
|
||||
set filetype=javascriptreact
|
||||
AssertLSPLanguage 'javascriptreact'
|
||||
|
||||
Execute(Should find project root containing biome.json):
|
||||
call ale#test#SetFilename('../test-files/biome/json/src/test.ts')
|
||||
|
||||
AssertLSPProject ale#path#Simplify(g:dir . '/../test-files/biome/json')
|
||||
|
||||
Execute(Should find project root containing biome.jsonc):
|
||||
call ale#test#SetFilename('../test-files/biome/jsonc/src/test.ts')
|
||||
|
||||
AssertLSPProject ale#path#Simplify(g:dir . '/../test-files/biome/jsonc')
|
||||
|
||||
Execute(Should use user-specified project root):
|
||||
let g:ale_biome_lsp_project_root = '/'
|
||||
|
||||
call ale#test#SetFilename('../test-files/biome/jsonc/src/test.ts')
|
||||
|
||||
AssertLSPProject '/'
|
||||
|
@ -1,10 +1,12 @@
|
||||
Before:
|
||||
Save g:ale_deno_import_map
|
||||
Save g:ale_deno_importMap
|
||||
Save g:ale_deno_unstable
|
||||
Save g:ale_deno_executable
|
||||
Save g:ale_deno_lsp_project_root
|
||||
|
||||
let g:ale_deno_import_map = 'import_map.json'
|
||||
let g:ale_deno_importMap = ''
|
||||
let g:ale_deno_unstable = 0
|
||||
let g:ale_deno_executable = 'deno'
|
||||
let g:ale_deno_lsp_project_root = ''
|
||||
|
0
test/test-files/biome/json/biome.json
Normal file
0
test/test-files/biome/json/biome.json
Normal file
0
test/test-files/biome/json/src/test.ts
Normal file
0
test/test-files/biome/json/src/test.ts
Normal file
0
test/test-files/biome/jsonc/biome.jsonc
Normal file
0
test/test-files/biome/jsonc/biome.jsonc
Normal file
0
test/test-files/biome/jsonc/src/test.ts
Normal file
0
test/test-files/biome/jsonc/src/test.ts
Normal file
Loading…
Reference in New Issue
Block a user