Skip to content

Commit

Permalink
feat(highlight): support check changedtick for updateHighlights
Browse files Browse the repository at this point in the history
  • Loading branch information
chemzqm committed Jan 17, 2022
1 parent 10754e2 commit d33f486
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 18 deletions.
28 changes: 19 additions & 9 deletions autoload/coc/highlight.vim
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,16 @@ function! coc#highlight#buffer_update(bufnr, key, highlights, ...) abort
return
endif
let priority = get(a:, 1, v:null)
let changedtick = getbufvar(a:bufnr, 'changedtick', 0)
if type(get(a:, 2, v:null)) == 0 && changedtick > a:2
return
endif
let hls = map(copy(a:highlights), "{'hlGroup':v:val[0],'lnum':v:val[1],'colStart':v:val[2],'colEnd':v:val[3]}")
let total = exists('*nvim_buf_line_count') ? nvim_buf_line_count(a:bufnr): getbufinfo(a:bufnr)[0]['linecount']
if total <= g:coc_highlight_batch_lines || get(g:, 'coc_node_env', '') ==# 'test'
call coc#highlight#update_highlights(a:bufnr, a:key, hls, 0, -1, priority)
return
endif
let changedtick = getbufvar(a:bufnr, 'changedtick', 0)
if bufnr('%') == a:bufnr
" Highlight visible region first
let ls = line('w0')
Expand Down Expand Up @@ -121,6 +124,9 @@ function! coc#highlight#update_highlights(bufnr, key, highlights, ...) abort
return
endif
let priority = get(a:, 3, v:null)
if type(get(a:, 4, v:null)) == 0 && getbufvar(bufnr, 'changedtick') > a:4
return
endif
let total = len(a:highlights)
" index list that exists with current highlights
let exists = []
Expand Down Expand Up @@ -281,14 +287,18 @@ function! coc#highlight#add_highlight(bufnr, src_id, hl_group, line, col_start,
let priority = get(opts, 'priority', v:null)
if has('nvim')
if s:set_extmark && a:src_id != -1
call nvim_buf_set_extmark(a:bufnr, a:src_id, a:line, a:col_start, {
\ 'end_col': a:col_end,
\ 'hl_group': a:hl_group,
\ 'hl_mode': get(opts, 'combine', 1) ? 'combine' : 'replace',
\ 'right_gravity': get(opts, 'start_incl', 0) ? v:false : v:true,
\ 'end_right_gravity': get(opts, 'end_incl', 0) ? v:true : v:false,
\ 'priority': type(priority) == 0 ? min([priority, 4096]) : 4096,
\ })
try
call nvim_buf_set_extmark(a:bufnr, a:src_id, a:line, a:col_start, {
\ 'end_col': a:col_end,
\ 'hl_group': a:hl_group,
\ 'hl_mode': get(opts, 'combine', 1) ? 'combine' : 'replace',
\ 'right_gravity': get(opts, 'start_incl', 0) ? v:false : v:true,
\ 'end_right_gravity': get(opts, 'end_incl', 0) ? v:true : v:false,
\ 'priority': type(priority) == 0 ? min([priority, 4096]) : 4096,
\ })
catch /^Vim\%((\a\+)\)\=:E5555/
" the end_col could be invalid, ignore this error
endtry
else
call nvim_buf_add_highlight(a:bufnr, a:src_id, a:hl_group, a:line, a:col_start, a:col_end)
endif
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
"vscode-languageserver": "7.0.0"
},
"dependencies": {
"@chemzqm/neovim": "^5.6.2",
"@chemzqm/neovim": "^5.6.3",
"bytes": "^3.1.0",
"tslib": "^2.0.3",
"ansi-styles": "^5.0.0",
Expand Down
25 changes: 21 additions & 4 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2229,6 +2229,25 @@ declare module 'coc.nvim' {
end_incl?: boolean
}

export interface HighlightOption {
/**
* 0 based start line, default to 0.
*/
start?: number
/**
* 0 based end line, default to 0.
*/
end?: number
/**
* Default to 0 on vim8, 4096 on neovim
*/
priority?: number
/**
* Buffer changedtick to match.
*/
changedtick?: number
}

export interface BufferKeymapOption {
nowait?: boolean
silent?: boolean
Expand Down Expand Up @@ -2844,11 +2863,9 @@ declare module 'coc.nvim' {
*
* @param {string} ns Namespace key.
* @param {HighlightItem[]} highlights Highlight items.
* @param {number} start 0 based line number, default to 0.
* @param {number} end 0 based line number, default to -1.
* @param {priority} priority Priority of this highlight.
* @param {HighlightOption} opts Highlight options.
*/
updateHighlights(ns: string, highlights: ExtendedHighlightItem[], start?: number, end?: number, priority?: number): void
updateHighlights(ns: string, highlights: ExtendedHighlightItem[], opts?: HighlightOption): void

/**
* Gets a map of buffer-local |user-commands|.
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -418,10 +418,10 @@
resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39"
integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==

"@chemzqm/neovim@^5.6.2":
version "5.6.2"
resolved "https://registry.yarnpkg.com/@chemzqm/neovim/-/neovim-5.6.2.tgz#089abd39a495f450ed7db6388b805321d4f8945d"
integrity sha512-QezAtwmETT25+/gAojCWugU73SJqrjF8ItQ9lNj3lqakUdAieHSM7d2Dz4gfRtkWILGaoOe3E8csPdPgA+eFYg==
"@chemzqm/neovim@^5.6.3":
version "5.6.3"
resolved "https://registry.yarnpkg.com/@chemzqm/neovim/-/neovim-5.6.3.tgz#4bdb1e5224d180f4739c40492181fae608a4c8b0"
integrity sha512-pEvLYzIPM8pUYUc5tzyiecc/AEEWhyt9NejHsWNpMQCf+y7CgWNK+zuL4ir9P6IleFjiPqGPADzuBGdpi/kNgA==
dependencies:
msgpack-lite "^0.1.26"

Expand Down

0 comments on commit d33f486

Please sign in to comment.