diff options
author | Blaž Hrastnik | 2020-12-23 07:20:49 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2020-12-23 07:20:49 +0000 |
commit | 56f2193811fca2fa20284442c2042fa271464445 (patch) | |
tree | 1ec99141a70b484f1fbcf0594e5aea61138cd097 /helix-lsp/src/client.rs | |
parent | 955cb81687db139422875d02b534d753dac5603f (diff) |
Retrieve completion options on ctrl-x.
Diffstat (limited to 'helix-lsp/src/client.rs')
-rw-r--r-- | helix-lsp/src/client.rs | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/helix-lsp/src/client.rs b/helix-lsp/src/client.rs index 160dd93b..c3bcddd2 100644 --- a/helix-lsp/src/client.rs +++ b/helix-lsp/src/client.rs @@ -196,6 +196,12 @@ impl Client { root_uri: None, // set to project root in the future initialization_options: None, capabilities: lsp::ClientCapabilities { + // text_document: + // { completion: { + // dynamic_registration: bool + // completion_item: { snippet, documentation_format, ... } + // completion_item_kind: { } + // } } ..Default::default() }, trace: None, @@ -358,4 +364,41 @@ impl Client { pub async fn text_document_did_save(&self) -> anyhow::Result<()> { unimplemented!() } + + pub async fn completion(&self, doc: &Document) -> anyhow::Result<Vec<lsp::CompletionItem>> { + // TODO: figure out what should happen when you complete with multiple cursors + + let params = lsp::CompletionParams { + text_document_position: lsp::TextDocumentPositionParams { + text_document: text_document_identifier(doc), + position: crate::util::pos_to_lsp_pos( + &doc.text().slice(..), + doc.selection().cursor(), + ), + }, + // TODO: support these tokens by async receiving and updating the choice list + work_done_progress_params: lsp::WorkDoneProgressParams { + work_done_token: None, + }, + partial_result_params: lsp::PartialResultParams { + partial_result_token: None, + }, + context: None, + // lsp::CompletionContext { trigger_kind: , trigger_character: Some(), } + }; + + let response = self.request::<lsp::request::Completion>(params).await?; + + let items = match response { + Some(lsp::CompletionResponse::Array(items)) => items, + // TODO: do something with is_incomplete + Some(lsp::CompletionResponse::List(lsp::CompletionList { + is_incomplete: _is_incomplete, + items, + })) => items, + None => Vec::new(), + }; + + Ok(items) + } } |