From eca2a73ad0e829dbd83da8f42a8a2bd5c17bbf75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bla=C5=BE=20Hrastnik?= Date: Tue, 16 Mar 2021 16:13:41 +0900 Subject: [PATCH] lsp: Pass through language_id on didOpenTextDocument. --- helix-lsp/src/client.rs | 3 ++- helix-term/src/commands.rs | 1 + helix-view/src/editor.rs | 7 +++++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/helix-lsp/src/client.rs b/helix-lsp/src/client.rs index edec10a92..a9b7fe202 100644 --- a/helix-lsp/src/client.rs +++ b/helix-lsp/src/client.rs @@ -244,11 +244,12 @@ impl Client { uri: lsp::Url, version: i32, doc: &Rope, + language_id: String, ) -> Result<()> { self.notify::(lsp::DidOpenTextDocumentParams { text_document: lsp::TextDocumentItem { uri, - language_id: "rust".to_string(), // TODO: hardcoded for now + language_id, version, text: String::from(doc), }, diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 16f43591b..d80662d73 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -1183,6 +1183,7 @@ pub fn completion(cx: &mut Context) { let pos = helix_lsp::util::pos_to_lsp_pos(doc.text().slice(..), doc.selection().cursor()); // TODO: handle fails + let res = smol::block_on(language_server.completion(doc.identifier(), pos)).unwrap_or_default(); // TODO: if no completion, show some message or something diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index f79eadad8..0dd0592c9 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -46,10 +46,17 @@ impl Editor { if let Some(language_server) = language_server { doc.set_language_server(Some(language_server.clone())); + let language_id = doc + .language() + .and_then(|s| s.split(".").last()) // source.rust + .map(ToOwned::to_owned) + .unwrap_or_default(); + smol::block_on(language_server.text_document_did_open( doc.url().unwrap(), doc.version(), doc.text(), + language_id, )) .unwrap(); }