mirror of
https://github.com/prabirshrestha/vim-lsp.git
synced 2025-12-14 20:35:59 +01:00
add support for window/showMessageRequest (#919)
* show message request * materialize so doesn't throw error and add message to input list * fix lint issues and rename flag to lsp_show_message_request_enabled * use action and fix filter * document g:lsp_show_message_request_enabled
This commit is contained in:
@@ -66,6 +66,7 @@ function! lsp#enable() abort
|
|||||||
call lsp#ui#vim#completion#_setup()
|
call lsp#ui#vim#completion#_setup()
|
||||||
call lsp#internal#diagnostics#_enable()
|
call lsp#internal#diagnostics#_enable()
|
||||||
call lsp#internal#highlight_references#_enable()
|
call lsp#internal#highlight_references#_enable()
|
||||||
|
call lsp#internal#show_message_request#_enable()
|
||||||
call s:register_events()
|
call s:register_events()
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
@@ -81,6 +82,7 @@ function! lsp#disable() abort
|
|||||||
call lsp#ui#vim#completion#_disable()
|
call lsp#ui#vim#completion#_disable()
|
||||||
call lsp#internal#diagnostics#_disable()
|
call lsp#internal#diagnostics#_disable()
|
||||||
call lsp#internal#highlight_references#_disable()
|
call lsp#internal#highlight_references#_disable()
|
||||||
|
call lsp#internal#show_message_request#_disable()
|
||||||
call s:unregister_events()
|
call s:unregister_events()
|
||||||
let s:enabled = 0
|
let s:enabled = 0
|
||||||
endfunction
|
endfunction
|
||||||
@@ -759,7 +761,7 @@ function! s:on_notification(server_name, id, data, event) abort
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:on_request(server_name, id, request) abort
|
function! s:on_request(server_name, id, request) abort
|
||||||
call lsp#log_verbose('<---', a:id, a:request)
|
call lsp#log_verbose('<---', 's:on_request', a:id, a:request)
|
||||||
|
|
||||||
let l:stream_data = { 'server': a:server_name, 'request': a:request }
|
let l:stream_data = { 'server': a:server_name, 'request': a:request }
|
||||||
call s:Stream(1, l:stream_data) " notify stream before callbacks
|
call s:Stream(1, l:stream_data) " notify stream before callbacks
|
||||||
|
|||||||
58
autoload/lsp/internal/show_message_request.vim
Normal file
58
autoload/lsp/internal/show_message_request.vim
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
function! lsp#internal#show_message_request#_enable() abort
|
||||||
|
if !g:lsp_show_message_request_enabled | return | endif
|
||||||
|
let s:Dispose = lsp#callbag#pipe(
|
||||||
|
\ lsp#stream(),
|
||||||
|
\ lsp#callbag#filter({x->
|
||||||
|
\ g:lsp_show_message_request_enabled &&
|
||||||
|
\ has_key(x, 'request') && !has_key(x, 'response') &&
|
||||||
|
\ has_key(x['request'], 'method') && x['request']['method'] ==# 'window/showMessageRequest'
|
||||||
|
\ }),
|
||||||
|
\ lsp#callbag#map({x->s:show_message_request(x['server'], x['request'])}),
|
||||||
|
\ lsp#callbag#map({x->s:send_message_response(x['server'], x['request'], x['action'])}),
|
||||||
|
\ lsp#callbag#flatten(),
|
||||||
|
\ lsp#callbag#materialize(),
|
||||||
|
\ lsp#callbag#subscribe({ 'error': function('s:on_error') }),
|
||||||
|
\ )
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! lsp#internal#show_message_request#_disable() abort
|
||||||
|
if exists('s:Dispose')
|
||||||
|
call s:Dispose()
|
||||||
|
unlet s:Dispose
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:on_error(e) abort
|
||||||
|
call lsp#log('lsp#internal#show_message_request error', a:e)
|
||||||
|
if exists('s:Dispose')
|
||||||
|
call s:Dispose()
|
||||||
|
unlet s:Dispose
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:show_message_request(server_name, request) abort
|
||||||
|
let l:params = a:request['params']
|
||||||
|
|
||||||
|
let l:selected_action = v:null
|
||||||
|
|
||||||
|
if has_key(l:params, 'actions') && !empty(l:params['actions'])
|
||||||
|
let l:options = map(copy(l:params['actions']), {i, action ->
|
||||||
|
\ printf('%d - [%s] %s', i + 1, a:server_name, action['title'])
|
||||||
|
\ })
|
||||||
|
let l:index = inputlist([l:params['message']] + l:options)
|
||||||
|
if l:index > 0 && l:index <= len(l:index)
|
||||||
|
let l:selected_action = l:params['actions'][l:index - 1]
|
||||||
|
endif
|
||||||
|
else
|
||||||
|
echom l:params['message']
|
||||||
|
endif
|
||||||
|
|
||||||
|
return { 'server': a:server_name, 'request': a:request, 'action': l:selected_action }
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:send_message_response(server_name, request, action) abort
|
||||||
|
return lsp#request(a:server_name, {
|
||||||
|
\ 'id': a:request['id'],
|
||||||
|
\ 'result': a:action
|
||||||
|
\})
|
||||||
|
endfunction
|
||||||
@@ -48,6 +48,7 @@ CONTENTS *vim-lsp-contents*
|
|||||||
g:lsp_snippet_expand |g:lsp_snippet_expand|
|
g:lsp_snippet_expand |g:lsp_snippet_expand|
|
||||||
g:lsp_completion_resolve_timeout |g:lsp_completion_resolve_timeout|
|
g:lsp_completion_resolve_timeout |g:lsp_completion_resolve_timeout|
|
||||||
g:lsp_tagfunc_source_methods |g:lsp_tagfunc_source_methods|
|
g:lsp_tagfunc_source_methods |g:lsp_tagfunc_source_methods|
|
||||||
|
g:lsp_show_message_request_enabled |g:lsp_show_message_request_enabled|
|
||||||
Functions |vim-lsp-functions|
|
Functions |vim-lsp-functions|
|
||||||
lsp#enable |lsp#enable()|
|
lsp#enable |lsp#enable()|
|
||||||
lsp#disable |lsp#disable()|
|
lsp#disable |lsp#disable()|
|
||||||
@@ -690,6 +691,13 @@ g:lsp_tagfunc_source_methods *g:lsp_tagfunc_source_methods*
|
|||||||
The LSP methods to call to get symbols for tag lookup. See
|
The LSP methods to call to get symbols for tag lookup. See
|
||||||
|vim-lsp-tagfunc|.
|
|vim-lsp-tagfunc|.
|
||||||
|
|
||||||
|
g:lsp_show_message_request_enabled *g:lsp_show_message_request_enabled*
|
||||||
|
Type: |Number|
|
||||||
|
Default: `1`
|
||||||
|
|
||||||
|
Determines whether or not `window/showMessageRequest` should show message to
|
||||||
|
the user or if it should be ignored. Set to `1` to enable.
|
||||||
|
|
||||||
==============================================================================
|
==============================================================================
|
||||||
FUNCTIONS *vim-lsp-functions*
|
FUNCTIONS *vim-lsp-functions*
|
||||||
|
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ let g:lsp_semantic_enabled = get(g:, 'lsp_semantic_enabled', 0)
|
|||||||
let g:lsp_text_document_did_save_delay = get(g:, 'lsp_text_document_did_save_delay', -1)
|
let g:lsp_text_document_did_save_delay = get(g:, 'lsp_text_document_did_save_delay', -1)
|
||||||
let g:lsp_completion_resolve_timeout = get(g:, 'lsp_completion_resolve_timeout', 200)
|
let g:lsp_completion_resolve_timeout = get(g:, 'lsp_completion_resolve_timeout', 200)
|
||||||
let g:lsp_tagfunc_source_methods = get(g:, 'lsp_tagfunc_source_methods', ['definition', 'declaration', 'implementation', 'typeDefinition'])
|
let g:lsp_tagfunc_source_methods = get(g:, 'lsp_tagfunc_source_methods', ['definition', 'declaration', 'implementation', 'typeDefinition'])
|
||||||
|
let g:lsp_show_message_request_enabled = get(g:, 'lsp_show_message_request_enabled', 1)
|
||||||
|
|
||||||
let g:lsp_get_supported_capabilities = get(g:, 'lsp_get_supported_capabilities', [function('lsp#default_get_supported_capabilities')])
|
let g:lsp_get_supported_capabilities = get(g:, 'lsp_get_supported_capabilities', [function('lsp#default_get_supported_capabilities')])
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user