mirror of
1
0
Fork 0

Update Coc.nvim.

This commit is contained in:
Kurtis Moxley 2022-09-13 19:48:57 +08:00
parent 3fa5ed14bb
commit 53dd1894bb
21 changed files with 4802 additions and 2841 deletions

View File

@ -20,7 +20,7 @@ _Custom popup menu with snippet support_
## Why?
- 🚀 **Fast**: separated NodeJS process that not block your vim most of the time.
- 🚀 **Fast**: separated NodeJS process that does not block your vim most of the time.
- 💎 **Reliable**: typed language, tested with CI.
- 🌟 **Featured**: all LSP 3.16 features are supported, see `:h coc-lsp`.
- ❤️ **Flexible**: [configured like VSCode](https://github.com/neoclide/coc.nvim/wiki/Using-the-configuration-file), [extensions work like in VSCode](https://github.com/neoclide/coc.nvim/wiki/Using-coc-extensions)
@ -107,10 +107,12 @@ set updatetime=300
set signcolumn=yes
" Use tab for trigger completion with characters ahead and navigate.
" NOTE: There's always complete item selected by default, you may want to enable
" no select by `"suggest.noselect": true` in your configuration file.
" NOTE: Use command ':verbose imap <tab>' to make sure tab is not mapped by
" other plugin before putting this into your config.
inoremap <silent><expr> <TAB>
\ coc#pum#visible() ? coc#pum#next(1):
\ coc#pum#visible() ? coc#pum#next(1) :
\ CheckBackspace() ? "\<Tab>" :
\ coc#refresh()
inoremap <expr><S-TAB> coc#pum#visible() ? coc#pum#prev(1) : "\<C-h>"
@ -319,6 +321,10 @@ Try these steps when you have problem with coc.nvim.
<a href="https://opencollective.com/cocnvim/backer/43/website?requireActive=false" target="_blank"><img src="https://opencollective.com/cocnvim/backer/43/avatar.svg?requireActive=false"></a>
<a href="https://opencollective.com/cocnvim/backer/44/website?requireActive=false" target="_blank"><img src="https://opencollective.com/cocnvim/backer/44/avatar.svg?requireActive=false"></a>
<a href="https://opencollective.com/cocnvim/backer/45/website?requireActive=false" target="_blank"><img src="https://opencollective.com/cocnvim/backer/45/avatar.svg?requireActive=false"></a>
<a href="https://opencollective.com/cocnvim/backer/46/website?requireActive=false" target="_blank"><img src="https://opencollective.com/cocnvim/backer/46/avatar.svg?requireActive=false"></a>
<a href="https://opencollective.com/cocnvim/backer/47/website?requireActive=false" target="_blank"><img src="https://opencollective.com/cocnvim/backer/47/avatar.svg?requireActive=false"></a>
<a href="https://opencollective.com/cocnvim/backer/48/website?requireActive=false" target="_blank"><img src="https://opencollective.com/cocnvim/backer/48/avatar.svg?requireActive=false"></a>
<a href="https://opencollective.com/cocnvim/backer/49/website?requireActive=false" target="_blank"><img src="https://opencollective.com/cocnvim/backer/49/avatar.svg?requireActive=false"></a>
<a href="https://opencollective.com/cocnvim#backer" target="_blank"><img src="https://images.opencollective.com/static/images/become_backer.svg"></a>
@ -595,6 +601,13 @@ Try these steps when you have problem with coc.nvim.
<td align="center"><a href="http://bigshans.github.io"><img src="https://avatars.githubusercontent.com/u/26884666?v=4?s=50" width="50px;" alt=""/><br /><sub><b>bigshans</b></sub></a><br /><a href="https://github.com/neoclide/coc.nvim/commits?author=bigshans" title="Documentation">📖</a></td>
<td align="center"><a href="https://github.com/rob-3"><img src="https://avatars.githubusercontent.com/u/24816247?v=4?s=50" width="50px;" alt=""/><br /><sub><b>Robert Boyd III</b></sub></a><br /><a href="https://github.com/neoclide/coc.nvim/issues?q=author%3Arob-3" title="Bug reports">🐛</a></td>
<td align="center"><a href="https://creasty.com"><img src="https://avatars.githubusercontent.com/u/1695538?v=4?s=50" width="50px;" alt=""/><br /><sub><b>Yuki Iwanaga</b></sub></a><br /><a href="https://github.com/neoclide/coc.nvim/commits?author=creasty" title="Code">💻</a></td>
<td align="center"><a href="https://www.dosk.win/"><img src="https://avatars.githubusercontent.com/u/2389889?v=4?s=50" width="50px;" alt=""/><br /><sub><b>SpringHack</b></sub></a><br /><a href="https://github.com/neoclide/coc.nvim/issues?q=author%3Aspringhack" title="Bug reports">🐛</a></td>
<td align="center"><a href="http://git.lmburns.com"><img src="https://avatars.githubusercontent.com/u/44355502?v=4?s=50" width="50px;" alt=""/><br /><sub><b>Lucas Burns</b></sub></a><br /><a href="https://github.com/neoclide/coc.nvim/commits?author=lmburns" title="Documentation">📖</a></td>
</tr>
<tr>
<td align="center"><a href="http://qiqi.boy.im"><img src="https://avatars.githubusercontent.com/u/3774036?v=4?s=50" width="50px;" alt=""/><br /><sub><b>qiqiboy</b></sub></a><br /><a href="https://github.com/neoclide/coc.nvim/commits?author=qiqiboy" title="Code">💻</a></td>
<td align="center"><a href="https://github.com/timsu92"><img src="https://avatars.githubusercontent.com/u/33785401?v=4?s=50" width="50px;" alt=""/><br /><sub><b>timsu92</b></sub></a><br /><a href="https://github.com/neoclide/coc.nvim/commits?author=timsu92" title="Documentation">📖</a></td>
<td align="center"><a href="https://sartak.org"><img src="https://avatars.githubusercontent.com/u/45430?v=4?s=50" width="50px;" alt=""/><br /><sub><b>Shawn M Moore</b></sub></a><br /><a href="https://github.com/neoclide/coc.nvim/commits?author=sartak" title="Code">💻</a></td>
</tr>
</table>

View File

@ -282,12 +282,14 @@ function! s:funcs.buf_add_highlight(bufnr, srcId, hlGroup, line, colStart, colEn
let srcId = a:srcId
endif
let bufnr = a:bufnr == 0 ? bufnr('%') : a:bufnr
let type = a:hlGroup.'_'.srcId
let type = srcId == -1 ? a:hlGroup : a:hlGroup.'_'.srcId
let types = get(s:id_types, srcId, [])
if index(types, type) == -1
call add(types, type)
let s:id_types[srcId] = types
call prop_type_add(type, extend({'highlight': a:hlGroup}, get(a:, 1, {})))
if empty(prop_type_get(type))
call prop_type_add(type, extend({'highlight': a:hlGroup}, get(a:, 1, {})))
endif
endif
let end = a:colEnd == -1 ? strlen(getbufline(bufnr, a:line + 1)[0]) + 1 : a:colEnd + 1
if end < a:colStart + 1
@ -648,6 +650,22 @@ function! coc#api#get_types(srcId) abort
return get(s:id_types, a:srcId, [])
endfunction
function! coc#api#get_id_types() abort
return s:id_types
endfunction
function! coc#api#create_type(srcId, hlGroup, opts) abort
let type = a:hlGroup.'_'.a:srcId
let types = get(s:id_types, a:srcId, [])
if index(types, type) == -1
call add(types, type)
let s:id_types[a:srcId] = types
let combine = get(a:opts, 'hl_mode', 'combine') ==# 'combine'
call prop_type_add(type, {'highlight': a:hlGroup, 'combine': combine})
endif
return type
endfunction
function! coc#api#func_names() abort
return keys(s:funcs)
endfunction

View File

@ -129,14 +129,45 @@ endfunction
function! s:on_stderr(name, msgs)
if get(g:, 'coc_vim_leaving', 0) | return | endif
if get(g:, 'coc_disable_uncaught_error', 0) | return | endif
let data = filter(copy(a:msgs), '!empty(v:val)')
if empty(data) | return | endif
let client = a:name ==# 'coc' ? '[coc.nvim]' : '['.a:name.']'
let data[0] = client.': '.data[0]
if a:name ==# 'coc' && len(filter(copy(data), 'v:val =~# "SyntaxError: Unexpected token"'))
call coc#client#check_version()
endif
if get(g:, 'coc_disable_uncaught_error', 0) | return | endif
call coc#ui#echo_messages('Error', data)
endfunction
function! coc#client#check_version() abort
if (has_key(g:, 'coc_node_path'))
let node = expand(g:coc_node_path)
else
let node = $COC_NODE_PATH == '' ? 'node' : $COC_NODE_PATH
endif
let output = system(node . ' --version')
let msgs = []
if v:shell_error
let msgs = ['Unexpected result from node --version'] + split(output, '\n')
else
let ms = matchlist(output, 'v\(\d\+\).\(\d\+\).\(\d\+\)')
if empty(ms)
let msgs = ['Unable to detect version of node, make sure your node executable is http://nodejs.org/']
elseif str2nr(ms[1]) < 14 || (str2nr(ms[1]) == 14 && str2nr(ms[2]) < 14)
let msgs = ['Current Node.js version '.trim(output).' < 14.14.0 ', 'Please upgrade your node.js']
endif
endif
if !empty(msgs)
call coc#notify#create(msgs, {
\ 'borderhighlight': 'CocErrorSign',
\ 'highlight': 'Normal',
\ 'timeout': 50000,
\ 'kind': 'error',
\ })
endif
endfunction
function! s:on_exit(name, code) abort
if get(g:, 'coc_vim_leaving', 0) | return | endif
let client = get(s:clients, a:name, v:null)

View File

