Skip to content

Commit

Permalink
refactor(highlight): use coc#highlight#ranges for performance
Browse files Browse the repository at this point in the history
Increase name space id of workspace
  • Loading branch information
chemzqm committed Dec 15, 2020
1 parent 5a2bf6e commit be55260
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 23 deletions.
37 changes: 20 additions & 17 deletions autoload/coc/highlight.vim
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,29 @@ if has('nvim-0.5.0')
endif

" highlight LSP range,
" TODO don't know how to count UTF16 code point, should work most cases.
function! coc#highlight#range(bufnr, key, hlGroup, range) abort
function! coc#highlight#ranges(bufnr, key, hlGroup, ranges) abort
let bufnr = a:bufnr == 0 ? bufnr('%') : a:bufnr
if !bufloaded(bufnr)
if !bufloaded(bufnr) || !exists('*getbufline')
return
endif
let srcId = s:create_namespace(a:key)
let start = a:range['start']
let end = a:range['end']
for lnum in range(start['line'] + 1, end['line'] + 1)
let arr = getbufline(bufnr, lnum)
let line = empty(arr) ? '' : arr[0]
if empty(line)
continue
endif
let colStart = lnum == start['line'] + 1 ? strlen(strcharpart(line, 0, start['character'])) : 0
let colEnd = lnum == end['line'] + 1 ? strlen(strcharpart(line, 0, end['character'])) : -1
if colStart == colEnd
continue
endif
call coc#highlight#add_highlight(bufnr, srcId, a:hlGroup, lnum - 1, colStart, colEnd)
for range in a:ranges
let start = range['start']
let end = range['end']
for lnum in range(start['line'] + 1, end['line'] + 1)
let arr = getbufline(bufnr, lnum)
let line = empty(arr) ? '' : arr[0]
if empty(line)
continue
endif
" TODO don't know how to count UTF16 code point, should work most cases.
let colStart = lnum == start['line'] + 1 ? strlen(strcharpart(line, 0, start['character'])) : 0
let colEnd = lnum == end['line'] + 1 ? strlen(strcharpart(line, 0, end['character'])) : -1
if colStart == colEnd
continue
endif
call coc#highlight#add_highlight(bufnr, srcId, a:hlGroup, lnum - 1, colStart, colEnd)
endfor
endfor
endfunction

Expand Down Expand Up @@ -125,6 +127,7 @@ function! coc#highlight#highlight_lines(winid, blocks) abort
endif
endfunction

" Copmpose hlGroups with foreground and background colors.
function! coc#highlight#compose_hlgroup(fgGroup, bgGroup) abort
let hlGroup = 'Fg'.a:fgGroup.'Bg'.a:bgGroup
if a:fgGroup == a:bgGroup
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
"vscode-languageserver": "next"
},
"dependencies": {
"@chemzqm/neovim": "^5.2.11",
"@chemzqm/neovim": "^5.2.12",
"ansi-styles": "^5.0.0",
"bser": "^2.1.1",
"bytes": "^3.1.0",
Expand Down
2 changes: 1 addition & 1 deletion src/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import window from './window'

const APIVERSION = 8
const logger = require('./util/logger')('workspace')
let NAME_SPACE = 1080
let NAME_SPACE = 2000
const methods = [
'showMessage',
'runTerminalCommand',
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,10 @@
resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39"
integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==

"@chemzqm/neovim@^5.2.11":
version "5.2.11"
resolved "https://registry.yarnpkg.com/@chemzqm/neovim/-/neovim-5.2.11.tgz#b7c961b7c5939b5044e92955dfc8fdda9a537a83"
integrity sha512-+wrRZVtgiTaMCVrTsxLzQ3Op8y0rX7gvym27rUfyMfWxvN7wvV1rCqCDjNtIQ11NLOJxigC7uVvftl7P8RP4ZA==
"@chemzqm/neovim@^5.2.12":
version "5.2.12"
resolved "https://registry.yarnpkg.com/@chemzqm/neovim/-/neovim-5.2.12.tgz#5b85f8385a8f49c3a0f0f542efb11d5e98f2bba5"
integrity sha512-MmnFaF7P8Sw/WsselXtoexTUxPJGWupUDMTz0T76mWU+M61TXt213UBgxA/idr7ZSCnFTyujDVqcaL5xYd9tig==
dependencies:
msgpack-lite "^0.1.26"

Expand Down

0 comments on commit be55260

Please sign in to comment.