aboutsummaryrefslogtreecommitdiff
path: root/helix-tui/src
diff options
context:
space:
mode:
authorFalco Hirschenberger2022-06-30 09:16:18 +0000
committerGitHub2022-06-30 09:16:18 +0000
commited89f8897eab84bf7614a718d5d1e3ec5c57086c (patch)
tree347bd0db6509b1c4a6e88f6ca7e461dc8a923215 /helix-tui/src
parent94fc41a41920fc705f01637e7902f06a1c32d998 (diff)
Add workspace and document diagnostics picker (#2013)
* Add workspace and document diagnostics picker fixes #1891 * Fix some of @archseer's annotations * Add From<&Spans> impl for String * More descriptive parameter names. * Adding From<Cow<str>> impls for Span and Spans * Add new keymap entries to docs * Avoid some clones * Fix api change * Update helix-term/src/application.rs Co-authored-by: Bjorn Ove Hay Andersen <bjrnove@gmail.com> * Fix a clippy hint * Sort diagnostics first by URL and then by severity. * Sort diagnostics first by URL and then by severity. * Ignore missing lsp severity entries * Add truncated filepath * Typo * Strip cwd from paths and use url-path without schema * Make tests a doctest * Better variable names Co-authored-by: Falco Hirschenberger <falco.hirschenberger@itwm.fraunhofer.de> Co-authored-by: Bjorn Ove Hay Andersen <bjrnove@gmail.com>
Diffstat (limited to 'helix-tui/src')
-rw-r--r--helix-tui/src/text.rs23
-rw-r--r--helix-tui/src/widgets/block.rs2
2 files changed, 20 insertions, 5 deletions
diff --git a/helix-tui/src/text.rs b/helix-tui/src/text.rs
index 8a974ddb..b4278c86 100644
--- a/helix-tui/src/text.rs
+++ b/helix-tui/src/text.rs
@@ -194,6 +194,12 @@ impl<'a> From<&'a str> for Span<'a> {
}
}
+impl<'a> From<Cow<'a, str>> for Span<'a> {
+ fn from(s: Cow<'a, str>) -> Span<'a> {
+ Span::raw(s)
+ }
+}
+
/// A string composed of clusters of graphemes, each with their own style.
#[derive(Debug, Default, Clone, PartialEq)]
pub struct Spans<'a>(pub Vec<Span<'a>>);
@@ -229,6 +235,12 @@ impl<'a> From<&'a str> for Spans<'a> {
}
}
+impl<'a> From<Cow<'a, str>> for Spans<'a> {
+ fn from(s: Cow<'a, str>) -> Spans<'a> {
+ Spans(vec![Span::raw(s)])
+ }
+}
+
impl<'a> From<Vec<Span<'a>>> for Spans<'a> {
fn from(spans: Vec<Span<'a>>) -> Spans<'a> {
Spans(spans)
@@ -243,10 +255,13 @@ impl<'a> From<Span<'a>> for Spans<'a> {
impl<'a> From<Spans<'a>> for String {
fn from(line: Spans<'a>) -> String {
- line.0.iter().fold(String::new(), |mut acc, s| {
- acc.push_str(s.content.as_ref());
- acc
- })
+ line.0.iter().map(|s| &*s.content).collect()
+ }
+}
+
+impl<'a> From<&Spans<'a>> for String {
+ fn from(line: &Spans<'a>) -> String {
+ line.0.iter().map(|s| &*s.content).collect()
}
}
diff --git a/helix-tui/src/widgets/block.rs b/helix-tui/src/widgets/block.rs
index 3c05a2a3..bd025a31 100644
--- a/helix-tui/src/widgets/block.rs
+++ b/helix-tui/src/widgets/block.rs
@@ -77,7 +77,7 @@ impl<'a> Block<'a> {
)]
pub fn title_style(mut self, style: Style) -> Block<'a> {
if let Some(t) = self.title {
- let title = String::from(t);
+ let title = String::from(&t);
self.title = Some(Spans::from(Span::styled(title, style)));
}
self