aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src/ui
diff options
context:
space:
mode:
authorMichael Davis2022-11-22 02:52:23 +0000
committerGitHub2022-11-22 02:52:23 +0000
commit9059c65a5385f6d3cc0bc7f6e3f835ae542635a5 (patch)
tree6fffacee213769a669c045f1c5c2a07bdf41ec02 /helix-term/src/ui
parent1db01caec7c91e270a23fd4f85955bb235ffbcb7 (diff)
lsp: Check server provider capabilities (#3554)
Language Servers may signal that they do not support a method in the initialization result (server capabilities). We can check these when making LSP requests and hint in the status line when a method is not supported by the server. This can also prevent crashes in servers which assume that clients do not send requests for methods which are disabled in the server capabilities. There is an existing pattern the LSP client module where a method returns `Option<impl Future<Output = Result<_>>>` with `None` signaling no support in the server. This change extends this pattern to the rest of the client functions. And we log an error to the statusline for manually triggered LSP calls which return `None`.
Diffstat (limited to 'helix-term/src/ui')
-rw-r--r--helix-term/src/ui/completion.rs17
1 files changed, 6 insertions, 11 deletions
diff --git a/helix-term/src/ui/completion.rs b/helix-term/src/ui/completion.rs
index 4e6ee424..ebb4fb46 100644
--- a/helix-term/src/ui/completion.rs
+++ b/helix-term/src/ui/completion.rs
@@ -245,21 +245,13 @@ impl Completion {
completion_item: lsp::CompletionItem,
) -> Option<CompletionItem> {
let language_server = doc.language_server()?;
- let completion_resolve_provider = language_server
- .capabilities()
- .completion_provider
- .as_ref()?
- .resolve_provider;
- if completion_resolve_provider != Some(true) {
- return None;
- }
- let future = language_server.resolve_completion_item(completion_item);
+ let future = language_server.resolve_completion_item(completion_item)?;
let response = helix_lsp::block_on(future);
match response {
Ok(value) => serde_json::from_value(value).ok(),
Err(err) => {
- log::error!("execute LSP command: {}", err);
+ log::error!("Failed to resolve completion item: {}", err);
None
}
}
@@ -330,7 +322,10 @@ impl Completion {
};
// This method should not block the compositor so we handle the response asynchronously.
- let future = language_server.resolve_completion_item(current_item.clone());
+ let future = match language_server.resolve_completion_item(current_item.clone()) {
+ Some(future) => future,
+ None => return false,
+ };
cx.callback(
future,