Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 9 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ on:
- main

jobs:
cargo-deny:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: EmbarkStudios/cargo-deny-action@v2
with:
arguments: --all-features --workspace
command-arguments: --hide-inclusion-graph

fmt:
name: Check formatting
runs-on: ubuntu-latest
Expand Down
87 changes: 29 additions & 58 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ anyhow = { version = "1.0.53" }
arc-swap = { version = "1.5.0" }
async-trait = { version = "0.1.52" }
clap = { version = "4.5.31", default-features = false, features = ["std"] }
codespan-reporting = { version = "0.13" }
either = { version = "1.6.1" }
futures = { version = "0.3.30" }
getrandom = { version = "0.4.3", default-features = false }
Expand All @@ -29,14 +30,17 @@ itertools = { version = "0.15" }
lru = { version = "0.18" }
lsp-types = { version = "0.93.0" }
once_cell = { version = "1.4" }
owo-colors = { version = "4" }
parking_lot = { version = "0.12.0" }
prettydiff = { version = "0.9", default-features = false } # `prettydiff` is also a CLI that pulls in `clap` by default
regex = { version = "1.5" }
reqwest = { version = "0.13", default-features = false }
rowan = { version = "0.16" }
schemars = { version = "1" }
serde = { version = "1" }
serde_json = { version = "1.0.78" }
sha1 = { version = "0.11" }
similar = { version = "3.1" }
tap = { version = "1.0.1" }
thiserror = { version = "2" }
time = { version = "0.3.7" }
Expand Down
6 changes: 3 additions & 3 deletions crates/olpat-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ olpat-lsp = { version = "0.8.0", path = "../olpat-lsp", default-features = fa

anyhow = { workspace = true }
clap = { workspace = true, features = ["derive", "cargo", "env", "default"] }
codespan-reporting = { version = "0.11.1" }
codespan-reporting = { workspace = true }
futures = { workspace = true }
glob = { workspace = true }
hex = { workspace = true }
Expand All @@ -47,10 +47,10 @@ url = { workspace = true }
[target.'cfg(not(target_family = "wasm"))'.dependencies]
olpat-lsp-async-stub = { version = "0.7.0", path = "../olpat-lsp-async-stub", features = ["tokio-tcp", "tokio-stdio"] }

ansi_term = { version = "0.12" }
owo-colors = { workspace = true }
async-ctrlc = { version = "1.2.0", features = ["stream"], optional = true }
clap_complete = { version = "4.4.18", optional = true }
prettydiff = { version = "0.6.1", default-features = false } # `prettydiff` is also a CLI that pulls in `clap` by default
prettydiff = { workspace = true, default-features = false } # `prettydiff` is also a CLI that pulls in `clap` by default

tokio = { workspace = true, features = ["sync", "fs", "time", "io-std", "rt-multi-thread", "parking_lot"] }

Expand Down
16 changes: 9 additions & 7 deletions crates/olpat-cli/src/commands/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,17 +125,19 @@ impl<E: Environment> Taplo<E> {
let mut post_line = 0_usize;

for (idx, diff_op) in hunks.into_iter().enumerate() {
use ansi_term::Colour::{self, Green, Red};
use owo_colors::Style;
use prettydiff::basic::DiffOp;

// apply the given color and prefix to the set of strings `s`
fn apply_color<'a>(
s: &'a [&'a str],
prefix: &'a str,
color: Colour,
style: Style,
) -> impl IntoIterator<Item = String> + 'a {
use owo_colors::OwoColorize as _;

s.iter()
.map(move |&s| color.paint(prefix.to_owned() + s).to_string())
.map(move |&s| (prefix.to_owned() + s).style(style).to_string())
}

let mut pre_length = 0_usize;
Expand Down Expand Up @@ -168,16 +170,16 @@ impl<E: Environment> Taplo<E> {
}
}
DiffOp::Insert(ins) => {
acc.extend(apply_color(ins, "+", Green));
acc.extend(apply_color(ins, "+", Style::new().green()));
post_length += ins.len();
}
DiffOp::Remove(rem) => {
acc.extend(apply_color(rem, "-", Red));
acc.extend(apply_color(rem, "-", Style::new().red()));
pre_length += rem.len();
}
DiffOp::Replace(rem, ins) => {
acc.extend(apply_color(rem, "-", Red));
acc.extend(apply_color(ins, "+", Green));
acc.extend(apply_color(rem, "-", Style::new().red()));
acc.extend(apply_color(ins, "+", Style::new().green()));
pre_length += rem.len();
post_length += ins.len();
}
Expand Down
12 changes: 6 additions & 6 deletions crates/olpat-cli/src/printing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ impl<E: Environment> Taplo<E> {
]));

if self.colors {
term::emit(&mut Ansi::new(&mut out_diag), &config, file, &diag)?;
term::emit_to_io_write(&mut Ansi::new(&mut out_diag), &config, file, &diag)?;
} else {
term::emit(&mut NoColor::new(&mut out_diag), &config, file, &diag)?;
term::emit_to_io_write(&mut NoColor::new(&mut out_diag), &config, file, &diag)?;
}
}

Expand Down Expand Up @@ -104,9 +104,9 @@ impl<E: Environment> Taplo<E> {
};

if self.colors {
term::emit(&mut Ansi::new(&mut out_diag), &config, file, &diag)?;
term::emit_to_io_write(&mut Ansi::new(&mut out_diag), &config, file, &diag)?;
} else {
term::emit(&mut NoColor::new(&mut out_diag), &config, file, &diag)?;
term::emit_to_io_write(&mut NoColor::new(&mut out_diag), &config, file, &diag)?;
}
}
let mut stderr = self.env.stderr();
Expand Down Expand Up @@ -134,9 +134,9 @@ impl<E: Environment> Taplo<E> {
]));

if self.colors {
term::emit(&mut Ansi::new(&mut out_diag), &config, file, &diag)?;
term::emit_to_io_write(&mut Ansi::new(&mut out_diag), &config, file, &diag)?;
} else {
term::emit(&mut NoColor::new(&mut out_diag), &config, file, &diag)?;
term::emit_to_io_write(&mut NoColor::new(&mut out_diag), &config, file, &diag)?;
};
}
}
Expand Down
6 changes: 3 additions & 3 deletions crates/olpat/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ serde = { workspace = true, features = ["derive"], optional = true }

[dev-dependencies]
assert-json-diff = { version = "2" }
criterion = { version = "0.5" } # criterion -> clap
difference = { version = "2.0.0" }
criterion = { version = "0.5" } # criterion -> clap
similar = { workspace = true }
serde_json = { version = "1" }
toml = { version = "0.7" }

[target.'cfg(unix)'.dev-dependencies]
pprof = { version = "0.14", features = ["flamegraph", "criterion"] } # pprof -> criterion -> clap
pprof = { version = "0.15.0", features = ["flamegraph", "criterion"] } # pprof -> criterion -> clap

[package.metadata.docs.rs]
features = ["serde", "schema"]
Expand Down
5 changes: 2 additions & 3 deletions crates/olpat/src/tests/formatter.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use difference::Changeset;

use similar::TextDiff;
use crate::formatter::{self, Options, OptionsIncomplete};

macro_rules! assert_format {
($expected:expr, $actual:expr) => {
if $expected != $actual {
println!("{}", Changeset::new($actual, $expected, "\n"));
println!("{}", TextDiff::from_lines($actual, $expected).unified_diff());
panic!("invalid formatting");
}
};
Expand Down
Loading
Loading