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
2 changes: 1 addition & 1 deletion bindings/node/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export interface Fallback {
*/
kind: 'no_grammar' | 'grammar_unavailable' | 'semantic' | 'request_budget'
/** Present when `kind` is `semantic`. */
reason?: 'too_large' | 'parse_errors' | 'error_coverage' | 'unparsed' | 'budget' | 'timeout'
reason?: 'too_large' | 'parse_errors' | 'error_coverage' | 'unparsed' | 'budget' | 'timeout' | 'invalid'
/** For people; wording may change. Branch on `kind` and `reason`. */
message: string
}
Expand Down
4 changes: 2 additions & 2 deletions crates/diffy-compare/FORMAT.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Render order: for each hunk, `gap_before`, header, rows; then `gap_after`.
| Field | Type | |
| --- | --- | --- |
| `kind` | `"no_grammar"` \| `"grammar_unavailable"` \| `"semantic"` \| `"request_budget"` | `no_grammar`: no language for the path. `grammar_unavailable`: the language's grammar failed to load. `semantic`: the semantic diff gave up, see `reason`. `request_budget`: the request's deadline passed before this file was diffed. |
| `reason` | `"too_large"` \| `"parse_errors"` \| `"error_coverage"` \| `"unparsed"` \| `"budget"` \| `"timeout"`? | Present when `kind` is `semantic`, in order: file too large; too many parse errors; parse errors cover too much; parser gave up; work budget ran out; time budget ran out. |
| `reason` | `"too_large"` \| `"parse_errors"` \| `"error_coverage"` \| `"unparsed"` \| `"budget"` \| `"timeout"` \| `"invalid"`? | Present when `kind` is `semantic`, in order: file too large; too many parse errors; parse errors cover too much; parser gave up; work budget ran out; time budget ran out; its result was unusable (a bug). |
| `message` | string | For people, e.g. `"exceeded the semantic time budget"`. Wording may change; branch on `kind` and `reason`. |

## Hunk
Expand Down Expand Up @@ -213,7 +213,7 @@ type File = {

type Fallback = {
kind: "no_grammar" | "grammar_unavailable" | "semantic" | "request_budget";
reason?: "too_large" | "parse_errors" | "error_coverage" | "unparsed" | "budget" | "timeout";
reason?: "too_large" | "parse_errors" | "error_coverage" | "unparsed" | "budget" | "timeout" | "invalid";
message: string;
};

Expand Down
20 changes: 16 additions & 4 deletions crates/diffy-compare/src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,22 @@ pub(crate) fn diff_one(
})
.collect(),
};
Ok(FileDiff {
document: document_from_rows(meta, old, new, chunks, true, semantics)?,
fallback: None,
})
match document_from_rows(meta.clone(), old, new, chunks, true, semantics) {
Ok(document) => Ok(FileDiff {
document,
fallback: None,
}),
// A bug in the semantic rows; the file still gets a diff.
Err(error) => {
tracing::warn!(
target: "diffy::semantic",
path = input.display_path(),
%error,
"semantic rows did not build; using a line diff"
);
line(meta, Fallback::Invalid(error.to_string()))
}
}
}
Err(fallback) => line(meta, Fallback::Semantic(fallback)),
}
Expand Down
3 changes: 3 additions & 0 deletions crates/diffy-compare/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ pub enum Fallback {
GrammarUnavailable(String),
/// The semantic diff gave up.
Semantic(diffy_semantic::Fallback),
/// The semantic diff's rows did not build a document (a bug).
Invalid(String),
/// The request's deadline passed before this file was diffed.
RequestBudget,
}
Expand All @@ -83,6 +85,7 @@ impl std::fmt::Display for Fallback {
Self::NoGrammar => f.write_str("no grammar for this file"),
Self::GrammarUnavailable(tag) => write!(f, "{tag} grammar unavailable"),
Self::Semantic(fallback) => fallback.fmt(f),
Self::Invalid(error) => write!(f, "semantic result unusable: {error}"),
Self::RequestBudget => f.write_str("request time budget exhausted"),
}
}
Expand Down
2 changes: 2 additions & 0 deletions crates/diffy-compare/src/wire.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ pub enum SemanticReason {
Unparsed,
Budget,
Timeout,
Invalid,
}

impl From<&crate::Fallback> for Fallback {
Expand All @@ -162,6 +163,7 @@ impl From<&crate::Fallback> for Fallback {
crate::Fallback::NoGrammar => (FallbackKind::NoGrammar, None),
crate::Fallback::GrammarUnavailable(_) => (FallbackKind::GrammarUnavailable, None),
crate::Fallback::RequestBudget => (FallbackKind::RequestBudget, None),
crate::Fallback::Invalid(_) => (FallbackKind::Semantic, Some(SemanticReason::Invalid)),
crate::Fallback::Semantic(semantic) => {
let reason = match semantic {
Semantic::TooLarge(_) => SemanticReason::TooLarge,
Expand Down
8 changes: 8 additions & 0 deletions crates/diffy-compare/src/wire/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,14 @@ fn fallbacks_serialize_as_stable_kinds() {
"message": "5 bytes exceeds the semantic byte limit",
}),
),
(
crate::Fallback::Invalid("bad rows".into()),
serde_json::json!({
"kind": "semantic",
"reason": "invalid",
"message": "semantic result unusable: bad rows",
}),
),
(
crate::Fallback::GrammarUnavailable("zig".into()),
serde_json::json!({
Expand Down
Loading