@@ -16,6 +16,7 @@ use helix_view::{
16use helix_lsp::{
16use helix_lsp::{
18 util::{lsp_pos_to_pos, pos_to_lsp_pos, range_to_lsp_range},
18 util::{lsp_pos_to_pos, pos_to_lsp_pos, range_to_lsp_range},
21use crate::{
22use crate::{
@@ -1117,18 +1118,24 @@ pub fn exit_select_mode(cx: &mut Context) {
1117 cx.doc().mode = Mode::Normal;
1118 cx.doc().mode = Mode::Normal;
1120−fn _goto(cx: &mut Context, locations: Vec<lsp::Location>) {
1121+fn _goto(cx: &mut Context, locations: Vec<lsp::Location>, offset_encoding: OffsetEncoding) {
1121 use helix_view::editor::Action;
1122 use helix_view::editor::Action;
1123 push_jump(cx);
1124 push_jump(cx);
1127+ editor: &mut Editor,
1125− fn jump_to(editor: &mut Editor, location: &lsp::Location, action: Action) {
1128+ location: &lsp::Location,
1129+ offset_encoding: OffsetEncoding,
1126 let id = editor
1132 let id = editor
1127 .open(PathBuf::from(location.uri.path()), action)
1133 .open(PathBuf::from(location.uri.path()), action)
1128 .expect("editor.open failed");
1134 .expect("editor.open failed");
1129 let (view, doc) = editor.current();
1135 let (view, doc) = editor.current();
1130 let definition_pos = location.range.start;
1136 let definition_pos = location.range.start;
1137+ // TODO: convert inside server
1131− let new_pos = lsp_pos_to_pos(doc.text(), definition_pos);
1138+ let new_pos = lsp_pos_to_pos(doc.text(), definition_pos, offset_encoding);
1132 doc.set_selection(view.id, Selection::point(new_pos));
1139 doc.set_selection(view.id, Selection::point(new_pos));
1133 let line = doc.text().char_to_line(new_pos);
1140 let line = doc.text().char_to_line(new_pos);
1134 view.first_line = line.saturating_sub(view.area.height as usize / 2);
1141 view.first_line = line.saturating_sub(view.area.height as usize / 2);
@@ -1136,7 +1143,7 @@ fn _goto(cx: &mut Context, locations: Vec<lsp::Location>) {
1137 match locations.as_slice() {
1144 match locations.as_slice() {
1138 [location] => {
1145 [location] => {
1139− jump_to(cx.editor, location, Action::Replace);
1146+ jump_to(cx.editor, location, offset_encoding, Action::Replace);
1141 [] => (), // maybe show user message that no definition was found?
1148 [] => (), // maybe show user message that no definition was found?
1142 _locations => {
1149 _locations => {
@@ -1147,7 +1154,9 @@ fn _goto(cx: &mut Context, locations: Vec<lsp::Location>) {
1147 let line = location.range.start.line;
1154 let line = location.range.start.line;
1148 format!("{}:{}", file, line).into()
1155 format!("{}:{}", file, line).into()
1150− move |editor: &mut Editor, location, action| jump_to(editor, location, action),
1157+ move |editor: &mut Editor, location, action| {
1158+ jump_to(editor, location, offset_encoding, action)
1152 cx.push_layer(Box::new(picker));
1161 cx.push_layer(Box::new(picker));
@@ -1161,12 +1170,14 @@ pub fn goto_definition(cx: &mut Context) {
1161 None => return,
1170 None => return,
1173+ let offset_encoding = language_server.offset_encoding();
1164− let pos = pos_to_lsp_pos(doc.text(), doc.selection(view.id).cursor());
1175+ let pos = pos_to_lsp_pos(doc.text(), doc.selection(view.id).cursor(), offset_encoding);
1166 // TODO: handle fails
1177 // TODO: handle fails
1167 let res =
1178 let res =
1168 smol::block_on(language_server.goto_definition(doc.identifier(), pos)).unwrap_or_default();
1179 smol::block_on(language_server.goto_definition(doc.identifier(), pos)).unwrap_or_default();
1169− _goto(cx, res);
1180+ _goto(cx, res, offset_encoding);
1172pub fn goto_type_definition(cx: &mut Context) {
1183pub fn goto_type_definition(cx: &mut Context) {
@@ -1176,12 +1187,14 @@ pub fn goto_type_definition(cx: &mut Context) {
1176 None => return,
1187 None => return,
1190+ let offset_encoding = language_server.offset_encoding();
1179− let pos = pos_to_lsp_pos(doc.text(), doc.selection(view.id).cursor());
1192+ let pos = pos_to_lsp_pos(doc.text(), doc.selection(view.id).cursor(), offset_encoding);
1181 // TODO: handle fails
1194 // TODO: handle fails
1182 let res = smol::block_on(language_server.goto_type_definition(doc.identifier(), pos))
1195 let res = smol::block_on(language_server.goto_type_definition(doc.identifier(), pos))
1183 .unwrap_or_default();
1196 .unwrap_or_default();
1184− _goto(cx, res);
1197+ _goto(cx, res, offset_encoding);
1187pub fn goto_implementation(cx: &mut Context) {
1200pub fn goto_implementation(cx: &mut Context) {
@@ -1191,12 +1204,14 @@ pub fn goto_implementation(cx: &mut Context) {
1191 None => return,
1204 None => return,
1207+ let offset_encoding = language_server.offset_encoding();
1194− let pos = pos_to_lsp_pos(doc.text(), doc.selection(view.id).cursor());
1209+ let pos = pos_to_lsp_pos(doc.text(), doc.selection(view.id).cursor(), offset_encoding);
1196 // TODO: handle fails
1211 // TODO: handle fails
1197 let res = smol::block_on(language_server.goto_implementation(doc.identifier(), pos))
1212 let res = smol::block_on(language_server.goto_implementation(doc.identifier(), pos))
1198 .unwrap_or_default();
1213 .unwrap_or_default();
1199− _goto(cx, res);
1214+ _goto(cx, res, offset_encoding);
1202pub fn goto_reference(cx: &mut Context) {
1217pub fn goto_reference(cx: &mut Context) {
@@ -1206,12 +1221,14 @@ pub fn goto_reference(cx: &mut Context) {
1206 None => return,
1221 None => return,
1224+ let offset_encoding = language_server.offset_encoding();
1209− let pos = pos_to_lsp_pos(doc.text(), doc.selection(view.id).cursor());
1226+ let pos = pos_to_lsp_pos(doc.text(), doc.selection(view.id).cursor(), offset_encoding);
1211 // TODO: handle fails
1228 // TODO: handle fails
1212 let res =
1229 let res =
1213 smol::block_on(language_server.goto_reference(doc.identifier(), pos)).unwrap_or_default();
1230 smol::block_on(language_server.goto_reference(doc.identifier(), pos)).unwrap_or_default();
1214− _goto(cx, res);
1231+ _goto(cx, res, offset_encoding);
1217pub fn signature_help(cx: &mut Context) {
1234pub fn signature_help(cx: &mut Context) {
@@ -1222,7 +1239,11 @@ pub fn signature_help(cx: &mut Context) {
1222 None => return,
1239 None => return,
1242+ let pos = pos_to_lsp_pos(
1225− let pos = pos_to_lsp_pos(doc.text(), doc.selection(view.id).cursor());
1244+ doc.selection(view.id).cursor(),
1245+ language_server.offset_encoding(),
1227 // TODO: handle fails
1248 // TODO: handle fails
@@ -1579,10 +1600,15 @@ pub fn format_selections(cx: &mut Context) {
1579 // via lsp if available
1600 // via lsp if available
1580 // else via tree-sitter indentation calculations
1601 // else via tree-sitter indentation calculations
1603+ let language_server = match doc.language_server() {
1604+ Some(language_server) => language_server,
1582 let ranges: Vec<lsp::Range> = doc
1608 let ranges: Vec<lsp::Range> = doc
1583 .selection(view.id)
1609 .selection(view.id)
1585− .map(|range| range_to_lsp_range(doc.text(), *range))
1611+ .map(|range| range_to_lsp_range(doc.text(), *range, language_server.offset_encoding()))
1586 .collect();
1612 .collect();
1588 for range in ranges {
1614 for range in ranges {
@@ -1590,7 +1616,6 @@ pub fn format_selections(cx: &mut Context) {
1590 Some(language_server) => language_server,
1616 Some(language_server) => language_server,
1591 None => return,
1617 None => return,
1594 // TODO: handle fails
1619 // TODO: handle fails
1595 // TODO: concurrent map
1620 // TODO: concurrent map
1596 let edits = smol::block_on(language_server.text_document_range_formatting(
1621 let edits = smol::block_on(language_server.text_document_range_formatting(
@@ -1600,7 +1625,11 @@ pub fn format_selections(cx: &mut Context) {
1601 .unwrap_or_default();
1626 .unwrap_or_default();
1603− let transaction = helix_lsp::util::generate_transaction_from_edits(doc.text(), edits);
1628+ let transaction = helix_lsp::util::generate_transaction_from_edits(
1631+ language_server.offset_encoding(),
1605 doc.apply(&transaction, view.id);
1634 doc.apply(&transaction, view.id);
@@ -1726,7 +1755,13 @@ pub fn completion(cx: &mut Context) {
1726 None => return,
1755 None => return,
1758+ let offset_encoding = language_server.offset_encoding();
1760+ let pos = pos_to_lsp_pos(
1729− let pos = pos_to_lsp_pos(doc.text(), doc.selection(view.id).cursor());
1762+ doc.selection(view.id).cursor(),
1763+ language_server.offset_encoding(),
1731 // TODO: handle fails
1766 // TODO: handle fails
1732 let res = smol::block_on(language_server.completion(doc.identifier(), pos)).unwrap();
1767 let res = smol::block_on(language_server.completion(doc.identifier(), pos)).unwrap();
@@ -1754,7 +1789,7 @@ pub fn completion(cx: &mut Context) {
1754 let size = compositor.size();
1789 let size = compositor.size();
1755 let ui = compositor.find("hx::ui::editor::EditorView").unwrap();
1790 let ui = compositor.find("hx::ui::editor::EditorView").unwrap();
1756 if let Some(ui) = ui.as_any_mut().downcast_mut::<ui::EditorView>() {
1791 if let Some(ui) = ui.as_any_mut().downcast_mut::<ui::EditorView>() {
1757− ui.set_completion(items, trigger_offset, size);
1792+ ui.set_completion(items, offset_encoding, trigger_offset, size);
@@ -1779,7 +1814,11 @@ pub fn hover(cx: &mut Context) {
1780 // TODO: blocking here is not ideal, make commands async fn?
1815 // TODO: blocking here is not ideal, make commands async fn?
1781 // not like we can process additional input meanwhile though
1816 // not like we can process additional input meanwhile though
1817+ let pos = pos_to_lsp_pos(
1782− let pos = pos_to_lsp_pos(doc.text(), doc.selection(view.id).cursor());
1819+ doc.selection(view.id).cursor(),
1820+ language_server.offset_encoding(),
1784 // TODO: handle fails
1823 // TODO: handle fails
1785 let res = smol::block_on(language_server.text_document_hover(doc.identifier(), pos))
1824 let res = smol::block_on(language_server.text_document_hover(doc.identifier(), pos))