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

refactor: further separate CLI logic from the API related functionality (see #117) #124

Merged
merged 29 commits into from
Nov 16, 2024
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
7281a5d
refactor: use `std::ops::Not::not` instead of custom `is_false` function
Rolv-Apneseth Oct 5, 2024
56f0ab8
refactor: further separate API logic from CLI, and create submodules …
Rolv-Apneseth Oct 5, 2024
3b6f9d7
fix: fmt
Rolv-Apneseth Oct 5, 2024
0342b89
fix: nightly `rustfmt` warning: the `version` option is deprecated. U…
Rolv-Apneseth Oct 5, 2024
dbd4caa
fix: fmt
Rolv-Apneseth Oct 5, 2024
12afefc
refactor: `ProcessCommand` -> `process::Command`
Rolv-Apneseth Oct 5, 2024
afe2b6e
fix: remove unused imports
Rolv-Apneseth Oct 5, 2024
00b9491
refactor: make link more readable for CLI
Rolv-Apneseth Oct 5, 2024
fd17b9e
fix: `clippy` and `doc` warnings
Rolv-Apneseth Oct 5, 2024
a6ea313
chore: bump minimum rust version
Rolv-Apneseth Oct 5, 2024
15d1454
fix: misc CI issues
Rolv-Apneseth Oct 5, 2024
673ff5d
feat: use `enum_dispatch` to avoid needing to manually call `cmd.exec…
Rolv-Apneseth Oct 6, 2024
2575c87
refactor: avoid cloning request input string
Rolv-Apneseth Oct 6, 2024
b863f36
refactor: use `Cow<'static, str>` instead of `String` for `check::Req…
Rolv-Apneseth Oct 8, 2024
9dd472f
chore(lib): adding Cow
jeertmans Oct 12, 2024
a1b258d
refactor: use `Cow<'source, str>` when not compiling with the `cli` f…
Rolv-Apneseth Oct 20, 2024
642c34f
fix: remove unnecessary clone of `split_pattern`
Rolv-Apneseth Oct 23, 2024
b6cd61b
refactor: use `Cow<'source, str>` for text referenced by `ResponseWit…
Rolv-Apneseth Oct 23, 2024
20e84db
Update CI.yml
jeertmans Nov 1, 2024
f091ffe
Update README.md
Rolv-Apneseth Nov 1, 2024
9273c68
Update benches/benchmarks/check_texts.rs
Rolv-Apneseth Nov 1, 2024
b9c1169
Update benches/benchmarks/check_texts.rs
Rolv-Apneseth Nov 1, 2024
47b07a4
Update src/api/server.rs
Rolv-Apneseth Nov 1, 2024
ba691a4
Update tests/match_positions.rs
Rolv-Apneseth Nov 1, 2024
5b2c235
fix: formatting
Rolv-Apneseth Oct 23, 2024
c875a5f
fix: remove unused imports
Rolv-Apneseth Nov 1, 2024
f162b17
fix: remove static lifetime from `with_text` and `with_data`
Rolv-Apneseth Nov 1, 2024
befbc52
fix: correct length addition and use `Cow::to_mut`
Rolv-Apneseth Nov 1, 2024
c7d342c
fix: satisfy `clippy` pre-commit hook
Rolv-Apneseth Nov 1, 2024
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
73 changes: 64 additions & 9 deletions Cargo.lock

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

6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ required-features = ["cli"]
annotate-snippets = {version = "^0.9.1", optional = true}
clap = {version = "^4.5.18", features = ["cargo", "derive", "env", "wrap_help"], optional = true}
clap_complete = {version = "^4.5.2", optional = true}
enum_dispatch = {version = "0.3.13", optional = true}
is-terminal = {version = "0.4.3", optional = true}
lifetime = { version = "0.1.0", features = ["macros"] }
pulldown-cmark = {version = "0.10.2", optional = true}
reqwest = {version = "^0.11", default-features = false, features = ["json"]}
serde = {version = "^1.0", features = ["derive"]}
Expand All @@ -33,7 +35,7 @@ tokio = {version = "^1.0", features = ["macros"]}

[features]
annotate = ["dep:annotate-snippets"]
cli = ["annotate", "color", "dep:clap", "dep:is-terminal", "multithreaded"]
cli = ["annotate", "color", "dep:clap", "dep:enum_dispatch", "dep:is-terminal", "multithreaded"]
cli-complete = ["cli", "clap_complete"]
color = ["annotate-snippets?/color", "dep:termcolor"]
default = ["cli", "native-tls"]
Expand Down Expand Up @@ -61,7 +63,7 @@ license = "MIT"
name = "languagetool-rust"
readme = "README.md"
repository = "https://github.com/jeertmans/languagetool-rust"
rust-version = "1.74.0"
rust-version = "1.75.0"
version = "2.1.4"

[package.metadata.docs.rs]
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,14 @@ languagetool-rust = "^2.1"

```rust
use languagetool_rust::api::{check, server::ServerClient};
use std::borrow::Cow;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = ServerClient::from_env_or_default();

let req = check::Request::default()
.with_text("Some phrase with a smal mistake".to_string()); // # codespell:ignore smal
.with_text(Cow::Borrowed("Some phrase with a smal mistake")); // # codespell:ignore smal
Rolv-Apneseth marked this conversation as resolved.
Show resolved Hide resolved

println!(
"{}",
Expand Down
12 changes: 7 additions & 5 deletions benches/benchmarks/check_texts.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::borrow::Cow;

use codspeed_criterion_compat::{criterion_group, Criterion, Throughput};
use futures::future::join_all;
use languagetool_rust::{
Expand All @@ -14,7 +16,7 @@ static FILES: [(&str, &str); 3] = [
("large", include_str!("../large.txt")),
];

async fn request_until_success(req: &Request, client: &ServerClient) -> Response {
async fn request_until_success<'source>(req: &Request<'source>, client: &ServerClient) -> Response {
loop {
match client.check(req).await {
Ok(resp) => return resp,
Expand All @@ -29,12 +31,12 @@ async fn request_until_success(req: &Request, client: &ServerClient) -> Response
}

#[tokio::main]
async fn check_text_basic(text: &str) -> Response {
async fn check_text_basic(text: &'static str) -> Response {
Rolv-Apneseth marked this conversation as resolved.
Show resolved Hide resolved
let client = ServerClient::from_env().expect(
"Please use a local server for benchmarking, and configure the environ variables to use \
it.",
);
let req = Request::default().with_text(text.to_string());
let req = Request::default().with_text(Cow::Borrowed(text));
Rolv-Apneseth marked this conversation as resolved.
Show resolved Hide resolved
request_until_success(&req, &client).await
}

Expand All @@ -48,9 +50,9 @@ async fn check_text_split(text: &str) -> Response {

let resps = join_all(lines.map(|line| {
async {
let req = Request::default().with_text(line.to_string());
let req = Request::default().with_text(Cow::Owned(line.to_string()));
Rolv-Apneseth marked this conversation as resolved.
Show resolved Hide resolved
let resp = request_until_success(&req, &client).await;
check::ResponseWithContext::new(req.get_text(), resp)
check::ResponseWithContext::new(req.get_text().into_owned(), resp)
}
}))
.await;
Expand Down
2 changes: 1 addition & 1 deletion rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
condense_wildcard_suffixes = true
edition = "2021"
# error_on_line_overflow = true
# error_on_unformatted = true
force_multiline_blocks = true
Expand All @@ -9,5 +10,4 @@ imports_granularity = "Crate"
match_block_trailing_comma = true
normalize_doc_attributes = true
unstable_features = true
version = "Two"
wrap_comments = true
Loading
Loading