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

fix: include ID in serialized matches #426

Merged
merged 7 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions crates/cli_bin/tests/snapshots/apply__output_jsonl.snap

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion crates/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ grit-util = { path = "../grit-util" }
tracing = { version = "0.1.40", default-features = false, features = [] }
tracing-opentelemetry = { version = "0.22.0", optional = true, default-features = false, features = [
] }

uuid = { version = "1.1", features = ["v4", "serde"] }
regex = { version = "1.7.3" }
anyhow = { version = "1.0.70" }
itertools = { version = "0.10.5" }
Expand Down
12 changes: 12 additions & 0 deletions crates/core/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use serde::{Deserialize, Serialize};
use serde_json::to_string_pretty;
use std::path::PathBuf;
use std::{fmt, str::FromStr, vec};
use uuid::Uuid;

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
#[serde(rename_all = "camelCase")]
Expand Down Expand Up @@ -343,6 +344,8 @@ pub struct Match {
pub ranges: Vec<Range>,
#[serde(default)]
pub reason: Option<MatchReason>,
#[serde(default)]
pub id: Uuid,
}

impl From<EntireFile> for Match {
Expand All @@ -354,6 +357,7 @@ impl From<EntireFile> for Match {
ranges: file_match.ranges,
reason: None,
content: file_match.content,
id: Uuid::new_v4(),
}
}
}
Expand Down Expand Up @@ -456,6 +460,8 @@ pub struct Rewrite {
pub rewritten: EntireFile,
#[serde(default)]
pub reason: Option<MatchReason>,
#[serde(default)]
pub id: Uuid,
}

impl From<Rewrite> for MatchResult {
Expand Down Expand Up @@ -558,6 +564,7 @@ impl Rewrite {
original,
rewritten,
reason,
id: Uuid::new_v4(),
}
}
}
Expand All @@ -568,6 +575,8 @@ pub struct CreateFile {
pub rewritten: EntireFile,
range: Option<Vec<Range>>,
pub reason: Option<MatchReason>,
#[serde(default)]
pub id: Uuid,
}

impl From<CreateFile> for MatchResult {
Expand All @@ -582,6 +591,7 @@ impl CreateFile {
rewritten: EntireFile::file_to_entire_file(name, body, None),
range: None,
reason: None,
id: Uuid::new_v4(),
}
}
}
Expand Down Expand Up @@ -622,6 +632,8 @@ pub struct RemoveFile {
pub original: EntireFile,
#[serde(default)]
pub reason: Option<MatchReason>,
#[serde(default)]
pub id: Uuid,
}

