@@ -10,7 +10,7 @@ use helix_core::{
1010use once_cell::sync::Lazy;
1111
1212use crate::{
13− compositor::Compositor,
13+ compositor::{Callback, Compositor},
1414 ui::{self, Popup, Prompt, PromptEvent},
1515};
1616
@@ -41,8 +41,8 @@ impl<'a> Context<'a> {
4141 }
4242
4343 #[inline]
44− pub fn doc(&mut self) -> &mut Document {
45− &mut self.editor.view_mut().doc
44+ pub fn doc(&mut self) -> std::cell::RefMut<Document> {
45+ self.editor.view().doc.borrow_mut()
4646 }
4747
4848 /// Push a new component onto the compositor.
@@ -72,7 +72,7 @@ pub type Command = fn(cx: &mut Context);
7272
7373pub fn move_char_left(cx: &mut Context) {
7474 let count = cx.count;
75− let doc = cx.doc();
75+ let mut doc = cx.doc();
7676 let text = doc.text().slice(..);
7777 let selection = doc.selection().transform(|range| {
7878 movement::move_horizontally(
@@ -88,7 +88,7 @@ pub fn move_char_left(cx: &mut Context) {
8888
8989pub fn move_char_right(cx: &mut Context) {
9090 let count = cx.count;
91− let doc = cx.doc();
91+ let mut doc = cx.doc();
9292 let text = doc.text().slice(..);
9393 let selection = doc.selection().transform(|range| {
9494 movement::move_horizontally(
@@ -104,7 +104,7 @@ pub fn move_char_right(cx: &mut Context) {
104104
105105pub fn move_line_up(cx: &mut Context) {
106106 let count = cx.count;
107− let doc = cx.doc();
107+ let mut doc = cx.doc();
108108 let text = doc.text().slice(..);
109109 let selection = doc.selection().transform(|range| {
110110 movement::move_vertically(
@@ -120,7 +120,7 @@ pub fn move_line_up(cx: &mut Context) {
120120
121121pub fn move_line_down(cx: &mut Context) {
122122 let count = cx.count;
123− let doc = cx.doc();
123+ let mut doc = cx.doc();
124124 let text = doc.text().slice(..);
125125 let selection = doc.selection().transform(|range| {
126126 movement::move_vertically(
@@ -135,7 +135,7 @@ pub fn move_line_down(cx: &mut Context) {
135135}
136136
137137pub fn move_line_end(cx: &mut Context) {
138− let doc = cx.doc();
138+ let mut doc = cx.doc();
139139 let lines = selection_lines(doc.text(), doc.selection());
140140
141141 let positions = lines
@@ -155,7 +155,7 @@ pub fn move_line_end(cx: &mut Context) {
155155}
156156
157157pub fn move_line_start(cx: &mut Context) {
158− let doc = cx.doc();
158+ let mut doc = cx.doc();
159159 let lines = selection_lines(doc.text(), doc.selection());
160160
161161 let positions = lines
@@ -177,7 +177,7 @@ pub fn move_line_start(cx: &mut Context) {
177177
178178pub fn move_next_word_start(cx: &mut Context) {
179179 let count = cx.count;
180− let doc = cx.doc();
180+ let mut doc = cx.doc();
181181 let text = doc.text().slice(..);
182182
183183 let selection = doc.selection().transform(|range| {
@@ -190,7 +190,7 @@ pub fn move_next_word_start(cx: &mut Context) {
190190
191191pub fn move_prev_word_start(cx: &mut Context) {
192192 let count = cx.count;
193− let doc = cx.doc();
193+ let mut doc = cx.doc();
194194 let text = doc.text().slice(..);
195195
196196 let selection = doc.selection().transform(|range| {
@@ -203,7 +203,7 @@ pub fn move_prev_word_start(cx: &mut Context) {
203203
204204pub fn move_next_word_end(cx: &mut Context) {
205205 let count = cx.count;
206− let doc = cx.doc();
206+ let mut doc = cx.doc();
207207 let text = doc.text().slice(..);
208208
209209 let selection = doc.selection().transform(|range| {
@@ -215,14 +215,14 @@ pub fn move_next_word_end(cx: &mut Context) {
215215}
216216
217217pub fn move_file_start(cx: &mut Context) {
218− let doc = cx.doc();
218+ let mut doc = cx.doc();
219219 doc.set_selection(Selection::point(0));
220220
221221 doc.mode = Mode::Normal;
222222}
223223
224224pub fn move_file_end(cx: &mut Context) {
225− let doc = cx.doc();
225+ let mut doc = cx.doc();
226226 let text = doc.text();
227227 let last_line = text.line_to_char(text.len_lines().saturating_sub(2));
228228 doc.set_selection(Selection::point(last_line));
@@ -232,7 +232,7 @@ pub fn move_file_end(cx: &mut Context) {
232232
233233pub fn extend_next_word_start(cx: &mut Context) {
234234 let count = cx.count;
235− let doc = cx.doc();
235+ let mut doc = cx.doc();
236236 let text = doc.text().slice(..);
237237
238238 let selection = doc.selection().transform(|mut range| {
@@ -245,7 +245,7 @@ pub fn extend_next_word_start(cx: &mut Context) {
245245
246246pub fn extend_prev_word_start(cx: &mut Context) {
247247 let count = cx.count;
248− let doc = cx.doc();
248+ let mut doc = cx.doc();
249249 let text = doc.text().slice(..);
250250
251251 let selection = doc.selection().transform(|mut range| {
@@ -257,7 +257,7 @@ pub fn extend_prev_word_start(cx: &mut Context) {
257257
258258pub fn extend_next_word_end(cx: &mut Context) {
259259 let count = cx.count;
260− let doc = cx.doc();
260+ let mut doc = cx.doc();
261261 let text = doc.text().slice(..);
262262
263263 let selection = doc.selection().transform(|mut range| {
@@ -286,7 +286,7 @@ where
286286 ..
287287 } = event
288288 {
289− let doc = cx.doc();
289+ let mut doc = cx.doc();
290290 let text = doc.text().slice(..);
291291
292292 let selection = doc.selection().transform(|mut range| {
@@ -382,11 +382,13 @@ pub fn extend_prev_char(cx: &mut Context) {
382382
383383fn scroll(view: &mut View, offset: usize, direction: Direction) {
384384 use Direction::*;
385− let text = view.doc.text().slice(..);
385+ // we use short lived borrows since view's methods read from doc too
386+ let doc = view.doc.borrow();
387+ let text = doc.text().slice(..);
388+ let cursor = coords_at_pos(doc.text().slice(..), doc.selection().cursor());
389+ let doc_last_line = doc.text().len_lines() - 1;
386390
387391 let last_line = view.last_line();
388− let cursor = coords_at_pos(text, view.doc.selection().cursor());
389− let doc_last_line = text.len_lines() - 1;
390392
391393 if direction == Backward && view.first_line == 0
392394 || direction == Forward && last_line == doc_last_line
@@ -412,7 +414,8 @@ fn scroll(view: &mut View, offset: usize, direction: Direction) {
412414 );
413415
414416 let pos = pos_at_coords(text, Position::new(line, cursor.col)); // this func will properly truncate to line end
415− view.doc.set_selection(Selection::point(pos));
417+ drop(doc); // upgrade to mutable borrow
418+ view.doc.borrow_mut().set_selection(Selection::point(pos));
416419}
417420
418421pub fn page_up(cx: &mut Context) {
@@ -437,7 +440,7 @@ pub fn half_page_down(cx: &mut Context) {
437440
438441pub fn extend_char_left(cx: &mut Context) {
439442 let count = cx.count;
440− let doc = cx.doc();
443+ let mut doc = cx.doc();
441444 let text = doc.text().slice(..);
442445 let selection = doc.selection().transform(|range| {
443446 movement::move_horizontally(
@@ -453,7 +456,7 @@ pub fn extend_char_left(cx: &mut Context) {
453456
454457pub fn extend_char_right(cx: &mut Context) {
455458 let count = cx.count;
456− let doc = cx.doc();
459+ let mut doc = cx.doc();
457460 let text = doc.text().slice(..);
458461 let selection = doc.selection().transform(|range| {
459462 movement::move_horizontally(
@@ -469,7 +472,7 @@ pub fn extend_char_right(cx: &mut Context) {
469472
470473pub fn extend_line_up(cx: &mut Context) {
471474 let count = cx.count;
472− let doc = cx.doc();
475+ let mut doc = cx.doc();
473476 let text = doc.text().slice(..);
474477 let selection = doc.selection().transform(|range| {
475478 movement::move_vertically(
@@ -485,7 +488,7 @@ pub fn extend_line_up(cx: &mut Context) {
485488
486489pub fn extend_line_down(cx: &mut Context) {
487490 let count = cx.count;
488− let doc = cx.doc();
491+ let mut doc = cx.doc();
489492 let text = doc.text().slice(..);
490493 let selection = doc.selection().transform(|range| {
491494 movement::move_vertically(
@@ -500,12 +503,10 @@ pub fn extend_line_down(cx: &mut Context) {
500503}
501504
502505pub fn select_all(cx: &mut Context) {
503− let doc = cx.doc();
506+ let mut doc = cx.doc();
504507
505− doc.set_selection(Selection::single(
506− 0,
507− doc.text().len_chars().saturating_sub(1),
508− ))
508+ let end = doc.text().len_chars().saturating_sub(1);
509+ doc.set_selection(Selection::single(0, end))
509510}
510511
511512pub fn select_regex(cx: &mut Context) {
@@ -530,7 +531,7 @@ pub fn split_selection(cx: &mut Context) {
530531}
531532
532533pub fn split_selection_on_newline(cx: &mut Context) {
533− let doc = cx.doc();
534+ let mut doc = cx.doc();
534535 let text = doc.text().slice(..);
535536 // only compile the regex once
536537 #[allow(clippy::trivial_regex)]
@@ -562,13 +563,14 @@ fn _search(doc: &mut Document, contents: &str, regex: &Regex) {
562563
563564// TODO: use one function for search vs extend
564565pub fn search(cx: &mut Context) {
565− let doc = cx.doc();
566+ let mut doc = cx.doc();
566567
567568 // TODO: could probably share with select_on_matches?
568569
569570 // HAXX: sadly we can't avoid allocating a single string for the whole buffer since we can't
570571 // feed chunks into the regex yet
571572 let contents = doc.text().slice(..).to_string();
573+ drop(doc);
572574
573575 let prompt = ui::regex_prompt(cx, "search:".to_string(), move |doc, regex| {
574576 let text = doc.text();
@@ -585,19 +587,20 @@ pub fn search(cx: &mut Context) {
585587pub fn search_next(cx: &mut Context) {
586588 if let Some(query) = register::get('\\') {
587589 let query = query.first().unwrap();
588− let doc = cx.doc();
590+ let mut doc = cx.doc();
589591 let contents = doc.text().slice(..).to_string();
590592 let regex = Regex::new(&query).unwrap();
591− _search(doc, &contents, ®ex);
593+ _search(&mut doc, &contents, ®ex);
592594 }
593595}
594596
595597pub fn search_selection(cx: &mut Context) {
596− let doc = cx.doc();
598+ let mut doc = cx.doc();
597599 let contents = doc.text().slice(..);
598600 let query = doc.selection().primary().fragment(contents);
599601 let regex = regex::escape(&query);
600602 register::set('\\', vec![regex]);
603+ drop(doc);
601604 search_next(cx);
602605}
603606
@@ -609,7 +612,7 @@ pub fn search_selection(cx: &mut Context) {
609612
610613pub fn select_line(cx: &mut Context) {
611614 let count = cx.count;
612− let doc = cx.doc();
615+ let mut doc = cx.doc();
613616
614617 let pos = doc.selection().primary();
615618 let text = doc.text();
@@ -622,7 +625,7 @@ pub fn select_line(cx: &mut Context) {
622625}
623626pub fn extend_line(cx: &mut Context) {
624627 let count = cx.count;
625− let doc = cx.doc();
628+ let mut doc = cx.doc();
626629
627630 let pos = doc.selection().primary();
628631 let text = doc.text();
@@ -650,20 +653,21 @@ fn _delete_selection(doc: &mut Document) {
650653}
651654
652655pub fn delete_selection(cx: &mut Context) {
653− let doc = cx.doc();
654− _delete_selection(doc);
656+ let mut doc = cx.doc();
657+ _delete_selection(&mut doc);
655658
656659 doc.append_changes_to_history();
657660}
658661
659662pub fn change_selection(cx: &mut Context) {
660− let doc = cx.doc();
661− _delete_selection(doc);
663+ let mut doc = cx.doc();
664+ _delete_selection(&mut doc);
665+ drop(doc);
662666 insert_mode(cx);
663667}
664668
665669pub fn collapse_selection(cx: &mut Context) {
666− let doc = cx.doc();
670+ let mut doc = cx.doc();
667671 let selection = doc
668672 .selection()
669673 .transform(|range| Range::new(range.head, range.head));
@@ -672,7 +676,7 @@ pub fn collapse_selection(cx: &mut Context) {
672676}
673677
674678pub fn flip_selections(cx: &mut Context) {
675− let doc = cx.doc();
679+ let mut doc = cx.doc();
676680 let selection = doc
677681 .selection()
678682 .transform(|range| Range::new(range.head, range.anchor));
@@ -686,8 +690,8 @@ fn enter_insert_mode(doc: &mut Document) {
686690
687691// inserts at the start of each selection
688692pub fn insert_mode(cx: &mut Context) {
689− let doc = cx.doc();
690− enter_insert_mode(doc);
693+ let mut doc = cx.doc();
694+ enter_insert_mode(&mut doc);
691695
692696 let selection = doc
693697 .selection()
@@ -697,8 +701,8 @@ pub fn insert_mode(cx: &mut Context) {
697701
698702// inserts at the end of each selection
699703pub fn append_mode(cx: &mut Context) {
700− let doc = cx.doc();
701− enter_insert_mode(doc);
704+ let mut doc = cx.doc();
705+ enter_insert_mode(&mut doc);
702706 doc.restore_cursor = true;
703707
704708 let text = doc.text().slice(..);
@@ -765,7 +769,7 @@ pub fn command_mode(cx: &mut Context) {
765769 }
766770 ["w"] | ["write"] => {
767771 // TODO: non-blocking via save() command
768− smol::block_on(editor.view_mut().doc.save());
772+ smol::block_on(editor.view().doc.borrow().save());
769773 }
770774
771775 _ => (),
@@ -800,16 +804,18 @@ fn selection_lines(doc: &Rope, selection: &Selection) -> Vec<usize> {
800804
801805// I inserts at the start of each line with a selection
802806pub fn prepend_to_line(cx: &mut Context) {
803− let doc = cx.doc();
804− enter_insert_mode(doc);
807+ let mut doc = cx.doc();
808+ enter_insert_mode(&mut doc);
809+ drop(doc);
805810
806811 move_line_start(cx);
807812}
808813
809814// A inserts at the end of each line with a selection
810815pub fn append_to_line(cx: &mut Context) {
811− let doc = cx.doc();
812− enter_insert_mode(doc);
816+ let mut doc = cx.doc();
817+ enter_insert_mode(&mut doc);
818+ drop(doc);
813819
814820 move_line_end(cx);
815821}
@@ -817,8 +823,8 @@ pub fn append_to_line(cx: &mut Context) {
817823// o inserts a new line after each line with a selection
818824pub fn open_below(cx: &mut Context) {
819825 let count = cx.count;
820− let doc = cx.doc();
821− enter_insert_mode(doc);
826+ let mut doc = cx.doc();
827+ enter_insert_mode(&mut doc);
822828
823829 let lines = selection_lines(doc.text(), doc.selection());
824830
@@ -875,7 +881,7 @@ pub fn open_below(cx: &mut Context) {
875881// O inserts a new line before each line with a selection
876882
877883pub fn normal_mode(cx: &mut Context) {
878− let doc = cx.doc();
884+ let mut doc = cx.doc();
879885
880886 doc.mode = Mode::Normal;
881887
@@ -909,14 +915,12 @@ pub fn exit_select_mode(cx: &mut Context) {
909915}
910916
911917fn goto(cx: &mut Context, locations: Vec<lsp::Location>) {
912− let doc = cx.doc();
913−
914− doc.mode = Mode::Normal;
918+ cx.doc().mode = Mode::Normal;
915919
916920 match locations.as_slice() {
917921 [location] => {
918922 cx.editor.open(PathBuf::from(location.uri.path()));
919− let doc = cx.doc();
923+ let mut doc = cx.doc();
920924 let definition_pos = location.range.start;
921925 let new_pos = helix_lsp::util::lsp_pos_to_pos(doc.text(), definition_pos);
922926 doc.set_selection(Selection::point(new_pos));
@@ -932,7 +936,8 @@ fn goto(cx: &mut Context, locations: Vec<lsp::Location>) {
932936 },
933937 move |editor: &mut Editor, item| {
934938 editor.open(PathBuf::from(item.uri.path()));
935− let mut doc = &mut editor.view_mut().doc;
939+ // TODO: issues with doc already being broo
940+ let mut doc = &mut editor.view().doc.borrow_mut();
936941 let definition_pos = item.range.start;
937942 let new_pos = helix_lsp::util::lsp_pos_to_pos(doc.text(), definition_pos);
938943 doc.set_selection(Selection::point(new_pos));
@@ -944,7 +949,7 @@ fn goto(cx: &mut Context, locations: Vec<lsp::Location>) {
944949}
945950
946951pub fn goto_definition(cx: &mut Context) {
947− let doc = cx.doc();
952+ let mut doc = cx.doc();
948953 let language_server = match doc.language_server() {
949954 Some(language_server) => language_server,
950955 None => return,
@@ -956,11 +961,12 @@ pub fn goto_definition(cx: &mut Context) {
956961 // TODO: handle fails
957962 let res =
958963 smol::block_on(language_server.goto_definition(doc.identifier(), pos)).unwrap_or_default();
964+ drop(doc);
959965 goto(cx, res);
960966}
961967
962968pub fn goto_type_definition(cx: &mut Context) {
963− let doc = cx.doc();
969+ let mut doc = cx.doc();
964970 let language_server = match doc.language_server() {
965971 Some(language_server) => language_server,
966972 None => return,
@@ -972,11 +978,12 @@ pub fn goto_type_definition(cx: &mut Context) {
972978 // TODO: handle fails
973979 let res = smol::block_on(language_server.goto_type_definition(doc.identifier(), pos))
974980 .unwrap_or_default();
981+ drop(doc);
975982 goto(cx, res);
976983}
977984
978985pub fn goto_implementation(cx: &mut Context) {
979− let doc = cx.doc();
986+ let mut doc = cx.doc();
980987 let language_server = match doc.language_server() {
981988 Some(language_server) => language_server,
982989 None => return,
@@ -988,11 +995,12 @@ pub fn goto_implementation(cx: &mut Context) {
988995 // TODO: handle fails
989996 let res = smol::block_on(language_server.goto_implementation(doc.identifier(), pos))
990997 .unwrap_or_default();
998+ drop(doc);
991999 goto(cx, res);
9921000}
9931001
9941002pub fn goto_reference(cx: &mut Context) {
995− let doc = cx.doc();
1003+ let mut doc = cx.doc();
9961004 let language_server = match doc.language_server() {
9971005 Some(language_server) => language_server,
9981006 None => return,
@@ -1004,6 +1012,7 @@ pub fn goto_reference(cx: &mut Context) {
10041012 // TODO: handle fails
10051013 let res =
10061014 smol::block_on(language_server.goto_reference(doc.identifier(), pos)).unwrap_or_default();
1015+ drop(doc);
10071016 goto(cx, res);
10081017}
10091018
@@ -1017,7 +1026,7 @@ pub mod insert {
10171026
10181027 // TODO: insert means add text just before cursor, on exit we should be on the last letter.
10191028 pub fn insert_char(cx: &mut Context, c: char) {
1020− let doc = cx.doc();
1029+ let mut doc = cx.doc();
10211030
10221031 // run through insert hooks, stopping on the first one that returns Some(t)
10231032 for hook in HOOKS {
@@ -1034,7 +1043,7 @@ pub mod insert {
10341043 }
10351044
10361045 pub fn insert_tab(cx: &mut Context) {
1037− let doc = cx.doc();
1046+ let mut doc = cx.doc();
10381047 // TODO: round out to nearest indentation level (for example a line with 3 spaces should
10391048 // indent by one to reach 4 spaces).
10401049
@@ -1044,7 +1053,7 @@ pub mod insert {
10441053 }
10451054
10461055 pub fn insert_newline(cx: &mut Context) {
1047− let doc = cx.doc();
1056+ let mut doc = cx.doc();
10481057 let text = doc.text().slice(..);
10491058 let transaction = Transaction::change_by_selection(doc.text(), doc.selection(), |range| {
10501059 let indent_level =
@@ -1061,7 +1070,7 @@ pub mod insert {
10611070 // TODO: handle indent-aware delete
10621071 pub fn delete_char_backward(cx: &mut Context) {
10631072 let count = cx.count;
1064− let doc = cx.doc();
1073+ let mut doc = cx.doc();
10651074 let text = doc.text().slice(..);
10661075 let transaction = Transaction::change_by_selection(doc.text(), doc.selection(), |range| {
10671076 (
@@ -1075,7 +1084,7 @@ pub mod insert {
10751084
10761085 pub fn delete_char_forward(cx: &mut Context) {
10771086 let count = cx.count;
1078− let doc = cx.doc();
1087+ let mut doc = cx.doc();
10791088 let text = doc.text().slice(..);
10801089 let transaction = Transaction::change_by_selection(doc.text(), doc.selection(), |range| {
10811090 (
@@ -1105,7 +1114,7 @@ pub fn redo(cx: &mut Context) {
11051114
11061115pub fn yank(cx: &mut Context) {
11071116 // TODO: should selections be made end inclusive?
1108− let doc = cx.doc();
1117+ let mut doc = cx.doc();
11091118 let values = doc
11101119 .selection()
11111120 .fragments(doc.text().slice(..))
@@ -1146,7 +1155,7 @@ pub fn paste(cx: &mut Context) {
11461155
11471156 let mut values = values.into_iter().map(Tendril::from).chain(repeat);
11481157
1149− let doc = cx.doc();
1158+ let mut doc = cx.doc();
11501159
11511160 let transaction = if linewise {
11521161 // paste on the next line
@@ -1185,8 +1194,8 @@ fn get_lines(doc: &Document) -> Vec<usize> {
11851194}
11861195
11871196pub fn indent(cx: &mut Context) {
1188− let doc = cx.doc();
1189− let lines = get_lines(doc);
1197+ let mut doc = cx.doc();
1198+ let lines = get_lines(&mut doc);
11901199
11911200 // Indent by one level
11921201 let indent = Tendril::from(doc.indent_unit());
@@ -1203,8 +1212,8 @@ pub fn indent(cx: &mut Context) {
12031212}
12041213
12051214pub fn unindent(cx: &mut Context) {
1206− let doc = cx.doc();
1207− let lines = get_lines(doc);
1215+ let mut doc = cx.doc();
1216+ let lines = get_lines(&mut doc);
12081217 let mut changes = Vec::with_capacity(lines.len());
12091218 let tab_width = doc.tab_width();
12101219
@@ -1238,7 +1247,7 @@ pub fn unindent(cx: &mut Context) {
12381247
12391248pub fn format_selections(cx: &mut Context) {
12401249 use helix_lsp::lsp;
1241− let doc = cx.doc();
1250+ let mut doc = cx.doc();
12421251
12431252 // via lsp if available
12441253 // else via tree-sitter indentation calculations
@@ -1276,7 +1285,7 @@ pub fn format_selections(cx: &mut Context) {
12761285
12771286pub fn join_selections(cx: &mut Context) {
12781287 use movement::skip_over_next;
1279− let doc = cx.doc();
1288+ let mut doc = cx.doc();
12801289 let text = doc.text();
12811290 let slice = doc.text().slice(..);
12821291
@@ -1319,7 +1328,6 @@ pub fn join_selections(cx: &mut Context) {
13191328}
13201329
13211330pub fn keep_selections(cx: &mut Context) {
1322− let doc = cx.doc();
13231331 // keep selections matching regex
13241332 let prompt = ui::regex_prompt(cx, "keep:".to_string(), |doc, regex| {
13251333 let text = doc.text().slice(..);
@@ -1333,7 +1341,7 @@ pub fn keep_selections(cx: &mut Context) {
13331341}
13341342
13351343pub fn keep_primary_selection(cx: &mut Context) {
1336− let doc = cx.doc();
1344+ let mut doc = cx.doc();
13371345
13381346 let range = doc.selection().primary();
13391347 let selection = Selection::single(range.anchor, range.head);
@@ -1350,7 +1358,7 @@ pub fn save(cx: &mut Context) {
13501358}
13511359
13521360pub fn completion(cx: &mut Context) {
1353− let doc = cx.doc();
1361+ let mut doc = cx.doc();
13541362
13551363 let language_server = match doc.language_server() {
13561364 Some(language_server) => language_server,
@@ -1364,6 +1372,8 @@ pub fn completion(cx: &mut Context) {
13641372
13651373 let res = smol::block_on(language_server.completion(doc.identifier(), pos)).unwrap_or_default();
13661374
1375+ drop(doc);
1376+
13671377 // TODO: if no completion, show some message or something
13681378 if !res.is_empty() {
13691379 // let snapshot = doc.state.clone();
@@ -1379,11 +1389,11 @@ pub fn completion(cx: &mut Context) {
13791389 match event {
13801390 PromptEvent::Abort => {
13811391 // revert state
1382− let doc = &mut editor.view_mut().doc;
1392+ let doc = &mut editor.view().doc.borrow_mut();
13831393 // doc.state = snapshot.clone();
13841394 }
13851395 PromptEvent::Validate => {
1386− let doc = &mut editor.view_mut().doc;
1396+ let doc = &mut editor.view().doc.borrow_mut();
13871397
13881398 // revert state to what it was before the last update
13891399 // doc.state = snapshot.clone();
@@ -1449,7 +1459,7 @@ pub fn completion(cx: &mut Context) {
14491459pub fn hover(cx: &mut Context) {
14501460 use helix_lsp::lsp;
14511461
1452− let doc = cx.doc();
1462+ let mut doc = cx.doc();
14531463
14541464 let language_server = match doc.language_server() {
14551465 Some(language_server) => language_server,
@@ -1466,6 +1476,8 @@ pub fn hover(cx: &mut Context) {
14661476 let res = smol::block_on(language_server.text_document_hover(doc.identifier(), pos))
14671477 .unwrap_or_default();
14681478
1479+ drop(doc);
1480+
14691481 if let Some(hover) = res {
14701482 // hover.contents / .range <- used for visualizing
14711483 let contents = match hover.contents {
@@ -1491,12 +1503,12 @@ pub fn hover(cx: &mut Context) {
14911503
14921504// view movements
14931505pub fn next_view(cx: &mut Context) {
1494− cx.editor.tree.focus_next()
1506+ cx.editor.focus_next()
14951507}
14961508
14971509// comments
14981510pub fn toggle_comments(cx: &mut Context) {
1499− let doc = cx.doc();
1511+ let mut doc = cx.doc();
15001512 let transaction = comment::toggle_line_comments(doc.text(), doc.selection());
15011513
15021514 doc.apply(&transaction);
@@ -1506,7 +1518,7 @@ pub fn toggle_comments(cx: &mut Context) {
15061518// tree sitter node selection
15071519
15081520pub fn expand_selection(cx: &mut Context) {
1509− let doc = cx.doc();
1521+ let mut doc = cx.doc();
15101522
15111523 if let Some(syntax) = doc.syntax() {
15121524 let text = doc.text().slice(..);