1
0
mirror of https://github.com/amix/vimrc synced 2025-07-27 15:04:59 +08:00

Change Rainbow-parenthese plugin into Rainbow plugin.

This commit is contained in:
Kurtis Moxley
2022-08-11 11:57:20 +08:00
parent bbbedb5311
commit 1f4af09835
53 changed files with 2745 additions and 845 deletions

View File

@ -9,7 +9,6 @@ let s:is_vim = !has('nvim')
let s:error_sign = get(g:, 'coc_status_error_sign', has('mac') ? '❌ ' : 'E')
let s:warning_sign = get(g:, 'coc_status_warning_sign', has('mac') ? '⚠️ ' : 'W')
let s:select_api = exists('*nvim_select_popupmenu_item')
let s:complete_info_api = exists('*complete_info')
let s:callbacks = {}
let s:hide_pum = has('nvim-0.6.1') || has('patch-8.2.3389')
@ -33,10 +32,6 @@ function! coc#add_command(id, cmd, ...)
call coc#rpc#notify('addCommand', [config])
endfunction
function! coc#refresh() abort
return "\<c-r>=coc#start()\<CR>"
endfunction
function! coc#on_enter()
call coc#rpc#notify('CocAutocmd', ['Enter', bufnr('%')])
return ''
@ -46,7 +41,6 @@ function! coc#_insert_key(method, key, ...) abort
let prefix = ''
if get(a:, 1, 1)
if pumvisible()
let g:coc_hide_pum = 1
if s:hide_pum
let prefix = "\<C-x>\<C-z>"
else
@ -86,77 +80,12 @@ function! coc#_do_complete(start, items, preselect, changedtick)
\ 'preselect': a:preselect
\}
if mode() =~# 'i'
if s:is_vim
" when the completeopt has longest, the input would be removed sometimes when not use feedkeys!
call feedkeys("\<Plug>CocRefresh", 'i')
else
call coc#_complete()
endif
endif
endfunction
function! coc#_select_confirm() abort
if !exists('*complete_info')
throw 'coc#_select_confirm requires complete_info function to work'
endif
let selected = complete_info()['selected']
if selected != -1
return "\<C-y>"
elseif pumvisible()
return "\<down>\<C-y>"
endif
return ''
endfunction
function! coc#_selected()
if !pumvisible() | return 0 | endif
return coc#rpc#request('hasSelected', [])
endfunction
" Deprecated
function! coc#_hide() abort
if pumvisible()
call feedkeys("\<C-e>", 'in')
call coc#_complete()
endif
endfunction
function! coc#_cancel(...)
" hack for close pum
" Use of <C-e> could cause bad insert when cursor just moved.
let g:coc#_context = {'start': 0, 'preselect': -1,'candidates': []}
if pumvisible()
let g:coc_hide_pum = 1
if get(a:, 1, 0)
" Avoid delayed CompleteDone cancel new completion
let g:coc_disable_complete_done = 1
endif
if s:hide_pum
call feedkeys("\<C-x>\<C-z>", 'in')
else
let g:coc_disable_space_report = 1
call feedkeys("\<space>\<bs>", 'in')
endif
endif
for winid in coc#float#get_float_win_list()
if getwinvar(winid, 'kind', '') ==# 'pum'
call coc#float#close(winid)
endif
endfor
let opt = get(a:, 2, '')
if !empty(opt)
execute 'noa set completeopt='.opt
endif
endfunction
function! coc#_select() abort
if !pumvisible() | return | endif
call feedkeys("\<C-y>", 'in')
endfunction
function! coc#start(...)
let opt = coc#util#get_complete_option()
call CocActionAsync('startCompletion', extend(opt, get(a:, 1, {})))
return ''
call coc#pum#close()
endfunction
" used for statusline
@ -217,10 +146,22 @@ function! coc#do_notify(id, method, result)
endif
endfunction
function! coc#start(...)
let opt = coc#util#get_complete_option()
call CocActionAsync('startCompletion', extend(opt, get(a:, 1, {})))
return ''
endfunction
function! coc#refresh() abort
return "\<c-r>=coc#start()\<CR>"
endfunction
function! coc#_select_confirm() abort
call timer_start(10, { -> coc#pum#select_confirm()})
return s:is_vim || has('nvim-0.5.0') ? "\<Ignore>" : "\<space>\<bs>"
endfunction
function! coc#complete_indent() abort
if has('patch-8.2.3100')
return 0
endif
let curpos = getcurpos()
let indent_len = len(matchstr(getline('.'), '^\s*'))
let startofline = &startofline
@ -234,11 +175,9 @@ function! coc#complete_indent() abort
let curpos[2] += shift
let curpos[4] += shift
call cursor(curpos[1:])
if shift != 0
if shift != 0
if s:is_vim
doautocmd TextChangedP
call timer_start(0, { -> execute('redraw')})
endif
return 1
endif
return 0
endfunction

View File

@ -98,13 +98,7 @@ function! coc#compat#matchaddpos(group, pos, priority, winid) abort
call matchaddpos(a:group, a:pos, a:priority, -1, {'window': a:winid})
endif
else
if has('nvim-0.4.0')
call matchaddpos(a:group, a:pos, a:priority, -1, {'window': a:winid})
elseif exists('*nvim_set_current_win')
noa call nvim_set_current_win(a:winid)
call matchaddpos(a:group, a:pos, a:priority, -1)
noa call nvim_set_current_win(curr)
endif
call matchaddpos(a:group, a:pos, a:priority, -1, {'window': a:winid})
endif
endif
endfunction
@ -129,25 +123,9 @@ endfunction
" hlGroup, pos, priority
function! coc#compat#matchaddgroups(winid, groups) abort
" add by winid
if has('patch-8.1.0218') || has('nvim-0.4.0')
for group in a:groups
call matchaddpos(group['hlGroup'], [group['pos']], group['priority'], -1, {'window': a:winid})
endfor
return
endif
let curr = win_getid()
if curr == a:winid
for group in a:groups
call matchaddpos(group['hlGroup'], [group['pos']], group['priority'], -1)
endfor
elseif exists('*nvim_set_current_win')
noa call nvim_set_current_win(a:winid)
for group in a:groups
call matchaddpos(group['hlGroup'], [group['pos']], group['priority'], -1)
endfor
noa call nvim_set_current_win(curr)
endif
for group in a:groups
call matchaddpos(group['hlGroup'], [group['pos']], group['priority'], -1, {'window': a:winid})
endfor
endfunction
function! coc#compat#del_var(name) abort

View File

@ -4,66 +4,70 @@ let s:root = expand('<sfile>:h:h:h')
let s:prompt_win_bufnr = 0
let s:list_win_bufnr = 0
let s:prompt_win_width = get(g:, 'coc_prompt_win_width', 32)
let s:float_supported = exists('*nvim_open_win') || has('patch-8.1.1719')
let s:frames = ['· ', '·· ', '···', ' ··', ' ·', ' ']
let s:sign_group = 'PopUpCocDialog'
let s:detail_bufnr = 0
" Float window aside pum
function! coc#dialog#create_pum_float(winid, bufnr, lines, config) abort
if !pumvisible() || !s:float_supported
return v:null
function! coc#dialog#create_pum_float(lines, config) abort
let winid = coc#float#get_float_by_kind('pumdetail')
if empty(a:lines) || !coc#pum#visible()
if winid
call coc#float#close(winid)
endif
return
endif
let pumbounding = a:config['pumbounding']
let pw = pumbounding['width'] + get(pumbounding, 'scrollbar', 0)
let pumbounding = coc#pum#info()
let border = get(a:config, 'border', [])
let pw = pumbounding['width'] + (pumbounding['border'] ? 0 : get(pumbounding, 'scrollbar', 0))
let rp = &columns - pumbounding['col'] - pw
let showRight = pumbounding['col'] > rp ? 0 : 1
let maxWidth = showRight ? coc#math#min(rp - 1, a:config['maxWidth']) : coc#math#min(pumbounding['col'] - 1, a:config['maxWidth'])
let border = get(a:config, 'border', [])
let bh = get(border, 0 ,0) + get(border, 2, 0)
let maxHeight = &lines - pumbounding['row'] - &cmdheight - 1 - bh
if maxWidth <= 2 || maxHeight < 1
return v:null
endif
let ch = 0
let width = 0
for line in a:lines
let dw = max([1, strdisplaywidth(line)])
let width = max([width, dw + 2])
let ch += float2nr(ceil(str2float(string(dw))/(maxWidth - 2)))
endfor
let width = float2nr(coc#math#min(maxWidth, width))
let ch = coc#string#content_height(a:lines, width - 2)
let height = float2nr(coc#math#min(maxHeight, ch))
let lines = map(a:lines, {_, s -> s =~# '^─' ? repeat('─', width - 2 + (s:is_vim && ch > height ? -1 : 0)) : s})
let opts = {
\ 'lines': lines,
\ 'highlights': get(a:config, 'highlights', []),
\ 'relative': 'editor',
\ 'col': showRight ? pumbounding['col'] + pw : pumbounding['col'] - width - 1,
\ 'col': showRight ? pumbounding['col'] + pw : pumbounding['col'] - width,
\ 'row': pumbounding['row'],
\ 'height': height,
\ 'width': width - 2 + (s:is_vim && ch > height ? -1 : 0),
\ 'scrollinside': showRight ? 0 : 1,
\ 'codes': get(a:config, 'codes', []),
\ }
for key in ['border', 'highlight', 'borderhighlight', 'winblend', 'focusable', 'shadow']
for key in ['border', 'highlight', 'borderhighlight', 'winblend', 'focusable', 'shadow', 'rounded']
if has_key(a:config, key)
let opts[key] = a:config[key]
endif
endfor
call s:close_auto_hide_wins(a:winid)
let res = coc#float#create_float_win(a:winid, a:bufnr, opts)
if empty(res)
return v:null
call s:close_auto_hide_wins(winid)
let result = coc#float#create_float_win(winid, s:detail_bufnr, opts)
if empty(result)
return
endif
call setwinvar(res[0], 'kind', 'pum')
if has('nvim')
call coc#float#nvim_scrollbar(res[0])
let s:detail_bufnr = result[1]
call setwinvar(result[0], 'kind', 'pumdetail')
if !s:is_vim
call coc#float#nvim_scrollbar(result[0])
endif
return res
endfunction
" Float window below/above cursor
function! coc#dialog#create_cursor_float(winid, bufnr, lines, config) abort
if !s:float_supported || coc#prompt#activated()
if coc#prompt#activated()
return v:null
endif
let pumAlignTop = get(a:config, 'pumAlignTop', 0)
@ -86,7 +90,7 @@ function! coc#dialog#create_cursor_float(winid, bufnr, lines, config) abort
if empty(dimension)
return v:null
endif
if pumvisible() && ((pumAlignTop && dimension['row'] <0)|| (!pumAlignTop && dimension['row'] > 0))
if coc#pum#visible() && ((pumAlignTop && dimension['row'] <0)|| (!pumAlignTop && dimension['row'] > 0))
return v:null
endif
let width = dimension['width']
@ -248,7 +252,6 @@ function! coc#dialog#create_menu(lines, config) abort
return
endif
let s:prompt_win_bufnr = ids[1]
call s:place_sign(s:prompt_win_bufnr, 1)
call coc#dialog#set_cursor(ids[0], ids[1], contentCount + 1)
redraw
if has('nvim')
@ -284,7 +287,7 @@ function! coc#dialog#create_dialog(lines, config) abort
return
endif
if get(a:config, 'cursorline', 0)
call s:place_sign(bufnr, 1)
call coc#dialog#place_sign(bufnr, 1)
endif
if has('nvim')
redraw
@ -324,7 +327,7 @@ function! coc#dialog#prompt_confirm(title, cb) abort
\ 'focusable': v:false,
\ 'relative': 'editor',
\ 'highlight': 'Normal',
\ 'borderhighlight': ['MoreMsg'],
\ 'borderhighlight': 'MoreMsg',
\ 'style': 'minimal',
\ 'lines': [text],
\ })
@ -425,14 +428,13 @@ function! coc#dialog#get_config_cursor(lines, config) abort
return v:null
endif
let maxHeight = coc#math#min(get(a:config, 'maxHeight', vh), vh)
let ch = 0
let width = coc#math#min(40, strdisplaywidth(title)) + 3
for line in a:lines
let dw = max([1, strdisplaywidth(line)])
let width = max([width, dw + 2])
let ch += float2nr(ceil(str2float(string(dw))/(maxWidth - 2)))
endfor
let width = coc#math#min(maxWidth, width)
let ch = coc#string#content_height(a:lines, width - 2)
let [lineIdx, colIdx] = coc#cursor#screen_pos()
" How much we should move left
let offsetX = coc#math#min(get(a:config, 'offsetX', 0), colIdx)
@ -590,7 +592,14 @@ function! coc#dialog#set_cursor(winid, bufnr, line) abort
else
call nvim_win_set_cursor(a:winid, [a:line, 0])
endif
call s:place_sign(a:bufnr, a:line)
call coc#dialog#place_sign(a:bufnr, a:line)
endfunction
function! coc#dialog#place_sign(bufnr, line) abort
call sign_unplace(s:sign_group, { 'buffer': a:bufnr })
if a:line > 0
call sign_place(6, s:sign_group, 'CocCurrentLine', a:bufnr, {'lnum': a:line})
endif
endfunction
" Could be center(with optional marginTop) or cursor
@ -673,10 +682,3 @@ function! s:change_loading_buf(bufnr, idx) abort
call timer_start(100, { -> s:change_loading_buf(a:bufnr, idx)})
endif
endfunction
function! s:place_sign(bufnr, line) abort
call sign_unplace(s:sign_group, { 'buffer': a:bufnr })
if a:line > 0
call sign_place(6, s:sign_group, 'CocCurrentLine', a:bufnr, {'lnum': a:line})
endif
endfunction

View File

@ -102,7 +102,7 @@ endfunction
" - cursorline: (optional) enable cursorline when is 1.
" - autohide: (optional) window should be closed on CursorMoved when is 1.
" - highlight: (optional) highlight of window, default to 'CocFloating'
" - borderhighlight: (optional) should be array for border highlights,
" - borderhighlight: (optional) should be array or string for border highlights,
" highlight all borders with first value.
" - close: (optional) show close button when is 1.
" - highlights: (optional) highlight items.
@ -114,9 +114,18 @@ endfunction
" - scrollinside: (optional) neovim only, create scrollbar inside window.
" - rounded: (optional) use rounded borderchars, ignored when borderchars exists.
" - borderchars: (optional) borderchars, should be length of 8
" - nopad: (optional) not add pad when 1
" - index: (optional) line index
function! coc#float#create_float_win(winid, bufnr, config) abort
let lines = get(a:config, 'lines', v:null)
let bufnr = coc#float#create_buf(a:bufnr, lines, 'hide')
let bufnr = a:bufnr
try
let bufnr = coc#float#create_buf(a:bufnr, lines, 'hide')
catch /E523:/
" happens when using getchar() #3921
return []
endtry
let lnum = max([1, get(a:config, 'index', 0) + 1])
" use exists
if a:winid && coc#float#valid(a:winid)
if s:is_vim
@ -129,21 +138,29 @@ function! coc#float#create_float_win(winid, bufnr, config) abort
\ 'minheight': a:config['height'],
\ 'maxwidth': a:config['width'],
\ 'maxheight': a:config['height'],
\ 'cursorline': get(a:config, 'cursorline', 0),
\ 'title': get(a:config, 'title', ''),
\ 'highlight': get(a:config, 'highlight', 'CocFloating'),
\ 'borderhighlight': [s:get_borderhighlight(a:config)],
\ }
if !s:empty_border(get(a:config, 'border', []))
let opts['border'] = a:config['border']
endif
call popup_setoptions(a:winid, opts)
call win_execute(a:winid, 'exe '.lnum)
call coc#float#vim_buttons(a:winid, a:config)
call s:add_highlights(a:winid, a:config, 0)
return [a:winid, winbufnr(a:winid)]
else
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]])
if winhl !=# current
call setwinvar(a:winid, '&winhl', winhl)
endif
call nvim_win_set_buf(a:winid, bufnr)
call nvim_win_set_config(a:winid, config)
call nvim_win_set_cursor(a:winid, [1, 0])
call nvim_win_set_cursor(a:winid, [lnum, 0])
call coc#float#nvim_create_related(a:winid, config, a:config)
call s:add_highlights(a:winid, a:config, 0)
return [a:winid, bufnr]
@ -155,34 +172,31 @@ function! coc#float#create_float_win(winid, bufnr, config) abort
let title = get(a:config, 'title', '')
let buttons = get(a:config, 'buttons', [])
let hlgroup = get(a:config, 'highlight', 'CocFloating')
let nopad = get(a:config, 'nopad', 0)
let border = s:empty_border(get(a:config, 'border', [])) ? [0, 0, 0, 0] : a:config['border']
let opts = {
\ 'title': title,
\ 'line': line,
\ 'col': col,
\ 'fixed': 1,
\ 'padding': [0, !border[1], 0, !border[3]],
\ 'padding': [0, !nopad && !border[1], 0, !nopad && !border[3]],
\ 'borderchars': s:get_borderchars(a:config),
\ 'highlight': hlgroup,
\ 'cursorline': get(a:config, 'cursorline', 0),
\ 'minwidth': a:config['width'],
\ 'minheight': a:config['height'],
\ 'maxwidth': a:config['width'],
\ 'maxheight': a:config['height'],
\ 'close': get(a:config, 'close', 0) ? 'button' : 'none',
\ 'border': border,
\ 'callback': { -> coc#float#on_close(winid)}
\ 'callback': { -> coc#float#on_close(winid)},
\ 'borderhighlight': [s:get_borderhighlight(a:config)],
\ }
if !empty(get(a:config, 'borderhighlight', v:null))
let borderhighlight = a:config['borderhighlight']
let opts['borderhighlight'] = type(borderhighlight) == 3
\ ? map(borderhighlight, 'coc#highlight#compose_hlgroup(v:val,"'.hlgroup.'")')
\ : [coc#highlight#compose_hlgroup(borderhighlight, hlgroup)]
endif
let winid = popup_create(bufnr, opts)
if !s:popup_list_api
call add(s:popup_list, winid)
endif
call s:set_float_defaults(winid, a:config)
call win_execute(winid, 'exe '.lnum)
call coc#float#vim_buttons(winid, a:config)
else
let config = s:convert_config_nvim(a:config, 1)
@ -194,31 +208,12 @@ function! coc#float#create_float_win(winid, bufnr, config) abort
if winid is 0
return []
endif
let hlgroup = get(a:config, 'highlight', 'CocFloating')
call setwinvar(winid, '&winhl', 'Normal:'.hlgroup.',NormalNC:'.hlgroup.',FoldColumn:'.hlgroup)
call setwinvar(winid, 'border', get(a:config, 'border', []))
call setwinvar(winid, 'scrollinside', get(a:config, 'scrollinside', 0))
call setwinvar(winid, '&foldcolumn', s:nvim_enable_foldcolumn(get(a:config, 'border', v:null)))
call setwinvar(winid, '&cursorline', get(a:config, 'cursorline', 0))
" cursorline highlight not work on old neovim
call s:nvim_set_defaults(winid)
call nvim_win_set_cursor(winid, [1, 0])
call s:set_float_defaults(winid, a:config)
call nvim_win_set_cursor(winid, [lnum, 0])
call coc#float#nvim_create_related(winid, config, a:config)
call coc#float#nvim_set_winblend(winid, get(a:config, 'winblend', v:null))
endif
if get(a:config, 'autohide', 0)
call setwinvar(winid, 'autohide', 1)
endif
if s:is_vim || has('nvim-0.5.0')
call setwinvar(winid, '&scrolloff', 0)
endif
if has('nvim-0.6.0') || has("patch-8.1.2281")
call setwinvar(winid, '&showbreak', 'NONE')
endif
call setwinvar(winid, 'float', 1)
call setwinvar(winid, '&wrap', !get(a:config, 'cursorline', 0))
call setwinvar(winid, '&linebreak', 1)
call setwinvar(winid, '&conceallevel', 0)
call s:add_highlights(winid, a:config, 1)
let g:coc_last_float_win = winid
call coc#util#do_autocmd('CocOpenFloat')
@ -229,11 +224,9 @@ function! coc#float#nvim_create_related(winid, config, opts) abort
let related = getwinvar(a:winid, 'related', [])
let exists = !empty(related)
let border = get(a:opts, 'border', [])
let highlights = get(a:opts, 'borderhighlight', [])
let borderhighlight = type(highlights) == 1 ? highlights : get(highlights, 0, 'CocFloating')
let borderhighlight = coc#highlight#compose_hlgroup(borderhighlight, get(a:opts, 'highlight', 'CocFloating'))
let borderhighlight = s:get_borderhighlight(a:opts)
let buttons = get(a:opts, 'buttons', [])
let pad = empty(border) || get(border, 1, 0) == 0
let pad = !get(a:opts, 'nopad', 0) && (empty(border) || get(border, 1, 0) == 0)
let shadow = get(a:opts, 'shadow', 0)
if get(a:opts, 'close', 0)
call coc#float#nvim_close_btn(a:config, a:winid, border, borderhighlight, related)
@ -284,11 +277,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)
call setwinvar(winid, '&winhl', 'Normal:'.a:hlgroup.',NormalNC:'.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
let winhl = 'Normal:'.a:hlgroup.',NormalNC:'.a:hlgroup.',Search:'
call s:nvim_add_related(winid, a:winid, 'border', winhl, a:related)
endif
endfunction
@ -432,7 +425,7 @@ endfunction
" Create or refresh scrollbar for winid
" Need called on create, config, buffer change, scrolled
function! coc#float#nvim_scrollbar(winid) abort
if !has('nvim-0.4.0')
if s:is_vim
return
endif
let winids = nvim_tabpage_list_wins(nvim_get_current_tabpage())
@ -590,6 +583,25 @@ function! coc#float#get_float_win_list(...) abort
return []
endfunction
function! coc#float#get_float_by_kind(kind) abort
if s:is_vim
if s:popup_list_api
return get(filter(popup_list(), 'popup_getpos(v:val)["visible"] && getwinvar(v:val, "kind", "") ==# "'.a:kind.'"'), 0, 0)
endif
return get(filter(s:popup_list, 's:popup_visible(v:val) && getwinvar(v:val, "kind", "") ==# "'.a:kind.'"'), 0, 0)
else
let res = []
for i in range(1, winnr('$'))
let winid = win_getid(i)
let config = nvim_win_get_config(winid)
if !empty(config['relative']) && getwinvar(winid, 'kind', '') ==# a:kind
return winid
endif
endfor
endif
return 0
endfunction
" Check if a float window is scrollable
function! coc#float#scrollable(winid) abort
let bufnr = winbufnr(a:winid)
@ -625,16 +637,12 @@ function! coc#float#scroll(forward, ...)
throw 'coc#float#scroll() requires nvim >= 0.4.0 or vim >= 8.2.0750'
endif
let amount = get(a:, 1, 0)
let winids = filter(coc#float#get_float_win_list(), 'coc#float#scrollable(v:val)')
let winids = filter(coc#float#get_float_win_list(), 'coc#float#scrollable(v:val) && getwinvar(v:val,"kind","") !=# "pum"')
if empty(winids)
return ''
return mode() =~ '^i' || mode() ==# 'v' ? "" : "\<Ignore>"
endif
for winid in winids
if s:is_vim
call coc#float#scroll_win(winid, a:forward, amount)
else
call timer_start(0, { -> coc#float#scroll_win(winid, a:forward, amount)})
endif
call s:scroll_win(winid, a:forward, amount)
endfor
return mode() =~ '^i' || mode() ==# 'v' ? "" : "\<Ignore>"
endfunction
@ -737,11 +745,11 @@ function! coc#float#check_related() abort
let ids = coc#float#get_float_win_list(1)
for id in ids
let target = getwinvar(id, 'target_winid', 0)
if (target && index(ids, target) == -1) || getwinvar(id, 'kind', '') == 'pum'
if target && index(ids, target) == -1
call add(invalids, id)
endif
endfor
if !s:popup_list_api
if s:is_vim && !s:popup_list_api
let s:popup_list = filter(ids, "index(invalids, v:val) == -1")
endif
for id in invalids
@ -988,7 +996,8 @@ function! coc#float#nvim_scroll_adjust(winid) abort
for winid in winids
if nvim_win_is_valid(winid)
if coc#window#get_var(winid, 'kind', '') != 'close'
let [row, column] = nvim_win_get_position(winid)
let config = nvim_win_get_config(winid)
let [row, column] = [config.row, config.col]
call nvim_win_set_config(winid, {
\ 'row': row,
\ 'col': column - 1,
@ -1041,7 +1050,7 @@ function! s:convert_config_nvim(config, create) abort
endif
let result['width'] = float2nr(result['width'] + 1 - get(border,3, 0))
else
let result['width'] = float2nr(result['width'] + 1)
let result['width'] = float2nr(result['width'] + (get(a:config, 'nopad', 0) ? 0 : 1))
endif
if has('nvim-0.5.1') && a:create
let result['noautocmd'] = v:true
@ -1300,16 +1309,45 @@ function! s:win_setview(winid, topline, lnum) abort
endif
endfunction
function! s:nvim_set_defaults(winid) abort
call setwinvar(a:winid, '&signcolumn', 'auto')
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, 'border', get(a:config, 'border', []))
call setwinvar(a:winid, 'scrollinside', get(a:config, 'scrollinside', 0))
if !get(a:config, 'nopad', 0)
call setwinvar(a:winid, '&foldcolumn', s:nvim_enable_foldcolumn(get(a:config, 'border', v:null)))
endif
call setwinvar(a:winid, '&signcolumn', 'no')
call setwinvar(a:winid, '&cursorcolumn', 0)
else
call setwinvar(a:winid, '&foldcolumn', 0)
endif
if !s:is_vim || !has("patch-8.2.3100")
call setwinvar(a:winid, '&number', 0)
call setwinvar(a:winid, '&relativenumber', 0)
call setwinvar(a:winid, '&cursorline', 0)
endif
call setwinvar(a:winid, '&foldenable', 0)
call setwinvar(a:winid, '&colorcolumn', '')
call setwinvar(a:winid, '&spell', 0)
call setwinvar(a:winid, '&linebreak', 1)
call setwinvar(a:winid, '&conceallevel', 0)
call setwinvar(a:winid, '&list', 0)
call setwinvar(a:winid, '&number', 0)
call setwinvar(a:winid, '&relativenumber', 0)
call setwinvar(a:winid, '&cursorcolumn', 0)
call setwinvar(a:winid, '&colorcolumn', 0)
call setwinvar(a:winid, '&wrap', !get(a:config, 'cursorline', 0))
if s:is_vim || has('nvim-0.5.0')
call setwinvar(a:winid, '&scrolloff', 0)
endif
if has('nvim-0.6.0') || has("patch-8.1.2281")
call setwinvar(a:winid, '&showbreak', 'NONE')
endif
if exists('*win_execute')
call win_execute(a:winid, 'setl fillchars+=eob:\ ')
endif
if get(a:config, 'autohide', 0)
call setwinvar(a:winid, 'autohide', 1)
endif
call setwinvar(a:winid, 'float', 1)
endfunction
function! s:nvim_add_related(winid, target, kind, winhl, related) abort
@ -1372,3 +1410,21 @@ function! s:get_borderchars(config) abort
endif
return get(a:config, 'rounded', 0) ? s:rounded_borderchars : s:borderchars
endfunction
function! s:scroll_win(winid, forward, amount) abort
if s:is_vim
call coc#float#scroll_win(a:winid, a:forward, a:amount)
else
call timer_start(0, { -> coc#float#scroll_win(a:winid, a:forward, a:amount)})
endif
endfunction
function! s:get_borderhighlight(config) abort
let hlgroup = get(a:config, 'highlight', 'CocFloating')
let borderhighlight = get(a:config, 'borderhighlight', v:null)
if empty(borderhighlight)
return hlgroup
endif
let highlight = type(borderhighlight) == 3 ? borderhighlight[0] : borderhighlight
return coc#highlight#compose_hlgroup(highlight, hlgroup)
endfunction

View File

@ -307,7 +307,7 @@ endfunction
function! coc#highlight#add_highlight(bufnr, src_id, hl_group, line, col_start, col_end, ...) abort
let opts = get(a:, 1, {})
let priority = get(opts, 'priority', v:null)
if has('nvim')
if !s:is_vim
if s:set_extmark && a:src_id != -1
" get(opts, 'start_incl', 0) ? v:true : v:false,
try
@ -369,7 +369,9 @@ function! coc#highlight#add_highlights(winid, codes, highlights) abort
endif
if !empty(a:highlights)
for item in a:highlights
call coc#highlight#add_highlight(bufnr, -1, item['hlGroup'], item['lnum'], item['colStart'], item['colEnd'])
let hlGroup = item['hlGroup']
let opts = hlGroup =~# 'Search$' ? {'priority': 999, 'combine': 1} : {}
call coc#highlight#add_highlight(bufnr, -1, hlGroup, item['lnum'], item['colStart'], item['colEnd'])
endfor
endif
endfunction
@ -421,7 +423,7 @@ function! coc#highlight#compose_hlgroup(fgGroup, bgGroup) abort
if a:fgGroup ==# a:bgGroup
return a:fgGroup
endif
if hlexists(hlGroup)
if hlexists(hlGroup) && match(execute('hi '.hlGroup, 'silent!'), 'cleared') == -1
return hlGroup
endif
let fgId = synIDtrans(hlID(a:fgGroup))

View File

@ -294,6 +294,7 @@ function! s:get_topline(config, lnum, winid) abort
endfunction
function! s:set_preview_options(winid) abort
call setwinvar(a:winid, '&foldmethod', 'manual')
call setwinvar(a:winid, '&signcolumn', 'no')
call setwinvar(a:winid, '&number', 1)
call setwinvar(a:winid, '&cursorline', 0)

View File

@ -166,7 +166,7 @@ function! coc#notify#create(lines, config) abort
let height = height + 1
endif
if !empty(actions)
let before = width - strwidth(actionText)
let before = max([width - strwidth(actionText), 0])
let lines = lines + [repeat(' ', before).actionText]
let height = height + 1
call s:add_action_highlights(before, height - 1, highlights, actions)

View File

@ -0,0 +1,495 @@
scriptencoding utf-8
let s:is_vim = !has('nvim')
let s:pum_bufnr = 0
let s:pum_winid = 0
let s:pum_index = -1
let s:inserted = 0
let s:virtual_text = 0
let s:virtual_text_ns = 0
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')
function! coc#pum#visible() abort
if !s:pum_winid
return 0
endif
return getwinvar(s:pum_winid, 'float', 0) == 1
endfunction
function! coc#pum#winid() abort
return s:pum_winid
endfunction
function! coc#pum#close_detail() abort
let winid = coc#float#get_float_by_kind('pumdetail')
if winid
call coc#float#close(winid)
if s:is_vim
call timer_start(0, { -> execute('redraw')})
endif
endif
endfunction
function! coc#pum#close(...) abort
if coc#float#valid(s:pum_winid)
if get(a:, 1, '') ==# 'cancel'
let input = getwinvar(s:pum_winid, 'input', '')
let s:pum_index = -1
call s:insert_word(input)
call s:on_pum_change(0)
doautocmd <nomodeline> TextChangedI
elseif get(a:, 1, '') ==# 'confirm'
let words = getwinvar(s:pum_winid, 'words', [])
if s:pum_index >= 0
let word = get(words, s:pum_index, '')
call s:insert_word(word)
endif
doautocmd <nomodeline> TextChangedI
endif
call s:close_pum()
if !get(a:, 2, 0)
let pretext = strpart(getline('.'), 0, col('.') - 1)
call coc#rpc#notify('CompleteStop', [get(a:, 1, ''), pretext])
endif
endif
endfunction
function! coc#pum#select_confirm() abort
if s:pum_index < 0
let s:pum_index = 0
call s:on_pum_change(0)
endif
call coc#pum#close('confirm')
endfunction
function! coc#pum#insert() abort
call timer_start(10, { -> s:insert_current()})
return s:ignore
endfunction
function! coc#pum#_close() abort
if coc#float#valid(s:pum_winid)
call s:close_pum()
if s:is_vim
call timer_start(0, { -> execute('redraw')})
endif
endif
endfunction
function! s:insert_current() abort
if coc#float#valid(s:pum_winid)
if s:pum_index >= 0
let words = getwinvar(s:pum_winid, 'words', [])
let word = get(words, s:pum_index, '')
call s:insert_word(word)
endif
doautocmd <nomodeline> TextChangedI
call s:close_pum()
let pretext = strpart(getline('.'), 0, col('.') - 1)
call coc#rpc#notify('CompleteStop', ['', pretext])
endif
endfunction
function! s:close_pum() abort
call s:clear_virtual_text()
call coc#float#close(s:pum_winid)
let s:pum_winid = 0
let winid = coc#float#get_float_by_kind('pumdetail')
if winid
call coc#float#close(winid)
endif
endfunction
function! coc#pum#next(insert) abort
call timer_start(10, { -> s:navigate(1, a:insert)})
return s:ignore
endfunction
function! coc#pum#prev(insert) abort
call timer_start(10, { -> s:navigate(0, a:insert)})
return s:ignore
endfunction
function! coc#pum#stop() abort
call timer_start(10, { -> coc#pum#close()})
return s:ignore
endfunction
function! coc#pum#cancel() abort
call timer_start(10, { -> coc#pum#close('cancel')})
return s:ignore
endfunction
function! coc#pum#confirm() abort
call timer_start(10, { -> coc#pum#close('confirm')})
return s:ignore
endfunction
function! coc#pum#select(index, insert, confirm) abort
if !coc#float#valid(s:pum_winid)
return ''
endif
if a:index == -1
call coc#pum#close('cancel')
return ''
endif
let total = coc#compat#buf_line_count(s:pum_bufnr)
if a:index < 0 || a:index >= total
throw 'index out of range ' . a:index
endif
call s:select_by_index(a:index, a:insert)
if a:confirm
call coc#pum#close('confirm')
endif
return ''
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
let pos = popup_getpos(s:pum_winid)
let border = has_key(popup_getoptions(s:pum_winid), 'border')
let add = pos['scrollbar'] && border ? 1 : 0
return {
\ 'word': word,
\ 'index': s:pum_index,
\ 'scrollbar': pos['scrollbar'],
\ 'row': pos['line'] - 1,
\ 'col': pos['col'] - 1,
\ 'width': pos['width'] + add,
\ 'height': pos['height'],
\ 'size': size,
\ 'border': border,
\ 'inserted': s:inserted ? v:true : v:false,
\ }
else
let scrollbar = coc#float#get_related(s:pum_winid, 'scrollbar')
let winid = coc#float#get_related(s:pum_winid, 'border', s:pum_winid)
let pos = nvim_win_get_position(winid)
return {
\ 'word': word,
\ 'index': s:pum_index,
\ 'scrollbar': scrollbar && nvim_win_is_valid(scrollbar) ? 1 : 0,
\ 'row': pos[0],
\ 'col': pos[1],
\ 'width': nvim_win_get_width(winid),
\ 'height': nvim_win_get_height(winid),
\ 'size': size,
\ 'border': winid != s:pum_winid,
\ 'inserted': s:inserted ? 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)})
endif
endif
return s:ignore
endfunction
function! s:get_height(winid) abort
if has('nvim')
return nvim_win_get_height(a:winid)
endif
return get(popup_getpos(a:winid), 'core_height', 0)
endfunction
function! s:scroll_pum(forward, height, size) abort
let topline = s:get_topline(s:pum_winid)
if !a:forward && topline == 1
if s:pum_index >= 0
call s:select_line(s:pum_winid, 1)
call s:on_pum_change(1)
endif
return
endif
if a:forward && topline + a:height - 1 >= a:size
if s:pum_index >= 0
call s:select_line(s:pum_winid, a:size)
call s:on_pum_change(1)
endif
return
endif
call coc#float#scroll_win(s:pum_winid, a:forward, a:height)
if s:pum_index >= 0
let lnum = s:pum_index + 1
let topline = s:get_topline(s:pum_winid)
if lnum >= topline && lnum <= topline + a:height - 1
return
endif
call s:select_line(s:pum_winid, topline)
call s:on_pum_change(1)
endif
endfunction
function! s:get_topline(winid) abort
if has('nvim')
let info = getwininfo(a:winid)[0]
return info['topline']
else
let pos = popup_getpos(a:winid)
return pos['firstline']
endif
endfunction
function! s:navigate(next, insert) abort
if !coc#float#valid(s:pum_winid)
return
endif
let index = s:get_index(a:next)
call s:select_by_index(index, a:insert)
endfunction
function! s:select_by_index(index, insert) abort
call s:set_cursor(s:pum_winid, a:index + 1)
if !s:is_vim
call coc#float#nvim_scrollbar(s:pum_winid)
endif
if a:insert
let s:inserted = 1
if a:index < 0
let input = getwinvar(s:pum_winid, 'input', '')
call s:insert_word(input)
call coc#pum#close_detail()
else
let words = getwinvar(s:pum_winid, 'words', [])
let word = get(words, a:index, '')
call s:insert_word(word)
endif
doautocmd <nomodeline> TextChangedP
endif
call s:on_pum_change(1)
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
else
let index = s:pum_index == -1 ? size - 1 : s:pum_index - 1
endif
return index
endfunction
function! s:insert_word(word) abort
let parts = getwinvar(s:pum_winid, 'parts', [])
if !empty(parts) && mode() ==# 'i'
let curr = getline('.')
if curr ==# parts[0].a:word.parts[1]
return
endif
let saved_completeopt = &completeopt
if saved_completeopt =~ 'menuone'
noa set completeopt=menu
endif
noa call complete(strlen(parts[0]) + 1, [a:word])
if s:hide_pum
" exit complete state
call feedkeys("\<C-x>\<C-z>", 'in')
else
let g:coc_disable_space_report = 1
call feedkeys("\<space>\<bs>", 'in')
endif
execute 'noa set completeopt='.saved_completeopt
endif
endfunction
" create or update pum with lines, CompleteOption and config.
" return winid & dimension
function! coc#pum#create(lines, opt, config) abort
if mode() !=# 'i' || a:opt['line'] != line('.')
return
endif
let len = col('.') - a:opt['col'] - 1
if len < 0
return
endif
let input = len == 0 ? '' : strpart(getline('.'), a:opt['col'], len)
if input !=# a:opt['input']
return
endif
let config = s:get_pum_dimension(a:lines, a:opt['col'], a:config)
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
call extend(config, {
\ 'lines': a:lines,
\ 'relative': 'cursor',
\ 'nopad': 1,
\ 'cursorline': 1,
\ 'index': a:opt['index'],
\ 'focusable': v:false
\ })
call extend(config, coc#dict#pick(a:config, ['highlight', 'rounded', 'highlights', 'winblend', 'shadow', 'border', 'borderhighlight']))
if empty(get(config, 'winblend', 0)) && exists('&pumblend')
let config['winblend'] = &pumblend
endif
let result = coc#float#create_float_win(s:pum_winid, s:pum_bufnr, config)
if empty(result)
return
endif
let s:inserted = 0
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])
if s:is_vim
call popup_setoptions(s:pum_winid, {
\ 'firstline': s:get_firstline(lnum, len(a:lines), config['height'])
\ })
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')
" 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'])
if !s:is_vim
if len(a:lines) > config['height']
redraw
call coc#float#nvim_scrollbar(s:pum_winid)
else
call coc#float#close_related(s:pum_winid, 'scrollbar')
endif
endif
call timer_start(10, { -> s:on_pum_change(0)})
endfunction
function! s:get_firstline(lnum, total, height) abort
if a:lnum <= a:height
return 1
endif
return min([a:total - a:height + 1, a:lnum - (a:height*2/3)])
endfunction
function! s:on_pum_change(move) abort
if coc#float#valid(s:pum_winid)
if s:virtual_text_ns
call s:insert_virtual_text()
endif
let ev = extend(coc#pum#info(), {'move': a:move ? v:true : v:false})
call coc#rpc#notify('CocAutocmd', ['MenuPopupChanged', ev, win_screenpos(winnr())[0] + winline() - 2])
endif
endfunction
function! s:get_pum_dimension(lines, col, config) abort
let linecount = len(a:lines)
let [lineIdx, colIdx] = coc#cursor#screen_pos()
let bh = empty(get(a:config, 'border', [])) ? 0 : 2
let width = min([&columns, max([exists('&pumwidth') ? &pumwidth : 15, a:config['width']])])
let vh = &lines - &cmdheight - 1 - !empty(&tabline)
if vh <= 0
return v:null
endif
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
let showTop = 1
else
let showTop = 0
endif
endif
let height = showTop ? min([lineIdx - bh - !empty(&tabline), linecount, pumheight]) : min([vh - lineIdx - bh - 1, linecount, pumheight])
if height <= 0
return v:null
endif
let col = - (col('.') - a:col - 1) - 1
let row = showTop ? - height : 1
let delta = colIdx + col
if delta < 0
let col = col - delta
elseif delta + width > &columns
let col = max([-colIdx, col - (delta + width - &columns)])
endif
return {
\ 'row': row,
\ 'col': col,
\ 'width': width,
\ 'height': height
\ }
endfunction
" can't use coc#dialog#set_cursor on vim8, don't know why
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
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]),
\ })
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])
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)
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)
else
" Check if could create
let insert = ''
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)
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)
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)
endif
endfunction

View File

@ -105,8 +105,8 @@ function! coc#snippet#disable()
endfunction
function! coc#snippet#select(start, end, text) abort
if pumvisible()
call coc#_cancel()
if coc#pum#visible()
call coc#pum#close()
endif
if mode() == 's'
call feedkeys("\<Esc>", 'in')
@ -134,8 +134,8 @@ function! coc#snippet#move(position) abort
let m = mode()
if m == 's'
call feedkeys("\<Esc>", 'in')
elseif pumvisible()
call coc#_cancel()
elseif coc#pum#visible()
call coc#pum#close()
endif
let pos = coc#snippet#to_cursor(a:position)
call cursor(pos)

View File

@ -39,6 +39,35 @@ function! coc#string#reflow(lines, width) abort
return empty(lines) ? [''] : lines
endfunction
function! coc#string#content_height(lines, width) abort
let len = 0
for line in a:lines
if strwidth(line) <= a:width
let len = 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
endif
else
let currlen = currlen + w
endif
endfor
if currlen > 0
let len = len + 1
endif
endif
endfor
return len == 0 ? 1 : len
endfunction
" get change between two lines
function! coc#string#diff(curr, previous, col) abort
let end = strpart(a:curr, a:col - 1)

View File

@ -4,6 +4,25 @@ let s:is_mac = has('mac')
let s:sign_api = exists('*sign_getplaced') && exists('*sign_place')
let s:sign_groups = []
" 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',
\ })
endif
endfor
endfunction
function! coc#ui#quickpick(title, items, cb) abort
if exists('*popup_menu')
function! s:QuickpickHandler(id, result) closure
@ -249,22 +268,25 @@ function! coc#ui#set_lines(bufnr, changedtick, original, replacement, start, end
if !empty(a:col)
let delta = col('.') - a:col
endif
if getbufvar(a:bufnr, 'changedtick') != a:changedtick && bufnr('%') == a:bufnr
if getbufvar(a:bufnr, 'changedtick') > a:changedtick && bufnr('%') == a:bufnr
" try apply current line change
let lnum = line('.')
let idx = a:start - lnum + 1
let previous = get(a:original, idx, 0)
if type(previous) == 1
let content = getline('.')
if previous !=# content
let diff = coc#string#diff(content, previous, col('.'))
let changed = get(a:replacement, idx, 0)
if type(changed) == 1 && strcharpart(previous, 0, diff['end']) ==# strcharpart(changed, 0, diff['end'])
let applied = coc#string#apply(changed, diff)
let replacement = copy(a:replacement)
let replacement[idx] = applied
call coc#compat#buf_set_lines(a:bufnr, a:start, a:end, replacement)
return
" change for current line
if a:end - a:start == 1 && a:end == lnum && len(a:replacement) == 1
let idx = a:start - lnum + 1
let previous = get(a:original, idx, 0)
if type(previous) == 1
let content = getline('.')
if previous !=# content
let diff = coc#string#diff(content, previous, col('.'))
let changed = get(a:replacement, idx, 0)
if type(changed) == 1 && strcharpart(previous, 0, diff['end']) ==# strcharpart(changed, 0, diff['end'])
let applied = coc#string#apply(changed, diff)
let replacement = copy(a:replacement)
let replacement[idx] = applied
call coc#compat#buf_set_lines(a:bufnr, a:start, a:end, replacement)
return
endif
endif
endif
endif
@ -340,11 +362,7 @@ function! coc#ui#rename_file(oldPath, newPath, write) abort
execute 'keepalt tab drop '.fnameescape(bufname(bufnr))
let winid = win_getid()
endif
if exists('*nvim_buf_set_name')
call nvim_buf_set_name(bufnr, bufname)
else
call coc#compat#execute(winid, 'file '.fnameescape(bufname), 'silent')
endif
call coc#compat#execute(winid, 'keepalt file '.fnameescape(bufname), 'silent')
call coc#compat#execute(winid, 'doautocmd BufEnter')
if a:write
call coc#compat#execute(winid, 'noa write!', 'silent')

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 = 30
let s:vim_api_version = 31
function! coc#util#remote_fns(name)
let fns = ['init', 'complete', 'should_complete', 'refresh', 'get_startcol', 'on_complete', 'on_enter']
@ -15,6 +15,19 @@ function! coc#util#remote_fns(name)
return res
endfunction
function! coc#util#merge_winhl(curr, hls) abort
let highlightMap = {}
for parts in map(split(a:curr, ','), 'split(v:val, ":")')
if len(parts) == 2
let highlightMap[parts[0]] = parts[1]
endif
endfor
for item in a:hls
let highlightMap[item[0]] = item[1]
endfor
return join(map(items(highlightMap), 'v:val[0].":".v:val[1]'), ',')
endfunction
function! coc#util#do_complete(name, opt, cb) abort
let handler = 'coc#source#'.a:name.'#complete'
let l:Cb = {res -> a:cb(v:null, res)}
@ -24,9 +37,9 @@ endfunction
function! coc#util#suggest_variables(bufnr) abort
return {
\ 'coc_suggest_disable': getbufvar(a:bufnr, 'coc_suggest_disable', 0),
\ 'coc_disabled_sources': getbufvar(a:bufnr, 'coc_disabled_sources', []),
\ 'coc_suggest_blacklist': getbufvar(a:bufnr, 'coc_suggest_blacklist', []),
\ 'disable': getbufvar(a:bufnr, 'coc_suggest_disable', 0),
\ 'disabled_sources': getbufvar(a:bufnr, 'coc_disabled_sources', []),
\ 'blacklist': getbufvar(a:bufnr, 'coc_suggest_blacklist', []),
\ }
endfunction
@ -282,7 +295,7 @@ function! coc#util#vim_info()
\ 'filetypeMap': get(g:, 'coc_filetype_map', {}),
\ 'version': coc#util#version(),
\ 'completeOpt': &completeopt,
\ 'pumevent': exists('##MenuPopupChanged') || exists('##CompleteChanged'),
\ 'pumevent': 1,
\ 'isVim': has('nvim') ? v:false : v:true,
\ 'isCygwin': has('win32unix') ? v:true : v:false,
\ 'isMacvim': has('gui_macvim') ? v:true : v:false,
@ -294,10 +307,12 @@ function! coc#util#vim_info()
\ 'locationlist': get(g:,'coc_enable_locationlist', 1),
\ 'progpath': v:progpath,
\ 'guicursor': &guicursor,
\ 'pumwidth': exists('&pumwidth') ? &pumwidth : 15,
\ 'tabCount': tabpagenr('$'),
\ 'updateHighlight': has('nvim-0.5.0') || has('patch-8.1.1719') ? 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,
\ 'semanticHighlights': coc#util#semantic_hlgroups()

View File

@ -22,6 +22,13 @@ function! coc#window#tabnr(winid) abort
endif
endfunction
function! coc#window#get_cursor(winid) abort
if exists('*nvim_win_get_cursor')
return nvim_win_get_cursor(a:winid)
endif
return coc#api#exec('win_get_cursor', [a:winid])
endfunction
" Check if winid visible on current tabpage
function! coc#window#visible(winid) abort
if s:is_vim

View File

@ -16,8 +16,8 @@ endfunction
function! s:checkEnvironment() abort
let valid
\ = s:checkVim(has('nvim'), 'nvim', 'nvim-0.3.2')
\ + s:checkVim(!has('nvim'), 'vim', 'patch-0.8.1453')
\ = s:checkVim(has('nvim'), 'nvim', 'nvim-0.4.0')
\ + s:checkVim(!has('nvim'), 'vim', 'patch-8.1.1719')
let node = get(g:, 'coc_node_path', $COC_NODE_PATH == '' ? 'node' : $COC_NODE_PATH)
if !executable(node)
let valid = 0
@ -32,9 +32,9 @@ function! s:checkEnvironment() abort
if empty(ms)
let valid = 0
call health#report_error('Unable to detect version of node, make sure your node executable is http://nodejs.org/')
elseif str2nr(ms[1]) < 12 || (str2nr(ms[1]) == 12 && str2nr(ms[2]) < 12)
elseif str2nr(ms[1]) < 14 || (str2nr(ms[1]) == 14 && str2nr(ms[2]) < 14)
let valid = 0
call health#report_warn('Node.js version '.trim(output).' < 12.12.0, please upgrade node.js')
call health#report_warn('Node.js version '.trim(output).' < 14.14.0, please upgrade node.js')
endif
if valid
call health#report_ok('Environment check passed')