Run DUB in a separate process as well, so it will not cause import lag.
This commit is contained in:
parent
a32b380b6f
commit
0bc4b4c14c
2 changed files with 26 additions and 39 deletions
|
@ -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
|
||||
|
||||
|
|
25
dmd-wrapper
25
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"
|
||||
|
|
Reference in a new issue