summaryrefslogtreecommitdiff
path: root/autoload
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2018-04-10 21:05:22 +0100
committerw0rp <devw0rp@gmail.com>2018-04-10 21:05:22 +0100
commitf064ba48f5893f25c1af9459b309a919a392db7c (patch)
tree00b33c7c7f86ae201ca5908b2a7e9f71c3588ac2 /autoload
parent3f0e1cd05dc526b073946ad96c64f6a5e2f9e4e6 (diff)
downloadale-f064ba48f5893f25c1af9459b309a919a392db7c.zip
Close #1494 - Prefer displaying higher severity problems for cursor messages, balloons, and highlights
Diffstat (limited to 'autoload')
-rw-r--r--autoload/ale/sign.vim36
-rw-r--r--autoload/ale/util.vim54
2 files changed, 62 insertions, 28 deletions
diff --git a/autoload/ale/sign.vim b/autoload/ale/sign.vim
index 1c439bc8..d1139c03 100644
--- a/autoload/ale/sign.vim
+++ b/autoload/ale/sign.vim
@@ -60,55 +60,35 @@ execute 'sign define ALEInfoSign text=' . g:ale_sign_info
\ . ' texthl=ALEInfoSign linehl=ALEInfoLine'
sign define ALEDummySign
-let s:error_priority = 1
-let s:warning_priority = 2
-let s:info_priority = 3
-let s:style_error_priority = 4
-let s:style_warning_priority = 5
-
function! ale#sign#GetSignName(sublist) abort
- let l:priority = s:style_warning_priority
+ let l:priority = g:ale#util#style_warning_priority
" Determine the highest priority item for the line.
for l:item in a:sublist
- if l:item.type is# 'I'
- let l:item_priority = s:info_priority
- elseif l:item.type is# 'W'
- if get(l:item, 'sub_type', '') is# 'style'
- let l:item_priority = s:style_warning_priority
- else
- let l:item_priority = s:warning_priority
- endif
- else
- if get(l:item, 'sub_type', '') is# 'style'
- let l:item_priority = s:style_error_priority
- else
- let l:item_priority = s:error_priority
- endif
- endif
+ let l:item_priority = ale#util#GetItemPriority(l:item)
- if l:item_priority < l:priority
+ if l:item_priority > l:priority
let l:priority = l:item_priority
endif
endfor
- if l:priority is# s:error_priority
+ if l:priority is# g:ale#util#error_priority
return 'ALEErrorSign'
endif
- if l:priority is# s:warning_priority
+ if l:priority is# g:ale#util#warning_priority
return 'ALEWarningSign'
endif
- if l:priority is# s:style_error_priority
+ if l:priority is# g:ale#util#style_error_priority
return 'ALEStyleErrorSign'
endif
- if l:priority is# s:style_warning_priority
+ if l:priority is# g:ale#util#style_warning_priority
return 'ALEStyleWarningSign'
endif
- if l:priority is# s:info_priority
+ if l:priority is# g:ale#util#info_priority
return 'ALEInfoSign'
endif
diff --git a/autoload/ale/util.vim b/autoload/ale/util.vim
index e0b31e2c..d160b34c 100644
--- a/autoload/ale/util.vim
+++ b/autoload/ale/util.vim
@@ -33,6 +33,32 @@ function! ale#util#GetFunction(string_or_ref) abort
return a:string_or_ref
endfunction
+let g:ale#util#error_priority = 5
+let g:ale#util#warning_priority = 4
+let g:ale#util#info_priority = 3
+let g:ale#util#style_error_priority = 2
+let g:ale#util#style_warning_priority = 1
+
+function! ale#util#GetItemPriority(item) abort
+ if a:item.type is# 'I'
+ return g:ale#util#info_priority
+ endif
+
+ if a:item.type is# 'W'
+ if get(a:item, 'sub_type', '') is# 'style'
+ return g:ale#util#style_warning_priority
+ endif
+
+ return g:ale#util#warning_priority
+ endif
+
+ if get(a:item, 'sub_type', '') is# 'style'
+ return g:ale#util#style_error_priority
+ endif
+
+ return g:ale#util#error_priority
+endfunction
+
" Compare two loclist items for ALE, sorted by their buffers, filenames, and
" line numbers and column numbers.
function! ale#util#LocItemCompare(left, right) abort
@@ -70,6 +96,23 @@ function! ale#util#LocItemCompare(left, right) abort
return 1
endif
+ " When either of the items lacks a problem type, then the two items should
+ " be considered equal. This is important for loclist jumping.
+ if !has_key(a:left, 'type') || !has_key(a:right, 'type')
+ return 0
+ endif
+
+ let l:left_priority = ale#util#GetItemPriority(a:left)
+ let l:right_priority = ale#util#GetItemPriority(a:right)
+
+ if l:left_priority < l:right_priority
+ return -1
+ endif
+
+ if l:left_priority > l:right_priority
+ return 1
+ endif
+
return 0
endfunction
@@ -139,6 +182,17 @@ function! ale#util#BinarySearch(loclist, buffer, line, column) abort
let l:index += 1
endwhile
+ " Scan forwards to find the last item on the column for the item
+ " we found, which will have the most serious problem.
+ let l:item_column = a:loclist[l:index].col
+
+ while l:index < l:max
+ \&& a:loclist[l:index + 1].bufnr == a:buffer
+ \&& a:loclist[l:index + 1].lnum == a:line
+ \&& a:loclist[l:index + 1].col == l:item_column
+ let l:index += 1
+ endwhile
+
return l:index
endif
endwhile