From e9bd9e72c3adf822ae569644dd87f4a5e04df18e Mon Sep 17 00:00:00 2001 From: Blaž Hrastnik Date: Thu, 18 Mar 2021 15:23:42 +0900 Subject: Pos conversions always operate on whole documents. --- helix-term/src/application.rs | 2 +- helix-term/src/commands.rs | 19 +++++++++---------- 2 files changed, 10 insertions(+), 11 deletions(-) (limited to 'helix-term') diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index ef33db16..48d7186f 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -134,7 +134,7 @@ impl Application { .find(|view| view.doc.path() == path.as_ref()); if let Some(view) = view { - let doc = view.doc.text().slice(..); + let doc = view.doc.text(); let diagnostics = params .diagnostics .into_iter() diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 97edaf66..291f8577 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -912,7 +912,7 @@ fn goto(cx: &mut Context, locations: Vec) { cx.editor.open(PathBuf::from(location.uri.path())); let doc = cx.doc(); let definition_pos = location.range.start; - let new_pos = helix_lsp::util::lsp_pos_to_pos(doc.text().slice(..), definition_pos); + let new_pos = helix_lsp::util::lsp_pos_to_pos(doc.text(), definition_pos); doc.set_selection(Selection::point(new_pos)); } [] => (), // maybe show user message that no definition was found? @@ -928,8 +928,7 @@ fn goto(cx: &mut Context, locations: Vec) { editor.open(PathBuf::from(item.uri.path())); let mut doc = &mut editor.view_mut().doc; let definition_pos = item.range.start; - let new_pos = - helix_lsp::util::lsp_pos_to_pos(doc.text().slice(..), definition_pos); + let new_pos = helix_lsp::util::lsp_pos_to_pos(doc.text(), definition_pos); doc.set_selection(Selection::point(new_pos)); }, ); @@ -946,7 +945,7 @@ pub fn goto_definition(cx: &mut Context) { }; // TODO: blocking here is not ideal - let pos = helix_lsp::util::pos_to_lsp_pos(doc.text().slice(..), doc.selection().cursor()); + let pos = helix_lsp::util::pos_to_lsp_pos(doc.text(), doc.selection().cursor()); // TODO: handle fails let res = @@ -962,7 +961,7 @@ pub fn goto_type_definition(cx: &mut Context) { }; // TODO: blocking here is not ideal - let pos = helix_lsp::util::pos_to_lsp_pos(doc.text().slice(..), doc.selection().cursor()); + let pos = helix_lsp::util::pos_to_lsp_pos(doc.text(), doc.selection().cursor()); // TODO: handle fails let res = smol::block_on(language_server.goto_type_definition(doc.identifier(), pos)) @@ -978,7 +977,7 @@ pub fn goto_implementation(cx: &mut Context) { }; // TODO: blocking here is not ideal - let pos = helix_lsp::util::pos_to_lsp_pos(doc.text().slice(..), doc.selection().cursor()); + let pos = helix_lsp::util::pos_to_lsp_pos(doc.text(), doc.selection().cursor()); // TODO: handle fails let res = smol::block_on(language_server.goto_implementation(doc.identifier(), pos)) @@ -994,7 +993,7 @@ pub fn goto_reference(cx: &mut Context) { }; // TODO: blocking here is not ideal - let pos = helix_lsp::util::pos_to_lsp_pos(doc.text().slice(..), doc.selection().cursor()); + let pos = helix_lsp::util::pos_to_lsp_pos(doc.text(), doc.selection().cursor()); // TODO: handle fails let res = @@ -1223,7 +1222,7 @@ pub fn format_selections(cx: &mut Context) { .selection() .ranges() .iter() - .map(|range| helix_lsp::util::range_to_lsp_range(doc.text().slice(..), *range)) + .map(|range| helix_lsp::util::range_to_lsp_range(doc.text(), *range)) .collect(); for range in ranges { @@ -1333,7 +1332,7 @@ pub fn completion(cx: &mut Context) { }; // TODO: blocking here is not ideal - let pos = helix_lsp::util::pos_to_lsp_pos(doc.text().slice(..), doc.selection().cursor()); + let pos = helix_lsp::util::pos_to_lsp_pos(doc.text(), doc.selection().cursor()); // TODO: handle fails @@ -1435,7 +1434,7 @@ pub fn hover(cx: &mut Context) { // TODO: blocking here is not ideal, make commands async fn? // not like we can process additional input meanwhile though - let pos = helix_lsp::util::pos_to_lsp_pos(doc.text().slice(..), doc.selection().cursor()); + let pos = helix_lsp::util::pos_to_lsp_pos(doc.text(), doc.selection().cursor()); // TODO: handle fails let res = smol::block_on(language_server.text_document_hover(doc.identifier(), pos)) -- cgit v1.2.3-70-g09d2