#729 - Use a wrapper for simplify to fix // problems on Windows

This commit is contained in:
w0rp 2017-07-05 15:51:31 +01:00
parent a04e73ddbc
commit 1bd9b0fbe2
6 changed files with 25 additions and 9 deletions

View File

@ -47,7 +47,7 @@ function! ale#c#FindLocalHeaderPaths(buffer) abort
" If we find an 'include' directory in the project root, then use that. " If we find an 'include' directory in the project root, then use that.
if isdirectory(l:project_root . '/include') if isdirectory(l:project_root . '/include')
return [simplify(l:project_root . '/include')] return [ale#path#Simplify(l:project_root . '/include')]
endif endif
return [] return []

View File

@ -1,6 +1,12 @@
" Author: w0rp <devw0rp@gmail.com> " Author: w0rp <devw0rp@gmail.com>
" Description: Functions for working with paths in the filesystem. " Description: Functions for working with paths in the filesystem.
function! ale#path#Simplify(path) abort
" //foo is turned into / to stop Windows doing stupid things with search
" paths.
return substitute(simplify(a:path), '^//\+', '/', 'g') " no-custom-checks
endfunction
" Given a buffer and a filename, find the nearest file by searching upwards " Given a buffer and a filename, find the nearest file by searching upwards
" through the paths relative to the given buffer. " through the paths relative to the given buffer.
function! ale#path#FindNearestFile(buffer, filename) abort function! ale#path#FindNearestFile(buffer, filename) abort
@ -89,7 +95,7 @@ function! ale#path#IsBufferPath(buffer, complex_filename) abort
return 1 return 1
endif endif
let l:test_filename = simplify(a:complex_filename) let l:test_filename = ale#path#Simplify(a:complex_filename)
if l:test_filename[:1] ==# './' if l:test_filename[:1] ==# './'
let l:test_filename = l:test_filename[2:] let l:test_filename = l:test_filename[2:]
@ -115,7 +121,7 @@ endfunction
function! ale#path#Upwards(path) abort function! ale#path#Upwards(path) abort
let l:pattern = ale#Has('win32') ? '\v/+|\\+' : '\v/+' let l:pattern = ale#Has('win32') ? '\v/+|\\+' : '\v/+'
let l:sep = ale#Has('win32') ? '\' : '/' let l:sep = ale#Has('win32') ? '\' : '/'
let l:parts = split(simplify(a:path), l:pattern) let l:parts = split(ale#path#Simplify(a:path), l:pattern)
let l:path_list = [] let l:path_list = []
while !empty(l:parts) while !empty(l:parts)
@ -128,8 +134,8 @@ function! ale#path#Upwards(path) abort
let l:path_list[-1] .= '\' let l:path_list[-1] .= '\'
elseif a:path[0] ==# '/' elseif a:path[0] ==# '/'
" If the path starts with /, even on Windows, add / and / to all paths. " If the path starts with /, even on Windows, add / and / to all paths.
call add(l:path_list, '')
call map(l:path_list, '''/'' . v:val') call map(l:path_list, '''/'' . v:val')
call add(l:path_list, '/')
endif endif
return l:path_list return l:path_list

View File

@ -28,10 +28,15 @@ endfunction
" Given a buffer number, find a virtualenv path for Python. " Given a buffer number, find a virtualenv path for Python.
function! ale#python#FindVirtualenv(buffer) abort function! ale#python#FindVirtualenv(buffer) abort
for l:path in ale#path#Upwards(expand('#' . a:buffer . ':p:h')) for l:path in ale#path#Upwards(expand('#' . a:buffer . ':p:h'))
for l:dirname in ale#Var(a:buffer, 'virtualenv_dir_names') " Skip empty path components returned in MSYS.
let l:venv_dir = simplify(l:path . '/' . l:dirname) if empty(l:path)
continue
endif
if filereadable(simplify(l:venv_dir . '/' . s:bin_dir . '/activate')) for l:dirname in ale#Var(a:buffer, 'virtualenv_dir_names')
let l:venv_dir = ale#path#Simplify(l:path . '/' . l:dirname)
if filereadable(ale#path#Simplify(l:venv_dir . '/' . s:bin_dir . '/activate'))
return l:venv_dir return l:venv_dir
endif endif
endfor endfor
@ -52,7 +57,7 @@ function! ale#python#FindExecutable(buffer, base_var_name, path_list) abort
if !empty(l:virtualenv) if !empty(l:virtualenv)
for l:path in a:path_list for l:path in a:path_list
let l:ve_executable = simplify(l:virtualenv . '/' . s:bin_dir . '/' . l:path) let l:ve_executable = ale#path#Simplify(l:virtualenv . '/' . s:bin_dir . '/' . l:path)
if executable(l:ve_executable) if executable(l:ve_executable)
return l:ve_executable return l:ve_executable

View File

@ -15,5 +15,5 @@ function! ale#test#SetFilename(path) abort
let l:dir = getcwd() let l:dir = getcwd()
endif endif
silent noautocmd execute 'file ' . fnameescape(simplify(l:dir . '/' . a:path)) silent noautocmd execute 'file ' . fnameescape(ale#path#Simplify(l:dir . '/' . a:path))
endfunction endfunction

View File

@ -78,6 +78,7 @@ check_errors $'\t' 'Use four spaces, not tabs'
# This check should prevent people from using a particular inconsistent name. # This check should prevent people from using a particular inconsistent name.
check_errors 'let g:ale_\w\+_\w\+_args =' 'Name your option g:ale_<filetype>_<lintername>_options instead' check_errors 'let g:ale_\w\+_\w\+_args =' 'Name your option g:ale_<filetype>_<lintername>_options instead'
check_errors 'shellescape(' 'Use ale#Escape instead of shellescape' check_errors 'shellescape(' 'Use ale#Escape instead of shellescape'
check_errors 'simplify(' 'Use ale#path#Simplify instead of simplify'
check_errors "expand(['\"]%" "Use expand('#' . a:buffer . '...') instead. You might get a filename for the wrong buffer." check_errors "expand(['\"]%" "Use expand('#' . a:buffer . '...') instead. You might get a filename for the wrong buffer."
exit $RETURN_CODE exit $RETURN_CODE

View File

@ -44,3 +44,7 @@ Execute(ale#path#Upwards should return the correct path components for Windows):
\ ale#path#Upwards('foo//..///foo2////bar') \ ale#path#Upwards('foo//..///foo2////bar')
" Expect an empty List for empty strings. " Expect an empty List for empty strings.
AssertEqual [], ale#path#Upwards('') AssertEqual [], ale#path#Upwards('')
" Paths starting with // return /
AssertEqual
\ ['/foo2\bar', '/foo2', '/'],
\ ale#path#Upwards('//foo//..///foo2////bar')