diff --git a/helix-view/src/commands/mod.rs b/helix-view/src/commands/mod.rs index 3f42bc4c9..82ecdcf8b 100644 --- a/helix-view/src/commands/mod.rs +++ b/helix-view/src/commands/mod.rs @@ -72,11 +72,6 @@ use once_cell::sync::Lazy; use serde::de::{self, Deserialize, Deserializer}; -use grep_regex::RegexMatcherBuilder; -use grep_searcher::{sinks, BinaryDetection, SearcherBuilder}; -use ignore::{DirEntry, WalkBuilder, WalkState}; -use tokio_stream::wrappers::UnboundedReceiverStream; - pub struct Context<'a> { pub register: Option, pub count: Option, @@ -103,6 +98,7 @@ pub fn on_next_key( self.on_next_key_callback = Some(Box::new(on_next_key_callback)); } + #[cfg(feature = "lsp")] #[inline] pub fn callback( &mut self, @@ -1767,7 +1763,17 @@ fn search_selection(cx: &mut Context) { cx.editor.set_status(msg); } +#[cfg(not(feature = "term"))] fn global_search(cx: &mut Context) { + // TODO +} + +#[cfg(feature = "term")] +fn global_search(cx: &mut Context) { + use grep_regex::RegexMatcherBuilder; + use grep_searcher::{sinks, BinaryDetection, SearcherBuilder}; + use ignore::{DirEntry, WalkBuilder, WalkState}; + let (all_matches_sx, all_matches_rx) = tokio::sync::mpsc::unbounded_channel::<(usize, PathBuf)>(); let config = cx.editor.config(); @@ -1858,6 +1864,8 @@ fn global_search(cx: &mut Context) { let current_path = doc_mut!(cx.editor).path().cloned(); let show_picker = async move { + use tokio_stream::wrappers::UnboundedReceiverStream; + let all_matches: Vec<(usize, PathBuf)> = UnboundedReceiverStream::new(all_matches_rx).collect().await; let call: job::Callback = diff --git a/helix-view/src/info.rs b/helix-view/src/info.rs index 9cc5c4288..cb6021bf6 100644 --- a/helix-view/src/info.rs +++ b/helix-view/src/info.rs @@ -80,6 +80,8 @@ pub fn from_registers(registers: &Registers) -> Self { compositor::{self, Component, RenderContext}, graphics::{Margin, Rect}, }; + +#[cfg(feature = "term")] use tui::widgets::{Block, Borders, Paragraph, Widget}; #[cfg(feature = "term")] diff --git a/helix-view/src/job.rs b/helix-view/src/job.rs index 17fdc85fb..b709bfb65 100644 --- a/helix-view/src/job.rs +++ b/helix-view/src/job.rs @@ -76,13 +76,6 @@ pub fn handle_callback( } } - pub async fn next_job(&mut self) -> Option>> { - tokio::select! { - event = self.futures.next() => { event } - event = self.wait_futures.next() => { event } - } - } - pub fn add(&self, j: Job) { if j.wait { self.wait_futures.push(j.future); diff --git a/helix-view/src/ui/editor.rs b/helix-view/src/ui/editor.rs index 7caf56edf..ac2a9c596 100644 --- a/helix-view/src/ui/editor.rs +++ b/helix-view/src/ui/editor.rs @@ -1,7 +1,7 @@ use crate::{ commands, compositor, key, keymap::{KeymapResult, Keymaps}, - ui::{Completion, ProgressSpinners}, + ui::{self, ProgressSpinners}, }; use crate::compositor::{Component, Context, Event, EventResult}; @@ -31,7 +31,8 @@ pub struct EditorView { pub keymaps: Keymaps, on_next_key: Option>, last_insert: (commands::MappableCommand, Vec), - pub(crate) completion: Option, + #[cfg(feature = "term")] + pub(crate) completion: Option, spinners: ProgressSpinners, } @@ -897,6 +898,7 @@ fn command_mode(&mut self, mode: Mode, cxt: &mut commands::Context, event: KeyEv } } + #[cfg(feature = "term")] pub fn set_completion( &mut self, editor: &mut Editor, @@ -907,7 +909,7 @@ pub fn set_completion( size: Rect, ) { let mut completion = - Completion::new(editor, items, offset_encoding, start_offset, trigger_offset); + ui::Completion::new(editor, items, offset_encoding, start_offset, trigger_offset); if completion.is_empty() { // skip if we got no completion results @@ -925,6 +927,7 @@ pub fn set_completion( self.completion = Some(completion); } + #[cfg(feature = "term")] pub fn clear_completion(&mut self, editor: &mut Editor) { self.completion = None; @@ -934,6 +937,7 @@ pub fn clear_completion(&mut self, editor: &mut Editor) { editor.clear_idle_timer(); // don't retrigger } + #[cfg(feature = "term")] pub fn handle_idle_timeout(&mut self, cx: &mut crate::compositor::Context) -> EventResult { if self.completion.is_some() || !cx.editor.config().auto_completion diff --git a/helix-view/src/ui/markdown.rs b/helix-view/src/ui/markdown.rs index eb5e0a430..760241d59 100644 --- a/helix-view/src/ui/markdown.rs +++ b/helix-view/src/ui/markdown.rs @@ -1,4 +1,6 @@ use crate::compositor::{self, Component, RenderContext}; + +#[cfg(feature = "term")] use tui::text::{Span, Spans, Text}; use std::sync::Arc; @@ -14,6 +16,7 @@ Rope, }; +#[cfg(feature = "term")] fn styled_multiline_text<'a>(text: String, style: Style) -> Text<'a> { let spans: Vec<_> = text .lines() @@ -23,6 +26,7 @@ fn styled_multiline_text<'a>(text: String, style: Style) -> Text<'a> { Text::from(spans) } +#[cfg(feature = "term")] pub fn highlighted_code_block<'a>( text: String, language: &str, @@ -140,6 +144,10 @@ pub fn new(contents: String, config_loader: Arc) -> Self { } } + #[cfg(not(feature = "term"))] + fn parse(&self, theme: Option<&Theme>) -> () {} + + #[cfg(feature = "term")] fn parse(&self, theme: Option<&Theme>) -> tui::text::Text<'_> { // // 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}}} // let text = "\n```rust\ncore::iter::traits::iterator::Iterator\n```\n\n```rust\nfn collect>(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`](https://doc.rust-lang.org/nightly/core/result/enum.Result.html) items can be collected\ninto `Result, 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 = 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` on the left-hand side. This is because\nwe could collect into, for example, a [`VecDeque`](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 = 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::>();\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::>();\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`](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, &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, &str> = results.iter().cloned().collect();\n\n// gives us the list of answers\nassert_eq!(Ok(vec![1, 3]), result);\n```"; @@ -275,6 +283,12 @@ fn render(&mut self, area: Rect, cx: &mut RenderContext<'_>) { } impl Component for Markdown { + #[cfg(not(feature = "term"))] + fn required_size(&mut self, viewport: (u16, u16)) -> Option<(u16, u16)> { + None + } + + #[cfg(feature = "term")] fn required_size(&mut self, viewport: (u16, u16)) -> Option<(u16, u16)> { let padding = 2; if padding >= viewport.1 || padding >= viewport.0 { diff --git a/helix-view/src/ui/mod.rs b/helix-view/src/ui/mod.rs index 0105175e7..0d10a1e95 100644 --- a/helix-view/src/ui/mod.rs +++ b/helix-view/src/ui/mod.rs @@ -1,22 +1,28 @@ +#[cfg(feature = "term")] mod completion; pub(crate) mod editor; mod markdown; +#[cfg(feature = "term")] pub mod menu; pub mod overlay; mod picker; mod popup; mod prompt; mod spinner; +#[cfg(feature = "term")] mod text; +#[cfg(feature = "term")] pub use completion::Completion; pub use editor::EditorView; pub use markdown::Markdown; +#[cfg(feature = "term")] pub use menu::Menu; pub use picker::{FileLocation, FilePicker, Picker}; pub use popup::Popup; pub use prompt::{Prompt, PromptEvent}; pub use spinner::{ProgressSpinners, Spinner}; +#[cfg(feature = "term")] pub use text::Text; use crate::{Document, Editor, View}; diff --git a/helix-view/src/ui/overlay.rs b/helix-view/src/ui/overlay.rs index f44374eb7..0b13212e9 100644 --- a/helix-view/src/ui/overlay.rs +++ b/helix-view/src/ui/overlay.rs @@ -48,6 +48,11 @@ fn render(&mut self, area: Rect, ctx: &mut RenderContext<'_>) { let dimensions = (self.calc_child_size)(area); self.content.render(dimensions, ctx) } + + fn cursor(&self, area: Rect, ctx: &Editor) -> (Option, CursorKind) { + let dimensions = (self.calc_child_size)(area); + self.content.cursor(dimensions, ctx) + } } impl Component for Overlay { @@ -67,9 +72,4 @@ fn required_size(&mut self, (width, height): (u16, u16)) -> Option<(u16, u16)> { fn handle_event(&mut self, event: Event, ctx: &mut Context) -> EventResult { self.content.handle_event(event, ctx) } - - fn cursor(&self, area: Rect, ctx: &Editor) -> (Option, CursorKind) { - let dimensions = (self.calc_child_size)(area); - self.content.cursor(dimensions, ctx) - } }