Unnamed repository; edit this file 'description' to name the repository.
Geate more code to get it all building
| -rw-r--r-- | helix-view/src/commands/mod.rs | 18 | ||||
| -rw-r--r-- | helix-view/src/info.rs | 2 | ||||
| -rw-r--r-- | helix-view/src/job.rs | 7 | ||||
| -rw-r--r-- | helix-view/src/ui/editor.rs | 10 | ||||
| -rw-r--r-- | helix-view/src/ui/markdown.rs | 14 | ||||
| -rw-r--r-- | helix-view/src/ui/mod.rs | 6 | ||||
| -rw-r--r-- | helix-view/src/ui/overlay.rs | 10 |
7 files changed, 47 insertions, 20 deletions
diff --git a/helix-view/src/commands/mod.rs b/helix-view/src/commands/mod.rs index 3f42bc4c..82ecdcf8 100644 --- a/helix-view/src/commands/mod.rs +++ b/helix-view/src/commands/mod.rs @@ -72,11 +72,6 @@ use std::{ 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<char>, pub count: Option<NonZeroUsize>, @@ -103,6 +98,7 @@ impl<'a> Context<'a> { self.on_next_key_callback = Some(Box::new(on_next_key_callback)); } + #[cfg(feature = "lsp")] #[inline] pub fn callback<T, F>( &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 9cc5c428..cb6021bf 100644 --- a/helix-view/src/info.rs +++ b/helix-view/src/info.rs @@ -80,6 +80,8 @@ use crate::{ 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 17fdc85f..b709bfb6 100644 --- a/helix-view/src/job.rs +++ b/helix-view/src/job.rs @@ -76,13 +76,6 @@ impl Jobs { } } - pub async fn next_job(&mut self) -> Option<anyhow::Result<Option<Callback>>> { - 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 7caf56ed..ac2a9c59 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<Box<dyn FnOnce(&mut commands::Context, KeyEvent)>>, last_insert: (commands::MappableCommand, Vec<InsertEvent>), - pub(crate) completion: Option<Completion>, + #[cfg(feature = "term")] + pub(crate) completion: Option<ui::Completion>, spinners: ProgressSpinners, } @@ -897,6 +898,7 @@ impl EditorView { } } + #[cfg(feature = "term")] pub fn set_completion( &mut self, editor: &mut Editor, @@ -907,7 +909,7 @@ impl EditorView { 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 @@ impl EditorView { self.completion = Some(completion); } + #[cfg(feature = "term")] pub fn clear_completion(&mut self, editor: &mut Editor) { self.completion = None; @@ -934,6 +937,7 @@ impl EditorView { 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 eb5e0a43..760241d5 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 @@ use helix_core::{ 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 @@ impl Markdown { } } + #[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<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```"; @@ -275,6 +283,12 @@ impl compositor::term::Render for Markdown { } 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 0105175e..0d10a1e9 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 f44374eb..0b13212e 100644 --- a/helix-view/src/ui/overlay.rs +++ b/helix-view/src/ui/overlay.rs @@ -48,6 +48,11 @@ impl<T: Component + 'static> compositor::term::Render for Overlay<T> { let dimensions = (self.calc_child_size)(area); self.content.render(dimensions, ctx) } + + fn cursor(&self, area: Rect, ctx: &Editor) -> (Option<Position>, CursorKind) { + let dimensions = (self.calc_child_size)(area); + self.content.cursor(dimensions, ctx) + } } impl<T: Component + 'static> Component for Overlay<T> { @@ -67,9 +72,4 @@ impl<T: Component + 'static> Component for Overlay<T> { 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<Position>, CursorKind) { - let dimensions = (self.calc_child_size)(area); - self.content.cursor(dimensions, ctx) - } } |