From bf88fb060b30b131f2b76b7dd58c8df3f5b3a29e Mon Sep 17 00:00:00 2001 From: Francisco Souza Date: Tue, 5 Mar 2019 22:59:17 -0500 Subject: [PATCH 1/3] Implement window/showMessageRequest --- autoload/LanguageClient.vim | 7 +++++++ src/language_server_protocol.rs | 26 ++++++++++++++++++++++++++ src/rpchandler.rs | 1 + 3 files changed, 34 insertions(+) diff --git a/autoload/LanguageClient.vim b/autoload/LanguageClient.vim index 3e78721fd..722a87330 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 b2f44d253..bd19ea6a6 100644 --- a/src/language_server_protocol.rs +++ b/src/language_server_protocol.rs @@ -1824,6 +1824,32 @@ 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 n_actions = msg_actions.len(); + 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 { + if answer > 0 && answer < (n_actions - 1) as i64 { + let raw_actions: Vec = try_get("actions", ¶ms)?.unwrap_or_default(); + v = raw_actions[(answer - 1) as usize].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 329ed8f00..6764aa3a7 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), From dbe2b6a0a704145aaaf0ebe562262470f2176cce Mon Sep 17 00:00:00 2001 From: Francisco Souza Date: Thu, 7 Mar 2019 00:33:44 -0500 Subject: [PATCH 2/3] Use Vec.get instead of indexing --- src/language_server_protocol.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/language_server_protocol.rs b/src/language_server_protocol.rs index bd19ea6a6..0f88614ad 100644 --- a/src/language_server_protocol.rs +++ b/src/language_server_protocol.rs @@ -1841,9 +1841,9 @@ impl LanguageClient { let mut v = Value::Null; let result: Option = self.vim()?.rpcclient.call("s:inputlist", options)?; if let Some(answer) = result { - if answer > 0 && answer < (n_actions - 1) as i64 { - let raw_actions: Vec = try_get("actions", ¶ms)?.unwrap_or_default(); - v = raw_actions[(answer - 1) as usize].clone(); + 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); From 825990f5f4b6c8f43169ee02081da67402a75b10 Mon Sep 17 00:00:00 2001 From: Francisco Souza Date: Thu, 7 Mar 2019 00:36:30 -0500 Subject: [PATCH 3/3] Remove now unused variable --- src/language_server_protocol.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/language_server_protocol.rs b/src/language_server_protocol.rs index 0f88614ad..0fa512edd 100644 --- a/src/language_server_protocol.rs +++ b/src/language_server_protocol.rs @@ -1828,7 +1828,6 @@ impl LanguageClient { info!("Begin {}", lsp::request::ShowMessageRequest::METHOD); let msg_params: ShowMessageRequestParams = params.clone().to_lsp()?; let msg_actions = msg_params.actions.unwrap_or_default(); - let n_actions = msg_actions.len(); let actions: Vec = msg_actions .into_iter() .enumerate()