@@ -7,27 +7,31 @@ use helix_core::{
77 SmallVec, Tendril, Transaction,
88};
99
10−use once_cell::sync::Lazy;
10+use helix_view::{
11+ document::Mode,
12+ view::{View, PADDING},
13+ Document, DocumentId, Editor, ViewId,
14+};
15+
16+use helix_lsp::{
17+ lsp,
18+ util::{lsp_pos_to_pos, pos_to_lsp_pos, range_to_lsp_range},
19+};
1120
1221use crate::{
1322 compositor::{Callback, Component, Compositor},
1423 ui::{self, Completion, Picker, Popup, Prompt, PromptEvent},
1524};
1625
26+use crate::application::{LspCallbackWrapper, LspCallbacks};
27+use futures_util::FutureExt;
28+use std::future::Future;
29+
1730use std::borrow::Cow;
1831use std::path::{Path, PathBuf};
1932
20−use helix_view::{
21− document::Mode,
22− view::{View, PADDING},
23− Document, DocumentId, Editor, ViewId,
24−};
25−
2633use crossterm::event::{KeyCode, KeyEvent};
27−
28−use helix_lsp::lsp;
29−
30−use crate::application::{LspCallbackWrapper, LspCallbacks};
34+use once_cell::sync::Lazy;
3135
3236pub struct Context<'a> {
3337 pub count: usize,
@@ -40,9 +44,6 @@ pub struct Context<'a> {
4044 pub status_msg: Option<String>,
4145}
4246
43−use futures_util::FutureExt;
44−use std::future::Future;
45−
4647impl<'a> Context<'a> {
4748 #[inline]
4849 pub fn view(&mut self) -> &mut View {
@@ -778,7 +779,6 @@ pub fn append_mode(cx: &mut Context) {
778779
779780const COMMAND_LIST: &[&str] = &["write", "open", "quit"];
780781
781−// TODO: I, A, o and O can share a lot of the primitives.
782782pub fn command_mode(cx: &mut Context) {
783783 let prompt = Prompt::new(
784784 ":".to_owned(),
@@ -1091,7 +1091,7 @@ fn _goto(cx: &mut Context, locations: Vec<lsp::Location>) {
10911091 .expect("editor.open failed");
10921092 let (view, doc) = editor.current();
10931093 let definition_pos = location.range.start;
1094− let new_pos = helix_lsp::util::lsp_pos_to_pos(doc.text(), definition_pos);
1094+ let new_pos = lsp_pos_to_pos(doc.text(), definition_pos);
10951095 doc.set_selection(view.id, Selection::point(new_pos));
10961096 }
10971097
@@ -1122,8 +1122,7 @@ pub fn goto_definition(cx: &mut Context) {
11221122 None => return,
11231123 };
11241124
1125− // TODO: blocking here is not ideal
1126− let pos = helix_lsp::util::pos_to_lsp_pos(doc.text(), doc.selection(view.id).cursor());
1125+ let pos = pos_to_lsp_pos(doc.text(), doc.selection(view.id).cursor());
11271126
11281127 // TODO: handle fails
11291128 let res =
@@ -1138,8 +1137,7 @@ pub fn goto_type_definition(cx: &mut Context) {
11381137 None => return,
11391138 };
11401139
1141− // TODO: blocking here is not ideal
1142− let pos = helix_lsp::util::pos_to_lsp_pos(doc.text(), doc.selection(view.id).cursor());
1140+ let pos = pos_to_lsp_pos(doc.text(), doc.selection(view.id).cursor());
11431141
11441142 // TODO: handle fails
11451143 let res = smol::block_on(language_server.goto_type_definition(doc.identifier(), pos))
@@ -1154,8 +1152,7 @@ pub fn goto_implementation(cx: &mut Context) {
11541152 None => return,
11551153 };
11561154
1157− // TODO: blocking here is not ideal
1158− let pos = helix_lsp::util::pos_to_lsp_pos(doc.text(), doc.selection(view.id).cursor());
1155+ let pos = pos_to_lsp_pos(doc.text(), doc.selection(view.id).cursor());
11591156
11601157 // TODO: handle fails
11611158 let res = smol::block_on(language_server.goto_implementation(doc.identifier(), pos))
@@ -1170,8 +1167,7 @@ pub fn goto_reference(cx: &mut Context) {
11701167 None => return,
11711168 };
11721169
1173− // TODO: blocking here is not ideal
1174− let pos = helix_lsp::util::pos_to_lsp_pos(doc.text(), doc.selection(view.id).cursor());
1170+ let pos = pos_to_lsp_pos(doc.text(), doc.selection(view.id).cursor());
11751171
11761172 // TODO: handle fails
11771173 let res =
@@ -1187,8 +1183,7 @@ pub fn signature_help(cx: &mut Context) {
11871183 None => return,
11881184 };
11891185
1190− // TODO: blocking here is not ideal
1191− let pos = helix_lsp::util::pos_to_lsp_pos(doc.text(), doc.selection(view.id).cursor());
1186+ let pos = pos_to_lsp_pos(doc.text(), doc.selection(view.id).cursor());
11921187
11931188 // TODO: handle fails
11941189
@@ -1519,18 +1514,15 @@ pub fn unindent(cx: &mut Context) {
15191514}
15201515
15211516pub fn format_selections(cx: &mut Context) {
1522− use helix_lsp::lsp;
15231517 let (view, doc) = cx.current();
15241518
15251519 // via lsp if available
15261520 // else via tree-sitter indentation calculations
15271521
1528− // TODO: blocking here is not ideal
1529−
15301522 let ranges: Vec<lsp::Range> = doc
15311523 .selection(view.id)
15321524 .iter()
1533− .map(|range| helix_lsp::util::range_to_lsp_range(doc.text(), *range))
1525+ .map(|range| range_to_lsp_range(doc.text(), *range))
15341526 .collect();
15351527
15361528 for range in ranges {
@@ -1675,11 +1667,9 @@ pub fn completion(cx: &mut Context) {
16751667 None => return,
16761668 };
16771669
1678− // TODO: blocking here is not ideal
1679− let pos = helix_lsp::util::pos_to_lsp_pos(doc.text(), doc.selection(view.id).cursor());
1670+ let pos = pos_to_lsp_pos(doc.text(), doc.selection(view.id).cursor());
16801671
16811672 // TODO: handle fails
1682−
16831673 let res = smol::block_on(language_server.completion(doc.identifier(), pos)).unwrap();
16841674
16851675 let trigger_offset = doc.selection(view.id).cursor();
@@ -1702,13 +1692,11 @@ pub fn completion(cx: &mut Context) {
17021692 // TODO: if no completion, show some message or something
17031693 if !items.is_empty() {
17041694 let completion = Completion::new(items, trigger_offset);
1705−
1706− // Server error: content modified
1707−
17081695 compositor.push(Box::new(completion));
17091696 }
17101697 },
17111698 );
1699+ // TODO: Server error: content modified
17121700
17131701 // // TODO!: when iterating over items, show the docs in popup
17141702
@@ -1717,8 +1705,6 @@ pub fn completion(cx: &mut Context) {
17171705}
17181706
17191707pub fn hover(cx: &mut Context) {
1720− use helix_lsp::lsp;
1721−
17221708 let (view, doc) = cx.current();
17231709
17241710 let language_server = match doc.language_server() {
@@ -1730,7 +1716,7 @@ pub fn hover(cx: &mut Context) {
17301716
17311717 // TODO: blocking here is not ideal, make commands async fn?
17321718 // not like we can process additional input meanwhile though
1733− let pos = helix_lsp::util::pos_to_lsp_pos(doc.text(), doc.selection(view.id).cursor());
1719+ let pos = pos_to_lsp_pos(doc.text(), doc.selection(view.id).cursor());
17341720
17351721 // TODO: handle fails
17361722 let res = smol::block_on(language_server.text_document_hover(doc.identifier(), pos))