From 2ab069bb3fc815394cccca50378b62932f3146f5 Mon Sep 17 00:00:00 2001 From: Blaž Hrastnik Date: Fri, 25 Dec 2020 17:20:09 +0900 Subject: lsp: Work on syncing the state with the language server. --- helix-term/src/application.rs | 16 ++++++++++++---- helix-term/src/commands.rs | 6 +++++- helix-term/src/ui/editor.rs | 3 ++- 3 files changed, 19 insertions(+), 6 deletions(-) (limited to 'helix-term/src') diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index 138f55c2..004c5c61 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -44,16 +44,23 @@ impl Application { let mut editor = Editor::new(); let size = terminal.size()?; + let language_servers = helix_lsp::Registry::new(); + let language_server = language_servers.get("rust", &executor).unwrap(); + if let Some(file) = args.values_of_t::("files").unwrap().pop() { editor.open(file, (size.width, size.height))?; + + // TODO: do this everywhere + editor + .view_mut() + .unwrap() + .doc + .set_language_server(Some(language_server.clone())); } let mut compositor = Compositor::new(); compositor.push(Box::new(ui::EditorView::new())); - let language_servers = helix_lsp::Registry::new(); - let language_server = language_servers.get("rust", &executor).unwrap(); - let mut app = Self { editor, terminal, @@ -90,8 +97,9 @@ impl Application { pub async fn event_loop(&mut self) { let mut reader = EventStream::new(); + let doc = &self.editor.view().unwrap().doc; self.language_server - .text_document_did_open(&self.editor.view().unwrap().doc) + .text_document_did_open(doc.url().unwrap(), doc.version, doc.text()) .await .unwrap(); diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 862cf312..59490864 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -841,9 +841,13 @@ pub fn completion(cx: &mut Context) { use std::time::Duration; // TODO: blocking here is not ideal + let pos = helix_lsp::util::pos_to_lsp_pos( + &cx.view.doc.text().slice(..), + cx.view.doc.selection().cursor(), + ); let res = smol::block_on( language_server - .completion(&cx.view.doc) + .completion(cx.view.doc.identifier(), pos) .timeout(Duration::from_secs(2)), ) .expect("completion failed!") diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index 25221922..629cb85c 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -41,7 +41,8 @@ impl EditorView { self.render_buffer(view, area, surface, theme); // clear with background color - surface.set_style(viewport, theme.get("ui.background")); + // TODO: this seems to prevent setting style later + // surface.set_style(viewport, theme.get("ui.background")); let area = Rect::new(0, viewport.height - 2, viewport.width, 1); self.render_statusline(view, area, surface, theme); -- cgit v1.2.3-70-g09d2