Merge pull request #2045 from jparise/elixir-ls-umbrella

elixir-ls now recognizes umbrella projects
This commit is contained in:
w0rp 2018-11-06 20:02:34 +00:00 committed by GitHub
commit ad98cb7448
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 32 additions and 10 deletions

View File

@ -16,6 +16,6 @@ call ale#linter#Define('elixir', {
\ 'lsp': 'stdio', \ 'lsp': 'stdio',
\ 'executable_callback': 'ale_linters#elixir#elixir_ls#GetExecutable', \ 'executable_callback': 'ale_linters#elixir#elixir_ls#GetExecutable',
\ 'command_callback': 'ale_linters#elixir#elixir_ls#GetExecutable', \ 'command_callback': 'ale_linters#elixir#elixir_ls#GetExecutable',
\ 'project_root_callback': 'ale#handlers#elixir#FindMixProjectRoot', \ 'project_root_callback': 'ale#handlers#elixir#FindMixUmbrellaRoot',
\ 'lsp_config_callback': ale#VarFunc('elixir_elixir_ls_config'), \ 'lsp_config_callback': ale#VarFunc('elixir_elixir_ls_config'),
\}) \})

View File

@ -1,13 +1,28 @@
" Author: Matteo Centenaro (bugant) - https://github.com/bugant " Author: Matteo Centenaro (bugant) - https://github.com/bugant
" " Author: Jon Parise <jon@indelible.org>
" Description: find the root directory for an elixir project that uses mix " Description: Functions for working with Elixir projects
" Find the root directory for an elixir project that uses mix.
function! ale#handlers#elixir#FindMixProjectRoot(buffer) abort function! ale#handlers#elixir#FindMixProjectRoot(buffer) abort
let l:mix_file = ale#path#FindNearestFile(a:buffer, 'mix.exs') let l:mix_file = ale#path#FindNearestFile(a:buffer, 'mix.exs')
if !empty(l:mix_file) if !empty(l:mix_file)
return fnamemodify(l:mix_file, ':p:h') return fnamemodify(l:mix_file, ':p:h')
endif endif
return '.' return '.'
endfunction endfunction
" Similar to ale#handlers#elixir#FindMixProjectRoot but also continue the
" search upward for a potential umbrella project root. If an umbrella root
" does not exist, the initial project root will be returned.
function! ale#handlers#elixir#FindMixUmbrellaRoot(buffer) abort
let l:app_root = ale#handlers#elixir#FindMixProjectRoot(a:buffer)
let l:umbrella_root = fnamemodify(l:app_root, ':h:h')
if filereadable(l:umbrella_root . '/mix.exs')
return l:umbrella_root
endif
return l:app_root
endfunction

View File

@ -22,12 +22,12 @@ Execute(should configure elixir-ls release location):
AssertLinter 'boo/language_server.sh', 'boo/language_server.sh' AssertLinter 'boo/language_server.sh', 'boo/language_server.sh'
Execute(should set correct LSP values): Execute(should set correct LSP values):
call ale#test#SetFilename('mix_paths/wrapped_project/lib/app.ex') call ale#test#SetFilename('elixir_paths/umbrella_project/apps/app1/lib/app.ex')
AssertLSPLanguage 'elixir' AssertLSPLanguage 'elixir'
AssertLSPOptions {} AssertLSPOptions {}
AssertLSPConfig {} AssertLSPConfig {}
AssertLSPProject ale#path#Simplify(g:dir . '/mix_paths/wrapped_project') AssertLSPProject ale#path#Simplify(g:dir . '/elixir_paths/umbrella_project')
Execute(should accept configuration settings): Execute(should accept configuration settings):
AssertLSPConfig {} AssertLSPConfig {}

View File

@ -18,9 +18,16 @@ Execute(The default mix command should be correct):
\ . g:env_prefix \ . g:env_prefix
\ . 'mix compile %s' \ . 'mix compile %s'
Execute(The FindMixProjectRoot should detect the project root directory via mix.exs): Execute(FindMixProjectRoot should detect the project root directory via mix.exs):
silent execute 'file ' . fnameescape(g:dir . '/elixir_paths/mix_project/lib/app.ex') silent execute 'file ' . fnameescape(g:dir . '/elixir_paths/mix_project/lib/app.ex')
AssertEqual AssertEqual
\ ale#path#Simplify(g:dir . '/elixir_paths/mix_project'), \ ale#path#Simplify(g:dir . '/elixir_paths/mix_project'),
\ ale#handlers#elixir#FindMixProjectRoot(bufnr('')) \ ale#handlers#elixir#FindMixProjectRoot(bufnr(''))
Execute(FindMixUmbrellaRoot should detect the umbrella root directory via mix.exs):
silent execute 'file ' . fnameescape(g:dir . '/elixir_paths/umbrella_project/apps/app1/lib/app.ex')
AssertEqual
\ ale#path#Simplify(g:dir . '/elixir_paths/umbrella_project'),
\ ale#handlers#elixir#FindMixUmbrellaRoot(bufnr(''))