From 864818a38528e91363fab3561c6359e272b35929 Mon Sep 17 00:00:00 2001 From: Colby Dehart Date: Thu, 7 Jun 2018 11:47:57 -0500 Subject: [PATCH] WIP cd to project path --- ale_linters/elixir/mix.vim | 10 +++++----- .../mix_paths/wrapped_project/mix.exs | 1 + .../test_elixir_mix_command_callbacks.vader | 13 +++++++++---- 3 files changed, 15 insertions(+), 9 deletions(-) create mode 100644 test/command_callback/mix_paths/wrapped_project/mix.exs diff --git a/ale_linters/elixir/mix.vim b/ale_linters/elixir/mix.vim index 25ee8fb8..3af99ab4 100644 --- a/ale_linters/elixir/mix.vim +++ b/ale_linters/elixir/mix.vim @@ -31,11 +31,11 @@ function! ale_linters#elixir#mix#Handle(buffer, lines) abort endfunction function! ale_linters#elixir#mix#FindProjectRoot(buffer) abort - let l:project_root = ale#path#FindNearestFile(a:buffer, 'mix.exs') - if !empty(l:project_root) - return fnamemodify(l:project_root, ':h') + let l:mix_file = ale#path#FindNearestFile(a:buffer, 'mix.exs') + if !empty(l:mix_file) + return fnamemodify(l:mix_file, ':p:h') endif - return '' + return '.' endfunction function! ale_linters#elixir#mix#GetCommand(buffer) abort @@ -47,7 +47,7 @@ function! ale_linters#elixir#mix#GetCommand(buffer) abort \ ? 'set MIX_BUILD_PATH=' . ale#Escape(l:temp_dir) . ' && ' \ : 'MIX_BUILD_PATH=' . ale#Escape(l:temp_dir) . ' ' - return ale#path#CdString(l:project_root) + return ale#path#CdString(l:project_root) \ . l:mix_build_path \ . ' mix compile %s' endfunction diff --git a/test/command_callback/mix_paths/wrapped_project/mix.exs b/test/command_callback/mix_paths/wrapped_project/mix.exs new file mode 100644 index 00000000..d2d855e6 --- /dev/null +++ b/test/command_callback/mix_paths/wrapped_project/mix.exs @@ -0,0 +1 @@ +use Mix.Config diff --git a/test/command_callback/test_elixir_mix_command_callbacks.vader b/test/command_callback/test_elixir_mix_command_callbacks.vader index 28c09e33..22d35eeb 100644 --- a/test/command_callback/test_elixir_mix_command_callbacks.vader +++ b/test/command_callback/test_elixir_mix_command_callbacks.vader @@ -3,13 +3,15 @@ Before: call ale#test#SetDirectory('/testplugin/test/command_callback') + let g:project_root = ale#path#Simplify(g:dir . '/mix_paths/wrapped_project') + let g:env_prefix = has('win32') \ ? 'set MIX_BUILD_PATH=TEMP && ' \ : 'MIX_BUILD_PATH=TEMP ' - function! GetCommand() abort - let l:command = ale_linters#elixir#mix#GetCommand(bufnr('')) + function! GetCommand(buffer) abort + let l:command = ale_linters#elixir#mix#GetCommand(a:buffer) let l:split_command = split(l:command, 'MIX_BUILD_PATH=[^ ]*\s') @@ -22,6 +24,7 @@ After: Restore unlet! g:env_prefix + unlet! g:project_root call ale#linter#Reset() call ale#test#RestoreDirectory() @@ -29,8 +32,10 @@ After: delfunction GetCommand Execute(The default mix command should be correct): + call ale#test#SetFilename('mix_paths/wrapped_project/lib/app.ex') + AssertEqual - \ GetCommand(), - \ 'cd '''' && ' + \ GetCommand(bufnr('')), + \ ale#path#CdString(g:project_root) \ . g:env_prefix \ . 'mix compile %s'