Support untitled buffer (#1152)

* Support untitled buffer

* Enable opt out

* Add documentation

* Add documentation

* Use correct buffer names

* Wipeout file contents
This commit is contained in:
mattn
2021-09-27 18:22:58 +09:00
committed by GitHub
parent 9f7359303b
commit ee38eb1bc6
4 changed files with 24 additions and 1 deletions

View File

@@ -212,6 +212,9 @@ function! s:register_events() abort
if exists('##TextChangedP')
autocmd TextChangedP * call s:on_text_document_did_change()
endif
if g:lsp_untitled_buffer_enabled
autocmd FileType * call s:on_filetype_changed(bufnr('<afile>'))
endif
augroup END
for l:bufnr in range(1, bufnr('$'))
@@ -228,6 +231,12 @@ function! s:unregister_events() abort
doautocmd <nomodeline> User lsp_unregister_server
endfunction
function! s:on_filetype_changed(buf) abort
call s:on_buf_wipeout(a:buf)
" TODO: stop unused servers
call s:on_text_document_did_open()
endfunction
function! s:on_text_document_did_open(...) abort
let l:buf = a:0 > 0 ? a:1 : bufnr('%')
if getbufvar(l:buf, '&buftype') ==# 'terminal' | return | endif

View File

@@ -167,7 +167,12 @@ function! lsp#utils#get_buffer_path(...) abort
endfunction
function! lsp#utils#get_buffer_uri(...) abort
return lsp#utils#path_to_uri(expand((a:0 > 0 ? '#' . a:1 : '%') . ':p'))
let l:name = a:0 > 0 ? bufname(a:1) : expand('%')
if empty(l:name)
let l:nr = a:0 > 0 ? a:1 : bufnr('%')
let l:name = printf('%s/__NO_NAME_%d__', getcwd(), l:nr)
endif
return lsp#utils#path_to_uri(fnamemodify(l:name, ':p'))
endfunction
" Find a nearest to a `path` parent directory `directoryname` by traversing the filesystem upwards

View File

@@ -75,6 +75,7 @@ CONTENTS *vim-lsp-contents*
g:lsp_show_message_request_enabled |g:lsp_show_message_request_enabled|
g:lsp_work_done_progress_enabled |g:lsp_work_done_progress_enabled|
g:lsp_show_message_log_level |g:lsp_show_message_log_level|
g:lsp_untitled_buffer_enabled |g:lsp_untitled_buffer_enabled|
Functions |vim-lsp-functions|
lsp#enable |lsp#enable()|
lsp#disable |lsp#disable()|
@@ -941,6 +942,13 @@ g:lsp_show_message_log_level *g:lsp_show_message_log_level*
shown but `'info'` level and `'log'` level messages are not shown. Setting
`'none'` disables to show messages completely.
g:lsp_untitled_buffer_enabled *g:lsp_untitled_buffer_enabled*
Type: |Number|
Default: `1`
Determines whether or not vim-lsp plugin is enabled for untitled buffer.
Set to `0` to disable for untitled buffer.
==============================================================================
FUNCTIONS *vim-lsp-functions*

View File

@@ -68,6 +68,7 @@ let g:lsp_tagfunc_source_methods = get(g:, 'lsp_tagfunc_source_methods', ['defin
let g:lsp_show_message_request_enabled = get(g:, 'lsp_show_message_request_enabled', 1)
let g:lsp_show_message_log_level = get(g:, 'lsp_show_message_log_level', 'warning')
let g:lsp_work_done_progress_enabled = get(g:, 'lsp_work_done_progress_enabled', 0)
let g:lsp_untitled_buffer_enabled = get(g:, 'lsp_untitled_buffer_enabled', 1)
let g:lsp_get_supported_capabilities = get(g:, 'lsp_get_supported_capabilities', [function('lsp#default_get_supported_capabilities')])