summaryrefslogtreecommitdiff
path: root/autoload
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2017-04-29 17:33:18 +0100
committerw0rp <devw0rp@gmail.com>2017-04-29 17:33:18 +0100
commit0b4acd645395d4196f2e346d65aeddf063927f4e (patch)
tree2701b1faefec6e1cc2dbfd5775d3bf94c6a5e022 /autoload
parentcbb01e32b950f4a5c14d56b41759945662b2db49 (diff)
downloadale-0b4acd645395d4196f2e346d65aeddf063927f4e.zip
Fix #518 Fix handling of spaces in filenames for various linters
Diffstat (limited to 'autoload')
-rw-r--r--autoload/ale/handlers/python.vim8
-rw-r--r--autoload/ale/handlers/unix.vim4
-rw-r--r--autoload/ale/path.vim27
3 files changed, 31 insertions, 8 deletions
diff --git a/autoload/ale/handlers/python.vim b/autoload/ale/handlers/python.vim
index 4777dd18..02f9758a 100644
--- a/autoload/ale/handlers/python.vim
+++ b/autoload/ale/handlers/python.vim
@@ -1,8 +1,6 @@
" Author: w0rp <devw0rp@gmail.com>
" Description: Error handling for flake8, etc.
-let s:path_pattern = '[a-zA-Z]\?\\\?:\?[[:alnum:]/\.\-_]\+'
-
function! ale#handlers#python#HandlePEP8Format(buffer, lines) abort
" Matches patterns line the following:
"
@@ -10,7 +8,7 @@ function! ale#handlers#python#HandlePEP8Format(buffer, lines) abort
"
" stdin:6:6: E111 indentation is not a multiple of four
" test.yml:35: [EANSIBLE0002] Trailing whitespace
- let l:pattern = '^' . s:path_pattern . ':\(\d\+\):\?\(\d\+\)\?: \[\?\(\([[:alpha:]]\)[[:alnum:]]\+\)\]\? \(.*\)$'
+ let l:pattern = '\v^[a-zA-Z]?:?[^:]+:(\d+):?(\d+)?: \[?([[:alnum:]]+)\]? (.*)$'
let l:output = []
for l:match in ale#util#GetMatches(a:lines, l:pattern)
@@ -30,8 +28,8 @@ function! ale#handlers#python#HandlePEP8Format(buffer, lines) abort
call add(l:output, {
\ 'lnum': l:match[1] + 0,
\ 'col': l:match[2] + 0,
- \ 'text': l:code . ': ' . l:match[5],
- \ 'type': l:match[4] ==# 'E' ? 'E' : 'W',
+ \ 'text': l:code . ': ' . l:match[4],
+ \ 'type': l:code[:0] ==# 'E' ? 'E' : 'W',
\})
endfor
diff --git a/autoload/ale/handlers/unix.vim b/autoload/ale/handlers/unix.vim
index be0f0823..f90fd591 100644
--- a/autoload/ale/handlers/unix.vim
+++ b/autoload/ale/handlers/unix.vim
@@ -1,10 +1,8 @@
" Author: w0rp <devw0rp@gmail.com>
" Description: Error handling for errors in a Unix format.
-let s:path_pattern = '[a-zA-Z]\?\\\?:\?[[:alnum:]/\.\-_]\+'
-
function! s:HandleUnixFormat(buffer, lines, type) abort
- let l:pattern = '^' . s:path_pattern . ':\(\d\+\):\?\(\d\+\)\?:\? \?\(.\+\)$'
+ let l:pattern = '\v^[a-zA-Z]?:?[^:]+:(\d+):?(\d+)?:? ?(.+)$'
let l:output = []
for l:match in ale#util#GetMatches(a:lines, l:pattern)
diff --git a/autoload/ale/path.vim b/autoload/ale/path.vim
index cbd4d886..6fd5142b 100644
--- a/autoload/ale/path.vim
+++ b/autoload/ale/path.vim
@@ -55,3 +55,30 @@ endfunction
function! ale#path#BufferCdString(buffer) abort
return ale#path#CdString(fnamemodify(bufname(a:buffer), ':p:h'))
endfunction
+
+" Return 1 if a path is an absolute path.
+function! ale#path#IsAbsolute(filename) abort
+ return match(a:filename, '^\v/|^[a-zA-Z]:\\') == 0
+endfunction
+
+" Given a directory and a filename, resolve the path, which may be relative
+" or absolute, and get an absolute path to the file, following symlinks.
+function! ale#path#Resolve(directory, filename) abort
+ return resolve(
+ \ ale#path#IsAbsolute(a:filename)
+ \ ? a:filename
+ \ : a:directory . '/' . a:filename
+ \)
+endfunction
+
+" Given a buffer number and a relative or absolute path, return 1 if the
+" two paths represent the same file on disk.
+function! ale#path#IsBufferPath(buffer, filename) abort
+ let l:buffer_filename = expand('#' . a:buffer . ':p')
+ let l:resolved_filename = ale#path#Resolve(
+ \ fnamemodify(l:buffer_filename, ':h'),
+ \ a:filename
+ \)
+
+ return resolve(l:buffer_filename) == l:resolved_filename
+endfunction