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

Update Coc.nvim

This commit is contained in:
Kurtis Moxley
2022-05-27 15:57:56 +08:00
parent 15599f5565
commit 71e3f2fa49
18 changed files with 1247 additions and 542 deletions

View File

@ -358,11 +358,12 @@ function! s:funcs.buf_get_lines(bufnr, start, end, strict) abort
endfunction
function! s:funcs.buf_set_lines(bufnr, start, end, strict, ...) abort
if !bufloaded(a:bufnr)
let bufnr = a:bufnr == 0 ? bufnr('%') : a:bufnr
if !bufloaded(bufnr)
return
endif
let replacement = get(a:, 1, [])
let lineCount = s:buf_line_count(a:bufnr)
let lineCount = s:buf_line_count(bufnr)
let startLnum = a:start >= 0 ? a:start + 1 : lineCount + a:start + 2
let end = a:end >= 0 ? a:end : lineCount + a:end + 1
if end == lineCount + 1
@ -371,11 +372,11 @@ function! s:funcs.buf_set_lines(bufnr, start, end, strict, ...) abort
let delCount = end - (startLnum - 1)
let changeBuffer = 0
let curr = bufnr('%')
if a:bufnr != curr && !exists('*setbufline')
if bufnr != curr && !exists('*setbufline')
let changeBuffer = 1
exe 'buffer '.a:bufnr
exe 'buffer '.bufnr
endif
if a:bufnr == curr || changeBuffer
if bufnr == curr || changeBuffer
" replace
let storeView = winsaveview()
if delCount == len(replacement)
@ -405,18 +406,18 @@ function! s:funcs.buf_set_lines(bufnr, start, end, strict, ...) abort
" replace
if delCount == len(replacement)
" 8.0.1039
call setbufline(a:bufnr, startLnum, replacement)
call setbufline(bufnr, startLnum, replacement)
else
if len(replacement)
" 8.10037
call appendbufline(a:bufnr, startLnum - 1, replacement)
call appendbufline(bufnr, startLnum - 1, replacement)
endif
if delCount
let start = startLnum + len(replacement)
let saved_reg = @"
let system_reg = @*
"8.1.0039
silent call deletebufline(a:bufnr, start, start + delCount - 1)
silent call deletebufline(bufnr, start, start + delCount - 1)
let @" = saved_reg
let @* = system_reg
endif

View File

@ -13,7 +13,7 @@ endfunction
function! coc#compat#buf_set_lines(bufnr, start, end, replacement) abort
if s:is_vim
call coc#api#notify('buf_set_lines', [a:bufnr, a:start, a:end, 0, a:replacement])
call coc#api#exec('buf_set_lines', [a:bufnr, a:start, a:end, 0, a:replacement])
else
call nvim_buf_set_lines(a:bufnr, a:start, a:end, 0, a:replacement)
endif

View File

@ -78,6 +78,10 @@ function! coc#dialog#create_cursor_float(winid, bufnr, lines, config) abort
" helps to fix undo issue, don't know why.
call feedkeys("\<C-g>u", 'n')
endif
if mode ==# 's' && has('patch-8.2.4969') && !has('patch-8.2.4996')
echohl WarningMsg | echon 'Popup not created to avoid issue #10466 on vim >= 8.2.4969' | echohl None
return v:null
endif
let dimension = coc#dialog#get_config_cursor(a:lines, a:config)
if empty(dimension)
return v:null
@ -206,35 +210,51 @@ function! coc#dialog#create_menu(lines, config) abort
let highlight = get(a:config, 'highlight', 'CocFloating')
let borderhighlight = get(a:config, 'borderhighlight', [highlight])
let relative = get(a:config, 'relative', 'cursor')
let lines = copy(a:lines)
let content = get(a:config, 'content', '')
let maxWidth = get(a:config, 'maxWidth', 80)
let highlights = get(a:config, 'highlights', [])
let contentCount = 0
if !empty(content)
let contentLines = coc#string#reflow(split(content, '\r\?\n'), maxWidth)
let contentCount = len(contentLines)
let lines = extend(contentLines, lines)
if !empty(highlights)
for item in highlights
let item['lnum'] = item['lnum'] + contentCount
endfor
endif
endif
let opts = {
\ 'lines': a:lines,
\ 'lines': lines,
\ 'highlight': highlight,
\ 'title': get(a:config, 'title', ''),
\ 'borderhighlight': borderhighlight,
\ 'maxWidth': get(a:config, 'maxWidth', 80),
\ 'maxWidth': maxWidth,
\ 'maxHeight': get(a:config, 'maxHeight', 80),
\ 'rounded': get(a:config, 'rounded', 0),
\ 'border': [1, 1, 1, 1],
\ 'highlights': get(a:config, 'highlights', []),
\ 'highlights': highlights,
\ 'relative': relative,
\ }
if relative ==# 'editor'
let dimension = coc#dialog#get_config_editor(a:lines, opts)
let dimension = coc#dialog#get_config_editor(lines, opts)
else
let dimension = coc#dialog#get_config_cursor(a:lines, opts)
let dimension = coc#dialog#get_config_cursor(lines, opts)
endif
call extend(opts, dimension)
let res = coc#float#create_float_win(0, s:prompt_win_bufnr, opts)
if empty(res)
let ids = coc#float#create_float_win(0, s:prompt_win_bufnr, opts)
if empty(ids)
return
endif
let s:prompt_win_bufnr = res[1]
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')
call coc#float#nvim_scrollbar(res[0])
call coc#float#nvim_scrollbar(ids[0])
endif
return res
return [ids[0], ids[1], contentCount]
endfunction
" Create dialog at center of screen

