mirror of
https://github.com/amix/vimrc
synced 2025-07-27 23:45:00 +08:00
Update Coc.nvim
This commit is contained in:
@ -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
|
||||
|
Reference in New Issue
Block a user