mirror of
https://github.com/helix-editor/helix.git
synced 2024-11-22 09:26:19 +04:00
Geate more code to get it all building
This commit is contained in:
parent
febc7ee0fa
commit
842cd2cc13
@ -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<char>,
|
||||
pub count: Option<NonZeroUsize>,
|
||||
@ -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<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 =
|
||||
|
@ -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")]
|
||||
|
@ -76,13 +76,6 @@ pub fn handle_callback(
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
@ -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 @@ 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
|
||||
|
@ -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<syntax::Loader>) -> 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<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 @@ 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 {
|
||||
|
@ -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};
|
||||
|
@ -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<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 @@ 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<Position>, CursorKind) {
|
||||
let dimensions = (self.calc_child_size)(area);
|
||||
self.content.cursor(dimensions, ctx)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user