on master help sign in
Pos conversions always operate on whole documents.
e9bd9e7Blaž Hrastnik
helix-lsp/src/client.rs−1
@@ -297,7 +297,6 @@ impl Client {
297 }
297 }
298
298
299 let old_text = old_text.slice(..);
299 let old_text = old_text.slice(..);
300− let new_text = new_text.slice(..);
301
300
302 while let Some(change) = iter.next() {
301 while let Some(change) = iter.next() {
303 let len = match change {
302 let len = match change {
helix-lsp/src/lib.rs+6−7
@@ -28,14 +28,14 @@ pub enum Error {
28
28
29pub mod util {
29pub mod util {
30 use super::*;
30 use super::*;
31− use helix_core::{Range, Rope, RopeSlice, Transaction};
31+ use helix_core::{Range, Rope, Transaction};
32
32
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 {
34 let line = doc.line_to_char(pos.line as usize);
34 let line = doc.line_to_char(pos.line as usize);
35 let line_start = doc.char_to_utf16_cu(line);
35 let line_start = doc.char_to_utf16_cu(line);
36 doc.utf16_cu_to_char(line_start + pos.character as usize)
36 doc.utf16_cu_to_char(line_start + pos.character as usize)
37 }
37 }
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 {
39 let line = doc.char_to_line(pos);
39 let line = doc.char_to_line(pos);
40 let line_start = doc.char_to_utf16_cu(doc.line_to_char(line));
40 let line_start = doc.char_to_utf16_cu(doc.line_to_char(line));
41 let col = doc.char_to_utf16_cu(pos) - line_start;
41 let col = doc.char_to_utf16_cu(pos) - line_start;
@@ -43,7 +43,7 @@ pub mod util {
43 lsp::Position::new(line as u32, col as u32)
43 lsp::Position::new(line as u32, col as u32)
44 }
44 }
45
45
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 {
47 let start = pos_to_lsp_pos(doc, range.from());
47 let start = pos_to_lsp_pos(doc, range.from());
48 let end = pos_to_lsp_pos(doc, range.to());
48 let end = pos_to_lsp_pos(doc, range.to());
49
49
@@ -51,7 +51,6 @@ pub mod util {
51 }
51 }
52
52
53 pub fn generate_transaction_from_edits(doc: &Rope, edits: Vec<lsp::TextEdit>) -> Transaction {
53 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
55 Transaction::change(
54 Transaction::change(
56 doc,
55 doc,
57 edits.into_iter().map(|edit| {
56 edits.into_iter().map(|edit| {
@@ -62,8 +61,8 @@ pub mod util {
62 None
61 None
63 };
62 };
64
63
65− let start = lsp_pos_to_pos(text, edit.range.start);
64+ let start = lsp_pos_to_pos(doc, edit.range.start);
66− let end = lsp_pos_to_pos(text, edit.range.end);
65+ let end = lsp_pos_to_pos(doc, edit.range.end);
67 (start, end, replacement)
66 (start, end, replacement)
68 }),
67 }),
69 )
68 )
helix-term/src/application.rs+1−1
@@ -134,7 +134,7 @@ impl Application {
134 .find(|view| view.doc.path() == path.as_ref());
134 .find(|view| view.doc.path() == path.as_ref());
135
135
136 if let Some(view) = view {
136 if let Some(view) = view {
137− let doc = view.doc.text().slice(..);
137+ let doc = view.doc.text();
138 let diagnostics = params
138 let diagnostics = params
139 .diagnostics
139 .diagnostics
140 .into_iter()
140 .into_iter()
helix-term/src/commands.rs+9−10
@@ -912,7 +912,7 @@ fn goto(cx: &mut Context, locations: Vec<lsp::Location>) {
912 cx.editor.open(PathBuf::from(location.uri.path()));
912 cx.editor.open(PathBuf::from(location.uri.path()));
913 let doc = cx.doc();
913 let doc = cx.doc();
914 let definition_pos = location.range.start;
914 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);
916 doc.set_selection(Selection::point(new_pos));
916 doc.set_selection(Selection::point(new_pos));
917 }
917 }
918 [] => (), // maybe show user message that no definition was found?
918 [] => (), // maybe show user message that no definition was found?
@@ -928,8 +928,7 @@ fn goto(cx: &mut Context, locations: Vec<lsp::Location>) {
928 editor.open(PathBuf::from(item.uri.path()));
928 editor.open(PathBuf::from(item.uri.path()));
929 let mut doc = &mut editor.view_mut().doc;
929 let mut doc = &mut editor.view_mut().doc;
930 let definition_pos = item.range.start;
930 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);
933 doc.set_selection(Selection::point(new_pos));
932 doc.set_selection(Selection::point(new_pos));
934 },
933 },
935 );
934 );
@@ -946,7 +945,7 @@ pub fn goto_definition(cx: &mut Context) {
946 };
945 };
947
946
948 // TODO: blocking here is not ideal
947 // 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());
950
949
951 // TODO: handle fails
950 // TODO: handle fails
952 let res =
951 let res =
@@ -962,7 +961,7 @@ pub fn goto_type_definition(cx: &mut Context) {
962 };
961 };
963
962
964 // TODO: blocking here is not ideal
963 // 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());
966
965
967 // TODO: handle fails
966 // TODO: handle fails
968 let res = smol::block_on(language_server.goto_type_definition(doc.identifier(), pos))
967 let res = smol::block_on(language_server.goto_type_definition(doc.identifier(), pos))
@@ -978,7 +977,7 @@ pub fn goto_implementation(cx: &mut Context) {
978 };
977 };
979
978
980 // TODO: blocking here is not ideal
979 // 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());
982
981
983 // TODO: handle fails
982 // TODO: handle fails
984 let res = smol::block_on(language_server.goto_implementation(doc.identifier(), pos))
983 let res = smol::block_on(language_server.goto_implementation(doc.identifier(), pos))
@@ -994,7 +993,7 @@ pub fn goto_reference(cx: &mut Context) {
994 };
993 };
995
994
996 // TODO: blocking here is not ideal
995 // 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());
998
997
999 // TODO: handle fails
998 // TODO: handle fails
1000 let res =
999 let res =
@@ -1223,7 +1222,7 @@ pub fn format_selections(cx: &mut Context) {
1223 .selection()
1222 .selection()
1224 .ranges()
1223 .ranges()
1225 .iter()
1224 .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))
1227 .collect();
1226 .collect();
1228
1227
1229 for range in ranges {
1228 for range in ranges {
@@ -1333,7 +1332,7 @@ pub fn completion(cx: &mut Context) {
1333 };
1332 };
1334
1333
1335 // TODO: blocking here is not ideal
1334 // 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());
1337
1336
1338 // TODO: handle fails
1337 // TODO: handle fails
1339
1338
@@ -1435,7 +1434,7 @@ pub fn hover(cx: &mut Context) {
1435
1434
1436 // TODO: blocking here is not ideal, make commands async fn?
1435 // TODO: blocking here is not ideal, make commands async fn?
1437 // not like we can process additional input meanwhile though
1436 // 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());
1439
1438
1440 // TODO: handle fails
1439 // TODO: handle fails
1441 let res = smol::block_on(language_server.text_document_hover(doc.identifier(), pos))
1440 let res = smol::block_on(language_server.text_document_hover(doc.identifier(), pos))