Skip to content

Commit

Permalink
fix: improve text search normalization
Browse files Browse the repository at this point in the history
  • Loading branch information
camshaft committed Jan 15, 2025
1 parent 780b089 commit c7539d3
Show file tree
Hide file tree
Showing 19 changed files with 305 additions and 59 deletions.
1 change: 1 addition & 0 deletions duvet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ url = "2"
v_jsonescape = "0.7"

[dev-dependencies]
bolero = "0.12"
insta = { version = "1", features = ["filters", "json"] }
serde_json = "1"
strip-ansi-escapes = "0.2"
Expand Down
2 changes: 1 addition & 1 deletion duvet/src/annotation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ impl Annotation {
Err(error!("Could not resolve file {:?}", file))
}

pub fn quote_range(&self, contents: &str) -> Option<Range<usize>> {
pub fn quote_range(&self, contents: &str) -> Option<(Range<usize>, crate::text::find::Kind)> {
crate::text::find(&self.quote, contents)
}
}
Expand Down
7 changes: 6 additions & 1 deletion duvet/src/reference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,12 @@ pub async fn build_references(
continue;
}

if let Some(range) = annotation.quote_range(&contents) {
if let Some((range, kind)) = annotation.quote_range(&contents) {
if kind.is_fuzzy() {
// TODO
//warnings.push(warn!(""));
}

for text in contents.ranges(range) {
references.push(Reference {
target: target.clone(),
Expand Down
14 changes: 6 additions & 8 deletions duvet/src/report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,21 @@ impl Report {
let specifications = annotation::specifications(annotations.clone(), spec_path).await?;
progress!(progress, "Loaded {} specifications", specifications.len());

let progress = progress!("Compiling references");
let progress = progress!("Mapping sections");
let reference_map = annotation::reference_map(annotations.clone()).await?;
progress!(progress, "Mapped {} sections", reference_map.len());

let progress = progress!("Matching references");
let mut report = ReportResult {
targets: Default::default(),
annotations,
blob_link: self.blob_link.as_deref(),
issue_link: self.issue_link.as_deref(),
};

let references = reference::query(reference_map.clone(), specifications.clone()).await?;
progress!(progress, "Matched {} references", references.len());

let progress = progress!("Sorting references");
for reference in references.iter() {
report
.targets
Expand All @@ -103,12 +106,7 @@ impl Report {
target.statuses.populate(&target.references)
});

progress!(
progress,
"Compiled {} references across {} sections",
references.len(),
reference_map.len()
);
progress!(progress, "Sorted {} references", references.len());

type ReportFn = fn(&ReportResult, &Path) -> crate::Result<()>;

Expand Down
2 changes: 1 addition & 1 deletion duvet/src/text.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

mod find;
pub mod find;
pub mod view;

pub use find::find;
Expand Down
Loading

0 comments on commit c7539d3

Please sign in to comment.