@ -14,6 +14,237 @@ elseif has('mac')
let s:activate = 'activate'
endif
let s:patterns = {}
let s:patterns['hex'] = '\v#?(\x{2})(\x{2})(\x{2})'
let s:patterns['shortHex'] = '\v#(\x{1})(\x{1})(\x{1})'
let s:xterm_colors = {
\ '0': '#000000', '1': '#800000', '2': '#008000', '3': '#808000', '4': '#000080',
\ '5': '#800080', '6': '#008080', '7': '#c0c0c0', '8': '#808080', '9': '#ff0000',
\ '10': '#00ff00', '11': '#ffff00', '12': '#0000ff', '13': '#ff00ff', '14': '#00ffff',
\ '15': '#ffffff', '16': '#000000', '17': '#00005f', '18': '#000087', '19': '#0000af',
\ '20': '#0000df', '21': '#0000ff', '22': '#005f00', '23': '#005f5f', '24': '#005f87',
\ '25': '#005faf', '26': '#005fdf', '27': '#005fff', '28': '#008700', '29': '#00875f',
\ '30': '#008787', '31': '#0087af', '32': '#0087df', '33': '#0087ff', '34': '#00af00',
\ '35': '#00af5f', '36': '#00af87', '37': '#00afaf', '38': '#00afdf', '39': '#00afff',
\ '40': '#00df00', '41': '#00df5f', '42': '#00df87', '43': '#00dfaf', '44': '#00dfdf',
\ '45': '#00dfff', '46': '#00ff00', '47': '#00ff5f', '48': '#00ff87', '49': '#00ffaf',
\ '50': '#00ffdf', '51': '#00ffff', '52': '#5f0000', '53': '#5f005f', '54': '#5f0087',
\ '55': '#5f00af', '56': '#5f00df', '57': '#5f00ff', '58': '#5f5f00', '59': '#5f5f5f',
\ '60': '#5f5f87', '61': '#5f5faf', '62': '#5f5fdf', '63': '#5f5fff', '64': '#5f8700',
\ '65': '#5f875f', '66': '#5f8787', '67': '#5f87af', '68': '#5f87df', '69': '#5f87ff',
\ '70': '#5faf00', '71': '#5faf5f', '72': '#5faf87', '73': '#5fafaf', '74': '#5fafdf',
\ '75': '#5fafff', '76': '#5fdf00', '77': '#5fdf5f', '78': '#5fdf87', '79': '#5fdfaf',
\ '80': '#5fdfdf', '81': '#5fdfff', '82': '#5fff00', '83': '#5fff5f', '84': '#5fff87',
\ '85': '#5fffaf', '86': '#5fffdf', '87': '#5fffff', '88': '#870000', '89': '#87005f',
\ '90': '#870087', '91': '#8700af', '92': '#8700df', '93': '#8700ff', '94': '#875f00',
\ '95': '#875f5f', '96': '#875f87', '97': '#875faf', '98': '#875fdf', '99': '#875fff',
\ '100': '#878700', '101': '#87875f', '102': '#878787', '103': '#8787af', '104': '#8787df',
\ '105': '#8787ff', '106': '#87af00', '107': '#87af5f', '108': '#87af87', '109': '#87afaf',
\ '110': '#87afdf', '111': '#87afff', '112': '#87df00', '113': '#87df5f', '114': '#87df87',
\ '115': '#87dfaf', '116': '#87dfdf', '117': '#87dfff', '118': '#87ff00', '119': '#87ff5f',
\ '120': '#87ff87', '121': '#87ffaf', '122': '#87ffdf', '123': '#87ffff', '124': '#af0000',
\ '125': '#af005f', '126': '#af0087', '127': '#af00af', '128': '#af00df', '129': '#af00ff',
\ '130': '#af5f00', '131': '#af5f5f', '132': '#af5f87', '133': '#af5faf', '134': '#af5fdf',
\ '135': '#af5fff', '136': '#af8700', '137': '#af875f', '138': '#af8787', '139': '#af87af',
\ '140': '#af87df', '141': '#af87ff', '142': '#afaf00', '143': '#afaf5f', '144': '#afaf87',
\ '145': '#afafaf', '146': '#afafdf', '147': '#afafff', '148': '#afdf00', '149': '#afdf5f',
\ '150': '#afdf87', '151': '#afdfaf', '152': '#afdfdf', '153': '#afdfff', '154': '#afff00',
\ '155': '#afff5f', '156': '#afff87', '157': '#afffaf', '158': '#afffdf', '159': '#afffff',
\ '160': '#df0000', '161': '#df005f', '162': '#df0087', '163': '#df00af', '164': '#df00df',
\ '165': '#df00ff', '166': '#df5f00', '167': '#df5f5f', '168': '#df5f87', '169': '#df5faf',
\ '170': '#df5fdf', '171': '#df5fff', '172': '#df8700', '173': '#df875f', '174': '#df8787',
\ '175': '#df87af', '176': '#df87df', '177': '#df87ff', '178': '#dfaf00', '179': '#dfaf5f',
\ '180': '#dfaf87', '181': '#dfafaf', '182': '#dfafdf', '183': '#dfafff', '184': '#dfdf00',
\ '185': '#dfdf5f', '186': '#dfdf87', '187': '#dfdfaf', '188': '#dfdfdf', '189': '#dfdfff',
\ '190': '#dfff00', '191': '#dfff5f', '192': '#dfff87', '193': '#dfffaf', '194': '#dfffdf',
\ '195': '#dfffff', '196': '#ff0000', '197': '#ff005f', '198': '#ff0087', '199': '#ff00af',
\ '200': '#ff00df', '201': '#ff00ff', '202': '#ff5f00', '203': '#ff5f5f', '204': '#ff5f87',
\ '205': '#ff5faf', '206': '#ff5fdf', '207': '#ff5fff', '208': '#ff8700', '209': '#ff875f',
\ '210': '#ff8787', '211': '#ff87af', '212': '#ff87df', '213': '#ff87ff', '214': '#ffaf00',
\ '215': '#ffaf5f', '216': '#ffaf87', '217': '#ffafaf', '218': '#ffafdf', '219': '#ffafff',
\ '220': '#ffdf00', '221': '#ffdf5f', '222': '#ffdf87', '223': '#ffdfaf', '224': '#ffdfdf',
\ '225': '#ffdfff', '226': '#ffff00', '227': '#ffff5f', '228': '#ffff87', '229': '#ffffaf',
\ '230': '#ffffdf', '231': '#ffffff', '232': '#080808', '233': '#121212', '234': '#1c1c1c',
\ '235': '#262626', '236': '#303030', '237': '#3a3a3a', '238': '#444444', '239': '#4e4e4e',
\ '240': '#585858', '241': '#606060', '242': '#666666', '243': '#767676', '244': '#808080',
\ '245': '#8a8a8a', '246': '#949494', '247': '#9e9e9e', '248': '#a8a8a8', '249': '#b2b2b2',
\ '250': '#bcbcbc', '251': '#c6c6c6', '252': '#d0d0d0', '253': '#dadada', '254': '#e4e4e4',
\ '255': '#eeeeee'}
let s:xterm_16colors = {
\ 'black': '#000000',
\ 'darkblue': '#00008B',
\ 'darkgreen': '#00CD00',
\ 'darkcyan': '#00CDCD',
\ 'darkred': '#CD0000',
\ 'darkmagenta': '#8B008B',
\ 'brown': '#CDCD00',
\ 'darkyellow': '#CDCD00',
\ 'lightgrey': '#E5E5E5',
\ 'lightgray': '#E5E5E5',
\ 'gray': '#E5E5E5',
\ 'grey': '#E5E5E5',
\ 'darkgrey': '#7F7F7F',
\ 'darkgray': '#7F7F7F',
\ 'blue': '#5C5CFF',
\ 'lightblue': '#5C5CFF',
\ 'green': '#00FF00',
\ 'lightgreen': '#00FF00',
\ 'cyan': '#00FFFF',
\ 'lightcyan': '#00FFFF',
\ 'red': '#FF0000',
\ 'lightred': '#FF0000',
\ 'magenta': '#FF00FF',
\ 'lightmagenta': '#FF00FF',
\ 'yellow': '#FFFF00',
\ 'lightyellow': '#FFFF00',
\ 'white': '#FFFFFF',
\ }
let s:w3c_color_names = {
\ 'aliceblue': '#F0F8FF',
\ 'antiquewhite': '#FAEBD7',
\ 'aqua': '#00FFFF',
\ 'aquamarine': '#7FFFD4',
\ 'azure': '#F0FFFF',
\ 'beige': '#F5F5DC',
\ 'bisque': '#FFE4C4',
\ 'black': '#000000',
\ 'blanchedalmond': '#FFEBCD',
\ 'blue': '#0000FF',
\ 'blueviolet': '#8A2BE2',
\ 'brown': '#A52A2A',
\ 'burlywood': '#DEB887',
\ 'cadetblue': '#5F9EA0',
\ 'chartreuse': '#7FFF00',
\ 'chocolate': '#D2691E',
\ 'coral': '#FF7F50',
\ 'cornflowerblue': '#6495ED',
\ 'cornsilk': '#FFF8DC',
\ 'crimson': '#DC143C',
\ 'cyan': '#00FFFF',
\ 'darkblue': '#00008B',
\ 'darkcyan': '#008B8B',
\ 'darkgoldenrod': '#B8860B',
\ 'darkgray': '#A9A9A9',
\ 'darkgreen': '#006400',
\ 'darkkhaki': '#BDB76B',
\ 'darkmagenta': '#8B008B',
\ 'darkolivegreen': '#556B2F',
\ 'darkorange': '#FF8C00',
\ 'darkorchid': '#9932CC',
\ 'darkred': '#8B0000',
\ 'darksalmon': '#E9967A',
\ 'darkseagreen': '#8FBC8F',
\ 'darkslateblue': '#483D8B',
\ 'darkslategray': '#2F4F4F',
\ 'darkturquoise': '#00CED1',
\ 'darkviolet': '#9400D3',
\ 'deeppink': '#FF1493',
\ 'deepskyblue': '#00BFFF',
\ 'dimgray': '#696969',
\ 'dodgerblue': '#1E90FF',
\ 'firebrick': '#B22222',
\ 'floralwhite': '#FFFAF0',
\ 'forestgreen': '#228B22',
\ 'fuchsia': '#FF00FF',
\ 'gainsboro': '#DCDCDC',
\ 'ghostwhite': '#F8F8FF',
\ 'gold': '#FFD700',
\ 'goldenrod': '#DAA520',
\ 'gray': '#808080',
\ 'green': '#008000',
\ 'greenyellow': '#ADFF2F',
\ 'honeydew': '#F0FFF0',
\ 'hotpink': '#FF69B4',
\ 'indianred': '#CD5C5C',
\ 'indigo': '#4B0082',
\ 'ivory': '#FFFFF0',
\ 'khaki': '#F0E68C',
\ 'lavender': '#E6E6FA',
\ 'lavenderblush': '#FFF0F5',
\ 'lawngreen': '#7CFC00',
\ 'lemonchiffon': '#FFFACD',
\ 'lightblue': '#ADD8E6',
\ 'lightcoral': '#F08080',
\ 'lightcyan': '#E0FFFF',
\ 'lightgoldenrodyellow': '#FAFAD2',
\ 'lightgray': '#D3D3D3',
\ 'lightgreen': '#90EE90',
\ 'lightpink': '#FFB6C1',
\ 'lightsalmon': '#FFA07A',
\ 'lightseagreen': '#20B2AA',
\ 'lightskyblue': '#87CEFA',
\ 'lightslategray': '#778899',
\ 'lightsteelblue': '#B0C4DE',
\ 'lightyellow': '#FFFFE0',
\ 'lime': '#00FF00',
\ 'limegreen': '#32CD32',
\ 'linen': '#FAF0E6',
\ 'magenta': '#FF00FF',
\ 'maroon': '#800000',
\ 'mediumaquamarine': '#66CDAA',
\ 'mediumblue': '#0000CD',
\ 'mediumorchid': '#BA55D3',
\ 'mediumpurple': '#9370D8',
\ 'mediumseagreen': '#3CB371',
\ 'mediumslateblue': '#7B68EE',
\ 'mediumspringgreen': '#00FA9A',
\ 'mediumturquoise': '#48D1CC',
\ 'mediumvioletred': '#C71585',
\ 'midnightblue': '#191970',
\ 'mintcream': '#F5FFFA',
\ 'mistyrose': '#FFE4E1',
\ 'moccasin': '#FFE4B5',
\ 'navajowhite': '#FFDEAD',
\ 'navy': '#000080',
\ 'oldlace': '#FDF5E6',
\ 'olive': '#808000',
\ 'olivedrab': '#6B8E23',
\ 'orange': '#FFA500',
\ 'orangered': '#FF4500',
\ 'orchid': '#DA70D6',
\ 'palegoldenrod': '#EEE8AA',
\ 'palegreen': '#98FB98',
\ 'paleturquoise': '#AFEEEE',
\ 'palevioletred': '#D87093',
\ 'papayawhip': '#FFEFD5',
\ 'peachpuff': '#FFDAB9',
\ 'peru': '#CD853F',
\ 'pink': '#FFC0CB',
\ 'plum': '#DDA0DD',
\ 'powderblue': '#B0E0E6',
\ 'purple': '#800080',
\ 'red': '#FF0000',
\ 'rosybrown': '#BC8F8F',
\ 'royalblue': '#4169E1',
\ 'saddlebrown': '#8B4513',
\ 'salmon': '#FA8072',
\ 'sandybrown': '#F4A460',
\ 'seagreen': '#2E8B57',
\ 'seashell': '#FFF5EE',
\ 'sienna': '#A0522D',
\ 'silver': '#C0C0C0',
\ 'skyblue': '#87CEEB',
\ 'slateblue': '#6A5ACD',
\ 'slategray': '#708090',
\ 'snow': '#FFFAFA',
\ 'springgreen': '#00FF7F',
\ 'steelblue': '#4682B4',
\ 'tan': '#D2B48C',
\ 'teal': '#008080',
\ 'thistle': '#D8BFD8',
\ 'tomato': '#FF6347',
\ 'turquoise': '#40E0D0',
\ 'violet': '#EE82EE',
\ 'wheat': '#F5DEB3',
\ 'white': '#FFFFFF',
\ 'whitesmoke': '#F5F5F5',
\ 'yellow': '#FFFF00',
\ 'yellowgreen': '#9ACD32'
\ }
" Returns an approximate grey index for the given grey level
fun! s:grey_number(x)
if &t_Co == 88
@ -199,12 +430,125 @@ fun! s:colour(r, g, b)
endif
endfun
function! coc#color#term2rgb(term) abort
if a:term < 0 || a:term > 255
return '#000000'
endif
return s:xterm_colors[a:term]
endfunction
function! coc#color#rgb2term(rgb)
let l:r = ("0x" . strpart(a:rgb, 0, 2)) + 0
let l:g = ("0x" . strpart(a:rgb, 2, 2)) + 0
let l:b = ("0x" . strpart(a:rgb, 4, 2)) + 0
return s:colour(l:r, l:g, l:b)
endfun
endfunction
function! coc#color#rgbToHex(...)
let [r, g, b] = ( a:0==1 ? a:1 : a:000 )
let num = printf('%02x', float2nr(r)) . ''
\ . printf('%02x', float2nr(g)) . ''
\ . printf('%02x', float2nr(b)) . ''
return '#' . num
endfunction
function! coc#color#hexToRgb(color)
if type(a:color) == 2
let color = printf('%x', a:color)
else
let color = a:color
end
let matches = matchlist(color, s:patterns['hex'])
let factor = 0x1
if empty(matches)
let matches = matchlist(color, s:patterns['shortHex'])
let factor = 0x10
end
if len(matches) < 4
echohl Error
echom 'Couldnt parse ' . string(color) . ' ' . string(matches)
echohl None
return
end
let r = str2nr(matches[1], 16) * factor
let g = str2nr(matches[2], 16) * factor
let b = str2nr(matches[3], 16) * factor
return [r, g, b]
endfunction
" @params String color The color
" @params {Number|String|Float} [amount=5] The percentage of light
function! coc#color#lighten(color, ...)
let amount = a:0 ?
\(type(a:1) < 2 ?
\str2float(a:1) : a:1 )
\: 5.0
if(amount < 1.0)
let amount = 1.0 + amount
else
let amount = 1.0 + (amount / 100.0)
end
let rgb = coc#color#hexToRgb(a:color)
let rgb = map(rgb, 'v:val * amount')
let rgb = map(rgb, 'v:val > 255.0 ? 255.0 : v:val')
let rgb = map(rgb, 'float2nr(v:val)')
let hex = coc#color#rgbToHex(rgb)
return hex
endfunction
" @params String color The color
" @params {Number|String|Float} [amount=5] The percentage of darkness
function! coc#color#darken(color, ...)
let amount = a:0 ?
\(type(a:1) < 2 ?
\str2float(a:1) : a:1 )
\: 5.0
if(amount < 1.0)
let amount = 1.0 - amount
else
let amount = 1.0 - (amount / 100.0)
end
if(amount < 0.0)
let amount = 0.0 | end
let rgb = coc#color#hexToRgb(a:color)
let rgb = map(rgb, 'v:val * amount')
let rgb = map(rgb, 'v:val > 255.0 ? 255.0 : v:val')
let rgb = map(rgb, 'float2nr(v:val)')
let hex = coc#color#rgbToHex(rgb)
return hex
endfu
function! coc#color#luminance(rgb) abort
let vals = []
for val in a:rgb
let val = (val + 0.0)/255
if val <= 0.03928
call add(vals, val/12.92)
else
call add(vals, pow((val + 0.055)/1.055, 2.4))
endif
endfor
return vals[0] * 0.2126 + vals[1] * 0.7152 + vals[2] * 0.0722
endfunction
function! coc#color#contrast(rgb1, rgb2) abort
let lnum1 = coc#color#luminance(a:rgb1)
let lnum2 = coc#color#luminance(a:rgb2)
let brightest = lnum1 > lnum2 ? lnum1 : lnum2
let darkest = lnum1 < lnum2 ? lnum1 : lnum2
return (brightest + 0.05) / (darkest + 0.05)
endfunction
function! coc#color#hex_contrast(hex1, hex2) abort
return coc#color#contrast(coc#color#hexToRgb(a:hex1), coc#color#hexToRgb(a:hex2))
endfunction
function! coc#color#nameToHex(name, term) abort
if a:term
return has_key(s:xterm_16colors, a:name) ? s:xterm_16colors[a:name] : v:null
endif
return has_key(s:w3c_color_names, a:name) ? s:w3c_color_names[a:name] : v:null
endfunction
" [r, g, b] ['255', '255', '255']
" return ['65535', '65535', '65535'] or return v:false to cancel
@ -280,4 +624,3 @@ csd.destroy()
endpython
return rgb
endfunction

