From b39849dde1b1277d14dbc4e2e1604e5d020db43d Mon Sep 17 00:00:00 2001 From: Blaž Hrastnik Date: Thu, 22 Oct 2020 14:35:07 +0900 Subject: Refactor: Document type as a wrapper around barebones State. --- helix-lsp/src/client.rs | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'helix-lsp/src/client.rs') diff --git a/helix-lsp/src/client.rs b/helix-lsp/src/client.rs index 93e137cb..56413768 100644 --- a/helix-lsp/src/client.rs +++ b/helix-lsp/src/client.rs @@ -6,6 +6,7 @@ use crate::{ type Result = core::result::Result; use helix_core::{State, Transaction}; +use helix_view::Document; // use std::collections::HashMap; @@ -190,13 +191,13 @@ impl Client { // Text document // ------------------------------------------------------------------------------------------- - pub async fn text_document_did_open(&mut self, state: &State) -> Result<()> { + pub async fn text_document_did_open(&mut self, doc: &Document) -> Result<()> { self.notify::(lsp::DidOpenTextDocumentParams { text_document: lsp::TextDocumentItem { - uri: lsp::Url::from_file_path(state.path().unwrap()).unwrap(), + uri: lsp::Url::from_file_path(doc.path().unwrap()).unwrap(), language_id: "rust".to_string(), // TODO: hardcoded for now - version: state.version, - text: String::from(&state.doc), + version: doc.version, + text: String::from(doc.text()), }, }) .await @@ -205,13 +206,13 @@ impl Client { // TODO: trigger any time history.commit_revision happens pub async fn text_document_did_change( &mut self, - state: &State, + doc: &Document, transaction: &Transaction, ) -> Result<()> { self.notify::(lsp::DidChangeTextDocumentParams { text_document: lsp::VersionedTextDocumentIdentifier::new( - lsp::Url::from_file_path(state.path().unwrap()).unwrap(), - state.version, + lsp::Url::from_file_path(doc.path().unwrap()).unwrap(), + doc.version, ), content_changes: vec![lsp::TextDocumentContentChangeEvent { // range = None -> whole document @@ -223,12 +224,12 @@ impl Client { .await } - // TODO: impl into() TextDocumentIdentifier / VersionedTextDocumentIdentifier for State. + // TODO: impl into() TextDocumentIdentifier / VersionedTextDocumentIdentifier for Document. - pub async fn text_document_did_close(&mut self, state: &State) -> Result<()> { + pub async fn text_document_did_close(&mut self, doc: &Document) -> Result<()> { self.notify::(lsp::DidCloseTextDocumentParams { text_document: lsp::TextDocumentIdentifier::new( - lsp::Url::from_file_path(state.path().unwrap()).unwrap(), + lsp::Url::from_file_path(doc.path().unwrap()).unwrap(), ), }) .await -- cgit v1.2.3-70-g09d2