From 0bc4b4c14c3cce61dd1838b5ed3ae5696f76f14d Mon Sep 17 00:00:00 2001 From: w0rp Date: Sun, 18 Sep 2016 10:38:54 +0100 Subject: [PATCH] Run DUB in a separate process as well, so it will not cause import lag. --- ale_linters/d/dmd.vim | 40 ++-------------------------------------- dmd-wrapper | 25 ++++++++++++++++++++++++- 2 files changed, 26 insertions(+), 39 deletions(-) diff --git a/ale_linters/d/dmd.vim b/ale_linters/d/dmd.vim index 6afdc45..25d4b91 100644 --- a/ale_linters/d/dmd.vim +++ b/ale_linters/d/dmd.vim @@ -7,7 +7,8 @@ let g:loaded_ale_linters_d_dmd = 1 " A function for finding the dmd-wrapper script in the Vim runtime paths function! s:FindWrapperScript() for parent in split(&runtimepath, ',') - let path = parent . '/' . 'dmd-wrapper' + " Expand the path to deal with ~ issues. + let path = expand(parent . '/' . 'dmd-wrapper') if filereadable(path) return path @@ -15,48 +16,11 @@ function! s:FindWrapperScript() endfor endfunction -function! ale_linters#d#dmd#GetDubImports(buffer) - if !executable('dub') - " If we don't have dub, then stop here. - return [] - endif - - " Try to find dub.json - let dub_path = findfile("dub.json", ",;") - - if dub_path == '' - " Try to find package.json if that fails - let dub_path = findfile("package.json", ",;") - endif - - if dub_path == '' - " We couldn't find the project root directory, so give up. - return - endif - - let dub_dir = fnamemodify(dub_path, ':h') - let old_path = getcwd() - - try - " Temporarily change to the project directory. - execute 'cd' . fnameescape(dub_dir) - - return split(system('dub describe --import-paths'), '\n') - finally - " Change back to the old path. - execute 'cd' . fnameescape(old_path) - endtry -endfunction - function! ale_linters#d#dmd#GetCommand(buffer) let wrapper_script = s:FindWrapperScript() let command = wrapper_script . ' -o- -vcolumns -c' - for path in ale_linters#d#dmd#GetDubImports(a:buffer) - let command .= ' -I' . shellescape(path) - endfor - return command endfunction diff --git a/dmd-wrapper b/dmd-wrapper index e413f08..dd2bb53 100755 --- a/dmd-wrapper +++ b/dmd-wrapper @@ -13,4 +13,27 @@ while read line; do echo "$line" >> "$temp_file" done -dmd "$@" "$temp_file" +# Read imports from DUB. +original_path="$(readlink -m .)" +path="$original_path" +import_line_options='' + +# We need to look for variable configuration files in parent directories. +while [ "$path" != '/' ]; do + if [ -f "$path/dub.sdl" ] || [ -f "$path/dub.json" ] || [ -f "$path/package.json" ]; then + + cd "$path" + + while read import_line; do + import_line_options="$import_line_options -I$import_line" + done <<< "$(dub describe --import-paths)" + + cd "$original_path" + + break + fi + + path="$(dirname "$path")" +done + +dmd $import_line_options "$@" "$temp_file"