mirror of
https://github.com/dense-analysis/ale
synced 2024-12-29 01:22:17 +00:00
#604 Add a function for creating positions needed for supporting highlights across many lines
This commit is contained in:
parent
fd49f7df90
commit
676a4049b3
@ -28,6 +28,30 @@ endif
|
||||
" the buffer is in focus when linting completes.
|
||||
let s:buffer_highlights = {}
|
||||
let s:buffer_restore_map = {}
|
||||
" The maximum number of items for the second argument of matchaddpos()
|
||||
let s:MAX_POS_VALUES = 8
|
||||
let s:MAX_COL_SIZE = 4294967296
|
||||
|
||||
function! ale#highlight#CreatePositions(line, col, end_line, end_col) abort
|
||||
if a:line >= a:end_line
|
||||
" For single lines, just return the one position.
|
||||
return [[[a:line, a:col, a:end_col - a:col + 1]]]
|
||||
endif
|
||||
|
||||
" Get positions from the first line at the first column, up to a large
|
||||
" integer for highlighting up to the end of the line, followed by
|
||||
" the lines in-between, for highlighting entire lines, and
|
||||
" a highlight for the last line, up to the end column.
|
||||
let l:all_positions =
|
||||
\ [[a:line, a:col, s:MAX_COL_SIZE]]
|
||||
\ + range(a:line + 1, a:end_line - 1)
|
||||
\ + [[a:end_line, 1, a:end_col]]
|
||||
|
||||
return map(
|
||||
\ range(0, len(l:all_positions) - 1, s:MAX_POS_VALUES),
|
||||
\ 'l:all_positions[v:val : v:val + s:MAX_POS_VALUES - 1]',
|
||||
\)
|
||||
endfunction
|
||||
|
||||
function! ale#highlight#UnqueueHighlights(buffer) abort
|
||||
if has_key(s:buffer_highlights, a:buffer)
|
||||
|
76
test/test_highlight_position_chunking.vader
Normal file
76
test/test_highlight_position_chunking.vader
Normal file
@ -0,0 +1,76 @@
|
||||
Execute(CreatePositions() should support single character matches):
|
||||
AssertEqual [[[1, 5, 1]]], ale#highlight#CreatePositions(1, 5, 1, 5)
|
||||
" When the end column is behind the start column, ignore it.
|
||||
AssertEqual [[[2, 5, 1]]], ale#highlight#CreatePositions(2, 5, 1, 5)
|
||||
|
||||
Execute(CreatePositions() should support multiple character matches on a single line):
|
||||
AssertEqual [[[1, 5, 6]]], ale#highlight#CreatePositions(1, 5, 1, 10)
|
||||
" When the end column is behind the start column, ignore it.
|
||||
AssertEqual [[[2, 5, 6]]], ale#highlight#CreatePositions(2, 5, 1, 10)
|
||||
|
||||
Execute(CreatePositions() should support character matches two lines):
|
||||
AssertEqual [[[1, 5, 4294967296], [2, 1, 10]]], ale#highlight#CreatePositions(1, 5, 2, 10)
|
||||
|
||||
Execute(CreatePositions() should support character matches across many lines):
|
||||
" Test chunks from 1,3 to 1,17
|
||||
AssertEqual [
|
||||
\ [[1, 5, 4294967296], 2, [3, 1, 10]],
|
||||
\], ale#highlight#CreatePositions(1, 5, 3, 10)
|
||||
AssertEqual [
|
||||
\ [[1, 5, 4294967296], 2, 3, [4, 1, 10]],
|
||||
\], ale#highlight#CreatePositions(1, 5, 4, 10)
|
||||
AssertEqual [
|
||||
\ [[1, 5, 4294967296], 2, 3, 4, [5, 1, 10]],
|
||||
\], ale#highlight#CreatePositions(1, 5, 5, 10)
|
||||
AssertEqual [
|
||||
\ [[1, 5, 4294967296], 2, 3, 4, 5, [6, 1, 10]],
|
||||
\], ale#highlight#CreatePositions(1, 5, 6, 10)
|
||||
AssertEqual [
|
||||
\ [[1, 5, 4294967296], 2, 3, 4, 5, 6, [7, 1, 10]],
|
||||
\], ale#highlight#CreatePositions(1, 5, 7, 10)
|
||||
AssertEqual [
|
||||
\ [[1, 5, 4294967296], 2, 3, 4, 5, 6, 7, [8, 1, 10]],
|
||||
\], ale#highlight#CreatePositions(1, 5, 8, 10)
|
||||
AssertEqual [
|
||||
\ [[1, 5, 4294967296], 2, 3, 4, 5, 6, 7, 8],
|
||||
\ [[9, 1, 10]],
|
||||
\], ale#highlight#CreatePositions(1, 5, 9, 10)
|
||||
AssertEqual [
|
||||
\ [[1, 5, 4294967296], 2, 3, 4, 5, 6, 7, 8],
|
||||
\ [9, [10, 1, 10]],
|
||||
\], ale#highlight#CreatePositions(1, 5, 10, 10)
|
||||
AssertEqual [
|
||||
\ [[1, 5, 4294967296], 2, 3, 4, 5, 6, 7, 8],
|
||||
\ [9, 10, [11, 1, 10]],
|
||||
\], ale#highlight#CreatePositions(1, 5, 11, 10)
|
||||
AssertEqual [
|
||||
\ [[1, 5, 4294967296], 2, 3, 4, 5, 6, 7, 8],
|
||||
\ [9, 10, 11, [12, 1, 10]],
|
||||
\], ale#highlight#CreatePositions(1, 5, 12, 10)
|
||||
AssertEqual [
|
||||
\ [[1, 5, 4294967296], 2, 3, 4, 5, 6, 7, 8],
|
||||
\ [9, 10, 11, 12, [13, 1, 10]],
|
||||
\], ale#highlight#CreatePositions(1, 5, 13, 10)
|
||||
AssertEqual [
|
||||
\ [[1, 5, 4294967296], 2, 3, 4, 5, 6, 7, 8],
|
||||
\ [9, 10, 11, 12, 13, [14, 1, 10]],
|
||||
\], ale#highlight#CreatePositions(1, 5, 14, 10)
|
||||
AssertEqual [
|
||||
\ [[1, 5, 4294967296], 2, 3, 4, 5, 6, 7, 8],
|
||||
\ [9, 10, 11, 12, 13, 14, [15, 1, 10]],
|
||||
\], ale#highlight#CreatePositions(1, 5, 15, 10)
|
||||
AssertEqual [
|
||||
\ [[1, 5, 4294967296], 2, 3, 4, 5, 6, 7, 8],
|
||||
\ [9, 10, 11, 12, 13, 14, 15, [16, 1, 10]],
|
||||
\], ale#highlight#CreatePositions(1, 5, 16, 10)
|
||||
AssertEqual [
|
||||
\ [[1, 5, 4294967296], 2, 3, 4, 5, 6, 7, 8],
|
||||
\ [9, 10, 11, 12, 13, 14, 15, 16],
|
||||
\ [[17, 1, 10]],
|
||||
\], ale#highlight#CreatePositions(1, 5, 17, 10)
|
||||
" Test another random sample at higher lines.
|
||||
AssertEqual [
|
||||
\ [[21, 8, 4294967296], 22, 23, 24, 25, 26, 27, 28],
|
||||
\ [29, 30, 31, 32, 33, 34, 35, 36],
|
||||
\ [[37, 1, 2]],
|
||||
\], ale#highlight#CreatePositions(21, 8, 37, 2)
|
Loading…
Reference in New Issue
Block a user