on master help sign in
Remove #[allow(unused)] from helix-term, and fix unused imports.

Lots of other warning still left. Will address in subsequent commits.

commit702a0491db0fef8ee15cd6fcff3138812da2c2aa authorNathan Vegdahl <cessen@cessen.com> dateThu 1 Jul 2021, 10:41 (5 years ago) parent79f0969
15 files changed+57−123
helix-term/src/application.rs+8−23 helix-term/src/commands.rs+10−22 helix-term/src/compositor.rs−1 helix-term/src/config.rs+3−3 helix-term/src/job.rs+1−1 helix-term/src/keymap.rs−4 helix-term/src/lib.rs−2 helix-term/src/ui/completion.rs+5−11 helix-term/src/ui/editor.rs+6−10 helix-term/src/ui/markdown.rs+13−12 helix-term/src/ui/menu.rs+1−7 helix-term/src/ui/mod.rs+4−7 helix-term/src/ui/popup.rs+1−6 helix-term/src/ui/prompt.rs+3−5 helix-term/src/ui/text.rs+2−9
helix-term/src/application.rs+8−23
@@ -1,37 +1,23 @@
11use helix_core::syntax;
2−use helix_lsp::{lsp, LspProgressMap};
3−use helix_view::{document::Mode, graphics::Rect, theme, Document, Editor, Theme, View};
4−
5−use crate::{
6− args::Args,
7− compositor::Compositor,
8− config::Config,
9− job::Jobs,
10− keymap::Keymaps,
11− ui::{self, Spinner},
12−};
2+use helix_lsp::{lsp, util::lsp_pos_to_pos, LspProgressMap};
3+use helix_view::{theme, Editor};
4+
5+use crate::{args::Args, compositor::Compositor, config::Config, job::Jobs, ui};
136
14−use log::{error, info};
7+use log::error;
158
169use std::{
17− collections::HashMap,
18− future::Future,
19− io::{self, stdout, Stdout, Write},
20− path::PathBuf,
21− pin::Pin,
10+ io::{stdout, Write},
2211 sync::Arc,
23− time::Duration,
2412};
2513
26−use anyhow::{Context, Error};
14+use anyhow::Error;
2715
2816use crossterm::{
2917 event::{Event, EventStream},
3018 execute, terminal,
3119};
3220
33−use futures_util::{future, stream::FuturesUnordered};
34−
3521pub struct Application {
3622 compositor: Compositor,
3723 editor: Editor,
@@ -239,10 +225,9 @@ impl Application {
239225 .into_iter()
240226 .filter_map(|diagnostic| {
241227 use helix_core::{
242− diagnostic::{Range, Severity, Severity::*},
228+ diagnostic::{Range, Severity::*},
243229 Diagnostic,
244230 };
245− use helix_lsp::{lsp, util::lsp_pos_to_pos};
246231 use lsp::DiagnosticSeverity;
247232
248233 let language_server = doc.language_server().unwrap();
helix-term/src/commands.rs+10−22
@@ -1,20 +1,21 @@
11use helix_core::{
22 comment, coords_at_pos, find_first_non_whitespace_char, find_root, graphemes, indent,
33 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,
55 str_is_line_ending,
66 },
77 match_brackets,
88 movement::{self, Direction},
99 object, pos_at_coords,
1010 regex::{self, Regex},
11− register::{self, Register, Registers},
12− search, selection, Change, ChangeSet, LineEnding, Position, Range, Rope, RopeGraphemes,
13− RopeSlice, Selection, SmallVec, Tendril, Transaction, DEFAULT_LINE_ENDING,
11+ register::Register,
12+ search, selection, LineEnding, Position, Range, Rope, RopeGraphemes, RopeSlice, Selection,
13+ SmallVec, Tendril, Transaction,
1414};
1515
1616use helix_view::{
1717 document::{IndentStyle, Mode},
18+ editor::Action,
1819 input::KeyEvent,
1920 keyboard::KeyCode,
2021 view::{View, PADDING},
@@ -25,19 +26,19 @@ use anyhow::anyhow;
2526use helix_lsp::{
2627 lsp,
2728 util::{lsp_pos_to_pos, lsp_range_to_range, pos_to_lsp_pos, range_to_lsp_range},
28− LspProgressMap, OffsetEncoding,
29+ OffsetEncoding,
2930};
3031use insert::*;
3132use movement::Movement;
3233
3334use crate::{
34− compositor::{self, Callback, Component, Compositor},
35− ui::{self, Completion, Picker, Popup, Prompt, PromptEvent},
35+ compositor::{self, Component, Compositor},
36+ ui::{self, Picker, Popup, Prompt, PromptEvent},
3637};
3738
38−use crate::job::{self, Job, JobFuture, Jobs};
39+use crate::job::{self, Job, Jobs};
3940use futures_util::{FutureExt, TryFutureExt};
40−use std::{fmt, future::Future, path::Display, str::FromStr};
41+use std::{fmt, future::Future};
4142
4243use std::{
4344 borrow::Cow,
@@ -1148,7 +1149,6 @@ mod cmd {
11481149 cx: &mut compositor::Context,
11491150 path: Option<P>,
11501151 ) -> Result<tokio::task::JoinHandle<Result<(), anyhow::Error>>, anyhow::Error> {
1151− use anyhow::anyhow;
11521152 let jobs = &mut cx.jobs;
11531153 let (view, doc) = current!(cx.editor);
11541154
@@ -1723,7 +1723,6 @@ fn command_mode(cx: &mut Context) {
17231723 // simple heuristic: if there's no just one part, complete command name.
17241724 // if there's a space, per command completion kicks in.
17251725 if parts.len() <= 1 {
1726− use std::{borrow::Cow, ops::Range};
17271726 let end = 0..;
17281727 cmd::TYPABLE_COMMAND_LIST
17291728 .iter()
@@ -1753,8 +1752,6 @@ fn command_mode(cx: &mut Context) {
17531752 }
17541753 }, // completion
17551754 move |cx: &mut compositor::Context, input: &str, event: PromptEvent| {
1756− use helix_view::editor::Action;
1757−
17581755 if event != PromptEvent::Validate {
17591756 return;
17601757 }
@@ -1792,7 +1789,6 @@ fn file_picker(cx: &mut Context) {
17921789}
17931790
17941791fn buffer_picker(cx: &mut Context) {
1795− use std::path::{Path, PathBuf};
17961792 let current = view!(cx.editor).doc;
17971793
17981794 let picker = Picker::new(
@@ -1815,7 +1811,6 @@ fn buffer_picker(cx: &mut Context) {
18151811 }
18161812 },
18171813 |editor: &mut Editor, (id, _path): &(DocumentId, Option<PathBuf>), _action| {
1818− use helix_view::editor::Action;
18191814 editor.switch(*id, Action::Replace);
18201815 },
18211816 );
@@ -2145,8 +2140,6 @@ fn goto_impl(
21452140 locations: Vec<lsp::Location>,
21462141 offset_encoding: OffsetEncoding,
21472142) {
2148− use helix_view::editor::Action;
2149−
21502143 push_jump(editor);
21512144
21522145 fn jump_to(
@@ -3181,7 +3174,6 @@ fn completion(cx: &mut Context) {
31813174 if items.is_empty() {
31823175 return;
31833176 }
3184− use crate::compositor::AnyComponent;
31853177 let size = compositor.size();
31863178 let ui = compositor
31873179 .find(std::any::type_name::<ui::EditorView>())
@@ -3332,11 +3324,7 @@ fn rotate_view(cx: &mut Context) {
33323324}
33333325
33343326// split helper, clear it later
3335−use helix_view::editor::Action;
3336−
3337−use self::cmd::TypableCommand;
33383327fn split(cx: &mut Context, action: Action) {
3339− use helix_view::editor::Action;
33403328 let (view, doc) = current!(cx.editor);
33413329 let id = doc.id();
33423330 let selection = doc.selection(view.id).clone();
helix-term/src/compositor.rs−1
@@ -2,7 +2,6 @@
22// Q: how does this work with popups?
33// cursive does compositor.screen_mut().add_layer_at(pos::absolute(x, y), <component>)
44use helix_core::Position;
5−use helix_lsp::LspProgressMap;
65use helix_view::graphics::{CursorKind, Rect};
76
87use crossterm::event::Event;
helix-term/src/config.rs+3−3
@@ -1,10 +1,10 @@
1−use anyhow::{Error, Result};
21use serde::Deserialize;
3−use std::collections::HashMap;
42
5−use crate::commands::Command;
63use crate::keymap::Keymaps;
74
5+#[cfg(test)]
6+use crate::commands::Command;
7+
88#[derive(Debug, Default, Clone, PartialEq, Deserialize)]
99pub struct Config {
1010 pub theme: Option<String>,
helix-term/src/job.rs+1−1
@@ -3,7 +3,7 @@ use helix_view::Editor;
33use crate::compositor::Compositor;
44
55use futures_util::future::{self, BoxFuture, Future, FutureExt};
6−use futures_util::stream::{self, FuturesUnordered, Select, StreamExt};
6+use futures_util::stream::{FuturesUnordered, StreamExt};
77
88pub type Callback = Box<dyn FnOnce(&mut Editor, &mut Compositor) + Send>;
99pub type JobFuture = BoxFuture<'static, anyhow::Result<Option<Callback>>>;
helix-term/src/keymap.rs−4
@@ -1,7 +1,5 @@
1−use crate::commands;
21pub use crate::commands::Command;
32use crate::config::Config;
4−use anyhow::{anyhow, Error, Result};
53use helix_core::hashmap;
64use helix_view::{
75 document::Mode,
@@ -11,9 +9,7 @@ use helix_view::{
119use serde::Deserialize;
1210use std::{
1311 collections::HashMap,
14− fmt::Display,
1512 ops::{Deref, DerefMut},
16− str::FromStr,
1713};
1814
1915// Kakoune-inspired:
helix-term/src/lib.rs−2
@@ -1,5 +1,3 @@
1−#![allow(unused)]
2−
31#[macro_use]
42extern crate helix_view;
53
helix-term/src/ui/completion.rs+5−11
@@ -1,19 +1,16 @@
1−use crate::compositor::{Component, Compositor, Context, EventResult};
2−use crossterm::event::{Event, KeyCode, KeyEvent, KeyModifiers};
1+use crate::compositor::{Component, Context, EventResult};
2+use crossterm::event::{Event, KeyCode, KeyEvent};
33use tui::buffer::Buffer as Surface;
44
55use std::borrow::Cow;
66
7−use helix_core::{Position, Transaction};
8−use helix_view::{
9− graphics::{Color, Rect, Style},
10− Editor,
11−};
7+use helix_core::Transaction;
8+use helix_view::{graphics::Rect, Editor};
129
1310use crate::commands;
1411use crate::ui::{menu, Markdown, Menu, Popup, PromptEvent};
1512
16−use helix_lsp::lsp;
13+use helix_lsp::{lsp, util};
1714use lsp::CompletionItem;
1815
1916impl menu::Item for CompletionItem {
@@ -88,8 +85,6 @@ impl Completion {
8885 // always present here
8986 let item = item.unwrap();
9087
91− use helix_lsp::{lsp, util};
92−
9388 // if more text was entered, remove it
9489 let cursor = doc.selection(view.id).cursor();
9590 if trigger_offset < cursor {
@@ -100,7 +95,6 @@ impl Completion {
10095 doc.apply(&remove, view.id);
10196 }
10297
103− use helix_lsp::OffsetEncoding;
10498 let transaction = if let Some(edit) = &item.text_edit {
10599 let edit = match edit {
106100 lsp::CompletionTextEdit::Edit(edit) => edit.clone(),
helix-term/src/ui/editor.rs+6−10
@@ -1,32 +1,28 @@
11use crate::{
22 commands,
3− compositor::{Component, Compositor, Context, EventResult},
3+ compositor::{Component, Context, EventResult},
44 key,
5− keymap::{self, Keymaps},
5+ keymap::Keymaps,
66 ui::{Completion, ProgressSpinners},
77};
88
99use helix_core::{
1010 coords_at_pos,
1111 graphemes::ensure_grapheme_boundary,
12− syntax::{self, Highlight, HighlightEvent},
12+ syntax::{self, HighlightEvent},
1313 LineEnding, Position, Range,
1414};
15−use helix_lsp::LspProgressMap;
1615use helix_view::{
1716 document::Mode,
18− graphics::{Color, CursorKind, Modifier, Rect, Style},
17+ graphics::{CursorKind, Modifier, Rect, Style},
1918 input::KeyEvent,
2019 keyboard::{KeyCode, KeyModifiers},
2120 Document, Editor, Theme, View,
2221};
2322use std::borrow::Cow;
2423
25−use crossterm::{
26− cursor,
27− event::{read, Event, EventStream},
28−};
29−use tui::{backend::CrosstermBackend, buffer::Buffer as Surface};
24+use crossterm::event::Event;
25+use tui::buffer::Buffer as Surface;
3026
3127pub struct EditorView {
3228 keymaps: Keymaps,
helix-term/src/ui/markdown.rs+13−12
@@ -1,13 +1,20 @@
1−use crate::compositor::{Component, Compositor, Context, EventResult};
2−use crossterm::event::{Event, KeyCode, KeyEvent, KeyModifiers};
3−use tui::{buffer::Buffer as Surface, text::Text};
1+use crate::compositor::{Component, Context};
2+use tui::{
3+ buffer::Buffer as Surface,
4+ text::{Span, Spans, Text},
5+};
6+
7+use std::sync::Arc;
48
5−use std::{borrow::Cow, sync::Arc};
9+use pulldown_cmark::{CodeBlockKind, CowStr, Event, Options, Parser, Tag};
610
7−use helix_core::{syntax, Position};
11+use helix_core::{
12+ syntax::{self, HighlightEvent, Syntax},
13+ Rope,
14+};
815use helix_view::{
916 graphics::{Color, Rect, Style},
10− Editor, Theme,
17+ Theme,
1118};
1219
1320pub struct Markdown {
@@ -33,9 +40,6 @@ fn parse<'a>(
3340 theme: Option<&Theme>,
3441 loader: &syntax::Loader,
3542) -> tui::text::Text<'a> {
36− use pulldown_cmark::{CodeBlockKind, CowStr, Event, Options, Parser, Tag};
37− use tui::text::{Span, Spans, Text};
38−
3943 // 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}}}
4044 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```";
4145
@@ -82,9 +86,6 @@ fn parse<'a>(
8286 // TODO: temp workaround
8387 if let Some(Tag::CodeBlock(CodeBlockKind::Fenced(language))) = tags.last() {
8488 if let Some(theme) = theme {
85− use helix_core::syntax::{self, HighlightEvent, Syntax};
86− use helix_core::Rope;
87−
8889 let rope = Rope::from(text.as_ref());
8990 let syntax = loader
9091 .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};
44
55pub use tui::widgets::{Cell, Row};
66
7−use std::borrow::Cow;
8−
97use fuzzy_matcher::skim::SkimMatcherV2 as Matcher;
108use fuzzy_matcher::FuzzyMatcher;
119
12−use helix_core::Position;
13−use helix_view::{
14− graphics::{Color, Rect, Style},
15− Editor,
16−};
10+use helix_view::{graphics::Rect, Editor};
1711
1812pub trait Item {
1913 // TODO: sort_text
helix-term/src/ui/mod.rs+4−7
@@ -20,12 +20,9 @@ pub use text::Text;
2020
2121use helix_core::regex::Regex;
2222use helix_core::register::Registers;
23−use helix_view::{
24− graphics::{Color, Modifier, Rect, Style},
25− Document, Editor, View,
26−};
23+use helix_view::{Document, Editor, View};
2724
28−use std::path::{Path, PathBuf};
25+use std::path::PathBuf;
2926
3027pub fn regex_prompt(
3128 cx: &mut crate::commands::Context,
@@ -133,8 +130,8 @@ pub mod completers {
133130 use fuzzy_matcher::skim::SkimMatcherV2 as Matcher;
134131 use fuzzy_matcher::FuzzyMatcher;
135132 use helix_view::theme;
133+ use std::borrow::Cow;
136134 use std::cmp::Reverse;
137− use std::{borrow::Cow, sync::Arc};
138135
139136 pub type Completer = fn(&str) -> Vec<Completion>;
140137
@@ -208,7 +205,7 @@ pub mod completers {
208205 // Rust's filename handling is really annoying.
209206
210207 use ignore::WalkBuilder;
211− use std::path::{Path, PathBuf};
208+ use std::path::Path;
212209
213210 let is_tilde = input.starts_with('~') && input.len() == 1;
214211 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};
22use crossterm::event::{Event, KeyCode, KeyEvent, KeyModifiers};
33use tui::buffer::Buffer as Surface;
44
5−use std::borrow::Cow;
6−
75use helix_core::Position;
8−use helix_view::{
9− graphics::{Color, Rect, Style},
10− Editor,
11−};
6+use helix_view::graphics::Rect;
127
138// TODO: share logic with Menu, it's essentially Popup(render_fn), but render fn needs to return
149// 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};
55use tui::buffer::Buffer as Surface;
66
77use helix_core::{
8− unicode::segmentation::{GraphemeCursor, GraphemeIncomplete},
9− unicode::width::UnicodeWidthStr,
10− Position,
8+ unicode::segmentation::GraphemeCursor, unicode::width::UnicodeWidthStr, Position,
119};
1210use helix_view::{
13− graphics::{Color, CursorKind, Margin, Modifier, Rect, Style},
14− Editor, Theme,
11+ graphics::{CursorKind, Margin, Rect},
12+ Editor,
1513};
1614
1715pub 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};
2−use crossterm::event::{Event, KeyCode, KeyEvent, KeyModifiers};
1+use crate::compositor::{Component, Context};
32use tui::buffer::Buffer as Surface;
43
5−use std::borrow::Cow;
6−
7−use helix_core::Position;
8−use helix_view::{
9− graphics::{Color, Rect, Style},
10− Editor,
11−};
4+use helix_view::graphics::Rect;
125
136pub struct Text {
147 contents: String,