on master help sign in
Remove #[allow(unused)] from helix-term, and fix unused imports.
702a049Nathan Vegdahl
helix-term/src/application.rs+8−23
@@ -1,37 +1,23 @@
1use helix_core::syntax;
1use helix_core::syntax;
2−use helix_lsp::{lsp, LspProgressMap};
2+use helix_lsp::{lsp, util::lsp_pos_to_pos, LspProgressMap};
3−use helix_view::{document::Mode, graphics::Rect, theme, Document, Editor, Theme, View};
3+use helix_view::{theme, Editor};
4−
4+
5−use crate::{
6− args::Args,
7− compositor::Compositor,
5+use crate::{args::Args, compositor::Compositor, config::Config, job::Jobs, ui};
8− config::Config,
9− job::Jobs,
10− keymap::Keymaps,
11− ui::{self, Spinner},
12−};
13
6
14−use log::{error, info};
7+use log::error;
15
8
16use std::{
9use std::{
17− collections::HashMap,
18− future::Future,
19− io::{self, stdout, Stdout, Write},
10+ io::{stdout, Write},
20− path::PathBuf,
21− pin::Pin,
22 sync::Arc,
11 sync::Arc,
23− time::Duration,
24};
12};
25
13
26−use anyhow::{Context, Error};
14+use anyhow::Error;
27
15
28use crossterm::{
16use crossterm::{
29 event::{Event, EventStream},
17 event::{Event, EventStream},
30 execute, terminal,
18 execute, terminal,
31};
19};
32
20
33−use futures_util::{future, stream::FuturesUnordered};
34−
35pub struct Application {
21pub struct Application {
36 compositor: Compositor,
22 compositor: Compositor,
37 editor: Editor,
23 editor: Editor,
@@ -239,10 +225,9 @@ impl Application {
239 .into_iter()
225 .into_iter()
240 .filter_map(|diagnostic| {
226 .filter_map(|diagnostic| {
241 use helix_core::{
227 use helix_core::{
242− diagnostic::{Range, Severity, Severity::*},
228+ diagnostic::{Range, Severity::*},
243 Diagnostic,
229 Diagnostic,
244 };
230 };
245− use helix_lsp::{lsp, util::lsp_pos_to_pos};
246 use lsp::DiagnosticSeverity;
231 use lsp::DiagnosticSeverity;
247
232
248 let language_server = doc.language_server().unwrap();
233 let language_server = doc.language_server().unwrap();
helix-term/src/commands.rs+10−22
@@ -1,20 +1,21 @@
1use helix_core::{
1use helix_core::{
2 comment, coords_at_pos, find_first_non_whitespace_char, find_root, graphemes, indent,
2 comment, coords_at_pos, find_first_non_whitespace_char, find_root, graphemes, indent,
3 line_ending::{
3 line_ending::{
4− get_line_ending, get_line_ending_of_str, line_end_char_index, rope_end_without_line_ending,
4+ get_line_ending_of_str, line_end_char_index, rope_end_without_line_ending,
5 str_is_line_ending,
5 str_is_line_ending,
6 },
6 },
7 match_brackets,
7 match_brackets,
8 movement::{self, Direction},
8 movement::{self, Direction},
9 object, pos_at_coords,
9 object, pos_at_coords,
10 regex::{self, Regex},
10 regex::{self, Regex},
11− register::{self, Register, Registers},
11+ register::Register,
12− search, selection, Change, ChangeSet, LineEnding, Position, Range, Rope, RopeGraphemes,
12+ search, selection, LineEnding, Position, Range, Rope, RopeGraphemes, RopeSlice, Selection,
13− RopeSlice, Selection, SmallVec, Tendril, Transaction, DEFAULT_LINE_ENDING,
13+ SmallVec, Tendril, Transaction,
14};
14};
15
15
16use helix_view::{
16use helix_view::{
17 document::{IndentStyle, Mode},
17 document::{IndentStyle, Mode},
18+ editor::Action,
18 input::KeyEvent,
19 input::KeyEvent,
19 keyboard::KeyCode,
20 keyboard::KeyCode,
20 view::{View, PADDING},
21 view::{View, PADDING},
@@ -25,19 +26,19 @@ use anyhow::anyhow;
25use helix_lsp::{
26use helix_lsp::{
26 lsp,
27 lsp,
27 util::{lsp_pos_to_pos, lsp_range_to_range, pos_to_lsp_pos, range_to_lsp_range},
28 util::{lsp_pos_to_pos, lsp_range_to_range, pos_to_lsp_pos, range_to_lsp_range},
28− LspProgressMap, OffsetEncoding,
29+ OffsetEncoding,
29};
30};
30use insert::*;
31use insert::*;
31use movement::Movement;
32use movement::Movement;
32
33
33use crate::{
34use crate::{
34− compositor::{self, Callback, Component, Compositor},
35+ compositor::{self, Component, Compositor},
35− ui::{self, Completion, Picker, Popup, Prompt, PromptEvent},
36+ ui::{self, Picker, Popup, Prompt, PromptEvent},
36};
37};
37
38
38−use crate::job::{self, Job, JobFuture, Jobs};
39+use crate::job::{self, Job, Jobs};
39use futures_util::{FutureExt, TryFutureExt};
40use futures_util::{FutureExt, TryFutureExt};
40−use std::{fmt, future::Future, path::Display, str::FromStr};
41+use std::{fmt, future::Future};
41
42
42use std::{
43use std::{
43 borrow::Cow,
44 borrow::Cow,
@@ -1148,7 +1149,6 @@ mod cmd {
1148 cx: &mut compositor::Context,
1149 cx: &mut compositor::Context,
1149 path: Option<P>,
1150 path: Option<P>,
1150 ) -> Result<tokio::task::JoinHandle<Result<(), anyhow::Error>>, anyhow::Error> {
1151 ) -> Result<tokio::task::JoinHandle<Result<(), anyhow::Error>>, anyhow::Error> {
1151− use anyhow::anyhow;
1152 let jobs = &mut cx.jobs;
1152 let jobs = &mut cx.jobs;
1153 let (view, doc) = current!(cx.editor);
1153 let (view, doc) = current!(cx.editor);
1154
1154
@@ -1723,7 +1723,6 @@ fn command_mode(cx: &mut Context) {
1723 // simple heuristic: if there's no just one part, complete command name.
1723 // simple heuristic: if there's no just one part, complete command name.
1724 // if there's a space, per command completion kicks in.
1724 // if there's a space, per command completion kicks in.
1725 if parts.len() <= 1 {
1725 if parts.len() <= 1 {
1726− use std::{borrow::Cow, ops::Range};
1727 let end = 0..;
1726 let end = 0..;
1728 cmd::TYPABLE_COMMAND_LIST
1727 cmd::TYPABLE_COMMAND_LIST
1729 .iter()
1728 .iter()
@@ -1753,8 +1752,6 @@ fn command_mode(cx: &mut Context) {
1753 }
1752 }
1754 }, // completion
1753 }, // completion
1755 move |cx: &mut compositor::Context, input: &str, event: PromptEvent| {
1754 move |cx: &mut compositor::Context, input: &str, event: PromptEvent| {
1756− use helix_view::editor::Action;
1757−
1758 if event != PromptEvent::Validate {
1755 if event != PromptEvent::Validate {
1759 return;
1756 return;
1760 }
1757 }
@@ -1792,7 +1789,6 @@ fn file_picker(cx: &mut Context) {
1792}
1789}
1793
1790
1794fn buffer_picker(cx: &mut Context) {
1791fn buffer_picker(cx: &mut Context) {
1795− use std::path::{Path, PathBuf};
1796 let current = view!(cx.editor).doc;
1792 let current = view!(cx.editor).doc;
1797
1793
1798 let picker = Picker::new(
1794 let picker = Picker::new(
@@ -1815,7 +1811,6 @@ fn buffer_picker(cx: &mut Context) {
1815 }
1811 }
1816 },
1812 },
1817 |editor: &mut Editor, (id, _path): &(DocumentId, Option<PathBuf>), _action| {
1813 |editor: &mut Editor, (id, _path): &(DocumentId, Option<PathBuf>), _action| {
1818− use helix_view::editor::Action;
1819 editor.switch(*id, Action::Replace);
1814 editor.switch(*id, Action::Replace);
1820 },
1815 },
1821 );
1816 );
@@ -2145,8 +2140,6 @@ fn goto_impl(
2145 locations: Vec<lsp::Location>,
2140 locations: Vec<lsp::Location>,
2146 offset_encoding: OffsetEncoding,
2141 offset_encoding: OffsetEncoding,
2147) {
2142) {
2148− use helix_view::editor::Action;
2149−
2150 push_jump(editor);
2143 push_jump(editor);
2151
2144
2152 fn jump_to(
2145 fn jump_to(
@@ -3181,7 +3174,6 @@ fn completion(cx: &mut Context) {
3181 if items.is_empty() {
3174 if items.is_empty() {
3182 return;
3175 return;
3183 }
3176 }
3184− use crate::compositor::AnyComponent;
3185 let size = compositor.size();
3177 let size = compositor.size();
3186 let ui = compositor
3178 let ui = compositor
3187 .find(std::any::type_name::<ui::EditorView>())
3179 .find(std::any::type_name::<ui::EditorView>())
@@ -3332,11 +3324,7 @@ fn rotate_view(cx: &mut Context) {
3332}
3324}
3333
3325
3334// split helper, clear it later
3326// split helper, clear it later
3335−use helix_view::editor::Action;
3336−
3337−use self::cmd::TypableCommand;
3338fn split(cx: &mut Context, action: Action) {
3327fn split(cx: &mut Context, action: Action) {
3339− use helix_view::editor::Action;
3340 let (view, doc) = current!(cx.editor);
3328 let (view, doc) = current!(cx.editor);
3341 let id = doc.id();
3329 let id = doc.id();
3342 let selection = doc.selection(view.id).clone();
3330 let selection = doc.selection(view.id).clone();
helix-term/src/compositor.rs−1
@@ -2,7 +2,6 @@
2// Q: how does this work with popups?
2// Q: how does this work with popups?
3// cursive does compositor.screen_mut().add_layer_at(pos::absolute(x, y), <component>)
3// cursive does compositor.screen_mut().add_layer_at(pos::absolute(x, y), <component>)
4use helix_core::Position;
4use helix_core::Position;
5−use helix_lsp::LspProgressMap;
6use helix_view::graphics::{CursorKind, Rect};
5use helix_view::graphics::{CursorKind, Rect};
7
6
8use crossterm::event::Event;
7use crossterm::event::Event;
helix-term/src/config.rs+3−3
@@ -1,10 +1,10 @@
1−use anyhow::{Error, Result};
2use serde::Deserialize;
1use serde::Deserialize;
3−use std::collections::HashMap;
4
2
5−use crate::commands::Command;
6use crate::keymap::Keymaps;
3use crate::keymap::Keymaps;
7
4
5+#[cfg(test)]
6+use crate::commands::Command;
7+
8#[derive(Debug, Default, Clone, PartialEq, Deserialize)]
8#[derive(Debug, Default, Clone, PartialEq, Deserialize)]
9pub struct Config {
9pub struct Config {
10 pub theme: Option<String>,
10 pub theme: Option<String>,
helix-term/src/job.rs+1−1
@@ -3,7 +3,7 @@ use helix_view::Editor;
3use crate::compositor::Compositor;
3use crate::compositor::Compositor;
4
4
5use futures_util::future::{self, BoxFuture, Future, FutureExt};
5use futures_util::future::{self, BoxFuture, Future, FutureExt};
6−use futures_util::stream::{self, FuturesUnordered, Select, StreamExt};
6+use futures_util::stream::{FuturesUnordered, StreamExt};
7
7
8pub type Callback = Box<dyn FnOnce(&mut Editor, &mut Compositor) + Send>;
8pub type Callback = Box<dyn FnOnce(&mut Editor, &mut Compositor) + Send>;
9pub type JobFuture = BoxFuture<'static, anyhow::Result<Option<Callback>>>;
9pub type JobFuture = BoxFuture<'static, anyhow::Result<Option<Callback>>>;
helix-term/src/keymap.rs−4
@@ -1,7 +1,5 @@
1−use crate::commands;
2pub use crate::commands::Command;
1pub use crate::commands::Command;
3use crate::config::Config;
2use crate::config::Config;
4−use anyhow::{anyhow, Error, Result};
5use helix_core::hashmap;
3use helix_core::hashmap;
6use helix_view::{
4use helix_view::{
7 document::Mode,
5 document::Mode,
@@ -11,9 +9,7 @@ use helix_view::{
11use serde::Deserialize;
9use serde::Deserialize;
12use std::{
10use std::{
13 collections::HashMap,
11 collections::HashMap,
14− fmt::Display,
15 ops::{Deref, DerefMut},
12 ops::{Deref, DerefMut},
16− str::FromStr,
17};
13};
18
14
19// Kakoune-inspired:
15// Kakoune-inspired:
helix-term/src/lib.rs−2
@@ -1,5 +1,3 @@
1−#![allow(unused)]
2−
3#[macro_use]
1#[macro_use]
4extern crate helix_view;
2extern crate helix_view;
5
3
helix-term/src/ui/completion.rs+5−11
@@ -1,19 +1,16 @@
1−use crate::compositor::{Component, Compositor, Context, EventResult};
1+use crate::compositor::{Component, Context, EventResult};
2−use crossterm::event::{Event, KeyCode, KeyEvent, KeyModifiers};
2+use crossterm::event::{Event, KeyCode, KeyEvent};
3use tui::buffer::Buffer as Surface;
3use tui::buffer::Buffer as Surface;
4
4
5use std::borrow::Cow;
5use std::borrow::Cow;
6
6
7−use helix_core::{Position, Transaction};
7+use helix_core::Transaction;
8−use helix_view::{
8+use helix_view::{graphics::Rect, Editor};
9− graphics::{Color, Rect, Style},
10− Editor,
11−};
12
9
13use crate::commands;
10use crate::commands;
14use crate::ui::{menu, Markdown, Menu, Popup, PromptEvent};
11use crate::ui::{menu, Markdown, Menu, Popup, PromptEvent};
15
12
16−use helix_lsp::lsp;
13+use helix_lsp::{lsp, util};
17use lsp::CompletionItem;
14use lsp::CompletionItem;
18
15
19impl menu::Item for CompletionItem {
16impl menu::Item for CompletionItem {
@@ -88,8 +85,6 @@ impl Completion {
88 // always present here
85 // always present here
89 let item = item.unwrap();
86 let item = item.unwrap();
90
87
91− use helix_lsp::{lsp, util};
92−
93 // if more text was entered, remove it
88 // if more text was entered, remove it
94 let cursor = doc.selection(view.id).cursor();
89 let cursor = doc.selection(view.id).cursor();
95 if trigger_offset < cursor {
90 if trigger_offset < cursor {
@@ -100,7 +95,6 @@ impl Completion {
100 doc.apply(&remove, view.id);
95 doc.apply(&remove, view.id);
101 }
96 }
102
97
103− use helix_lsp::OffsetEncoding;
104 let transaction = if let Some(edit) = &item.text_edit {
98 let transaction = if let Some(edit) = &item.text_edit {
105 let edit = match edit {
99 let edit = match edit {
106 lsp::CompletionTextEdit::Edit(edit) => edit.clone(),
100 lsp::CompletionTextEdit::Edit(edit) => edit.clone(),
helix-term/src/ui/editor.rs+6−10
@@ -1,32 +1,28 @@
1use crate::{
1use crate::{
2 commands,
2 commands,
3− compositor::{Component, Compositor, Context, EventResult},
3+ compositor::{Component, Context, EventResult},
4 key,
4 key,
5− keymap::{self, Keymaps},
5+ keymap::Keymaps,
6 ui::{Completion, ProgressSpinners},
6 ui::{Completion, ProgressSpinners},
7};
7};
8
8
9use helix_core::{
9use helix_core::{
10 coords_at_pos,
10 coords_at_pos,
11 graphemes::ensure_grapheme_boundary,
11 graphemes::ensure_grapheme_boundary,
12− syntax::{self, Highlight, HighlightEvent},
12+ syntax::{self, HighlightEvent},
13 LineEnding, Position, Range,
13 LineEnding, Position, Range,
14};
14};
15−use helix_lsp::LspProgressMap;
16use helix_view::{
15use helix_view::{
17 document::Mode,
16 document::Mode,
18− graphics::{Color, CursorKind, Modifier, Rect, Style},
17+ graphics::{CursorKind, Modifier, Rect, Style},
19 input::KeyEvent,
18 input::KeyEvent,
20 keyboard::{KeyCode, KeyModifiers},
19 keyboard::{KeyCode, KeyModifiers},
21 Document, Editor, Theme, View,
20 Document, Editor, Theme, View,
22};
21};
23use std::borrow::Cow;
22use std::borrow::Cow;
24
23
25−use crossterm::{
24+use crossterm::event::Event;
26− cursor,
27− event::{read, Event, EventStream},
28−};
29−use tui::{backend::CrosstermBackend, buffer::Buffer as Surface};
25+use tui::buffer::Buffer as Surface;
30
26
31pub struct EditorView {
27pub struct EditorView {
32 keymaps: Keymaps,
28 keymaps: Keymaps,
helix-term/src/ui/markdown.rs+13−12
@@ -1,13 +1,20 @@
1−use crate::compositor::{Component, Compositor, Context, EventResult};
1+use crate::compositor::{Component, Context};
2−use crossterm::event::{Event, KeyCode, KeyEvent, KeyModifiers};
2+use tui::{
3−use tui::{buffer::Buffer as Surface, text::Text};
3+ buffer::Buffer as Surface,
4+ text::{Span, Spans, Text},
5+};
6+
7+use std::sync::Arc;
4
8
5−use std::{borrow::Cow, sync::Arc};
9+use pulldown_cmark::{CodeBlockKind, CowStr, Event, Options, Parser, Tag};
6
10
7−use helix_core::{syntax, Position};
11+use helix_core::{
12+ syntax::{self, HighlightEvent, Syntax},
13+ Rope,
14+};
8use helix_view::{
15use helix_view::{
9 graphics::{Color, Rect, Style},
16 graphics::{Color, Rect, Style},
10− Editor, Theme,
17+ Theme,
11};
18};
12
19
13pub struct Markdown {
20pub struct Markdown {
@@ -33,9 +40,6 @@ fn parse<'a>(
33 theme: Option<&Theme>,
40 theme: Option<&Theme>,
34 loader: &syntax::Loader,
41 loader: &syntax::Loader,
35) -> tui::text::Text<'a> {
42) -> tui::text::Text<'a> {
36− use pulldown_cmark::{CodeBlockKind, CowStr, Event, Options, Parser, Tag};
37− use tui::text::{Span, Spans, Text};
38−
39 // also 2021-03-04T16:33:58.553 helix_lsp::transport [INFO] <- {"contents":{"kind":"markdown","value":"\n```rust\ncore::num\n```\n\n```rust\npub const fn saturating_sub(self, rhs:Self) ->Self\n```\n\n---\n\n```rust\n```"},"range":{"end":{"character":61,"line":101},"start":{"character":47,"line":101}}}
43 // also 2021-03-04T16:33:58.553 helix_lsp::transport [INFO] <- {"contents":{"kind":"markdown","value":"\n```rust\ncore::num\n```\n\n```rust\npub const fn saturating_sub(self, rhs:Self) ->Self\n```\n\n---\n\n```rust\n```"},"range":{"end":{"character":61,"line":101},"start":{"character":47,"line":101}}}
40 let text = "\n```rust\ncore::iter::traits::iterator::Iterator\n```\n\n```rust\nfn collect<B: FromIterator<Self::Item>>(self) -> B\nwhere\n Self: Sized,\n```\n\n---\n\nTransforms an iterator into a collection.\n\n`collect()` can take anything iterable, and turn it into a relevant\ncollection. This is one of the more powerful methods in the standard\nlibrary, used in a variety of contexts.\n\nThe most basic pattern in which `collect()` is used is to turn one\ncollection into another. You take a collection, call [`iter`](https://doc.rust-lang.org/nightly/core/iter/traits/iterator/trait.Iterator.html) on it,\ndo a bunch of transformations, and then `collect()` at the end.\n\n`collect()` can also create instances of types that are not typical\ncollections. For example, a [`String`](https://doc.rust-lang.org/nightly/core/iter/std/string/struct.String.html) can be built from [`char`](type@char)s,\nand an iterator of [`Result<T, E>`](https://doc.rust-lang.org/nightly/core/result/enum.Result.html) items can be collected\ninto `Result<Collection<T>, E>`. See the examples below for more.\n\nBecause `collect()` is so general, it can cause problems with type\ninference. As such, `collect()` is one of the few times you'll see\nthe syntax affectionately known as the 'turbofish': `::<>`. This\nhelps the inference algorithm understand specifically which collection\nyou're trying to collect into.\n\n# Examples\n\nBasic usage:\n\n```rust\nlet a = [1, 2, 3];\n\nlet doubled: Vec<i32> = a.iter()\n .map(|&x| x * 2)\n .collect();\n\nassert_eq!(vec![2, 4, 6], doubled);\n```\n\nNote that we needed the `: Vec<i32>` on the left-hand side. This is because\nwe could collect into, for example, a [`VecDeque<T>`](https://doc.rust-lang.org/nightly/core/iter/std/collections/struct.VecDeque.html) instead:\n\n```rust\nuse std::collections::VecDeque;\n\nlet a = [1, 2, 3];\n\nlet doubled: VecDeque<i32> = a.iter().map(|&x| x * 2).collect();\n\nassert_eq!(2, doubled[0]);\nassert_eq!(4, doubled[1]);\nassert_eq!(6, doubled[2]);\n```\n\nUsing the 'turbofish' instead of annotating `doubled`:\n\n```rust\nlet a = [1, 2, 3];\n\nlet doubled = a.iter().map(|x| x * 2).collect::<Vec<i32>>();\n\nassert_eq!(vec![2, 4, 6], doubled);\n```\n\nBecause `collect()` only cares about what you're collecting into, you can\nstill use a partial type hint, `_`, with the turbofish:\n\n```rust\nlet a = [1, 2, 3];\n\nlet doubled = a.iter().map(|x| x * 2).collect::<Vec<_>>();\n\nassert_eq!(vec![2, 4, 6], doubled);\n```\n\nUsing `collect()` to make a [`String`](https://doc.rust-lang.org/nightly/core/iter/std/string/struct.String.html):\n\n```rust\nlet chars = ['g', 'd', 'k', 'k', 'n'];\n\nlet hello: String = chars.iter()\n .map(|&x| x as u8)\n .map(|x| (x + 1) as char)\n .collect();\n\nassert_eq!(\"hello\", hello);\n```\n\nIf you have a list of [`Result<T, E>`](https://doc.rust-lang.org/nightly/core/result/enum.Result.html)s, you can use `collect()` to\nsee if any of them failed:\n\n```rust\nlet results = [Ok(1), Err(\"nope\"), Ok(3), Err(\"bad\")];\n\nlet result: Result<Vec<_>, &str> = results.iter().cloned().collect();\n\n// gives us the first error\nassert_eq!(Err(\"nope\"), result);\n\nlet results = [Ok(1), Ok(3)];\n\nlet result: Result<Vec<_>, &str> = results.iter().cloned().collect();\n\n// gives us the list of answers\nassert_eq!(Ok(vec![1, 3]), result);\n```";
44 let text = "\n```rust\ncore::iter::traits::iterator::Iterator\n```\n\n```rust\nfn collect<B: FromIterator<Self::Item>>(self) -> B\nwhere\n Self: Sized,\n```\n\n---\n\nTransforms an iterator into a collection.\n\n`collect()` can take anything iterable, and turn it into a relevant\ncollection. This is one of the more powerful methods in the standard\nlibrary, used in a variety of contexts.\n\nThe most basic pattern in which `collect()` is used is to turn one\ncollection into another. You take a collection, call [`iter`](https://doc.rust-lang.org/nightly/core/iter/traits/iterator/trait.Iterator.html) on it,\ndo a bunch of transformations, and then `collect()` at the end.\n\n`collect()` can also create instances of types that are not typical\ncollections. For example, a [`String`](https://doc.rust-lang.org/nightly/core/iter/std/string/struct.String.html) can be built from [`char`](type@char)s,\nand an iterator of [`Result<T, E>`](https://doc.rust-lang.org/nightly/core/result/enum.Result.html) items can be collected\ninto `Result<Collection<T>, E>`. See the examples below for more.\n\nBecause `collect()` is so general, it can cause problems with type\ninference. As such, `collect()` is one of the few times you'll see\nthe syntax affectionately known as the 'turbofish': `::<>`. This\nhelps the inference algorithm understand specifically which collection\nyou're trying to collect into.\n\n# Examples\n\nBasic usage:\n\n```rust\nlet a = [1, 2, 3];\n\nlet doubled: Vec<i32> = a.iter()\n .map(|&x| x * 2)\n .collect();\n\nassert_eq!(vec![2, 4, 6], doubled);\n```\n\nNote that we needed the `: Vec<i32>` on the left-hand side. This is because\nwe could collect into, for example, a [`VecDeque<T>`](https://doc.rust-lang.org/nightly/core/iter/std/collections/struct.VecDeque.html) instead:\n\n```rust\nuse std::collections::VecDeque;\n\nlet a = [1, 2, 3];\n\nlet doubled: VecDeque<i32> = a.iter().map(|&x| x * 2).collect();\n\nassert_eq!(2, doubled[0]);\nassert_eq!(4, doubled[1]);\nassert_eq!(6, doubled[2]);\n```\n\nUsing the 'turbofish' instead of annotating `doubled`:\n\n```rust\nlet a = [1, 2, 3];\n\nlet doubled = a.iter().map(|x| x * 2).collect::<Vec<i32>>();\n\nassert_eq!(vec![2, 4, 6], doubled);\n```\n\nBecause `collect()` only cares about what you're collecting into, you can\nstill use a partial type hint, `_`, with the turbofish:\n\n```rust\nlet a = [1, 2, 3];\n\nlet doubled = a.iter().map(|x| x * 2).collect::<Vec<_>>();\n\nassert_eq!(vec![2, 4, 6], doubled);\n```\n\nUsing `collect()` to make a [`String`](https://doc.rust-lang.org/nightly/core/iter/std/string/struct.String.html):\n\n```rust\nlet chars = ['g', 'd', 'k', 'k', 'n'];\n\nlet hello: String = chars.iter()\n .map(|&x| x as u8)\n .map(|x| (x + 1) as char)\n .collect();\n\nassert_eq!(\"hello\", hello);\n```\n\nIf you have a list of [`Result<T, E>`](https://doc.rust-lang.org/nightly/core/result/enum.Result.html)s, you can use `collect()` to\nsee if any of them failed:\n\n```rust\nlet results = [Ok(1), Err(\"nope\"), Ok(3), Err(\"bad\")];\n\nlet result: Result<Vec<_>, &str> = results.iter().cloned().collect();\n\n// gives us the first error\nassert_eq!(Err(\"nope\"), result);\n\nlet results = [Ok(1), Ok(3)];\n\nlet result: Result<Vec<_>, &str> = results.iter().cloned().collect();\n\n// gives us the list of answers\nassert_eq!(Ok(vec![1, 3]), result);\n```";
41
45
@@ -82,9 +86,6 @@ fn parse<'a>(
82 // TODO: temp workaround
86 // TODO: temp workaround
83 if let Some(Tag::CodeBlock(CodeBlockKind::Fenced(language))) = tags.last() {
87 if let Some(Tag::CodeBlock(CodeBlockKind::Fenced(language))) = tags.last() {
84 if let Some(theme) = theme {
88 if let Some(theme) = theme {
85− use helix_core::syntax::{self, HighlightEvent, Syntax};
86− use helix_core::Rope;
87−
88 let rope = Rope::from(text.as_ref());
89 let rope = Rope::from(text.as_ref());
89 let syntax = loader
90 let syntax = loader
90 .language_config_for_scope(&format!("source.{}", language))
91 .language_config_for_scope(&format!("source.{}", language))
helix-term/src/ui/menu.rs+1−7
@@ -4,16 +4,10 @@ use tui::{buffer::Buffer as Surface, widgets::Table};
4
4
5pub use tui::widgets::{Cell, Row};
5pub use tui::widgets::{Cell, Row};
6
6
7−use std::borrow::Cow;
8−
9use fuzzy_matcher::skim::SkimMatcherV2 as Matcher;
7use fuzzy_matcher::skim::SkimMatcherV2 as Matcher;
10use fuzzy_matcher::FuzzyMatcher;
8use fuzzy_matcher::FuzzyMatcher;
11
9
12−use helix_core::Position;
13−use helix_view::{
10+use helix_view::{graphics::Rect, Editor};
14− graphics::{Color, Rect, Style},
15− Editor,
16−};
17
11
18pub trait Item {
12pub trait Item {
19 // TODO: sort_text
13 // TODO: sort_text
helix-term/src/ui/mod.rs+4−7
@@ -20,12 +20,9 @@ pub use text::Text;
20
20
21use helix_core::regex::Regex;
21use helix_core::regex::Regex;
22use helix_core::register::Registers;
22use helix_core::register::Registers;
23−use helix_view::{
24− graphics::{Color, Modifier, Rect, Style},
25− Document, Editor, View,
23+use helix_view::{Document, Editor, View};
26−};
27
24
28−use std::path::{Path, PathBuf};
25+use std::path::PathBuf;
29
26
30pub fn regex_prompt(
27pub fn regex_prompt(
31 cx: &mut crate::commands::Context,
28 cx: &mut crate::commands::Context,
@@ -133,8 +130,8 @@ pub mod completers {
133 use fuzzy_matcher::skim::SkimMatcherV2 as Matcher;
130 use fuzzy_matcher::skim::SkimMatcherV2 as Matcher;
134 use fuzzy_matcher::FuzzyMatcher;
131 use fuzzy_matcher::FuzzyMatcher;
135 use helix_view::theme;
132 use helix_view::theme;
133+ use std::borrow::Cow;
136 use std::cmp::Reverse;
134 use std::cmp::Reverse;
137− use std::{borrow::Cow, sync::Arc};
138
135
139 pub type Completer = fn(&str) -> Vec<Completion>;
136 pub type Completer = fn(&str) -> Vec<Completion>;
140
137
@@ -208,7 +205,7 @@ pub mod completers {
208 // Rust's filename handling is really annoying.
205 // Rust's filename handling is really annoying.
209
206
210 use ignore::WalkBuilder;
207 use ignore::WalkBuilder;
211− use std::path::{Path, PathBuf};
208+ use std::path::Path;
212
209
213 let is_tilde = input.starts_with('~') && input.len() == 1;
210 let is_tilde = input.starts_with('~') && input.len() == 1;
214 let path = helix_view::document::expand_tilde(Path::new(input));
211 let path = helix_view::document::expand_tilde(Path::new(input));
helix-term/src/ui/popup.rs+1−6
@@ -2,13 +2,8 @@ use crate::compositor::{Component, Compositor, Context, EventResult};
2use crossterm::event::{Event, KeyCode, KeyEvent, KeyModifiers};
2use crossterm::event::{Event, KeyCode, KeyEvent, KeyModifiers};
3use tui::buffer::Buffer as Surface;
3use tui::buffer::Buffer as Surface;
4
4
5−use std::borrow::Cow;
6−
7use helix_core::Position;
5use helix_core::Position;
8−use helix_view::{
6+use helix_view::graphics::Rect;
9− graphics::{Color, Rect, Style},
10− Editor,
11−};
12
7
13// TODO: share logic with Menu, it's essentially Popup(render_fn), but render fn needs to return
8// TODO: share logic with Menu, it's essentially Popup(render_fn), but render fn needs to return
14// a width/height hint. maybe Popup(Box<Component>)
9// a width/height hint. maybe Popup(Box<Component>)
helix-term/src/ui/prompt.rs+3−5
@@ -5,13 +5,11 @@ use std::{borrow::Cow, ops::RangeFrom};
5use tui::buffer::Buffer as Surface;
5use tui::buffer::Buffer as Surface;
6
6
7use helix_core::{
7use helix_core::{
8− unicode::segmentation::{GraphemeCursor, GraphemeIncomplete},
9− unicode::width::UnicodeWidthStr,
8+ unicode::segmentation::GraphemeCursor, unicode::width::UnicodeWidthStr, Position,
10− Position,
11};
9};
12use helix_view::{
10use helix_view::{
13− graphics::{Color, CursorKind, Margin, Modifier, Rect, Style},
11+ graphics::{CursorKind, Margin, Rect},
14− Editor, Theme,
12+ Editor,
15};
13};
16
14
17pub type Completion = (RangeFrom<usize>, Cow<'static, str>);
15pub type Completion = (RangeFrom<usize>, Cow<'static, str>);
helix-term/src/ui/text.rs+2−9
@@ -1,14 +1,7 @@
1−use crate::compositor::{Component, Compositor, Context, EventResult};
1+use crate::compositor::{Component, Context};
2−use crossterm::event::{Event, KeyCode, KeyEvent, KeyModifiers};
3use tui::buffer::Buffer as Surface;
2use tui::buffer::Buffer as Surface;
4
3
5−use std::borrow::Cow;
6−
7−use helix_core::Position;
8−use helix_view::{
4+use helix_view::graphics::Rect;
9− graphics::{Color, Rect, Style},
10− Editor,
11−};
12
5
13pub struct Text {
6pub struct Text {
14 contents: String,
7 contents: String,