Fix borderchars and debug=throw (#1178)

This commit is contained in:
hrsh7th
2021-06-02 12:56:57 +09:00
committed by GitHub
parent 83c0e4fcab
commit ddd5abb5b6
3 changed files with 64 additions and 16 deletions

View File

@@ -206,7 +206,7 @@ function! s:register_events() abort
autocmd BufReadPost * call s:on_text_document_did_open()
autocmd BufWritePost * call s:on_text_document_did_save()
autocmd BufWinLeave * call s:on_text_document_did_close()
autocmd BufWipeout * call s:on_buf_wipeout(bufnr('<afile>'))
autocmd BufWipeout * call s:on_buf_wipeout(expand('<afile>'))
autocmd InsertLeave * call s:on_text_document_did_change()
autocmd TextChanged * call s:on_text_document_did_change()
if exists('##TextChangedP')

View File

@@ -4,7 +4,7 @@
function! s:_SID() abort
return matchstr(expand('<sfile>'), '<SNR>\zs\d\+\ze__SID$')
endfunction
execute join(['function! vital#_lsp#VS#Vim#Buffer#import() abort', printf("return map({'get_line_count': '', 'do': '', 'create': '', 'load': ''}, \"vital#_lsp#function('<SNR>%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n")
execute join(['function! vital#_lsp#VS#Vim#Buffer#import() abort', printf("return map({'get_line_count': '', 'do': '', 'create': '', 'pseudo': '', 'ensure': '', 'load': ''}, \"vital#_lsp#function('<SNR>%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n")
delfunction s:_SID
" ___vital___
let s:Do = { -> {} }
@@ -36,29 +36,43 @@ endif
"
function! s:create(...) abort
let g:___VS_Vim_Buffer_id += 1
let l:bufnr = bufnr(printf('VS.Vim.Buffer: %s: %s',
let l:bufname = printf('VS.Vim.Buffer: %s: %s',
\ g:___VS_Vim_Buffer_id,
\ get(a:000, 0, 'VS.Vim.Buffer.Default')
\ ), v:true)
call s:load(l:bufnr)
return l:bufnr
\ )
return s:load(l:bufname)
endfunction
"
" ensure
"
function! s:ensure(expr) abort
if !bufexists(a:expr)
if type(a:expr) == type(0)
throw printf('VS.Vim.Buffer: `%s` is not valid expr.', l:bufnr)
else
badd `=a:expr`
endif
endif
return bufnr(a:expr)
endfunction
"
" load
"
if exists('*bufload')
function! s:load(bufnr_or_path) abort
let l:bufnr = bufnr(a:bufnr_or_path, v:true)
silent call bufload(l:bufnr)
function! s:load(expr) abort
let l:bufnr = s:ensure(a:expr)
if !bufloaded(l:bufnr)
call bufload(l:bufnr)
endif
return l:bufnr
endfunction
else
function! s:load(bufnr_or_path) abort
function! s:load(expr) abort
let l:curr_bufnr = bufnr('%')
try
let l:bufnr = bufnr(a:bufnr_or_path, v:true)
let l:bufnr = s:ensure(a:expr)
execute printf('keepalt keepjumps silent %sbuffer', l:bufnr)
catch /.*/
echomsg string({ 'exception': v:exception, 'throwpoint': v:throwpoint })
@@ -89,3 +103,25 @@ function! s:do(bufnr, func) abort
endtry
endfunction
"
" pseudo
"
function! s:pseudo(filepath) abort
if !filereadable(a:filepath)
throw printf('VS.Vim.Buffer: `%s` is not valid filepath.', a:filepath)
endif
" create pseudo buffer
let l:bufname = printf('VSVimBufferPseudo://%s', a:filepath)
if bufexists(l:bufname)
return s:ensure(l:bufname)
endif
let l:bufnr = s:ensure(l:bufname)
let l:group = printf('VS_Vim_Buffer_pseudo:%s', l:bufnr)
execute printf('augroup %s', l:group)
execute printf('autocmd BufReadCmd <buffer=%s> call setline(1, readfile(bufname("%")[20 : -1])) | try | filetype detect | catch /.*/ | endtry | augroup %s | autocmd! | augroup END', l:bufnr, l:group)
augroup END
return l:bufnr
endfunction

View File

@@ -327,7 +327,11 @@ endif
"
if has('nvim')
function! s:_exists(winid) abort
return type(a:winid) == type(0) && nvim_win_is_valid(a:winid) && nvim_win_get_number(a:winid) != -1
try
return type(a:winid) == type(0) && nvim_win_is_valid(a:winid) && nvim_win_get_number(a:winid) != -1
catch /.*/
return v:false
endtry
endfunction
else
function! s:_exists(winid) abort
@@ -442,7 +446,11 @@ endfunction
if has('nvim')
function! s:_resolve_border(style) abort
if !empty(get(a:style, 'border', v:null))
let a:style.border = ['┌', '─', '┐', '│', '┘', '─', '└', '│']
if &ambiwidth ==# 'single'
let a:style.border = ['┌', '─', '┐', '│', '┘', '─', '└', '│']
else
let a:style.border = ['+', '-', '+', '|', '+', '-', '+', '|']
endif
elseif has_key(a:style, 'border')
unlet a:style.border
endif
@@ -451,7 +459,11 @@ if has('nvim')
else
function! s:_resolve_border(style) abort
if !empty(get(a:style, 'border', v:null))
let a:style.border = ['─', '│', '─', '│', '┌', '┐', '┘', '└']
if &ambiwidth ==# 'single'
let a:style.border = ['─', '│', '─', '│', '┌', '┐', '┘', '└']
else
let a:style.border = ['-', '|', '-', '|', '+', '+', '+', '+']
endif
elseif has_key(a:style, 'border')
unlet a:style.border
endif
@@ -468,7 +480,7 @@ function! s:_init() abort
return
endif
let s:has_init = v:true
augroup printf('<sfile>')
augroup printf('VS_Vim_Window_FloatingWindow:%s', expand('<sfile>'))
autocmd!
autocmd WinEnter * call <SID>_notify_closed()
augroup END