View File

@ -145,7 +145,7 @@ function! coc#dialog#create_prompt_win(title, default, opts) abort
let bufnr = res[1]
if has('nvim')
let s:prompt_win_bufnr = res[1]
execute 'sign unplace 6 buffer='.s:prompt_win_bufnr
call sign_unplace(s:sign_group, { 'buffer': s:prompt_win_bufnr })
call nvim_set_current_win(winid)
inoremap <buffer> <C-a> <Home>
inoremap <buffer><expr><C-e> pumvisible() ? "\<C-e>" : "\<End>"
@ -312,66 +312,49 @@ function! coc#dialog#prompt_confirm(title, cb) abort
endtry
return
endif
if has('nvim-0.4.0')
let text = ' '. a:title . ' (y/n)? '
let maxWidth = coc#math#min(78, &columns - 2)
let width = coc#math#min(maxWidth, strdisplaywidth(text))
let maxHeight = &lines - &cmdheight - 1
let height = coc#math#min(maxHeight, float2nr(ceil(str2float(string(strdisplaywidth(text)))/width)))
let arr = coc#float#create_float_win(0, s:prompt_win_bufnr, {
\ 'col': &columns/2 - width/2 - 1,
\ 'row': maxHeight/2 - height/2 - 1,
\ 'width': width,
\ 'height': height,
\ 'border': [1,1,1,1],
\ 'focusable': v:false,
\ 'relative': 'editor',
\ 'highlight': 'Normal',
\ 'borderhighlight': 'MoreMsg',
\ 'style': 'minimal',
\ 'lines': [text],
\ })
if empty(arr)
call a:cb('Window create failed!')
return
endif
let winid = arr[0]
let s:prompt_win_bufnr = arr[1]
let res = 0
redraw
" same result as vim
while 1
let key = nr2char(getchar())
if key == "\<C-c>"
let res = -1
break
elseif key == "\<esc>" || key == 'n' || key == 'N'
let res = 0
break
elseif key == 'y' || key == 'Y'
let res = 1
break
endif
endw
call coc#float#close(winid)
call a:cb(v:null, res)
" use relative editor since neovim doesn't support center position
elseif exists('*confirm')
let choice = confirm(a:title, "&Yes\n&No")
call a:cb(v:null, choice == 1)
else
echohl MoreMsg
echom a:title.' (y/n)'
echohl None
let confirm = nr2char(getchar())
redraw!
if !(confirm ==? "y" || confirm ==? "\r")
echohl Moremsg | echo 'Cancelled.' | echohl None
return 0
call a:cb(v:null, 0)
end
call a:cb(v:null, 1)
let text = ' '. a:title . ' (y/n)? '
let maxWidth = coc#math#min(78, &columns - 2)
let width = coc#math#min(maxWidth, strdisplaywidth(text))
let maxHeight = &lines - &cmdheight - 1
let height = coc#math#min(maxHeight, float2nr(ceil(str2float(string(strdisplaywidth(text)))/width)))
let arr = coc#float#create_float_win(0, s:prompt_win_bufnr, {
\ 'col': &columns/2 - width/2 - 1,
\ 'row': maxHeight/2 - height/2 - 1,
\ 'width': width,
\ 'height': height,
\ 'border': [1,1,1,1],
\ 'focusable': v:false,
\ 'relative': 'editor',
\ 'highlight': 'Normal',
\ 'borderhighlight': 'MoreMsg',
\ 'style': 'minimal',
\ 'lines': [text],
\ })
if empty(arr)
call a:cb('Window create failed!')
return
endif
let winid = arr[0]
let s:prompt_win_bufnr = arr[1]
call sign_unplace(s:sign_group, { 'buffer': s:prompt_win_bufnr })
let res = 0
redraw
" same result as vim
while 1
let key = nr2char(getchar())
if key == "\<C-c>"
let res = -1
break
elseif key == "\<esc>" || key == 'n' || key == 'N'
let res = 0
break
elseif key == 'y' || key == 'Y'
let res = 1
break
endif
endw
call coc#float#close(winid)
call a:cb(v:null, res)
endfunction
function! coc#dialog#get_config_editor(lines, config) abort
@ -469,7 +452,7 @@ function! coc#dialog#change_border_hl(winid, hlgroup) abort
else
let winid = coc#float#get_related(a:winid, 'border')
if winid > 0
call setwinvar(winid, '&winhl', 'Normal:'.a:hlgroup.',NormalNC:'.a:hlgroup)
call setwinvar(winid, '&winhl', 'Normal:'.a:hlgroup)
endif
endif
endfunction

View File

