on master help sign in
Pos conversions always operate on whole documents.
commite9bd9e72c3adf822ae569644dd87f4a5e04df18e authorBlaž Hrastnik <blaz@mxxn.io> dateThu 18 Mar 2021, 15:23 (6 years ago) parent175d38c
4 files changed+16−19
helix-lsp/src/client.rs−1 helix-lsp/src/lib.rs+6−7 helix-term/src/application.rs+1−1 helix-term/src/commands.rs+9−10
helix-lsp/src/client.rs−1
@@ -297,7 +297,6 @@ impl Client {
297297 }
298298
299299 let old_text = old_text.slice(..);
300− let new_text = new_text.slice(..);
301300
302301 while let Some(change) = iter.next() {
303302 let len = match change {
helix-lsp/src/lib.rs+6−7
@@ -28,14 +28,14 @@ pub enum Error {
2828
2929pub mod util {
3030 use super::*;
31− use helix_core::{Range, Rope, RopeSlice, Transaction};
31+ use helix_core::{Range, Rope, Transaction};
3232
33− pub fn lsp_pos_to_pos(doc: RopeSlice, pos: lsp::Position) -> usize {
33+ pub fn lsp_pos_to_pos(doc: &Rope, pos: lsp::Position) -> usize {
3434 let line = doc.line_to_char(pos.line as usize);
3535 let line_start = doc.char_to_utf16_cu(line);
3636 doc.utf16_cu_to_char(line_start + pos.character as usize)
3737 }
38− pub fn pos_to_lsp_pos(doc: RopeSlice, pos: usize) -> lsp::Position {
38+ pub fn pos_to_lsp_pos(doc: &Rope, pos: usize) -> lsp::Position {
3939 let line = doc.char_to_line(pos);
4040 let line_start = doc.char_to_utf16_cu(doc.line_to_char(line));
4141 let col = doc.char_to_utf16_cu(pos) - line_start;
@@ -43,7 +43,7 @@ pub mod util {
4343 lsp::Position::new(line as u32, col as u32)
4444 }
4545
46− pub fn range_to_lsp_range(doc: RopeSlice, range: Range) -> lsp::Range {
46+ pub fn range_to_lsp_range(doc: &Rope, range: Range) -> lsp::Range {
4747 let start = pos_to_lsp_pos(doc, range.from());
4848 let end = pos_to_lsp_pos(doc, range.to());
4949
@@ -51,7 +51,6 @@ pub mod util {
5151 }
5252
5353 pub fn generate_transaction_from_edits(doc: &Rope, edits: Vec<lsp::TextEdit>) -> Transaction {
54− let text = doc.slice(..); // would be unnecessary if Transaction::change took Rope | RopeSlice
5554 Transaction::change(
5655 doc,
5756 edits.into_iter().map(|edit| {
@@ -62,8 +61,8 @@ pub mod util {
6261 None
6362 };
6463
65− let start = lsp_pos_to_pos(text, edit.range.start);
66− let end = lsp_pos_to_pos(text, edit.range.end);
64+ let start = lsp_pos_to_pos(doc, edit.range.start);
65+ let end = lsp_pos_to_pos(doc, edit.range.end);
6766 (start, end, replacement)
6867 }),
6968 )
helix-term/src/application.rs+1−1
@@ -134,7 +134,7 @@ impl Application {
134134 .find(|view| view.doc.path() == path.as_ref());
135135
136136 if let Some(view) = view {
137− let doc = view.doc.text().slice(..);
137+ let doc = view.doc.text();
138138 let diagnostics = params
139139 .diagnostics
140140 .into_iter()
helix-term/src/commands.rs+9−10
@@ -912,7 +912,7 @@ fn goto(cx: &mut Context, locations: Vec<lsp::Location>) {
912912 cx.editor.open(PathBuf::from(location.uri.path()));
913913 let doc = cx.doc();
914914 let definition_pos = location.range.start;
915− let new_pos = helix_lsp::util::lsp_pos_to_pos(doc.text().slice(..), definition_pos);
915+ let new_pos = helix_lsp::util::lsp_pos_to_pos(doc.text(), definition_pos);
916916 doc.set_selection(Selection::point(new_pos));
917917 }
918918 [] => (), // maybe show user message that no definition was found?
@@ -928,8 +928,7 @@ fn goto(cx: &mut Context, locations: Vec<lsp::Location>) {
928928 editor.open(PathBuf::from(item.uri.path()));
929929 let mut doc = &mut editor.view_mut().doc;
930930 let definition_pos = item.range.start;
931− let new_pos =
932− helix_lsp::util::lsp_pos_to_pos(doc.text().slice(..), definition_pos);
931+ let new_pos = helix_lsp::util::lsp_pos_to_pos(doc.text(), definition_pos);
933932 doc.set_selection(Selection::point(new_pos));
934933 },
935934 );
@@ -946,7 +945,7 @@ pub fn goto_definition(cx: &mut Context) {
946945 };
947946
948947 // TODO: blocking here is not ideal
949− let pos = helix_lsp::util::pos_to_lsp_pos(doc.text().slice(..), doc.selection().cursor());
948+ let pos = helix_lsp::util::pos_to_lsp_pos(doc.text(), doc.selection().cursor());
950949
951950 // TODO: handle fails
952951 let res =
@@ -962,7 +961,7 @@ pub fn goto_type_definition(cx: &mut Context) {
962961 };
963962
964963 // TODO: blocking here is not ideal
965− let pos = helix_lsp::util::pos_to_lsp_pos(doc.text().slice(..), doc.selection().cursor());
964+ let pos = helix_lsp::util::pos_to_lsp_pos(doc.text(), doc.selection().cursor());
966965
967966 // TODO: handle fails
968967 let res = smol::block_on(language_server.goto_type_definition(doc.identifier(), pos))
@@ -978,7 +977,7 @@ pub fn goto_implementation(cx: &mut Context) {
978977 };
979978
980979 // TODO: blocking here is not ideal
981− let pos = helix_lsp::util::pos_to_lsp_pos(doc.text().slice(..), doc.selection().cursor());
980+ let pos = helix_lsp::util::pos_to_lsp_pos(doc.text(), doc.selection().cursor());
982981
983982 // TODO: handle fails
984983 let res = smol::block_on(language_server.goto_implementation(doc.identifier(), pos))
@@ -994,7 +993,7 @@ pub fn goto_reference(cx: &mut Context) {
994993 };
995994
996995 // TODO: blocking here is not ideal
997− let pos = helix_lsp::util::pos_to_lsp_pos(doc.text().slice(..), doc.selection().cursor());
996+ let pos = helix_lsp::util::pos_to_lsp_pos(doc.text(), doc.selection().cursor());
998997
999998 // TODO: handle fails
1000999 let res =
@@ -1223,7 +1222,7 @@ pub fn format_selections(cx: &mut Context) {
12231222 .selection()
12241223 .ranges()
12251224 .iter()
1226− .map(|range| helix_lsp::util::range_to_lsp_range(doc.text().slice(..), *range))
1225+ .map(|range| helix_lsp::util::range_to_lsp_range(doc.text(), *range))
12271226 .collect();
12281227
12291228 for range in ranges {
@@ -1333,7 +1332,7 @@ pub fn completion(cx: &mut Context) {
13331332 };
13341333
13351334 // TODO: blocking here is not ideal
1336− let pos = helix_lsp::util::pos_to_lsp_pos(doc.text().slice(..), doc.selection().cursor());
1335+ let pos = helix_lsp::util::pos_to_lsp_pos(doc.text(), doc.selection().cursor());
13371336
13381337 // TODO: handle fails
13391338
@@ -1435,7 +1434,7 @@ pub fn hover(cx: &mut Context) {
14351434
14361435 // TODO: blocking here is not ideal, make commands async fn?
14371436 // not like we can process additional input meanwhile though
1438− let pos = helix_lsp::util::pos_to_lsp_pos(doc.text().slice(..), doc.selection().cursor());
1437+ let pos = helix_lsp::util::pos_to_lsp_pos(doc.text(), doc.selection().cursor());
14391438
14401439 // TODO: handle fails
14411440 let res = smol::block_on(language_server.text_document_hover(doc.identifier(), pos))