#729 - Use a wrapper for simplify to fix // problems on Windows
This commit is contained in:
parent
a04e73ddbc
commit
1bd9b0fbe2
@ -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 []
|
||||
|
@ -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
|
||||
|
@ -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'))
|
||||
for l:dirname in ale#Var(a:buffer, 'virtualenv_dir_names')
|
||||
let l:venv_dir = simplify(l:path . '/' . l:dirname)
|
||||
" Skip empty path components returned in MSYS.
|
||||
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
|
||||
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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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')
|
||||
|
Loading…
Reference in New Issue
Block a user