@ -154,7 +154,7 @@ function! coc#float#create_float_win(winid, bufnr, config) abort
let config = s:convert_config_nvim(a:config, 0)
let hlgroup = get(a:config, 'highlight', 'CocFloating')
let current = getwinvar(a:winid, '&winhl', '')
let winhl = coc#util#merge_winhl(current, [['Normal', hlgroup], ['NormalNC', hlgroup], ['FoldColumn', hlgroup]])
let winhl = coc#util#merge_winhl(current, [['Normal', hlgroup], ['FoldColumn', hlgroup], ['Search', '']])
if winhl !=# current
call setwinvar(a:winid, '&winhl', winhl)
endif
@ -190,6 +190,8 @@ function! coc#float#create_float_win(winid, bufnr, config) abort
\ 'border': border,
\ 'callback': { -> coc#float#on_close(winid)},
\ 'borderhighlight': [s:get_borderhighlight(a:config)],
\ 'scrollbarhighlight': 'CocFloatSbar',
\ 'thumbhighlight': 'CocFloatThumb',
\ }
let winid = popup_create(bufnr, opts)
if !s:popup_list_api
@ -277,11 +279,11 @@ function! coc#float#nvim_border_win(config, borderchars, winid, border, title, h
endif
if winid
call nvim_win_set_config(winid, opt)
call setwinvar(winid, '&winhl', 'Normal:'.a:hlgroup.',NormalNC:'.a:hlgroup.',Search:')
call setwinvar(winid, '&winhl', 'Normal:'.a:hlgroup.',Search:')
else
noa let winid = nvim_open_win(bufnr, 0, opt)
call setwinvar(winid, 'delta', -1)
let winhl = 'Normal:'.a:hlgroup.',NormalNC:'.a:hlgroup.',Search:'
let winhl = 'Normal:'.a:hlgroup.',Search:'
call s:nvim_add_related(winid, a:winid, 'border', winhl, a:related)
endif
endfunction
@ -306,7 +308,7 @@ function! coc#float#nvim_close_btn(config, winid, border, hlgroup, related) abor
else
let bufnr = coc#float#create_buf(0, ['X'])
noa let winid = nvim_open_win(bufnr, 0, config)
let winhl = 'Normal:'.a:hlgroup.',NormalNC:'.a:hlgroup
let winhl = 'Normal:'.a:hlgroup.',Search:'
call s:nvim_add_related(winid, a:winid, 'close', winhl, a:related)
endif
endfunction
@ -511,9 +513,9 @@ function! coc#float#nvim_scrollbar(winid) abort
call nvim_buf_clear_namespace(sbuf, -1, 0, -1)
for idx in range(0, height - 1)
if idx >= start && idx < start + thumb_height
call nvim_buf_add_highlight(sbuf, -1, 'PmenuThumb', idx, 0, 1)
call nvim_buf_add_highlight(sbuf, -1, 'CocFloatThumb', idx, 0, 1)
else
call nvim_buf_add_highlight(sbuf, -1, 'PmenuSbar', idx, 0, 1)
call nvim_buf_add_highlight(sbuf, -1, 'CocFloatSbar', idx, 0, 1)
endif
endfor
endfunction
@ -610,8 +612,8 @@ function! coc#float#scrollable(winid) abort
endif
if s:is_vim
let pos = popup_getpos(a:winid)
if get(popup_getoptions(a:winid), 'scrollbar', 0)
return get(pos, 'scrollbar', 0)
if get(pos, 'scrollbar', 0)
return 1
endif
let ch = coc#float#content_height(bufnr, pos['core_width'], getwinvar(a:winid, '&wrap'))
return ch > pos['core_height']
@ -685,15 +687,10 @@ function! coc#float#content_height(bufnr, width, wrap) abort
return 0
endif
if !a:wrap
return has('nvim') ? nvim_buf_line_count(a:bufnr) : len(getbufline(a:bufnr, 1, '$'))
return coc#compat#buf_line_count(a:bufnr)
endif
let lines = has('nvim') ? nvim_buf_get_lines(a:bufnr, 0, -1, 0) : getbufline(a:bufnr, 1, '$')
let total = 0
for line in lines
let dw = max([1, strdisplaywidth(line)])
let total += float2nr(ceil(str2float(string(dw))/a:width))
endfor
return total
return coc#string#content_height(lines, a:width)
endfunction
function! coc#float#nvim_refresh_scrollbar(winid) abort
@ -1312,7 +1309,7 @@ endfunction
function! s:set_float_defaults(winid, config) abort
if !s:is_vim
let hlgroup = get(a:config, 'highlight', 'CocFloating')
call setwinvar(a:winid, '&winhl', 'Normal:'.hlgroup.',NormalNC:'.hlgroup.',FoldColumn:'.hlgroup.',Search:')
call setwinvar(a:winid, '&winhl', 'Normal:'.hlgroup.',FoldColumn:'.hlgroup.',Search:')
call setwinvar(a:winid, 'border', get(a:config, 'border', []))
call setwinvar(a:winid, 'scrollinside', get(a:config, 'scrollinside', 0))
if !get(a:config, 'nopad', 0)
@ -1356,7 +1353,7 @@ function! s:nvim_add_related(winid, target, kind, winhl, related) abort
endif
" minimal not work
if !has('nvim-0.4.3')
call setwinvar(a:winid, '&colorcolumn', 0)
call setwinvar(a:winid, '&colorcolumn', '')
call setwinvar(a:winid, '&number', 0)
call setwinvar(a:winid, '&relativenumber', 0)
call setwinvar(a:winid, '&foldcolumn', 0)

View File

