summaryrefslogtreecommitdiff
path: root/autoload
diff options
context:
space:
mode:
Diffstat (limited to 'autoload')
-rw-r--r--autoload/ale.vim2
-rw-r--r--autoload/ale/c.vim7
-rw-r--r--autoload/ale/code_action.vim39
-rw-r--r--autoload/ale/completion.vim13
-rw-r--r--autoload/ale/fix.vim32
-rw-r--r--autoload/ale/handlers/gcc.vim19
-rw-r--r--autoload/ale/util.vim11
7 files changed, 92 insertions, 31 deletions
diff --git a/autoload/ale.vim b/autoload/ale.vim
index b75c9fc9..5ec22f57 100644
--- a/autoload/ale.vim
+++ b/autoload/ale.vim
@@ -263,6 +263,8 @@ function! ale#GetLocItemMessage(item, format_string) abort
let l:msg = substitute(l:msg, '\V%linter%', '\=l:linter_name', 'g')
" Replace %s with the text.
let l:msg = substitute(l:msg, '\V%s', '\=a:item.text', 'g')
+ " Windows may insert carriage return line endings (^M), strip these characters.
+ let l:msg = substitute(l:msg, '\r', '', 'g')
return l:msg
endfunction
diff --git a/autoload/ale/c.vim b/autoload/ale/c.vim
index d0a4fa06..cff53125 100644
--- a/autoload/ale/c.vim
+++ b/autoload/ale/c.vim
@@ -2,7 +2,9 @@
" Description: Functions for integrating with C-family linters.
call ale#Set('c_parse_makefile', 0)
+call ale#Set('c_always_make', has('unix') && !has('macunix'))
call ale#Set('c_parse_compile_commands', 1)
+
let s:sep = has('win32') ? '\' : '/'
" Set just so tests can override it.
@@ -504,7 +506,10 @@ function! ale#c#GetMakeCommand(buffer) abort
let l:path = ale#path#FindNearestFile(a:buffer, 'Makefile')
if !empty(l:path)
- return ale#path#CdString(fnamemodify(l:path, ':h')) . 'make -n'
+ let l:always_make = ale#Var(a:buffer, 'c_always_make')
+
+ return ale#path#CdString(fnamemodify(l:path, ':h'))
+ \ . 'make -n' . (l:always_make ? ' --always-make' : '')
endif
endif
diff --git a/autoload/ale/code_action.vim b/autoload/ale/code_action.vim
index 60c3bbef..8c7263f3 100644
--- a/autoload/ale/code_action.vim
+++ b/autoload/ale/code_action.vim
@@ -24,6 +24,42 @@ function! ale#code_action#HandleCodeAction(code_action, should_save) abort
endfor
endfunction
+function! s:ChangeCmp(left, right) abort
+ if a:left.start.line < a:right.start.line
+ return -1
+ endif
+
+ if a:left.start.line > a:right.start.line
+ return 1
+ endif
+
+ if a:left.start.offset < a:right.start.offset
+ return -1
+ endif
+
+ if a:left.start.offset > a:right.start.offset
+ return 1
+ endif
+
+ if a:left.end.line < a:right.end.line
+ return -1
+ endif
+
+ if a:left.end.line > a:right.end.line
+ return 1
+ endif
+
+ if a:left.end.offset < a:right.end.offset
+ return -1
+ endif
+
+ if a:left.end.offset > a:right.end.offset
+ return 1
+ endif
+
+ return 0
+endfunction
+
function! ale#code_action#ApplyChanges(filename, changes, should_save) abort
let l:current_buffer = bufnr('')
" The buffer is used to determine the fileformat, if available.
@@ -48,7 +84,8 @@ function! ale#code_action#ApplyChanges(filename, changes, should_save) abort
let l:column_offset = 0
let l:last_end_line = 0
- for l:code_edit in a:changes
+ " Changes have to be sorted so we apply them from top-to-bottom.
+ for l:code_edit in sort(copy(a:changes), function('s:ChangeCmp'))
if l:code_edit.start.line isnot l:last_end_line
let l:column_offset = 0
endif
diff --git a/autoload/ale/completion.vim b/autoload/ale/completion.vim
index f6a0c350..c2cfd74a 100644
--- a/autoload/ale/completion.vim
+++ b/autoload/ale/completion.vim
@@ -5,7 +5,7 @@ scriptencoding utf-8
" The omnicompletion menu is shown through a special Plug mapping which is
" only valid in Insert mode. This way, feedkeys() won't send these keys if you
" quit Insert mode quickly enough.
-inoremap <silent> <Plug>(ale_show_completion_menu) <C-x><C-o>
+inoremap <silent> <Plug>(ale_show_completion_menu) <C-x><C-o><C-p>
" If we hit the key sequence in normal mode, then we won't show the menu, so
" we should restore the old settings right away.
nnoremap <silent> <Plug>(ale_show_completion_menu) :call ale#completion#RestoreCompletionOptions()<CR>
@@ -324,6 +324,12 @@ function! ale#completion#AutomaticOmniFunc(findstart, base) abort
endif
endfunction
+function! s:OpenCompletionMenu(...) abort
+ if !&l:paste
+ call ale#util#FeedKeys("\<Plug>(ale_show_completion_menu)")
+ endif
+endfunction
+
function! ale#completion#Show(result) abort
if ale#util#Mode() isnot# 'i'
return
@@ -344,10 +350,7 @@ function! ale#completion#Show(result) abort
let l:source = get(get(b:, 'ale_completion_info', {}), 'source', '')
if l:source is# 'ale-automatic' || l:source is# 'ale-manual'
- call timer_start(
- \ 0,
- \ {-> ale#util#FeedKeys("\<Plug>(ale_show_completion_menu)")}
- \)
+ call timer_start(0, function('s:OpenCompletionMenu'))
endif
if l:source is# 'ale-callback'
diff --git a/autoload/ale/fix.vim b/autoload/ale/fix.vim
index 3ad0a433..8b841b13 100644
--- a/autoload/ale/fix.vim
+++ b/autoload/ale/fix.vim
@@ -15,22 +15,29 @@ function! ale#fix#ApplyQueuedFixes(buffer) abort
call remove(g:ale_fix_buffer_data, a:buffer)
- if l:data.changes_made
- let l:new_lines = ale#util#SetBufferContents(a:buffer, l:data.output)
-
- if l:data.should_save
- if a:buffer is bufnr('')
- if empty(&buftype)
- noautocmd :w!
+ try
+ if l:data.changes_made
+ let l:new_lines = ale#util#SetBufferContents(a:buffer, l:data.output)
+
+ if l:data.should_save
+ if a:buffer is bufnr('')
+ if empty(&buftype)
+ noautocmd :w!
+ else
+ set nomodified
+ endif
else
- set nomodified
+ call writefile(l:new_lines, expand('#' . a:buffer . ':p')) " no-custom-checks
+ call setbufvar(a:buffer, '&modified', 0)
endif
- else
- call writefile(l:new_lines, expand('#' . a:buffer . ':p')) " no-custom-checks
- call setbufvar(a:buffer, '&modified', 0)
endif
endif
- endif
+ catch /E21/
+ " If we cannot modify the buffer now, try again later.
+ let g:ale_fix_buffer_data[a:buffer] = l:data
+
+ return
+ endtry
if l:data.should_save
let l:should_lint = ale#Var(a:buffer, 'fix_on_save')
@@ -376,3 +383,4 @@ endfunction
augroup ALEBufferFixGroup
autocmd!
autocmd BufEnter * call ale#fix#ApplyQueuedFixes(str2nr(expand('<abuf>')))
+augroup END
diff --git a/autoload/ale/handlers/gcc.vim b/autoload/ale/handlers/gcc.vim
index ec16b977..0b37c98a 100644
--- a/autoload/ale/handlers/gcc.vim
+++ b/autoload/ale/handlers/gcc.vim
@@ -10,7 +10,7 @@ let s:pragma_error = '#pragma once in main file'
" <stdin>:8:5: warning: conversion lacks type at end of format [-Wformat=]
" <stdin>:10:27: error: invalid operands to binary - (have ‘int’ and ‘char *’)
" -:189:7: note: $/${} is unnecessary on arithmetic variables. [SC2004]
-let s:pattern = '\v^([a-zA-Z]?:?[^:]+):(\d+):(\d+)?:? ([^:]+): (.+)$'
+let s:pattern = '\v^([a-zA-Z]?:?[^:]+):(\d+)?:?(\d+)?:? ([^:]+): (.+)$'
let s:inline_pattern = '\v inlined from .* at \<stdin\>:(\d+):(\d+):$'
function! s:IsHeaderFile(filename) abort
@@ -117,6 +117,23 @@ function! ale#handlers#gcc#HandleGCCFormat(buffer, lines) abort
if !empty(l:output)
if !has_key(l:output[-1], 'detail')
let l:output[-1].detail = l:output[-1].text
+
+ " handle macro expansion errors/notes
+ if l:match[5] =~? '^in expansion of macro ‘\w*\w’$'
+ " if the macro expansion is in the file we're in, add
+ " the lnum and col keys to the previous error
+ if l:match[1] is# '<stdin>'
+ \ && !has_key(l:output[-1], 'col')
+ let l:output[-1].lnum = str2nr(l:match[2])
+ let l:output[-1].col = str2nr(l:match[3])
+ else
+ " the error is not in the current file, and since
+ " macro expansion errors don't show the full path to
+ " the error from the current file, we have to just
+ " give out a generic error message
+ let l:output[-1].text = 'Error found in macro expansion. See :ALEDetail'
+ endif
+ endif
endif
let l:output[-1].detail = l:output[-1].detail . "\n"
diff --git a/autoload/ale/util.vim b/autoload/ale/util.vim
index 05f11993..1f396377 100644
--- a/autoload/ale/util.vim
+++ b/autoload/ale/util.vim
@@ -505,13 +505,6 @@ function! ale#util#SetBufferContents(buffer, lines) abort
\ : a:lines
let l:first_line_to_remove = len(l:new_lines) + 1
- " We'll temporarily make a buffer modifiable, to force edits.
- let l:modifiable = getbufvar(a:buffer, '&modifiable')
-
- if !l:modifiable
- call setbufvar(a:buffer, '&modifiable', 1)
- endif
-
" Use a Vim API for setting lines in other buffers, if available.
if l:has_bufline_api
call setbufline(a:buffer, 1, l:new_lines)
@@ -530,9 +523,5 @@ function! ale#util#SetBufferContents(buffer, lines) abort
call setline(1, l:new_lines)
endif
- if !l:modifiable
- call setbufvar(a:buffer, '&modifiable', 0)
- endif
-
return l:new_lines
endfunction