Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmark files and multiline fragments #74

Merged
merged 30 commits into from
Jul 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
2e727e5
refactor/terminal: raw mode guard drop code simplification
drahnr Jul 16, 2020
aef15df
fix/warning: add allow unused in a few spots
drahnr Jul 16, 2020
e535f38
fix/commonmark: allow common mark input
drahnr Jul 16, 2020
1e548ab
feat/multiline: initial handling of multiline literals
drahnr Jul 16, 2020
0a8715a
fix/multiline: better test macros and helpers
drahnr Jul 16, 2020
bdcb4b9
fix/multiline: more test infra fixes for multiline handling
drahnr Jul 16, 2020
dd594af
refactor/chunk: find_spans
drahnr Jul 16, 2020
d1c1eb5
fix/multiline: find_spans again
drahnr Jul 16, 2020
abc591d
docs/fix: fragment explanation
drahnr Jul 17, 2020
74ddae5
fix/test: avoid dbg!(suggestion) and a few slips of pens
drahnr Jul 17, 2020
e4b9115
fix/chunk: single character tokens must also have a span length of 1
drahnr Jul 17, 2020
110f81b
fix/span: assure the correct range is asserted
drahnr Jul 17, 2020
15ae31e
feat/test: verify suggestion is dbg printable
drahnr Jul 17, 2020
b8012a3
fix/multiline: span, chunk, and tests are now multiline ready
drahnr Jul 17, 2020
27c8c0f
chore: cargo fmt + cargo fix
drahnr Jul 17, 2020
c5dd04c
docs/spelling: dev comment
drahnr Jul 17, 2020
ca1a9d8
fix/log: warn -> trace
drahnr Jul 17, 2020
147dcdd
chore/cleanup: remove commented dbg! helpers
drahnr Jul 17, 2020
28bf82e
Revert "refactor/terminal: raw mode guard drop code simplification"
drahnr Jul 20, 2020
9194444
fix/ci: exit code must be zero now unless there was an error in the p…
drahnr Jul 20, 2020
736554f
fix/test: failed span calc for indented lines
drahnr Jul 20, 2020
f27ea72
fix/test: adjust spans properly
drahnr Jul 20, 2020
bfc516c
feat/test: allow prefix syntax for chyrp_up with @
drahnr Jul 20, 2020
c974458
refactor/literal: Err(anyhow!(...)) becomes bail!(...)
drahnr Jul 23, 2020
a6b6a71
fix/literal: improve the detection & span adjustments of /// comments
drahnr Jul 23, 2020
01a3387
fix/fluff: if no indentation str is given, use ""
drahnr Jul 23, 2020
51b1360
refactor/*: Err(anyhow!(...)) becomes bail!(...)
drahnr Jul 23, 2020
22e304f
chore: cargo fmt + cargo fix
drahnr Jul 23, 2020
342eb39
fix/literal: extract the spans properly
drahnr Jul 23, 2020
ca8d386
chore: use vs cargo fix
drahnr Jul 23, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .concourse.yml
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,9 @@ jobs:
export CARGO_HOME="$(pwd)/../cargo"
sudo chown $(whoami): -Rf ${CARGO_HOME} .
cargo +stable run -- --version
cargo +stable run -- spellcheck demo/Cargo.toml || echo "$?"
cargo +stable run -- spellcheck demo/src/main.rs || echo "$?"
cargo +stable run -- spellcheck demo/ || echo "$?"
cargo +stable run -- spellcheck demo/Cargo.toml
cargo +stable run -- spellcheck demo/src/main.rs
cargo +stable run -- spellcheck demo/
dir: git-repo
caches:
- path: cargo
Expand Down
65 changes: 45 additions & 20 deletions src/action/bandaid.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::span::Span;
use crate::suggestion::Suggestion;
use anyhow::{anyhow, Error, Result};
use anyhow::{bail, Error, Result};
use log::trace;
use std::convert::TryFrom;

Expand Down Expand Up @@ -45,7 +45,7 @@ impl<'s> TryFrom<(&Suggestion<'s>, usize)> for BandAid {
if let Some(replacement) = suggestion.replacements.iter().nth(pick_idx) {
Ok(Self::new(replacement.as_str(), &suggestion.span))
} else {
Err(anyhow!("Does not contain any replacements"))
bail!("Does not contain any replacements")
}
}
}
Expand All @@ -67,9 +67,9 @@ impl From<(String, Span)> for BandAid {
pub(crate) mod tests {
use super::*;
use crate::span::Span;
use anyhow::bail;
use anyhow::anyhow;
use proc_macro2::LineColumn;
use std::io::BufRead;
use std::io::Read;
use std::path::Path;

/// Extract span from file as String
Expand All @@ -95,9 +95,9 @@ pub(crate) mod tests {
/// Helpful to validate bandaids against what's actually in the string
// @todo does not handle cross line spans @todo yet
#[allow(unused)]
pub(crate) fn load_span_from<S>(mut source: S, span: Span) -> Result<String>
pub(crate) fn load_span_from<R>(mut source: R, span: Span) -> Result<String>
where
S: BufRead,
R: Read,
{
log::trace!("Loading {:?} from source", &span);
if span.start.line < 1 {
Expand All @@ -106,22 +106,47 @@ pub(crate) mod tests {
if span.end.line < span.start.line {
bail!("Line range would be negative, bail")
}
if span.end.column < span.start.column {
if span.end.line == span.start.line && span.end.column < span.start.column {
bail!("Column range would be negative, bail")
}
let line = (&mut source)
.lines()
.skip(span.start.line - 1)
.filter_map(|line| line.ok())
.next()
.ok_or_else(|| anyhow!("Line not in buffer or invalid"))?;

let range = dbg!(span.start.column..(span.end.column + 1));
log::trace!("Loading {:?} from line >{}<", &range, &line);
dbg!(line)
.get(range.clone())
.map(|s| dbg!(s.to_owned()))
.ok_or_else(|| anyhow!("Columns not in line: {:?}", &range))
let mut s = String::with_capacity(256);
source
.read_to_string(&mut s)
.expect("Must read successfully");
let cursor = LineColumn { line: 1, column: 0 };
let extraction = s
.chars()
.enumerate()
.scan(cursor, |cursor, (idx, c)| {
let x = (idx, c, cursor.clone());
match c {
'\n' => {
cursor.line += 1;
cursor.column = 0;
}
_ => cursor.column += 1,
}
Some(x)
})
.filter_map(|(idx, c, cursor)| {
if cursor.line < span.start.line {
return None;
}
if cursor.line > span.end.line {
return None;
}
// bounding lines
if cursor.line == span.start.line && cursor.column < span.start.column {
return None;
}
if cursor.line == span.end.line && cursor.column > span.end.column {
return None;
}
Some(c)
})
.collect::<String>();
// log::trace!("Loading {:?} from line >{}<", &range, &line);
Ok(extraction)
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion src/checker/dummy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl Checker for DummyChecker {
chunk,
description: None,
};
acc.add(origin.clone(), dbg!(suggestion));
acc.add(origin.clone(), suggestion);
}
}
Ok(acc)
Expand Down
13 changes: 4 additions & 9 deletions src/checker/hunspell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use log::{debug, trace};

use hunspell_rs::Hunspell;

use anyhow::{anyhow, Result};
use anyhow::{anyhow, bail, Result};

pub struct HunspellChecker;

Expand Down Expand Up @@ -89,19 +89,14 @@ impl Checker for HunspellChecker {
for extra_dic in config.extra_dictonaries().iter() {
trace!("Adding extra hunspell dictionary {}", extra_dic.display());
if !extra_dic.is_file() {
return Err(anyhow!(
"Extra dictionary {} is not a file",
extra_dic.display()
));
bail!("Extra dictionary {} is not a file", extra_dic.display())
}
if let Some(extra_dic) = extra_dic.to_str() {
if !hunspell.add_dictionary(extra_dic) {
return Err(anyhow!("Failed to add additional dict to hunspell"));
bail!("Failed to add additional dict to hunspell")
}
} else {
return Err(anyhow!(
"Failed to convert one of the extra dictionaries to a str"
));
bail!("Failed to convert one of the extra dictionaries to a str")
}
}

Expand Down
10 changes: 3 additions & 7 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//! location by default. Default. Default default default.

use crate::suggestion::Detector;
use anyhow::{anyhow, Error, Result};
use anyhow::{anyhow, bail, Error, Result};
use log::trace;
use serde::{Deserialize, Serialize};
use std::fs::File;
Expand Down Expand Up @@ -133,9 +133,7 @@ impl Config {
.join("config.toml"),
)
} else {
Err(anyhow!(
"No idea where your config directory is located. XDG compliance would be nice."
))
bail!("No idea where your config directory is located. XDG compliance would be nice.")
}
}

Expand Down Expand Up @@ -185,9 +183,7 @@ impl Config {
{
Ok(base.config_dir().join("config.toml"))
} else {
Err(anyhow!(
"No idea where your config directory is located. `$HOME` must be set."
))
bail!("No idea where your config directory is located. `$HOME` must be set.")
}
}

Expand Down
Loading