Skip to content

Commit

Permalink
refactor!: Move around items in the public api
Browse files Browse the repository at this point in the history
BREAKING CHANGE: This moves `snippet::*` and `Renderer` to root
  • Loading branch information
Muscraft committed Dec 5, 2023
1 parent 51506e9 commit b016a59
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 43 deletions.
3 changes: 1 addition & 2 deletions benches/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ extern crate criterion;

use criterion::{black_box, Criterion};

use annotate_snippets::renderer::Renderer;
use annotate_snippets::snippet::{Annotation, AnnotationType, Slice, Snippet, SourceAnnotation};
use annotate_snippets::{Annotation, AnnotationType, Renderer, Slice, Snippet, SourceAnnotation};

fn create_snippet(renderer: Renderer) {
let snippet = Snippet {
Expand Down
3 changes: 1 addition & 2 deletions examples/expected_type.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use annotate_snippets::renderer::Renderer;
use annotate_snippets::snippet::{Annotation, AnnotationType, Slice, Snippet, SourceAnnotation};
use annotate_snippets::{Annotation, AnnotationType, Renderer, Slice, Snippet, SourceAnnotation};

fn main() {
let snippet = Snippet {
Expand Down
3 changes: 1 addition & 2 deletions examples/footer.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use annotate_snippets::renderer::Renderer;
use annotate_snippets::snippet::{Annotation, AnnotationType, Slice, Snippet, SourceAnnotation};
use annotate_snippets::{Annotation, AnnotationType, Renderer, Slice, Snippet, SourceAnnotation};

fn main() {
let snippet = Snippet {
Expand Down
3 changes: 1 addition & 2 deletions examples/format.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use annotate_snippets::renderer::Renderer;
use annotate_snippets::snippet::{Annotation, AnnotationType, Slice, Snippet, SourceAnnotation};
use annotate_snippets::{Annotation, AnnotationType, Renderer, Slice, Snippet, SourceAnnotation};

fn main() {
let snippet = Snippet {
Expand Down
3 changes: 1 addition & 2 deletions examples/multislice.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use annotate_snippets::renderer::Renderer;
use annotate_snippets::snippet::{Annotation, AnnotationType, Slice, Snippet};
use annotate_snippets::{Annotation, AnnotationType, Renderer, Slice, Snippet};

fn main() {
let snippet = Snippet {
Expand Down
12 changes: 8 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,22 @@
//! Snippet --> Renderer --> impl Display
//! ```
//!
//! The input type - [Snippet](self::snippet) is a structure designed
//! The input type - [Snippet] is a structure designed
//! to align with likely output from any parser whose code snippet is to be
//! annotated.
//!
//! The middle structure - [Renderer](self::renderer) is a structure designed
//! The middle structure - [Renderer] is a structure designed
//! to convert a snippet into an internal structure that is designed to store
//! the snippet data in a way that is easy to format.
//! [Renderer](self::renderer) also handles the user-configurable formatting
//! [Renderer] also handles the user-configurable formatting
//! options, such as color, or margins.
//!
//! Finally, `impl Display` into a final `String` output.
mod display_list;
pub mod renderer;
pub mod snippet;
mod snippet;

#[doc(inline)]
pub use renderer::Renderer;
pub use snippet::*;
3 changes: 1 addition & 2 deletions src/renderer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
//!
//! # Example
//! ```
//! use annotate_snippets::renderer::Renderer;
//! use annotate_snippets::snippet::{Annotation, AnnotationType, Slice, Snippet};
//! use annotate_snippets::{Annotation, AnnotationType, Renderer, Slice, Snippet};
//! let snippet = Snippet {
//! title: Some(Annotation {
//! label: Some("mismatched types"),
Expand Down
2 changes: 1 addition & 1 deletion src/snippet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//! Example:
//!
//! ```
//! use annotate_snippets::snippet::*;
//! use annotate_snippets::*;
//!
//! Snippet {
//! title: Some(Annotation {
Expand Down
4 changes: 1 addition & 3 deletions tests/deserialize/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use serde::{Deserialize, Deserializer, Serialize};

use annotate_snippets::renderer::Renderer;
use annotate_snippets::{
renderer::Margin,
snippet::{Annotation, AnnotationType, Slice, Snippet, SourceAnnotation},
renderer::Margin, Annotation, AnnotationType, Renderer, Slice, Snippet, SourceAnnotation,
};

#[derive(Deserialize)]
Expand Down
4 changes: 2 additions & 2 deletions tests/fixtures_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ mod deserialize;
mod diff;

use crate::deserialize::Fixture;
use annotate_snippets::renderer::Renderer;
use annotate_snippets::snippet::Snippet;
use annotate_snippets::Renderer;
use annotate_snippets::Snippet;
use glob::glob;
use std::{error::Error, fs::File, io, io::prelude::*};

Expand Down
41 changes: 20 additions & 21 deletions tests/formatter.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
use annotate_snippets::renderer::Renderer;
use annotate_snippets::snippet::{self, Snippet};
use annotate_snippets::{Annotation, AnnotationType, Renderer, Slice, Snippet, SourceAnnotation};

#[test]
fn test_i_29() {
let snippets = Snippet {
title: Some(snippet::Annotation {
title: Some(Annotation {
id: None,
label: Some("oops"),
annotation_type: snippet::AnnotationType::Error,
annotation_type: AnnotationType::Error,
}),
footer: vec![],
slices: vec![snippet::Slice {
slices: vec![Slice {
source: "First line\r\nSecond oops line",
line_start: 1,
origin: Some("<current file>"),
annotations: vec![snippet::SourceAnnotation {
annotations: vec![SourceAnnotation {
range: (19, 23),
label: "oops",
annotation_type: snippet::AnnotationType::Error,
annotation_type: AnnotationType::Error,
}],
fold: true,
}],
Expand All @@ -37,14 +36,14 @@ fn test_i_29() {
#[test]
fn test_point_to_double_width_characters() {
let snippets = Snippet {
slices: vec![snippet::Slice {
slices: vec![Slice {
source: "こんにちは、世界",
line_start: 1,
origin: Some("<current file>"),
annotations: vec![snippet::SourceAnnotation {
annotations: vec![SourceAnnotation {
range: (6, 8),
label: "world",
annotation_type: snippet::AnnotationType::Error,
annotation_type: AnnotationType::Error,
}],
fold: false,
}],
Expand All @@ -65,14 +64,14 @@ fn test_point_to_double_width_characters() {
#[test]
fn test_point_to_double_width_characters_across_lines() {
let snippets = Snippet {
slices: vec![snippet::Slice {
slices: vec![Slice {
source: "おはよう\nございます",
line_start: 1,
origin: Some("<current file>"),
annotations: vec![snippet::SourceAnnotation {
annotations: vec![SourceAnnotation {
range: (2, 8),
label: "Good morning",
annotation_type: snippet::AnnotationType::Error,
annotation_type: AnnotationType::Error,
}],
fold: false,
}],
Expand All @@ -95,20 +94,20 @@ fn test_point_to_double_width_characters_across_lines() {
#[test]
fn test_point_to_double_width_characters_multiple() {
let snippets = Snippet {
slices: vec![snippet::Slice {
slices: vec![Slice {
source: "お寿司\n食べたい🍣",
line_start: 1,
origin: Some("<current file>"),
annotations: vec![
snippet::SourceAnnotation {
SourceAnnotation {
range: (0, 3),
label: "Sushi1",
annotation_type: snippet::AnnotationType::Error,
annotation_type: AnnotationType::Error,
},
snippet::SourceAnnotation {
SourceAnnotation {
range: (6, 8),
label: "Sushi2",
annotation_type: snippet::AnnotationType::Note,
annotation_type: AnnotationType::Note,
},
],
fold: false,
Expand All @@ -132,14 +131,14 @@ fn test_point_to_double_width_characters_multiple() {
#[test]
fn test_point_to_double_width_characters_mixed() {
let snippets = Snippet {
slices: vec![snippet::Slice {
slices: vec![Slice {
source: "こんにちは、新しいWorld!",
line_start: 1,
origin: Some("<current file>"),
annotations: vec![snippet::SourceAnnotation {
annotations: vec![SourceAnnotation {
range: (6, 14),
label: "New world",
annotation_type: snippet::AnnotationType::Error,
annotation_type: AnnotationType::Error,
}],
fold: false,
}],
Expand Down

0 comments on commit b016a59

Please sign in to comment.