diff --git a/autoload/LanguageClient.vim b/autoload/LanguageClient.vim index 3e78721f..722a8733 100644 --- a/autoload/LanguageClient.vim +++ b/autoload/LanguageClient.vim @@ -183,6 +183,13 @@ function! s:getInput(prompt, default) abort return l:input endfunction +function! s:inputlist(...) abort + call inputsave() + let l:selection = inputlist(a:000) + call inputrestore() + return l:selection +endfunction + function! s:FZF(source, sink) abort if !get(g:, 'loaded_fzf') call s:Echoerr('FZF not loaded!') diff --git a/src/language_server_protocol.rs b/src/language_server_protocol.rs index b2f44d25..0fa512ed 100644 --- a/src/language_server_protocol.rs +++ b/src/language_server_protocol.rs @@ -1824,6 +1824,31 @@ impl LanguageClient { Ok(()) } + pub fn window_showMessageRequest(&self, params: &Value) -> Fallible { + info!("Begin {}", lsp::request::ShowMessageRequest::METHOD); + let msg_params: ShowMessageRequestParams = params.clone().to_lsp()?; + let msg_actions = msg_params.actions.unwrap_or_default(); + let actions: Vec = msg_actions + .into_iter() + .enumerate() + .map(|(i, item)| Value::String(format!("{}) {}", i + 1, item.title))) + .collect(); + let mut options: Vec = Vec::with_capacity(actions.len() + 1); + options.push(Value::String(msg_params.message)); + options.extend(actions); + + let mut v = Value::Null; + let result: Option = self.vim()?.rpcclient.call("s:inputlist", options)?; + if let Some(answer) = result { + let raw_actions: Vec = try_get("actions", ¶ms)?.unwrap_or_default(); + if let Some(action) = raw_actions.get((answer - 1) as usize) { + v = action.clone(); + } + } + info!("End {}", lsp::request::ShowMessageRequest::METHOD); + Ok(v) + } + pub fn client_registerCapability(&self, languageId: &str, params: &Value) -> Fallible { info!("Begin {}", lsp::request::RegisterCapability::METHOD); let params: RegistrationParams = params.clone().to_lsp()?; diff --git a/src/rpchandler.rs b/src/rpchandler.rs index 329ed8f0..6764aa3a 100644 --- a/src/rpchandler.rs +++ b/src/rpchandler.rs @@ -70,6 +70,7 @@ impl LanguageClient { lsp::request::DocumentSymbolRequest::METHOD => { self.textDocument_documentSymbol(¶ms) } + lsp::request::ShowMessageRequest::METHOD => self.window_showMessageRequest(¶ms), lsp::request::WorkspaceSymbol::METHOD => self.workspace_symbol(¶ms), lsp::request::CodeActionRequest::METHOD => self.textDocument_codeAction(¶ms), lsp::request::Completion::METHOD => self.textDocument_completion(¶ms),