summaryrefslogtreecommitdiff
path: root/helix-core
diff options
context:
space:
mode:
Diffstat (limited to 'helix-core')
-rw-r--r--helix-core/src/diagnostic.rs2
-rw-r--r--helix-core/src/doc_formatter/test.rs56
-rw-r--r--helix-core/src/text_annotations.rs43
3 files changed, 32 insertions, 69 deletions
diff --git a/helix-core/src/diagnostic.rs b/helix-core/src/diagnostic.rs
index 6b5da17e..58ddb038 100644
--- a/helix-core/src/diagnostic.rs
+++ b/helix-core/src/diagnostic.rs
@@ -35,7 +35,7 @@ pub enum DiagnosticTag {
Deprecated,
}
-/// Corresponds to [`lsp_types::Diagnostic`](https://docs.rs/lsp-types/0.91.0/lsp_types/struct.Diagnostic.html)
+/// Corresponds to [`lsp_types::Diagnostic`](https://docs.rs/lsp-types/0.94.0/lsp_types/struct.Diagnostic.html)
#[derive(Debug, Clone)]
pub struct Diagnostic {
pub range: Range,
diff --git a/helix-core/src/doc_formatter/test.rs b/helix-core/src/doc_formatter/test.rs
index e68b31fd..ac8918bb 100644
--- a/helix-core/src/doc_formatter/test.rs
+++ b/helix-core/src/doc_formatter/test.rs
@@ -119,16 +119,7 @@ fn overlay() {
"foobar",
0,
false,
- &[
- Overlay {
- char_idx: 0,
- grapheme: "X".into(),
- },
- Overlay {
- char_idx: 2,
- grapheme: "\t".into(),
- },
- ]
+ &[Overlay::new(0, "X"), Overlay::new(2, "\t")],
),
"Xo bar "
);
@@ -138,18 +129,9 @@ fn overlay() {
0,
true,
&[
- Overlay {
- char_idx: 2,
- grapheme: "\t".into(),
- },
- Overlay {
- char_idx: 5,
- grapheme: "\t".into(),
- },
- Overlay {
- char_idx: 16,
- grapheme: "X".into(),
- },
+ Overlay::new(2, "\t"),
+ Overlay::new(5, "\t"),
+ Overlay::new(16, "X"),
]
),
"fo f o foo \n.foo Xoo foo foo \n.foo foo foo "
@@ -170,24 +152,14 @@ fn annotate_text(text: &str, softwrap: bool, annotations: &[InlineAnnotation]) -
#[test]
fn annotation() {
assert_eq!(
- annotate_text(
- "bar",
- false,
- &[InlineAnnotation {
- char_idx: 0,
- text: "foo".into(),
- }]
- ),
+ annotate_text("bar", false, &[InlineAnnotation::new(0, "foo")]),
"foobar "
);
assert_eq!(
annotate_text(
&"foo ".repeat(10),
true,
- &[InlineAnnotation {
- char_idx: 0,
- text: "foo ".into(),
- }]
+ &[InlineAnnotation::new(0, "foo ")]
),
"foo foo foo foo \n.foo foo foo foo \n.foo foo foo "
);
@@ -199,20 +171,8 @@ fn annotation_and_overlay() {
"bbar".into(),
&TextFormat::new_test(false),
TextAnnotations::default()
- .add_inline_annotations(
- Rc::new([InlineAnnotation {
- char_idx: 0,
- text: "fooo".into(),
- }]),
- None
- )
- .add_overlay(
- Rc::new([Overlay {
- char_idx: 0,
- grapheme: "\t".into(),
- }]),
- None
- ),
+ .add_inline_annotations(Rc::new([InlineAnnotation::new(0, "fooo")]), None)
+ .add_overlay(Rc::new([Overlay::new(0, "\t")]), None),
0,
)
.0
diff --git a/helix-core/src/text_annotations.rs b/helix-core/src/text_annotations.rs
index 1956f6b5..3e48de4d 100644
--- a/helix-core/src/text_annotations.rs
+++ b/helix-core/src/text_annotations.rs
@@ -15,6 +15,15 @@ pub struct InlineAnnotation {
pub char_idx: usize,
}
+impl InlineAnnotation {
+ pub fn new(char_idx: usize, text: impl Into<Tendril>) -> Self {
+ Self {
+ char_idx,
+ text: text.into(),
+ }
+ }
+}
+
/// Represents a **single Grapheme** that is part of the document
/// that start at `char_idx` that will be replaced with
/// a different `grapheme`.
@@ -33,22 +42,13 @@ pub struct InlineAnnotation {
/// use helix_core::text_annotations::Overlay;
///
/// // replaces a
-/// Overlay {
-/// char_idx: 0,
-/// grapheme: "X".into(),
-/// };
+/// Overlay::new(0, "X");
///
/// // replaces X͎̊͢͜͝͡
-/// Overlay{
-/// char_idx: 1,
-/// grapheme: "\t".into(),
-/// };
+/// Overlay::new(1, "\t");
///
/// // replaces b
-/// Overlay{
-/// char_idx: 6,
-/// grapheme: "X̢̢̟͖̲͌̋̇͑͝".into(),
-/// };
+/// Overlay::new(6, "X̢̢̟͖̲͌̋̇͑͝");
/// ```
///
/// The following examples are invalid uses
@@ -57,16 +57,10 @@ pub struct InlineAnnotation {
/// use helix_core::text_annotations::Overlay;
///
/// // overlay is not aligned at grapheme boundary
-/// Overlay{
-/// char_idx: 3,
-/// grapheme: "x".into(),
-/// };
+/// Overlay::new(3, "x");
///
/// // overlay contains multiple graphemes
-/// Overlay{
-/// char_idx: 0,
-/// grapheme: "xy".into(),
-/// };
+/// Overlay::new(0, "xy");
/// ```
#[derive(Debug, Clone)]
pub struct Overlay {
@@ -74,6 +68,15 @@ pub struct Overlay {
pub grapheme: Tendril,
}
+impl Overlay {
+ pub fn new(char_idx: usize, grapheme: impl Into<Tendril>) -> Self {
+ Self {
+ char_idx,
+ grapheme: grapheme.into(),
+ }
+ }
+}
+
/// Line annotations allow for virtual text between normal
/// text lines. They cause `height` empty lines to be inserted
/// below the document line that contains `anchor_char_idx`.