diff options
-rw-r--r-- | autoload/ale/c.vim | 2 | ||||
-rw-r--r-- | autoload/ale/path.vim | 12 | ||||
-rw-r--r-- | autoload/ale/python.vim | 11 | ||||
-rw-r--r-- | autoload/ale/test.vim | 2 | ||||
-rwxr-xr-x | custom-checks | 1 | ||||
-rw-r--r-- | test/test_path_upwards.vader | 4 |
6 files changed, 24 insertions, 8 deletions
diff --git a/autoload/ale/c.vim b/autoload/ale/c.vim index 4fe2f547..1703da78 100644 --- a/autoload/ale/c.vim +++ b/autoload/ale/c.vim @@ -47,7 +47,7 @@ function! ale#c#FindLocalHeaderPaths(buffer) abort " If we find an 'include' directory in the project root, then use that. if isdirectory(l:project_root . '/include') - return [simplify(l:project_root . '/include')] + return [ale#path#Simplify(l:project_root . '/include')] endif return [] diff --git a/autoload/ale/path.vim b/autoload/ale/path.vim index 2a38d740..8d2c547f 100644 --- a/autoload/ale/path.vim +++ b/autoload/ale/path.vim @@ -1,6 +1,12 @@ " Author: w0rp <devw0rp@gmail.com> " 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 " through the paths relative to the given buffer. function! ale#path#FindNearestFile(buffer, filename) abort @@ -89,7 +95,7 @@ function! ale#path#IsBufferPath(buffer, complex_filename) abort return 1 endif - let l:test_filename = simplify(a:complex_filename) + let l:test_filename = ale#path#Simplify(a:complex_filename) if l:test_filename[:1] ==# './' let l:test_filename = l:test_filename[2:] @@ -115,7 +121,7 @@ endfunction function! ale#path#Upwards(path) abort let l:pattern = ale#Has('win32') ? '\v/+|\\+' : '\v/+' 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 = [] while !empty(l:parts) @@ -128,8 +134,8 @@ function! ale#path#Upwards(path) abort let l:path_list[-1] .= '\' elseif a:path[0] ==# '/' " 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 add(l:path_list, '/') endif return l:path_list diff --git a/autoload/ale/python.vim b/autoload/ale/python.vim index 95fa58c7..346163a5 100644 --- a/autoload/ale/python.vim +++ b/autoload/ale/python.vim @@ -28,10 +28,15 @@ endfunction " Given a buffer number, find a virtualenv path for Python. function! ale#python#FindVirtualenv(buffer) abort for l:path in ale#path#Upwards(expand('#' . a:buffer . ':p:h')) + " Skip empty path components returned in MSYS. + if empty(l:path) + continue + endif + for l:dirname in ale#Var(a:buffer, 'virtualenv_dir_names') - let l:venv_dir = simplify(l:path . '/' . l:dirname) + let l:venv_dir = ale#path#Simplify(l:path . '/' . l:dirname) - if filereadable(simplify(l:venv_dir . '/' . s:bin_dir . '/activate')) + if filereadable(ale#path#Simplify(l:venv_dir . '/' . s:bin_dir . '/activate')) return l:venv_dir endif endfor @@ -52,7 +57,7 @@ function! ale#python#FindExecutable(buffer, base_var_name, path_list) abort if !empty(l:virtualenv) 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) return l:ve_executable diff --git a/autoload/ale/test.vim b/autoload/ale/test.vim index f63fc3ab..7f06ae91 100644 --- a/autoload/ale/test.vim +++ b/autoload/ale/test.vim @@ -15,5 +15,5 @@ function! ale#test#SetFilename(path) abort let l:dir = getcwd() endif - silent noautocmd execute 'file ' . fnameescape(simplify(l:dir . '/' . a:path)) + silent noautocmd execute 'file ' . fnameescape(ale#path#Simplify(l:dir . '/' . a:path)) endfunction diff --git a/custom-checks b/custom-checks index 6145478b..3bb60cda 100755 --- a/custom-checks +++ b/custom-checks @@ -78,6 +78,7 @@ check_errors $'\t' 'Use four spaces, not tabs' # 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 '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." exit $RETURN_CODE diff --git a/test/test_path_upwards.vader b/test/test_path_upwards.vader index 2f7b2c0f..5e7d576e 100644 --- a/test/test_path_upwards.vader +++ b/test/test_path_upwards.vader @@ -44,3 +44,7 @@ Execute(ale#path#Upwards should return the correct path components for Windows): \ ale#path#Upwards('foo//..///foo2////bar') " Expect an empty List for empty strings. AssertEqual [], ale#path#Upwards('') + " Paths starting with // return / + AssertEqual + \ ['/foo2\bar', '/foo2', '/'], + \ ale#path#Upwards('//foo//..///foo2////bar') |