@ -8,6 +8,7 @@ let s:ns_id = 1
let s:diagnostic_hlgroups = ['CocErrorHighlight', 'CocWarningHighlight', 'CocInfoHighlight', 'CocHintHighlight', 'CocDeprecatedHighlight', 'CocUnusedHighlight']
" Maximum count to highlight each time.
let g:coc_highlight_maximum_count = get(g:, 'coc_highlight_maximum_count', 100)
let s:term = &termguicolors == 0 && !has('gui_running')
if has('nvim-0.5.0') && s:clear_match_by_window == 0
try
@ -417,17 +418,9 @@ function! coc#highlight#highlight_lines(winid, blocks) abort
endif
endfunction
" Compose 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
return a:fgGroup
endif
if hlexists(hlGroup) && match(execute('hi '.hlGroup, 'silent!'), 'cleared') == -1
return hlGroup
endif
let fgId = synIDtrans(hlID(a:fgGroup))
let bgId = synIDtrans(hlID(a:bgGroup))
function! coc#highlight#compose(fg, bg) abort
let fgId = synIDtrans(hlID(a:fg))
let bgId = synIDtrans(hlID(a:bg))
let isGuiReversed = synIDattr(fgId, 'reverse', 'gui') !=# '1' || synIDattr(bgId, 'reverse', 'gui') !=# '1'
let guifg = isGuiReversed ? synIDattr(fgId, 'fg', 'gui') : synIDattr(fgId, 'bg', 'gui')
let guibg = isGuiReversed ? synIDattr(bgId, 'bg', 'gui') : synIDattr(bgId, 'fg', 'gui')
@ -437,7 +430,7 @@ function! coc#highlight#compose_hlgroup(fgGroup, bgGroup) abort
let bold = synIDattr(fgId, 'bold') ==# '1'
let italic = synIDattr(fgId, 'italic') ==# '1'
let underline = synIDattr(fgId, 'underline') ==# '1'
let cmd = 'silent hi ' . hlGroup
let cmd = ''
if !empty(guifg)
let cmd .= ' guifg=' . guifg
endif
@ -461,13 +454,88 @@ function! coc#highlight#compose_hlgroup(fgGroup, bgGroup) abort
elseif underline
let cmd .= ' cterm=underline gui=underline'
endif
if cmd ==# 'silent hi ' . hlGroup
return cmd
endfunction
" Compose 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
return a:fgGroup
endif
if hlexists(hlGroup) && match(execute('hi '.hlGroup, 'silent!'), 'cleared') == -1
return hlGroup
endif
let cmd = coc#highlight#compose(a:fgGroup, a:bgGroup)
if empty(cmd)
return 'Normal'
endif
execute cmd
execute 'silent hi ' . hlGroup . cmd
return hlGroup
endfunction
" hlGroup id, key => 'fg' | 'bg', kind => 'cterm' | 'gui'
function! coc#highlight#get_color(id, key, kind) abort
if synIDattr(a:id, 'reverse', a:kind) !=# '1'
return synIDattr(a:id, a:key, a:kind)
endif
return synIDattr(a:id, a:key ==# 'bg' ? 'fg' : 'bg', a:kind)
endfunction
function! coc#highlight#get_hl_command(id, key, cterm, gui) abort
let cterm = coc#highlight#get_color(a:id, a:key, 'cterm')
let gui = coc#highlight#get_color(a:id, a:key, 'gui')
let cmd = ' cterm'.a:key.'=' . (empty(cterm) ? a:cterm : cterm)
let cmd .= ' gui'.a:key.'=' . (empty(gui) ? a:gui : gui)
return cmd
endfunction
function! coc#highlight#reversed(id) abort
let gui = has('gui_running') || &termguicolors == 1
if synIDattr(synIDtrans(a:id), 'reverse', gui ? 'gui' : 'cterm') == '1'
return 1
endif
return 0
endfunction
function! coc#highlight#get_contrast(group1, group2) abort
let bg1 = coc#highlight#get_hex_color(synIDtrans(hlID(a:group1)), 'bg', '#000000')
let bg2 = coc#highlight#get_hex_color(synIDtrans(hlID(a:group2)), 'bg', '#000000')
return coc#color#hex_contrast(bg1, bg2)
endfunction
" Darken or lighten background
function! coc#highlight#create_bg_command(group, amount) abort
let id = synIDtrans(hlID(a:group))
let bg = coc#highlight#get_hex_color(id, 'bg', &background ==# 'dark' ? '#282828' : '#fefefe')
let hex = a:amount > 0 ? coc#color#darken(bg, a:amount) : coc#color#lighten(bg, -a:amount)
return 'ctermbg=' . coc#color#rgb2term(strpart(hex, 1)).' guibg=' . hex
endfunction
function! coc#highlight#get_hex_color(id, kind, fallback) abort
let attr = coc#highlight#get_color(a:id, a:kind, s:term ? 'cterm' : 'gui')
let hex = s:to_hex_color(attr, s:term)
if empty(hex) && !s:term
let attr = coc#highlight#get_color(a:id, a:kind, 'cterm')
let hex = s:to_hex_color(attr, 1)
endif
return empty(hex) ? a:fallback : hex
endfunction
function! s:to_hex_color(color, term) abort
if empty(a:color)
return ''
endif
if a:color =~# '^#\x\+$'
return a:color
endif
if a:term && a:color =~# '^\d\+$'
return coc#color#term2rgb(a:color)
endif
let hex = coc#color#nameToHex(tolower(a:color), a:term)
return empty(hex) ? '' : hex
endfunction
" add matches for winid, use 0 for current window.
function! coc#highlight#match_ranges(winid, bufnr, ranges, hlGroup, priority) abort
let winid = a:winid == 0 ? win_getid() : a:winid
@ -694,6 +762,9 @@ function! s:to_group(items) abort
endfunction
function! s:get_priority(key, hlGroup, priority) abort
if a:hlGroup ==# 'CocListSearch'
return 2048
endif
if a:hlGroup ==# 'CocSearch'
return 999
endif

View File

@ -192,6 +192,7 @@ function! coc#list#preview(lines, config) abort
let filetype = get(s:filetype_map, extname, '')
endif
let range = get(a:config, 'range', v:null)
let targetRange = get(a:config, 'targetRange', v:null)
let hlGroup = get(a:config, 'hlGroup', 'Search')
let lnum = get(a:config, 'lnum', 1)
let position = get(a:config, 'position', 'below')
@ -261,7 +262,13 @@ function! coc#list#preview(lines, config) abort
call coc#compat#execute(winid, 'nnoremap <silent><nowait><buffer> <esc> :call CocActionAsync("listCancel")<CR>')
endif
if !empty(range)
call sign_place(1, 'CocCursorLine', 'CocCurrentLine', bufnr, {'lnum': lnum})
if !empty(targetRange)
for lnum in range(targetRange['start']['line'] + 1, targetRange['end']['line'] + 1)
call sign_place(0, 'CocCursorLine', 'CocListCurrent', bufnr, {'lnum': lnum})
endfor
else
call sign_place(0, 'CocCursorLine', 'CocCurrentLine', bufnr, {'lnum': lnum})
endif
call coc#highlight#match_ranges(winid, bufnr, [range], hlGroup, 10)
endif
endfunction

View File

@ -3,11 +3,22 @@ let s:is_vim = !has('nvim')
let s:pum_bufnr = 0
let s:pum_winid = 0
let s:pum_index = -1
let s:pum_size = 0
let s:inserted = 0
let s:virtual_text = 0
let s:virtual_text_ns = 0
let s:virtual_text_ns = coc#highlight#create_namespace('pum-virtual')
let s:ignore = s:is_vim || has('nvim-0.5.0') ? "\<Ignore>" : "\<space>\<bs>"
let s:hide_pum = has('nvim-0.6.1') || has('patch-8.2.3389')
let s:virtual_text_support = has('nvim-0.5.0') || has('patch-9.0.0067')
let s:prop_id = 0
let s:reversed = 0
let s:check_hl_group = 0
if s:is_vim && s:virtual_text_support
if empty(prop_type_get('CocPumVirtualText'))
call prop_type_add('CocPumVirtualText', {'highlight': 'CocPumVirtualText'})
endif
endif
function! coc#pum#visible() abort
if !s:pum_winid
@ -94,6 +105,7 @@ function! s:close_pum() abort
call s:clear_virtual_text()
call coc#float#close(s:pum_winid)
let s:pum_winid = 0
let s:pum_size = 0
let winid = coc#float#get_float_by_kind('pumdetail')
if winid
call coc#float#close(winid)
@ -133,8 +145,7 @@ function! coc#pum#select(index, insert, confirm) abort
call coc#pum#close('cancel')
return ''
endif
let total = coc#compat#buf_line_count(s:pum_bufnr)
if a:index < 0 || a:index >= total
if a:index < 0 || a:index >= s:pum_size
throw 'index out of range ' . a:index
endif
call s:select_by_index(a:index, a:insert)
@ -146,7 +157,6 @@ endfunction
function! coc#pum#info() abort
let bufnr = winbufnr(s:pum_winid)
let size = coc#compat#buf_line_count(bufnr)
let words = getwinvar(s:pum_winid, 'words', [])
let word = s:pum_index < 0 ? '' : get(words, s:pum_index, '')
if s:is_vim
@ -161,9 +171,10 @@ function! coc#pum#info() abort
\ 'col': pos['col'] - 1,
\ 'width': pos['width'] + add,
\ 'height': pos['height'],
\ 'size': size,
\ 'size': s:pum_size,
\ 'border': border,
\ 'inserted': s:inserted ? v:true : v:false,
\ 'reversed': s:reversed ? v:true : v:false,
\ }
else
let scrollbar = coc#float#get_related(s:pum_winid, 'scrollbar')
@ -177,19 +188,19 @@ function! coc#pum#info() abort
\ 'col': pos[1],
\ 'width': nvim_win_get_width(winid),
\ 'height': nvim_win_get_height(winid),
\ 'size': size,
\ 'size': s:pum_size,
\ 'border': winid != s:pum_winid,
\ 'inserted': s:inserted ? v:true : v:false,
\ 'reversed': s:reversed ? v:true : v:false,
\ }
endif
endfunction
function! coc#pum#scroll(forward) abort
if coc#pum#visible()
let size = coc#compat#buf_line_count(s:pum_bufnr)
let height = s:get_height(s:pum_winid)
if size > height
call timer_start(10, { -> s:scroll_pum(a:forward, height, size)})
if s:pum_size > height
call timer_start(10, { -> s:scroll_pum(a:forward, height, s:pum_size)})
endif
endif
return s:ignore
@ -249,7 +260,8 @@ function! s:navigate(next, insert) abort
endfunction
function! s:select_by_index(index, insert) abort
call s:set_cursor(s:pum_winid, a:index + 1)
let lnum = a:index == -1 ? 0 : s:index_to_lnum(a:index)
call s:set_cursor(s:pum_winid, lnum)
if !s:is_vim
call coc#float#nvim_scrollbar(s:pum_winid)
endif
@ -270,11 +282,10 @@ function! s:select_by_index(index, insert) abort
endfunction
function! s:get_index(next) abort
let size = coc#compat#buf_line_count(s:pum_bufnr)
if a:next
let index = s:pum_index + 1 == size ? -1 : s:pum_index + 1
let index = s:pum_index + 1 == s:pum_size ? -1 : s:pum_index + 1
else
let index = s:pum_index == -1 ? size - 1 : s:pum_index - 1
let index = s:pum_index == -1 ? s:pum_size - 1 : s:pum_index - 1
endif
return index
endfunction
@ -290,9 +301,9 @@ function! s:insert_word(word) abort
if saved_completeopt =~ 'menuone'
noa set completeopt=menu
endif
noa call complete(strlen(parts[0]) + 1, [a:word])
noa call complete(strlen(parts[0]) + 1, [{ 'empty': v:true, 'word': a:word }])
" exit complete state
if s:hide_pum
" exit complete state
call feedkeys("\<C-x>\<C-z>", 'in')
else
let g:coc_disable_space_report = 1
@ -320,20 +331,25 @@ function! coc#pum#create(lines, opt, config) abort
if empty(config)
return
endif
let s:virtual_text = has('nvim-0.5.0') && a:opt['virtualText']
if s:virtual_text && !s:virtual_text_ns
let s:virtual_text_ns = coc#highlight#create_namespace('pum-virtual')
endif
let selected = a:opt['index'] + 1
let s:reversed = get(a:config, 'reverse', 0) && config['row'] < 0
let s:virtual_text = s:virtual_text_support && a:opt['virtualText']
let s:pum_size = len(a:lines)
let s:pum_index = a:opt['index']
let lnum = s:index_to_lnum(s:pum_index)
call extend(config, {
\ 'lines': a:lines,
\ 'lines': s:reversed ? reverse(copy(a:lines)) : a:lines,
\ 'relative': 'cursor',
\ 'nopad': 1,
\ 'cursorline': 1,
\ 'index': a:opt['index'],
\ 'index': lnum - 1,
\ 'focusable': v:false
\ })
call extend(config, coc#dict#pick(a:config, ['highlight', 'rounded', 'highlights', 'winblend', 'shadow', 'border', 'borderhighlight']))
if s:reversed
for item in config['highlights']
let item['lnum'] = s:pum_size - item['lnum'] - 1
endfor
endif
if empty(get(config, 'winblend', 0)) && exists('&pumblend')
let config['winblend'] = &pumblend
endif
@ -345,26 +361,22 @@ function! coc#pum#create(lines, opt, config) abort
let s:pum_winid = result[0]
let s:pum_bufnr = result[1]
call setwinvar(s:pum_winid, 'above', config['row'] < 0)
let lnum = max([1, a:opt['index'] + 1])
let firstline = s:get_firstline(lnum, s:pum_size, config['height'])
if s:is_vim
call popup_setoptions(s:pum_winid, {
\ 'firstline': s:get_firstline(lnum, len(a:lines), config['height'])
\ })
call popup_setoptions(s:pum_winid, { 'firstline': firstline })
else
let firstline = s:get_firstline(lnum, len(a:lines), config['height'])
call coc#compat#execute(s:pum_winid, 'call winrestview({"lnum":'.lnum.',"topline":'.firstline.'})')
endif
let s:pum_index = get(config, 'index', -1)
call coc#dialog#place_sign(s:pum_bufnr, s:pum_index + 1)
call setwinvar(s:pum_winid, 'kind', 'pum')
call coc#dialog#place_sign(s:pum_bufnr, s:pum_index == -1 ? 0 : lnum)
" content before col and content after cursor
let linetext = getline('.')
let parts = [strpart(linetext, 0, a:opt['col']), strpart(linetext, col('.') - 1)]
call setwinvar(s:pum_winid, 'input', input)
call setwinvar(s:pum_winid, 'parts', parts)
call setwinvar(s:pum_winid, 'words', a:opt['words'])
call setwinvar(s:pum_winid, 'kind', 'pum')
if !s:is_vim
if len(a:lines) > config['height']
if s:pum_size > config['height']
redraw
call coc#float#nvim_scrollbar(s:pum_winid)
else
@ -383,7 +395,7 @@ endfunction
function! s:on_pum_change(move) abort
if coc#float#valid(s:pum_winid)
if s:virtual_text_ns
if s:virtual_text
call s:insert_virtual_text()
endif
let ev = extend(coc#pum#info(), {'move': a:move ? v:true : v:false})
@ -391,6 +403,16 @@ function! s:on_pum_change(move) abort
endif
endfunction
function! s:index_to_lnum(index) abort
if s:reversed
if a:index <= 0
return s:pum_size
endif
return s:pum_size - a:index
endif
return max([1, a:index + 1])
endfunction
function! s:get_pum_dimension(lines, col, config) abort
let linecount = len(a:lines)
let [lineIdx, colIdx] = coc#cursor#screen_pos()
@ -403,7 +425,7 @@ function! s:get_pum_dimension(lines, col, config) abort
let pumheight = empty(&pumheight) ? vh : &pumheight
let showTop = getwinvar(s:pum_winid, 'above', v:null)
if type(showTop) != v:t_number
if vh - lineIdx - bh - 1 < min([pumheight, linecount]) && lineIdx > vh - lineIdx
if vh - lineIdx - bh - 1 < min([pumheight, linecount]) && vh - lineIdx < min([10, vh/2])
let showTop = 1
else
let showTop = 0
@ -433,63 +455,87 @@ endfunction
function! s:set_cursor(winid, line) abort
if s:is_vim
let pos = popup_getpos(a:winid)
let lastline = pos['firstline'] + pos['core_height'] - 1
let core_height = pos['core_height']
let lastline = pos['firstline'] + core_height - 1
if a:line > lastline
call popup_setoptions(a:winid, {
\ 'firstline': pos['firstline'] + a:line - lastline,
\ })
elseif a:line < pos['firstline']
call popup_setoptions(a:winid, {
\ 'firstline': max([1, a:line]),
\ })
if s:reversed
call popup_setoptions(a:winid, {
\ 'firstline': a:line == 0 ? s:pum_size - core_height + 1 : a:line - core_height + 1,
\ })
else
call popup_setoptions(a:winid, {
\ 'firstline': max([1, a:line]),
\ })
endif
endif
endif
call s:select_line(a:winid, a:line)
endfunction
function! s:select_line(winid, line) abort
let s:pum_index = a:line - 1
let lnum = max([1, a:line])
let s:pum_index = s:reversed ? (a:line == 0 ? -1 : s:pum_size - a:line) : a:line - 1
let lnum = s:reversed ? (a:line == 0 ? s:pum_size : a:line) : max([1, a:line])
if s:is_vim
call coc#compat#execute(a:winid, 'exe '.lnum)
else
call nvim_win_set_cursor(a:winid, [lnum, 0])
endif
call coc#dialog#place_sign(winbufnr(a:winid), a:line)
call coc#dialog#place_sign(s:pum_bufnr, a:line == 0 ? 0 : lnum)
endfunction
function! s:insert_virtual_text() abort
if !s:virtual_text_ns
return
endif
let bufnr = bufnr('%')
if !s:virtual_text || !coc#pum#visible() || s:pum_index < 0
call nvim_buf_clear_namespace(bufnr, s:virtual_text_ns, 0, -1)
if !s:virtual_text || s:pum_index < 0
call s:clear_virtual_text()
else
" Check if could create
let insert = ''
let line = line('.') - 1
let words = getwinvar(s:pum_winid, 'words', [])
let word = get(words, s:pum_index, '')
let parts = getwinvar(s:pum_winid, 'parts', [])
let input = strpart(getline('.'), strlen(parts[0]), col('.') - 1)
let start = strlen(parts[0])
let input = strpart(getline('.'), start, col('.') - 1 - start)
if strchars(word) > strchars(input) && strcharpart(word, 0, strchars(input)) ==# input
let insert = strcharpart(word, strchars(input))
endif
call nvim_buf_clear_namespace(bufnr, s:virtual_text_ns, 0, -1)
if !empty(insert)
let opts = {
\ 'hl_mode': 'combine',
\ 'virt_text': [[insert, 'CocPumVirtualText']],
\ 'virt_text_pos': 'overlay',
\ 'virt_text_win_col': virtcol('.') - 1,
\ }
call nvim_buf_set_extmark(bufnr, s:virtual_text_ns, line('.') - 1, col('.') - 1, opts)
if s:is_vim
if s:prop_id != 0
call prop_remove({'id': s:prop_id}, line + 1, line + 1)
endif
if !empty(insert)
let s:prop_id = prop_add(line + 1, col('.'), {
\ 'text': insert,
\ 'type': 'CocPumVirtualText'
\ })
endif
else
call nvim_buf_clear_namespace(bufnr, s:virtual_text_ns, line, line + 1)
if !empty(insert)
let opts = {
\ 'hl_mode': 'combine',
\ 'virt_text': [[insert, 'CocPumVirtualText']],
\ 'virt_text_pos': 'overlay',
\ 'virt_text_win_col': virtcol('.') - 1,
\ }
call nvim_buf_set_extmark(bufnr, s:virtual_text_ns, line, col('.') - 1, opts)
endif
endif
endif
endfunction
function! s:clear_virtual_text() abort
if s:virtual_text_ns
call nvim_buf_clear_namespace(bufnr('%'), s:virtual_text_ns, 0, -1)
if s:virtual_text_support
if s:is_vim
if s:prop_id != 0
call prop_remove({'id': s:prop_id})
endif
else
call nvim_buf_clear_namespace(bufnr('%'), s:virtual_text_ns, 0, -1)
endif
endif
endfunction

View File

@ -27,12 +27,16 @@ function! coc#snippet#_select_mappings()
snoremap <c-r> <c-g>"_c<c-r>
endfunction
function! coc#snippet#show_choices(lnum, col, len, values) abort
function! coc#snippet#cursor(lnum, col) abort
let m = mode()
call cursor(a:lnum, a:col + a:len)
call cursor(a:lnum, a:col)
if m !=# 'i'
call feedkeys("\<Esc>i", 'in')
endif
endfunction
function! coc#snippet#show_choices(lnum, col, len, values) abort
call coc#snippet#cursor(a:lnum, a:col + a:len)
let changedtick = b:changedtick
call timer_start(20, { -> coc#_do_complete(a:col - 1, a:values, 0, changedtick)})
redraw

View File

@ -39,33 +39,35 @@ function! coc#string#reflow(lines, width) abort
return empty(lines) ? [''] : lines
endfunction
" Used when 'wrap' and 'linebreak' is enabled
function! coc#string#content_height(lines, width) abort
let len = 0
let pattern = empty(&breakat) ? '.\zs' : '['.substitute(&breakat, '\([\[\]]\)', '\\\1', 'g').']\zs'
for line in a:lines
if strwidth(line) <= a:width
let len = len + 1
let len += 1
else
let currlen = 0
for part in split(line, '\<\|\>\|\ze\s')
let w = strwidth(part)
if currlen + w >= a:width
if currlen + w == a:width
let len = len + 1
let currlen = 0
else
let len = len + (a:width + w)/a:width
let currlen = w%a:width
for part in split(line, pattern)
let wl = strwidth(part)
if currlen == 0 && wl > 0
let len += 1
endif
let delta = currlen + wl - a:width
if delta >= 0
let len = len + (delta > 0)
let currlen = delta == 0 ? 0 : wl
if wl >= a:width
let currlen = wl%a:width
let len += float2nr(ceil(wl/(a:width + 0.0))) - (currlen == 0)
endif
else
let currlen = currlen + w
let currlen = currlen + wl
endif
endfor
if currlen > 0
let len = len + 1
endif
endif
endfor
return len == 0 ? 1 : len
return len
endfunction
" get change between two lines

View File

@ -3,22 +3,21 @@ let s:is_win = has('win32') || has('win64')
let s:is_mac = has('mac')
let s:sign_api = exists('*sign_getplaced') && exists('*sign_place')
let s:sign_groups = []
let s:outline_preview_bufnr = 0
" Check <Tab> and <CR>
function! coc#ui#check_pum_keymappings() abort
for key in ['<cr>', '<tab>', '<c-y>']
let lhs = maparg(key, 'i')
if lhs =~# '\<pumvisible()' && lhs !~# '\<coc#pum#visible()'
let lines = [
\ 'coc.nvim switched to custom popup menu from 0.0.82',
\ 'you have to change key-mapping of '.key.' to make it work.',
\ 'checkout current key-mapping by ":verbose imap '.key.'"',
\ 'checkout documentation by ":h coc-completion"']
call coc#notify#create(lines, {
\ 'borderhighlight': 'CocInfoSign',
\ 'timeout': 30000,
\ 'kind': 'warning',
\ })
for key in ['<cr>', '<tab>', '<c-y>', '<s-tab>']
let arg = maparg(key, 'i', 0, 1)
if get(arg, 'expr', 0)
let rhs = get(arg, 'rhs', '')
if rhs =~# '\<pumvisible()' && rhs !~# '\<coc#pum#visible()'
let rhs = substitute(rhs, '\Cpumvisible()', 'coc#pum#visible()', 'g')
let rhs = substitute(rhs, '\c"\\<C-n>"', 'coc#pum#next(1)', '')
let rhs = substitute(rhs, '\c"\\<C-p>"', 'coc#pum#prev(1)', '')
let rhs = substitute(rhs, '\c"\\<C-y>"', 'coc#pum#confirm()', '')
execute 'inoremap <silent><nowait><expr> '.arg['lhs'].' '.rhs
endif
endif
endfor
endfunction
@ -407,38 +406,66 @@ function! coc#ui#update_signs(bufnr, group, signs) abort
if !s:sign_api || !bufloaded(a:bufnr)
return
endif
if len(a:signs)
call add(s:sign_groups, a:group)
endif
let current = get(get(sign_getplaced(a:bufnr, {'group': a:group}), 0, {}), 'signs', [])
let exists = []
let unplaceList = []
for item in current
let index = 0
let placed = 0
for def in a:signs
if def['name'] ==# item['name'] && def['lnum'] == item['lnum']
let placed = 1
call add(exists, index)
break
endif
let index = index + 1
endfor
if !placed
call add(unplaceList, item['id'])
call sign_unplace(a:group, {'buffer': a:bufnr})
for def in a:signs
let opts = {'lnum': def['lnum']}
if has_key(def, 'priority')
let opts['priority'] = def['priority']
endif
endfor
for idx in range(0, len(a:signs) - 1)
if index(exists, idx) == -1
let def = a:signs[idx]
let opts = {'lnum': def['lnum']}
if has_key(def, 'priority')
let opts['priority'] = def['priority']
endif
call sign_place(0, a:group, def['name'], a:bufnr, opts)
endif
endfor
for id in unplaceList
call sign_unplace(a:group, {'buffer': a:bufnr, 'id': id})
call sign_place(0, a:group, def['name'], a:bufnr, opts)
endfor
endfunction
function! coc#ui#outline_preview(config) abort
let view_id = get(w:, 'cocViewId', '')
if view_id !=# 'OUTLINE'
return
endif
let wininfo = get(getwininfo(win_getid()), 0, v:null)
if empty(wininfo)
return
endif
let border = get(a:config, 'border', v:true)
let th = &lines - &cmdheight - 2
let range = a:config['range']
let height = min([range['end']['line'] - range['start']['line'] + 1, th - 4])
let to_left = &columns - wininfo['wincol'] - wininfo['width'] < wininfo['wincol']
let start_lnum = range['start']['line'] + 1
let end_lnum = range['end']['line'] + 1 - start_lnum > &lines ? start_lnum + &lines : range['end']['line'] + 1
let lines = getbufline(a:config['bufnr'], start_lnum, end_lnum)
let content_width = max(map(copy(lines), 'strdisplaywidth(v:val)'))
let width = min([content_width, a:config['maxWidth'], to_left ? wininfo['wincol'] - 3 : &columns - wininfo['wincol'] - wininfo['width']])
let filetype = getbufvar(a:config['bufnr'], '&filetype')
let cursor_row = coc#cursor#screen_pos()[0]
let config = {
\ 'relative': 'editor',
\ 'row': cursor_row - 1 + height < th ? cursor_row - (border ? 1 : 0) : th - height - (border ? 1 : -1),
\ 'col': to_left ? wininfo['wincol'] - 4 - width : wininfo['wincol'] + wininfo['width'],
\ 'width': width,
\ 'height': height,
\ 'lines': lines,
\ 'border': border ? [1,1,1,1] : v:null,
\ 'rounded': get(a:config, 'rounded', 1) ? 1 : 0,
\ 'winblend': a:config['winblend'],
\ 'highlight': a:config['highlight'],
\ 'borderhighlight': a:config['borderhighlight'],
\ }
let winid = coc#float#get_float_by_kind('outline-preview')
let result = coc#float#create_float_win(winid, s:outline_preview_bufnr, config)
if empty(result)
return v:null
endif
call setwinvar(result[0], 'kind', 'outline-preview')
let s:outline_preview_bufnr = result[1]
if !empty(filetype)
call coc#compat#execute(result[0], 'setfiletype '.filetype)
endif
return result[1]
endfunction
function! coc#ui#outline_close_preview() abort
let winid = coc#float#get_float_by_kind('outline-preview')
if winid
call coc#float#close(winid)
endif
endfunction

View File

@ -2,7 +2,7 @@ scriptencoding utf-8
let s:root = expand('<sfile>:h:h:h')
let s:is_win = has('win32') || has('win64')
let s:is_vim = !has('nvim')
let s:vim_api_version = 31
let s:vim_api_version = 32
function! coc#util#remote_fns(name)
let fns = ['init', 'complete', 'should_complete', 'refresh', 'get_startcol', 'on_complete', 'on_enter']
@ -116,9 +116,6 @@ function! coc#util#check_refresh(bufnr)
if getbufvar(a:bufnr, 'coc_diagnostic_disable', 0)
return 0
endif
if get(g: , 'EasyMotion_loaded', 0)
return EasyMotion#is_active() != 1
endif
return 1
endfunction
@ -294,7 +291,6 @@ function! coc#util#vim_info()
\ 'pid': coc#util#getpid(),
\ 'filetypeMap': get(g:, 'coc_filetype_map', {}),
\ 'version': coc#util#version(),
\ 'completeOpt': &completeopt,
\ 'pumevent': 1,
\ 'isVim': has('nvim') ? v:false : v:true,
\ 'isCygwin': has('win32unix') ? v:true : v:false,
@ -309,12 +305,13 @@ function! coc#util#vim_info()
\ 'guicursor': &guicursor,
\ 'pumwidth': exists('&pumwidth') ? &pumwidth : 15,
\ 'tabCount': tabpagenr('$'),
\ 'updateHighlight': has('nvim-0.5.0') || has('patch-8.1.1719') ? v:true : v:false,
\ 'updateHighlight': has('nvim-0.5.0') || has('textprop') ? v:true : v:false,
\ 'vimCommands': get(g:, 'coc_vim_commands', []),
\ 'sign': exists('*sign_place') && exists('*sign_unplace'),
\ 'ambiguousIsNarrow': &ambiwidth ==# 'single' ? v:true : v:false,
\ 'textprop': has('textprop') && has('patch-8.1.1719') && !has('nvim') ? v:true : v:false,
\ 'dialog': has('nvim-0.4.0') || has('patch-8.2.0750') ? v:true : v:false,
\ 'textprop': has('textprop') ? v:true : v:false,
\ 'virtualText': has('nvim-0.5.0') || has('patch-9.0.0067') ? v:true : v:false,
\ 'dialog': has('nvim-0.4.0') || has('popupwin') ? v:true : v:false,
\ 'semanticHighlights': coc#util#semantic_hlgroups()
\}
endfunction
@ -475,26 +472,23 @@ function! coc#util#get_indentkeys() abort
return &indentkeys
endfunction
function! coc#util#get_bufoptions(bufnr) abort
function! coc#util#get_bufoptions(bufnr, max) abort
if !bufloaded(a:bufnr) | return v:null | endif
let bufname = bufname(a:bufnr)
let buftype = getbufvar(a:bufnr, '&buftype')
let winid = bufwinid(a:bufnr)
let size = -1
if bufnr('%') == a:bufnr
let size = line2byte(line("$") + 1)
elseif !empty(bufname)
let size = getfsize(bufname)
endif
let size = coc#util#bufsize(a:bufnr)
let lines = v:null
if getbufvar(a:bufnr, 'coc_enabled', 1) && (buftype == '' || buftype == 'acwrite') && size < get(g:, 'coc_max_filesize', 2097152)
if getbufvar(a:bufnr, 'coc_enabled', 1)
\ && (buftype == '' || buftype == 'acwrite' || getbufvar(a:bufnr, 'coc_force_attach', 0))
\ && size != -2
\ && size < a:max
let lines = getbufline(a:bufnr, 1, '$')
endif
return {
\ 'bufnr': a:bufnr,
\ 'size': size,
\ 'lines': lines,
\ 'winid': winid,
\ 'winid': bufwinid(a:bufnr),
\ 'bufname': bufname,
\ 'buftype': buftype,
\ 'previewwindow': v:false,
@ -508,6 +502,17 @@ function! coc#util#get_bufoptions(bufnr) abort
\}
endfunction
function! coc#util#bufsize(bufnr) abort
if bufnr('%') == a:bufnr
return line2byte(line("$") + 1)
endif
let bufname = bufname(a:bufnr)
if !getbufvar(a:bufnr, '&modified') && filereadable(bufname)
return getfsize(bufname)
endif
return strlen(join(getbufline(a:bufnr, 1, '$'), '\n'))
endfunction
function! coc#util#get_config_home()
if !empty(get(g:, 'coc_config_home', ''))
return resolve(expand(g:coc_config_home))
@ -564,8 +569,13 @@ function! coc#util#get_complete_option()
let line = getline(pos[1])
let input = matchstr(strpart(line, 0, pos[2] - 1), '\k*$')
let col = pos[2] - strlen(input)
let position = {
\ 'line': line('.')-1,
\ 'character': strchars(strpart(getline('.'), 0, col('.') - 1))
\ }
return {
\ 'word': matchstr(strpart(line, col - 1), '^\k\+'),
\ 'position': position,
\ 'input': empty(input) ? '' : input,
\ 'line': line,
\ 'filetype': &filetype,

View File

@ -0,0 +1,36 @@
let s:is_vim = !has('nvim')
let s:virtual_text_support = has('nvim-0.5.0') || has('patch-9.0.0067')
let s:text_options = has('patch-9.0.0121')
" opts.hl_mode default to 'combine'.
" opts.col not used on neovim.
" opts.virt_text_win_col neovim only.
" opts.text_align could be 'after' 'right' 'below', vim9 only.
" opts.text_wrap could be 'wrap' and 'truncate', vim9 only.
function! coc#vtext#add(bufnr, src_id, line, blocks, opts) abort
if !s:virtual_text_support
return
endif
if s:is_vim
for [text, hl] in a:blocks
let type = coc#api#create_type(a:src_id, hl, a:opts)
let column = get(a:opts, 'col', 0)
let opts = { 'text': text, 'type': type }
if s:text_options && column == 0
let opts['text_align'] = get(a:opts, 'text_align', 'after')
let opts['text_wrap'] = get(a:opts, 'text_wrap', 'truncate')
endif
call prop_add(a:line + 1, column, opts)
endfor
else
let opts = {
\ 'virt_text': a:blocks,
\ 'hl_mode': get(a:opts, 'hl_mode', 'combine'),
\ }
if has('nvim-0.5.1') && has_key(a:opts, 'virt_text_win_col')
let opts['virt_text_win_col'] = a:opts['virt_text_win_col']
let opts['virt_text_pos'] = 'overlay'
endif
call nvim_buf_set_extmark(a:bufnr, a:src_id, a:line, 0, opts)
endif
endfunction

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,3 +1,110 @@
# 2022-09-12
- All configurations are now scoped #4185
- No `onDidChangeConfiguration` event fired when workspace folder changed.
- Deprecated configuration `suggest.detailMaxLength`, use `suggest.labelMaxLength` instead.
- Deprecated configuration `inlayHint.filetypes`, use `inlayHint.enable` with scoped languages instead.
- Deprecated configuration `semanticTokens.filetypes`, use `semanticTokens.enable` with scoped languages instead.
- Use `workspaceFolderValue` instead of `workspaceValue` for `ConfigurationInspect` returned by `WorkspaceConfiguration.inspect()`.
# 2022-09-04
- Add configuration "snippet.choicesMenuPicker".
# 2022-09-03
- Send "WinClosed" event to node client.
- Add `onDidFilterStateChange` and `onDidCursorMoved` to `TreeView`.
- Support `autoPreview` for outline.
# 2022-09-02
- Support `diagnostic.virtualTextFormat`.
- Add command `workspace.writeHeapSnapshot`.
# 2022-09-01
- Add configuration "suggest.asciiMatch"
- Support `b:coc_force_attach`.
# 2022-08-31
- Add configuration "suggest.reversePumAboveCursor".
- Use `DiagnosticSign*` highlight groups when possible.
- Use `DiagnosticUnderline*` highlight groups when possible.
# 2022-08-30
- Export `LineBuilder` class.
# 2022-08-29
- Fix semanticTokens highlights unexpected cleared
- Fix range of `doQuickfix` action.
- Check reverse of `CocFloating`, use `border` and `Normal` highlight when reversed.
- Make `CocInlayHint` use background of `SignColumn`.
- Add command `document.toggleInlayHint`.
# 2022-08-28
- Make `CocMenuSel` use background of `PmenuSel`.
- Snippet related configuration changed (old configuration still works until next release)
- "coc.preferences.snippetStatusText" -> "snippet.statusText"
- "coc.preferences.snippetHighlight" -> "snippet.highlight"
- "coc.preferences.nextPlaceholderOnDelete" -> "snippet.nextPlaceholderOnDelete"
- Add configuration `"list.smartCase"`
- Add configurations for inlay hint
- "inlayHint.refreshOnInsertMode"
- "inlayHint.enableParameter"
- "inlayHint.typeSeparator"
- "inlayHint.parameterSeparator"
- "inlayHint.subSeparator"
# 2022-08-27
- Avoid use `EasyMotion#is_active`, use autocmd to disable linting.
- Show message when call hierarchy provider not found or bad position.
# 2022-08-26
- Remove `completeOpt` from `workspace.env`.
- Add configuration `"diagnostic.virtualTextAlign"`.
- Add warning when required features not compiled with vim.
- Not echo error for semanticTokens request (log only).
- Merge results form providers when possible.
# 2022-08-24
- Virtual text of suggest on vim9.
- Virtual text of diagnostics on vim9.
- Add configuration `inlayHint.filetypes`.
- Inlay hint support on vim9.
# 2022-08-23
- Retry semanticTokens request on server cancel (LSP 3.17).
- `RelativePattern` support for `workspace.createFileSystemWatcher()`.
- `relativePatternSupport` for `DidChangeWatchedFiles` (LSP 3.17).
- Not echo error on `doComplete()`.
# 2022-08-21
- Added `window.createFloatFactory()`, deprecated `FloatFactory` class.
- Support `labelDetails` field of `CompleteItem`(LSP 3.17).
- Added `triggerKind` to `CodeActionContext`, export `CodeActionTriggerKind`.
# 2022-08-20
- Support pull diagnostics `:h coc-pullDiagnostics`.
- Break change: avoid extension overwrite builtin configuration defaults.
- Change default value of configuration "diagnostic.format".
- 'line' changes to 'currline' for `CocAction('codeAction')`.
- Check NodeJS version on syntax error.
# 2022-08-10
- Change "notification.highlightGroup" default to "Normal".
# 2022-08-07
- Add configuration 'suggest.pumFloatConfig'.
@ -481,7 +588,7 @@
- **Break change** logic for resolve workspace folder changed.
- Add `Task` module.
- Add `getCurrentFunctionSymbol` action.
- Add `list.source.outline.ctagsFilestypes` setting.
- Add `list.source.outline.ctagsFiletypes` setting.
- Add `suggest.disableMenu` and `suggest.disableMenu` settings.
- Add `equal` support for complete items.
- Add support for do action with visual select lines of list.

View File

@ -31,6 +31,14 @@ function! s:checkVersion() abort
echom "Note that some features may behave incorrectly."
echohl None
sleep 2
elseif !has('nvim') && (!has('job') || !has('popupwin') || !has('textprop'))
echohl WarningMsg
echom "coc.nvim requires job, popupwin and textprop features of vim, consider recompile your vim."
echom "You can add this to your vimrc to avoid this message:"
echom " let g:coc_disable_startup_warning = 1"
echom "Note that some features may behave incorrectly."
echohl None
sleep 2
endif
endif
endif
@ -231,6 +239,15 @@ function! s:AddAnsiGroups() abort
endtry
endfunction
function! s:CreateHighlight(group, fg, bg) abort
let cmd = coc#highlight#compose(a:fg, a:bg)
if !empty(trim(cmd))
exe 'hi default '.a:group.' '.cmd
else
exe 'hi default link '.a:group.' '.a:fg
endif
endfunction
function! s:CursorRangeFromSelected(type, ...) abort
" add range by operator
call coc#rpc#request('cursorsSelect', [bufnr('%'), 'operator', a:type])
@ -284,6 +301,12 @@ function! s:HandleWinScrolled(winid) abort
call s:Autocmd('WinScrolled', a:winid)
endfunction
function! s:HandleWinClosed(winid) abort
call coc#float#on_close(a:winid)
call coc#notify#on_close(a:winid)
call s:Autocmd('WinClosed', a:winid)
endfunction
function! s:SyncAutocmd(...)
if !get(g:, 'coc_workspace_initialized', 0)
return
@ -291,6 +314,14 @@ function! s:SyncAutocmd(...)
call coc#rpc#request('CocAutocmd', a:000)
endfunction
function! s:CheckHighlight() abort
let fgId = synIDtrans(hlID('CocSelectedText'))
let guifg = synIDattr(fgId, 'fg', 'gui')
if empty(guifg)
call s:Highlight()
endif
endfunction
function! s:Enable(initialize)
if get(g:, 'coc_enabled', 0) == 1
return
@ -305,6 +336,11 @@ function! s:Enable(initialize)
elseif get(g:, 'coc_start_at_startup', 1)
autocmd VimEnter * call coc#rpc#start_server()
endif
if v:vim_did_enter
call s:CheckHighlight()
else
autocmd VimEnter * call timer_start(0, { -> s:CheckHighlight()})
endif
if s:is_vim
if exists('##DirChanged')
autocmd DirChanged * call s:Autocmd('DirChanged', getcwd())
@ -323,8 +359,7 @@ function! s:Enable(initialize)
autocmd CursorMoved list:///* call coc#list#select(bufnr('%'), line('.'))
autocmd CursorHold * call coc#float#check_related()
if exists('##WinClosed')
autocmd WinClosed * call coc#float#on_close(+expand('<amatch>'))
autocmd WinClosed * call coc#notify#on_close(+expand('<amatch>'))
autocmd WinClosed * call s:HandleWinClosed(+expand('<amatch>'))
elseif exists('##TabEnter')
autocmd TabEnter * call coc#notify#reflow()
endif
@ -363,7 +398,7 @@ function! s:Enable(initialize)
autocmd VimLeavePre * call s:Autocmd('VimLeavePre')
autocmd BufReadCmd,FileReadCmd,SourceCmd list://* call coc#list#setup(expand('<amatch>'))
autocmd BufWriteCmd __coc_refactor__* :call coc#rpc#notify('saveRefactor', [+expand('<abuf>')])
autocmd ColorScheme * call s:Hi()
autocmd ColorScheme * call s:Highlight()
augroup end
if a:initialize == 0
call coc#rpc#request('attach', [])
@ -373,37 +408,38 @@ function! s:Enable(initialize)
endif
endfunction
function! s:FgColor(hlGroup) abort
let fgId = synIDtrans(hlID(a:hlGroup))
let ctermfg = synIDattr(fgId, 'reverse', 'cterm') ==# '1' ? synIDattr(fgId, 'bg', 'cterm') : synIDattr(fgId, 'fg', 'cterm')
let guifg = synIDattr(fgId, 'reverse', 'gui') ==# '1' ? synIDattr(fgId, 'bg', 'gui') : synIDattr(fgId, 'fg', 'gui')
let cmd = ' ctermfg=' . (empty(ctermfg) ? '223' : ctermfg)
let cmd .= ' guifg=' . (empty(guifg) ? '#ebdbb2' : guifg)
return cmd
endfunction
function! s:Hi() abort
hi default CocErrorSign ctermfg=Red guifg=#ff0000 guibg=NONE
hi default CocWarningSign ctermfg=Brown guifg=#ff922b guibg=NONE
hi default CocInfoSign ctermfg=Yellow guifg=#fab005 guibg=NONE
hi default CocHintSign ctermfg=Blue guifg=#15aabf guibg=NONE
function! s:Highlight() abort
hi default CocSelectedText ctermfg=Red guifg=#fb4934 guibg=NONE
hi default CocCodeLens ctermfg=Gray guifg=#999999 guibg=NONE
hi default CocUnderline term=underline cterm=underline gui=underline
hi default CocUnderline term=underline cterm=underline gui=underline guisp=#ebdbb2
hi default CocBold term=bold cterm=bold gui=bold
hi default CocItalic term=italic cterm=italic gui=italic
hi default CocStrikeThrough term=strikethrough cterm=strikethrough gui=strikethrough
hi default CocMarkdownLink ctermfg=Blue guifg=#15aabf guibg=NONE
hi default CocDisabled guifg=#999999 ctermfg=gray
hi default CocSearch ctermfg=Blue guifg=#15aabf guibg=NONE
hi default CocMenuSel ctermbg=237 guibg=#13354A
if coc#highlight#get_contrast('Normal', has('nvim') ? 'NormalFloat' : 'Pmenu') > 2.0
exe 'hi default CocFloating '.coc#highlight#create_bg_command('Normal', &background ==# 'dark' ? -0.4 : 0.1)
exe 'hi default CocMenuSel '.coc#highlight#create_bg_command('Normal', &background ==# 'dark' ? -0.2 : 0.05)
exe 'hi default CocFloatThumb '.coc#highlight#create_bg_command('Normal', &background ==# 'dark' ? -0.3 : 0.2)
exe 'hi default CocFloatSbar '.coc#highlight#create_bg_command('Normal', &background ==# 'dark' ? -0.5 : 0.3)
else
exe 'hi default link CocFloating '.(has('nvim') ? 'NormalFloat' : 'Pmenu')
if coc#highlight#get_contrast('CocFloating', 'PmenuSel') > 2.0
if &background ==# 'dark'
hi default CocMenuSel ctermbg=237 guibg=#13354A
else
exe 'hi default CocMenuSel '.coc#highlight#create_bg_command('CocFloating', &background ==# 'dark' ? -0.2 : 0.05)
endif
else
exe 'hi default CocMenuSel '.coc#highlight#get_hl_command(synIDtrans(hlID('PmenuSel')), 'bg', '237', '#13354A')
endif
hi default link CocFloatThumb PmenuThumb
hi default link CocFloatSbar PmenuSbar
endif
hi default link CocFadeOut Conceal
hi default link CocMarkdownCode markdownCode
hi default link CocMarkdownHeader markdownH1
hi default link CocErrorHighlight CocUnderline
hi default link CocWarningHighlight CocUnderline
hi default link CocInfoHighlight CocUnderline
hi default link CocHintHighlight CocUnderline
hi default link CocDeprecatedHighlight CocStrikeThrough
hi default link CocUnusedHighlight CocFadeOut
hi default link CocListLine CursorLine
@ -416,7 +452,6 @@ function! s:Hi() abort
hi default link CocLinkedEditing CocCursorRange
hi default link CocHighlightRead CocHighlightText
hi default link CocHighlightWrite CocHighlightText
hi default link CocInlayHint CocHintSign
" Notification
hi default CocNotificationProgress ctermfg=Blue guifg=#15aabf guibg=NONE
hi default link CocNotificationButton CocUnderline
@ -435,16 +470,12 @@ function! s:Hi() abort
hi default link CocSymbolDefault MoreMsg
"Pum
hi default link CocPumSearch CocSearch
hi default link CocPumDetail Comment
hi default link CocPumMenu CocFloating
hi default link CocPumShortcut Comment
hi default link CocPumDeprecated CocStrikeThrough
hi default CocPumVirtualText ctermfg=239 guifg=#504945
hi default link CocPumVirtualText NonText
if has('nvim')
hi default link CocFloating NormalFloat
else
hi default link CocFloating Pmenu
endif
hi default link CocFloatDividingLine NonText
if !exists('*sign_getdefined') || empty(sign_getdefined('CocCurrentLine'))
sign define CocCurrentLine linehl=CocMenuSel
@ -459,27 +490,37 @@ function! s:Hi() abort
hi default CocCursorTransparent gui=strikethrough blend=100
endif
if has('nvim')
let names = ['Error', 'Warning', 'Info', 'Hint']
for name in names
let suffix = name ==# 'Warning' ? 'Warn' : name
if hlexists('DiagnosticVirtualText'.suffix)
exe 'hi default link Coc'.name.'VirtualText DiagnosticVirtualText'.suffix
else
exe 'hi default link Coc'.name.'VirtualText Coc'.name.'Sign'
endif
if hlexists('Diagnostic'.suffix)
exe 'hi default link Coc'.name.'Float Diagnostic'.suffix
else
exe 'hi default link Coc'.name.'Float '.coc#highlight#compose_hlgroup('Coc'.name.'Sign', 'CocFloating')
endif
endfor
else
execute 'hi default link CocErrorFloat '.coc#highlight#compose_hlgroup('CocErrorSign', 'CocFloating')
execute 'hi default link CocWarningFloat '.coc#highlight#compose_hlgroup('CocWarningSign', 'CocFloating')
execute 'hi default link CocInfoFloat '.coc#highlight#compose_hlgroup('CocInfoSign', 'CocFloating')
execute 'hi default link CocHintFloat '.coc#highlight#compose_hlgroup('CocHintSign', 'CocFloating')
endif
let sign_colors = {
\ 'Error': ['Red', '#ff0000'],
\ 'Warn': ['Brown', '#ff922b'],
\ 'Info': ['Yellow', '#fab005'],
\ 'Hint': ['Blue', '#15aabf']
\ }
for name in ['Error', 'Warning', 'Info', 'Hint']
let suffix = name ==# 'Warning' ? 'Warn' : name
if hlexists('DiagnosticUnderline'.suffix)
exe 'hi default link Coc'.name.'Highlight DiagnosticUnderline'.suffix
else
exe 'hi default link Coc'.name.'Highlight CocUnderline'
endif
if hlexists('DiagnosticSign'.suffix)
exe 'hi default link Coc'.name.'Sign DiagnosticSign'.suffix
else
exe 'hi default Coc'.name.'Sign ctermfg='.sign_colors[suffix][0].' guifg='.sign_colors[suffix][1]
endif
if hlexists('DiagnosticVirtualText'.suffix)
exe 'hi default link Coc'.name.'VirtualText DiagnosticVirtualText'.suffix
else
call s:CreateHighlight('Coc'.name.'VirtualText', 'Coc'.name.'Sign', 'Normal')
endif
if hlexists('Diagnostic'.suffix)
exe 'hi default link Coc'.name.'Float Diagnostic'.suffix
else
call s:CreateHighlight('Coc'.name.'Float', 'Coc'.name.'Sign', 'CocFloating')
endif
endfor
call s:CreateHighlight('CocInlayHint', 'CocHintSign', 'SignColumn')
call s:AddAnsiGroups()
if get(g:, 'coc_default_semantic_highlight_groups', 1)
@ -555,7 +596,7 @@ function! s:Hi() abort
for [key, value] in items(symbolMap)
let hlGroup = hlexists(value[0]) ? value[0] : get(value, 1, 'CocSymbolDefault')
if hlexists(hlGroup)
execute 'hi default CocSymbol'.key.' '.s:FgColor(hlGroup)
execute 'hi default CocSymbol'.key.' '.coc#highlight#get_hl_command(synIDtrans(hlID(hlGroup)), 'fg', '223', '#ebdbb2')
endif
endfor
endfunction
@ -629,8 +670,8 @@ command! -nargs=0 CocUpdate :call coc#util#update_extensions(1)
command! -nargs=0 -bar CocUpdateSync :call coc#util#update_extensions()
command! -nargs=* -bar -complete=custom,s:InstallOptions CocInstall :call coc#util#install_extension([<f-args>])
call s:Highlight()
call s:Enable(1)
call s:Hi()
" Default key-mappings for completion
if empty(mapcheck('<C-n>', 'i'))
@ -666,7 +707,7 @@ vnoremap <silent> <Plug>(coc-format-selected) :<C-u>call CocActionAs
vnoremap <silent> <Plug>(coc-codeaction-selected) :<C-u>call CocActionAsync('codeAction', visualmode())<CR>
nnoremap <Plug>(coc-codeaction-selected) :<C-u>set operatorfunc=<SID>CodeActionFromSelected<CR>g@
nnoremap <Plug>(coc-codeaction) :<C-u>call CocActionAsync('codeAction', '')<CR>
nnoremap <Plug>(coc-codeaction-line) :<C-u>call CocActionAsync('codeAction', 'line')<CR>
nnoremap <Plug>(coc-codeaction-line) :<C-u>call CocActionAsync('codeAction', 'currline')<CR>
nnoremap <Plug>(coc-codeaction-cursor) :<C-u>call CocActionAsync('codeAction', 'cursor')<CR>
nnoremap <silent> <Plug>(coc-rename) :<C-u>call CocActionAsync('rename')<CR>
nnoremap <silent> <Plug>(coc-format-selected) :<C-u>set operatorfunc=<SID>FormatFromSelected<CR>g@