impl From<RemoveFile> for MatchResult {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ expression: results
end: 68
ranges: []
reason: ~
id: e85d7dd6-f904-487d-886b-5d8b8f97d930
- __typename: DoneFile
relativeFilePath: test-file.tsx
- __typename: AnalysisLog
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ expression: results
end: 68
ranges: []
reason: ~
id: 1af99230-59df-440a-b81d-793a81b3e5c9
- __typename: DoneFile
relativeFilePath: test-file.tsx
- __typename: AnalysisLog
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,6 @@ expression: results
end: 16
ranges: []
reason: ~
id: d2331c02-d629-41d5-b094-8ad767b0ebdb
- __typename: DoneFile
relativeFilePath: test-file.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,6 @@ expression: results
end: 15
ranges: []
reason: ~
id: 4d5e4055-d403-4bc2-82f3-ef41e1792a71
- __typename: DoneFile
relativeFilePath: foo.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,6 @@ expression: results
end: 19
ranges: []
reason: ~
id: 360ca51a-75f5-4983-9c0c-65f495d8a457
- __typename: DoneFile
relativeFilePath: foo.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,6 @@ expression: results
end: 19
ranges: []
reason: ~
id: d31b0355-94c1-4224-9238-768301fe2609
- __typename: DoneFile
relativeFilePath: test-file.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,6 @@ expression: results
end: 16
ranges: []
reason: ~
id: 1f6a6899-20e2-43b7-9034-3d6eee8405f3
- __typename: DoneFile
relativeFilePath: test-file.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ expression: results
content: "import { findConfigs } from './configs';\n// Remember: ./packages/timekeeper/src/__generated__/stdlib.ts\nexport const stdlib = {\n show,\n apply,\n sh,\n};\n\nexport type StdLibFunctions = typeof stdlib;"
ranges: []
reason: ~
id: ca03132b-0df4-4609-93bb-bc4d4bcb01f9
- __typename: Rewrite
original:
messages: []
Expand Down Expand Up @@ -123,6 +124,7 @@ expression: results
end: 47
ranges: []
reason: ~
id: 83bc6d7c-e7a9-40d3-8ed4-c96d2287bd11
- __typename: DoneFile
relativeFilePath: ~/dev/rewriter/packages/sdk/src/stdlib/index.ts
- __typename: DoneFile
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,6 @@ expression: results
end: 12
ranges: []
reason: ~
id: 6dcbd7ea-d791-44ad-8fac-f106513235e5
- __typename: DoneFile
relativeFilePath: foo.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,6 @@ expression: results
end: 27
ranges: []
reason: ~
id: 9b78b2ce-48a4-4cd3-95ce-a1fd183a8929
- __typename: DoneFile
relativeFilePath: test-file.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,6 @@ expression: results
end: 13
ranges: []
reason: ~
id: b60f8fd4-92d9-42c9-bbf3-62ef437326fe
- __typename: DoneFile
relativeFilePath: test-file.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,6 @@ expression: results
end: 7
ranges: []
reason: ~
id: f3827a97-072b-44db-87a6-173880f669b0
- __typename: DoneFile
relativeFilePath: test-file.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -176,5 +176,6 @@ expression: results
startByte: 9
endByte: 12
reason: ~
id: 12ee34d4-409f-450d-98a9-a8fb702459db
- __typename: DoneFile
relativeFilePath: test-file.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -229,5 +229,6 @@ expression: results
end: 95
ranges: []
reason: ~
id: 10f98d3b-7cac-4b00-a5f8-cf0dd2977498
- __typename: DoneFile
relativeFilePath: test-file.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -369,5 +369,6 @@ expression: results
end: 114
ranges: []
reason: ~
id: e9ca0036-830e-467c-a852-748d7662e6a5
- __typename: DoneFile
relativeFilePath: test-file.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,5 +153,6 @@ expression: results
startByte: 9
endByte: 12
reason: ~
id: 565e3ee4-25d2-4c51-b811-0223324979ff
- __typename: DoneFile
relativeFilePath: test-file.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,6 @@ expression: results
end: 63
ranges: []
reason: ~
id: 47fdf5a5-3ea6-4bf3-8cc3-efdc395f4087
- __typename: DoneFile
relativeFilePath: foo.package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,6 @@ expression: results
end: 63
ranges: []
reason: ~
id: 9aeb278c-bc90-4725-a58d-76651d9ca998
- __typename: DoneFile
relativeFilePath: foo.package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,6 @@ expression: results
end: 30
ranges: []
reason: ~
id: 012709e4-88b7-45fa-82ec-8b3782c1c3f9
- __typename: DoneFile
relativeFilePath: foo.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,6 @@ expression: results
end: 27
ranges: []
reason: ~
id: cedd3270-e0b7-4181-96b3-b721df9e0d87
- __typename: DoneFile
relativeFilePath: foo.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ expression: results
end: 27
ranges: []
reason: ~
id: f3fceeac-e794-400d-a751-ac0ce7ffe2ba
- __typename: Rewrite
original:
messages: []
Expand Down Expand Up @@ -294,6 +295,7 @@ expression: results
end: 34
ranges: []
reason: ~
id: ae665794-6b9e-4879-846b-f36e2dd71ad7
- __typename: DoneFile
relativeFilePath: file1.tsx
- __typename: DoneFile
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ expression: results
content: foo(1)
ranges: []
reason: ~
id: 5a1d2081-64f2-4d85-adc6-82b96513be74
- __typename: Rewrite
original:
messages: []
Expand Down Expand Up @@ -141,6 +142,7 @@ expression: results
end: 6
ranges: []
reason: ~
id: 0d33377a-ba30-4374-9953-8b81cd95c98a
- __typename: DoneFile
relativeFilePath: file1.tsx
- __typename: DoneFile
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,6 @@ expression: results
end: 30
ranges: []
reason: ~
id: 0c15a1f3-411e-4733-b379-35c106f587c5
- __typename: DoneFile
relativeFilePath: test-file.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,6 @@ expression: results
end: 7
ranges: []
reason: ~
id: 603c11ab-b6de-4868-92b4-3d841cd54324
- __typename: DoneFile
relativeFilePath: test-file.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ expression: results
byteRanges: []
ranges: []
reason: ~
id: a2bb646e-9869-4b29-b04a-80179de53be1
- __typename: DoneFile
relativeFilePath: test-file.tsx
- __typename: AnalysisLog
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,6 @@ expression: results
end: 110
ranges: []
reason: ~
id: 1b16414e-ffd7-4a2d-8140-0dc98780e67c
- __typename: DoneFile
relativeFilePath: test-file.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ expression: results
end: 18
ranges: []
reason: ~
id: 574550d2-27e2-4bbf-a9d7-349c1ad9841c
- __typename: DoneFile
relativeFilePath: test-file.tsx
- __typename: AnalysisLog
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ expression: results
startByte: 8
endByte: 11
reason: ~
id: 5c7312ed-5293-44d6-b6b6-e55fbfa69c75
- __typename: DoneFile
relativeFilePath: test-file.tsx
- __typename: AnalysisLog
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ expression: results
end: 42
ranges: []
reason: ~
id: 9ccffce6-ca5b-4c9e-a2c7-f4a417a75a91
- __typename: DoneFile
relativeFilePath: test-file.tsx
- __typename: AnalysisLog
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ expression: results
startByte: 0
endByte: 13
reason: ~
id: 9d14940e-074a-4f92-80c0-0611608383d3
- __typename: DoneFile
relativeFilePath: test-file.tsx
- __typename: AnalysisLog
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ expression: results
startByte: 0
endByte: 13
reason: ~
id: e7e3b9b6-2474-4df6-b0cf-62e84725be39
- __typename: DoneFile
relativeFilePath: test-file.tsx
- __typename: AnalysisLog
Expand Down
Loading