@@ -7,27 +7,31 @@ use helix_core::{
7 SmallVec, Tendril, Transaction,
7 SmallVec, Tendril, Transaction,
10−use once_cell::sync::Lazy;
10+use helix_view::{
12+ view::{View, PADDING},
13+ Document, DocumentId, Editor, ViewId,
18+ util::{lsp_pos_to_pos, pos_to_lsp_pos, range_to_lsp_range},
12use crate::{
21use crate::{
13 compositor::{Callback, Component, Compositor},
22 compositor::{Callback, Component, Compositor},
14 ui::{self, Completion, Picker, Popup, Prompt, PromptEvent},
23 ui::{self, Completion, Picker, Popup, Prompt, PromptEvent},
26+use crate::application::{LspCallbackWrapper, LspCallbacks};
27+use futures_util::FutureExt;
28+use std::future::Future;
17use std::borrow::Cow;
30use std::borrow::Cow;
18use std::path::{Path, PathBuf};
31use std::path::{Path, PathBuf};
22− view::{View, PADDING},
23− Document, DocumentId, Editor, ViewId,
26use crossterm::event::{KeyCode, KeyEvent};
33use crossterm::event::{KeyCode, KeyEvent};
27−
34+use once_cell::sync::Lazy;
30−use crate::application::{LspCallbackWrapper, LspCallbacks};
32pub struct Context<'a> {
36pub struct Context<'a> {
33 pub count: usize,
37 pub count: usize,
@@ -40,9 +44,6 @@ pub struct Context<'a> {
40 pub status_msg: Option<String>,
44 pub status_msg: Option<String>,
43−use futures_util::FutureExt;
44−use std::future::Future;
46impl<'a> Context<'a> {
47impl<'a> Context<'a> {
48 pub fn view(&mut self) -> &mut View {
49 pub fn view(&mut self) -> &mut View {
@@ -778,7 +779,6 @@ pub fn append_mode(cx: &mut Context) {
779const COMMAND_LIST: &[&str] = &["write", "open", "quit"];
780const COMMAND_LIST: &[&str] = &["write", "open", "quit"];
781−// TODO: I, A, o and O can share a lot of the primitives.
782pub fn command_mode(cx: &mut Context) {
782pub fn command_mode(cx: &mut Context) {
783 let prompt = Prompt::new(
783 let prompt = Prompt::new(
784 ":".to_owned(),
784 ":".to_owned(),
@@ -1091,7 +1091,7 @@ fn _goto(cx: &mut Context, locations: Vec<lsp::Location>) {
1091 .expect("editor.open failed");
1091 .expect("editor.open failed");
1092 let (view, doc) = editor.current();
1092 let (view, doc) = editor.current();
1093 let definition_pos = location.range.start;
1093 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);
1095 doc.set_selection(view.id, Selection::point(new_pos));
1095 doc.set_selection(view.id, Selection::point(new_pos));
@@ -1122,8 +1122,7 @@ pub fn goto_definition(cx: &mut Context) {
1122 None => return,
1122 None => return,
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());
1128 // TODO: handle fails
1127 // TODO: handle fails
1129 let res =
1128 let res =
@@ -1138,8 +1137,7 @@ pub fn goto_type_definition(cx: &mut Context) {
1138 None => return,
1137 None => return,
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());
1144 // TODO: handle fails
1142 // TODO: handle fails
1145 let res = smol::block_on(language_server.goto_type_definition(doc.identifier(), pos))
1143 let res = smol::block_on(language_server.goto_type_definition(doc.identifier(), pos))
@@ -1154,8 +1152,7 @@ pub fn goto_implementation(cx: &mut Context) {
1154 None => return,
1152 None => return,
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());
1160 // TODO: handle fails
1157 // TODO: handle fails
1161 let res = smol::block_on(language_server.goto_implementation(doc.identifier(), pos))
1158 let res = smol::block_on(language_server.goto_implementation(doc.identifier(), pos))
@@ -1170,8 +1167,7 @@ pub fn goto_reference(cx: &mut Context) {
1170 None => return,
1167 None => return,
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());
1176 // TODO: handle fails
1172 // TODO: handle fails
1177 let res =
1173 let res =
@@ -1187,8 +1183,7 @@ pub fn signature_help(cx: &mut Context) {
1187 None => return,
1183 None => return,
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());
1193 // TODO: handle fails
1188 // TODO: handle fails
@@ -1519,18 +1514,15 @@ pub fn unindent(cx: &mut Context) {
1521pub fn format_selections(cx: &mut Context) {
1516pub fn format_selections(cx: &mut Context) {
1522− use helix_lsp::lsp;
1523 let (view, doc) = cx.current();
1517 let (view, doc) = cx.current();
1525 // via lsp if available
1519 // via lsp if available
1526 // else via tree-sitter indentation calculations
1520 // else via tree-sitter indentation calculations
1528− // TODO: blocking here is not ideal
1530 let ranges: Vec<lsp::Range> = doc
1522 let ranges: Vec<lsp::Range> = doc
1531 .selection(view.id)
1523 .selection(view.id)
1533− .map(|range| helix_lsp::util::range_to_lsp_range(doc.text(), *range))
1525+ .map(|range| range_to_lsp_range(doc.text(), *range))
1534 .collect();
1526 .collect();
1536 for range in ranges {
1528 for range in ranges {
@@ -1675,11 +1667,9 @@ pub fn completion(cx: &mut Context) {
1675 None => return,
1667 None => return,
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());
1681 // TODO: handle fails
1672 // TODO: handle fails
1683 let res = smol::block_on(language_server.completion(doc.identifier(), pos)).unwrap();
1673 let res = smol::block_on(language_server.completion(doc.identifier(), pos)).unwrap();
1685 let trigger_offset = doc.selection(view.id).cursor();
1675 let trigger_offset = doc.selection(view.id).cursor();
@@ -1702,13 +1692,11 @@ pub fn completion(cx: &mut Context) {
1702 // TODO: if no completion, show some message or something
1692 // TODO: if no completion, show some message or something
1703 if !items.is_empty() {
1693 if !items.is_empty() {
1704 let completion = Completion::new(items, trigger_offset);
1694 let completion = Completion::new(items, trigger_offset);
1706− // Server error: content modified
1708 compositor.push(Box::new(completion));
1695 compositor.push(Box::new(completion));
1699+ // TODO: Server error: content modified
1713 // // TODO!: when iterating over items, show the docs in popup
1701 // // TODO!: when iterating over items, show the docs in popup
@@ -1717,8 +1705,6 @@ pub fn completion(cx: &mut Context) {
1719pub fn hover(cx: &mut Context) {
1707pub fn hover(cx: &mut Context) {
1720− use helix_lsp::lsp;
1722 let (view, doc) = cx.current();
1708 let (view, doc) = cx.current();
1724 let language_server = match doc.language_server() {
1710 let language_server = match doc.language_server() {
@@ -1730,7 +1716,7 @@ pub fn hover(cx: &mut Context) {
1731 // TODO: blocking here is not ideal, make commands async fn?
1717 // TODO: blocking here is not ideal, make commands async fn?
1732 // not like we can process additional input meanwhile though
1718 // 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());
1735 // TODO: handle fails
1721 // TODO: handle fails
1736 let res = smol::block_on(language_server.text_document_hover(doc.identifier(), pos))
1722 let res = smol::block_on(language_server.text_document_hover(doc.identifier(), pos))