View File

@ -935,8 +935,8 @@ function! coc#float#create_buf(bufnr, ...) abort
if has('nvim')
call nvim_buf_set_lines(bufnr, 0, -1, v:false, lines)
else
silent call deletebufline(bufnr, 1, '$')
silent call setbufline(bufnr, 1, lines)
silent noa call setbufline(bufnr, 1, lines)
silent noa call deletebufline(bufnr, len(lines) + 1, '$')
endif
endif
return bufnr

View File

@ -689,7 +689,7 @@ function! s:to_group(items) abort
endfunction
function! s:get_priority(key, hlGroup, priority) abort
if a:hlGroup ==# 'Search'
if a:hlGroup ==# 'CocSearch'
return 999
endif
if strpart(a:key, 0, 10) !=# 'diagnostic'

View File

@ -104,20 +104,29 @@ function! coc#snippet#disable()
silent! execute 'sunmap <buffer> <silent> '.nextkey
endfunction
function! coc#snippet#select(position, text) abort
function! coc#snippet#select(start, end, text) abort
if pumvisible()
call coc#_cancel()
endif
if mode() == 's'
call feedkeys("\<Esc>", 'in')
endif
let cursor = coc#snippet#to_cursor(a:position)
call cursor([cursor[0], cursor[1] - (&selection !~# 'exclusive')])
let len = strchars(a:text) - (&selection !~# 'exclusive')
let cmd = ''
let cmd .= mode()[0] ==# 'i' ? "\<Esc>l" : ''
let cmd .= printf('v%s', len > 0 ? len . 'h' : '')
let cmd .= "o\<C-g>"
if &selection ==# 'exclusive'
let cursor = coc#snippet#to_cursor(a:start)
call cursor([cursor[0], cursor[1]])
let cmd = ''
let cmd .= mode()[0] ==# 'i' ? "\<Esc>".(col('.') == 1 ? '' : 'l') : ''
let cmd .= printf('v%s', strchars(a:text) . 'l')
let cmd .= "\<C-g>"
else
let cursor = coc#snippet#to_cursor(a:end)
call cursor([cursor[0], cursor[1] - 1])
let len = strchars(a:text) - 1
let cmd = ''
let cmd .= mode()[0] ==# 'i' ? "\<Esc>l" : ''
let cmd .= printf('v%s', len > 0 ? len . 'h' : '')
let cmd .= "o\<C-g>"
endif
call feedkeys(cmd, 'n')
endfunction

View File

@ -1,5 +1,6 @@
let s:is_vim = !has('nvim')
let s:is_win = has('win32') || has('win64')
let s:is_mac = has('mac')
function! coc#ui#quickpick(title, items, cb) abort
if exists('*popup_menu')
@ -314,3 +315,62 @@ function! coc#ui#open_url(url)
return
endif
endfunction
function! coc#ui#rename_file(oldPath, newPath, write) abort
let bufnr = bufnr(a:oldPath)
if bufnr == -1
throw 'Unable to get bufnr of '.a:oldPath
endif
if a:oldPath =~? a:newPath && (s:is_mac || s:is_win)
return coc#ui#safe_rename(bufnr, a:oldPath, a:newPath, a:write)
endif
if bufloaded(a:newPath)
execute 'silent bdelete! '.bufnr(a:newPath)
endif
let current = bufnr == bufnr('%')
let bufname = fnamemodify(a:newPath, ":~:.")
let filepath = fnamemodify(bufname(bufnr), '%:p')
let winid = coc#compat#buf_win_id(bufnr)
let curr = -1
if winid == -1
let curr = win_getid()
let file = fnamemodify(bufname(bufnr), ':.')
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, 'doautocmd BufEnter')
if a:write
call coc#compat#execute(winid, 'noa write!', 'silent')
call delete(filepath, '')
endif
if curr != -1
call win_gotoid(curr)
endif
return bufnr
endfunction
" System is case in sensitive and newPath have different case.
function! coc#ui#safe_rename(bufnr, oldPath, newPath, write) abort
let winid = win_getid()
let lines = getbufline(a:bufnr, 1, '$')
execute 'keepalt tab drop '.fnameescape(fnamemodify(a:oldPath, ':.'))
let view = winsaveview()
execute 'keepalt bwipeout! '.a:bufnr
if a:write
call delete(a:oldPath, '')
endif
execute 'keepalt edit '.fnameescape(fnamemodify(a:newPath, ':~:.'))
let bufnr = bufnr('%')
call coc#compat#buf_set_lines(bufnr, 0, -1, lines)
if a:write
execute 'noa write'
endif
call winrestview(view)
call win_gotoid(winid)
return bufnr
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 = 29
let s:vim_api_version = 30
function! coc#util#remote_fns(name)
let fns = ['init', 'complete', 'should_complete', 'refresh', 'get_startcol', 'on_complete', 'on_enter']
@ -135,8 +135,8 @@ function! coc#util#diagnostic_info(bufnr, checkInsert) abort
endfunction
function! coc#util#open_file(cmd, file)
let file = fnameescape(a:file)
execute a:cmd .' '.file
execute a:cmd .' '.fnameescape(fnamemodify(a:file, ':~:.'))
return bufnr('%')
endfunction
function! coc#util#job_command()