Debian Codegraph @

src/handlers/ripgrep_json.rs

raw symbols SCIP
1 // See https://github.com/BurntSushi/ripgrep
2 // This module implements handling of `rg --json` output. It is called by the
3 // handler in handlers/grep.rs. Normal rg output (i.e. without --json) is
4 // handled by the same code paths as `git grep` etc output, in handlers/grep.rs.
5 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::borrowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/::Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#;
6
7 use craterust-analyzer cargo git-delta 0.19.2 crate/::handlersrust-analyzer cargo git-delta 0.19.2 handlers/::greprust-analyzer cargo git-delta 0.19.2 handlers/grep/;
8 use serderust-analyzer cargo serde 1.0.228 crate/::Deserializerust-analyzer cargo serde_core 1.0.228 de/Deserialize#;
9 use serde_jsonrust-analyzer cargo serde_json 1.0.111 crate/::Valuerust-analyzer cargo serde_json 1.0.111 value/Value#;
10
11 pub fn parse_linerust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/parse_line().(line: &str) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<greprust-analyzer cargo git-delta 0.19.2 handlers/grep/::GrepLinerust-analyzer cargo git-delta 0.19.2 handlers/grep/GrepLine#<'_>> {
12 let ripgrep_line: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<RipGrepLinerust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLine#> = serde_jsonrust-analyzer cargo serde_json 1.0.111 crate/::from_strrust-analyzer cargo serde_json 1.0.111 de/from_str().(line).okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().();
13 match ripgrep_line {
14 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ripgrep_line) => {
15 // A real line of rg --json output, i.e. either of type "match" or
16 // "context".
17 let mut code = ripgrep_line.datarust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLine#data..linesrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineData#lines..textrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineText#text.;
18 // Keep newlines so the syntax highlighter handles C-style line comments
19 // correctly. Also remove \r, see [EndCRLF] in src/delta.rs, but this time
20 // it is syntect which adds an ANSI escape sequence in between \r\n later.
21 if code.ends_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]ends_with().("\r\n") {
22 code.truncaterust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]truncate().(code.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().2);
23 code.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().('\n');
24 }
25 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(greprust-analyzer cargo git-delta 0.19.2 handlers/grep/::GrepLinerust-analyzer cargo git-delta 0.19.2 handlers/grep/GrepLine# {
26 grep_typerust-analyzer cargo git-delta 0.19.2 handlers/grep/GrepLine#grep_type.: craterust-analyzer cargo git-delta 0.19.2 crate/::configrust-analyzer cargo git-delta 0.19.2 config/::GrepTyperust-analyzer cargo git-delta 0.19.2 config/GrepType#::Ripgreprust-analyzer cargo git-delta 0.19.2 config/GrepType#Ripgrep#,
27 line_typerust-analyzer cargo git-delta 0.19.2 handlers/grep/GrepLine#line_type.: ripgrep_line._typerust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLine#_type.,
28 line_numberrust-analyzer cargo git-delta 0.19.2 handlers/grep/GrepLine#line_number.: ripgrep_line.datarust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLine#data..line_numberrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineData#line_number.,
29 pathrust-analyzer cargo git-delta 0.19.2 handlers/grep/GrepLine#path.: Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::fromrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[`Cow<'a, str>`][`From<String>`]from().(ripgrep_line.datarust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLine#data..pathrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineData#path..textrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineText#text.),
30 coderust-analyzer cargo git-delta 0.19.2 handlers/grep/GrepLine#code.: Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::fromrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[`Cow<'a, str>`][`From<String>`]from().(code),
31 submatchesrust-analyzer cargo git-delta 0.19.2 handlers/grep/GrepLine#submatches.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(
32 ripgrep_line
33 .datarust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLine#data.
34 .submatchesrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineData#submatches.
35 .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().()
36 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|m| (m.startrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineSubmatch#start., m.endrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineSubmatch#end.))
37 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(),
38 ),
39 })
40 }
41 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => {
42 let value: Valuerust-analyzer cargo serde_json 1.0.111 value/Value# = serde_jsonrust-analyzer cargo serde_json 1.0.111 crate/::from_strrust-analyzer cargo serde_json 1.0.111 de/from_str().(line).okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().;
43 match &value[rust-analyzer cargo serde_json 1.0.111 value/index/impl#[Value][`Index<I>`]index()."type"]rust-analyzer cargo serde_json 1.0.111 value/index/impl#[Value][`Index<I>`]index(). {
44 Valuerust-analyzer cargo serde_json 1.0.111 value/Value#::Stringrust-analyzer cargo serde_json 1.0.111 value/Value#String#(s) if s rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq()."begin" || s rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq()."end" || s rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq()."summary" => {
45 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(greprust-analyzer cargo git-delta 0.19.2 handlers/grep/::GrepLinerust-analyzer cargo git-delta 0.19.2 handlers/grep/GrepLine# {
46 // ripgrep --json also emits these metadata lines at
47 // file boundaries. We emit nothing but signal that the
48 // line has been handled.
49 grep_typerust-analyzer cargo git-delta 0.19.2 handlers/grep/GrepLine#grep_type.: craterust-analyzer cargo git-delta 0.19.2 crate/::configrust-analyzer cargo git-delta 0.19.2 config/::GrepTyperust-analyzer cargo git-delta 0.19.2 config/GrepType#::Ripgreprust-analyzer cargo git-delta 0.19.2 config/GrepType#Ripgrep#,
50 line_typerust-analyzer cargo git-delta 0.19.2 handlers/grep/GrepLine#line_type.: greprust-analyzer cargo git-delta 0.19.2 handlers/grep/::LineTyperust-analyzer cargo git-delta 0.19.2 handlers/grep/LineType#::Ignorerust-analyzer cargo git-delta 0.19.2 handlers/grep/LineType#Ignore#,
51 line_numberrust-analyzer cargo git-delta 0.19.2 handlers/grep/GrepLine#line_number.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
52 pathrust-analyzer cargo git-delta 0.19.2 handlers/grep/GrepLine#path.: "".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(),
53 coderust-analyzer cargo git-delta 0.19.2 handlers/grep/GrepLine#code.: "".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(),
54 submatchesrust-analyzer cargo git-delta 0.19.2 handlers/grep/GrepLine#submatches.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
55 })
56 }
57 _ => {
58 // Failed to interpret the line as ripgrep output; allow
59 // another delta handler to try.
60 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
61 }
62 }
63 }
64 }
65 }
66
67 // {
68 // "type": "match",
69 // "data": {
70 // "path": {
71 // "text": "src/cli.rs"
72 // },
73 // "lines": {
74 // "text": " fn from_clap_and_git_config(\n"
75 // },
76 // "line_number": null,
77 // "absolute_offset": 35837,
78 // "submatches": [
79 // {
80 // "match": {
81 // "text": "fn"
82 // },
83 // "start": 4,
84 // "end": 6
85 // }
86 // ]
87 // }
88 // }
89
90 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Deserializerust-analyzer cargo serde_derive 1.0.228 Deserialize:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
91 struct RipGrepLinerust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLine# {
92 #[serderust-analyzer cargo serde_derive 1.0.228 serde:(rename(deserialize = "type"))]
93 _typerust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLine#_type.: greprust-analyzer cargo git-delta 0.19.2 handlers/grep/::LineTyperust-analyzer cargo git-delta 0.19.2 handlers/grep/LineType#,
94 datarust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLine#data.: RipGrepLineDatarust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineData#,
95 }
96
97 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Deserializerust-analyzer cargo serde_derive 1.0.228 Deserialize:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
98 struct RipGrepLineDatarust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineData# {
99 pathrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineData#path.: RipGrepLineTextrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineText#,
100 linesrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineData#lines.: RipGrepLineTextrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineText#,
101 line_numberrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineData#line_number.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize>,
102 absolute_offsetrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineData#absolute_offset.: usize,
103 submatchesrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineData#submatches.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<RipGrepLineSubmatchrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineSubmatch#>,
104 }
105
106 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Deserializerust-analyzer cargo serde_derive 1.0.228 Deserialize:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
107 struct RipGrepLineTextrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineText# {
108 textrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineText#text.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
109 }
110
111 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Deserializerust-analyzer cargo serde_derive 1.0.228 Deserialize:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
112 struct RipGrepLineSubmatchrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineSubmatch# {
113 #[serderust-analyzer cargo serde_derive 1.0.228 serde:(rename(deserialize = "match"))]
114 _matchrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineSubmatch#_match.: RipGrepLineTextrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineText#,
115 startrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineSubmatch#start.: usize,
116 endrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineSubmatch#end.: usize,
117 }
118
119 #[cfg(test)]
120 mod testsrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/tests/ {
121 use superrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/::*;
122
123 use craterust-analyzer cargo git-delta 0.19.2 crate/::testsrust-analyzer cargo git-delta 0.19.2 tests/::integration_test_utilsrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/::DeltaTestrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/DeltaTest#;
124 use instarust-analyzer cargo insta 1.39.0 crate/::assert_snapshotrust-analyzer cargo insta 1.39.0 macros/assert_snapshot!;
125
126 /* FILE test.c:
127 // i ABC
128 int f() { return 4; }
129 const char* i = "ABC";
130 double n = 1.23;
131 */
132 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
133 fn test_syntax_in_rg_output_with_contextrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/tests/test_syntax_in_rg_output_with_context().() {
134 // `rg int -C2 --json test.c`
135 let data = r#"{"type":"begin","data":{"path":{"text":"test.c"}}}
136 {"type":"context","data":{"path":{"text":"test.c"},"lines":{"text":"// i ABC\n"},"line_number":1,"absolute_offset":0,"submatches":[]}}
137 {"type":"match","data":{"path":{"text":"test.c"},"lines":{"text":"int f() { return 4; }\n"},"line_number":2,"absolute_offset":9,"submatches":[{"match":{"text":"int"},"start":0,"end":3}]}}
138 {"type":"context","data":{"path":{"text":"test.c"},"lines":{"text":"const char* i = \"ABC\";\n"},"line_number":3,"absolute_offset":31,"submatches":[]}}
139 {"type":"context","data":{"path":{"text":"test.c"},"lines":{"text":"double n = 1.23;\n"},"line_number":4,"absolute_offset":54,"submatches":[]}}
140 {"type":"end","data":{"path":{"text":"test.c"},"binary_offset":null,"stats":{"elapsed":{"secs":0,"nanos":26941,"human":"0.000027s"},"searches":1,"searches_with_match":1,"bytes_searched":71,"bytes_printed":670,"matched_lines":1,"matches":1}}}
141 {"data":{"elapsed_total":{"human":"0.000479s","nanos":478729,"secs":0},"stats":{"bytes_printed":670,"bytes_searched":71,"elapsed":{"human":"0.000027s","nanos":26941,"secs":0},"matched_lines":1,"matches":1,"searches":1,"searches_with_match":1}},"type":"summary"}"#;
142 let result = DeltaTestrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/DeltaTest#::with_argsrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/impl#[`DeltaTest<'a>`]with_args().(&[]).explain_ansirust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/impl#[`DeltaTest<'a>`]explain_ansi().().with_inputrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/impl#[`DeltaTest<'a>`]with_input().(data);
143 // eprintln!("{}", result.raw_output);
144 assert_snapshotrust-analyzer cargo insta 1.39.0 macros/assert_snapshot!!(result.outputrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/DeltaTestOutput#output., @r#"
145 (purple)test.c(normal)
146 (green)1(normal)-(242)// i ABC(normal)
147 (green)2(normal):(81 28)int(231) (149)f(231)() { (203)return(231) (141)4(231); }(normal)
148 (green)3(normal)-(203)const(231) (81)char(203)*(231) i (203)=(231) (186)"ABC"(231);(normal)
149 (green)4(normal)-(81)double(231) n (203)=(231) (141)1.23(231);(normal)
150 "#);
151 }
152
153 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
154 fn test_syntax_in_rg_output_no_contextrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/tests/test_syntax_in_rg_output_no_context().() {
155 // `rg i --json test.c`
156 let data = r#"{"type":"begin","data":{"path":{"text":"test.c"}}}
157 {"type":"match","data":{"path":{"text":"test.c"},"lines":{"text":"// i ABC\n"},"line_number":1,"absolute_offset":0,"submatches":[{"match":{"text":"i"},"start":3,"end":4}]}}
158 {"type":"match","data":{"path":{"text":"test.c"},"lines":{"text":"int f() { return 4; }\n"},"line_number":2,"absolute_offset":9,"submatches":[{"match":{"text":"i"},"start":0,"end":1}]}}
159 {"type":"match","data":{"path":{"text":"test.c"},"lines":{"text":"const char* i = \"ABC\";\n"},"line_number":3,"absolute_offset":31,"submatches":[{"match":{"text":"i"},"start":12,"end":13}]}}
160 {"type":"end","data":{"path":{"text":"test.c"},"binary_offset":null,"stats":{"elapsed":{"secs":0,"nanos":23885,"human":"0.000024s"},"searches":1,"searches_with_match":1,"bytes_searched":71,"bytes_printed":602,"matched_lines":3,"matches":3}}}
161 {"data":{"elapsed_total":{"human":"0.000433s","nanos":432974,"secs":0},"stats":{"bytes_printed":602,"bytes_searched":71,"elapsed":{"human":"0.000024s","nanos":23885,"secs":0},"matched_lines":3,"matches":3,"searches":1,"searches_with_match":1}},"type":"summary"}
162 "#;
163 let result = DeltaTestrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/DeltaTest#::with_argsrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/impl#[`DeltaTest<'a>`]with_args().(&[]).explain_ansirust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/impl#[`DeltaTest<'a>`]explain_ansi().().with_inputrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/impl#[`DeltaTest<'a>`]with_input().(data);
164 // eprintln!("{}", result.raw_output);
165 assert_snapshotrust-analyzer cargo insta 1.39.0 macros/assert_snapshot!!(result.outputrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/DeltaTestOutput#output., @r#"
166 (purple)test.c(normal)
167 (green)1(normal):(242)// (normal 28)i(242) ABC(normal)
168 (green)2(normal):(81 28)i(81)nt(231) (149)f(231)() { (203)return(231) (141)4(231); }(normal)
169 (green)3(normal):(203)const(231) (81)char(203)*(231) (normal 28)i(231) (203)=(231) (186)"ABC"(231);(normal)
170 "#);
171 }
172
173 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
174 fn test_deserializerust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/tests/test_deserialize().() {
175 let line = r#"{"type":"match","data":{"path":{"text":"src/cli.rs"},"lines":{"text":" fn from_clap_and_git_config(\n"},"line_number":null,"absolute_offset":35837,"submatches":[{"match":{"text":"fn"},"start":4,"end":6}]}}"#;
176 let ripgrep_line: RipGrepLinerust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLine# = serde_jsonrust-analyzer cargo serde_json 1.0.111 crate/::from_strrust-analyzer cargo serde_json 1.0.111 de/from_str().(line).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
177 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
178 ripgrep_line,
179 RipGrepLinerust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLine# {
180 _typerust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLine#_type.: greprust-analyzer cargo git-delta 0.19.2 handlers/grep/::LineTyperust-analyzer cargo git-delta 0.19.2 handlers/grep/LineType#::Matchrust-analyzer cargo git-delta 0.19.2 handlers/grep/LineType#Match#,
181 datarust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLine#data.: RipGrepLineDatarust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineData# {
182 pathrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineData#path.: RipGrepLineTextrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineText# {
183 textrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineText#text.: "src/cli.rs".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()
184 },
185 linesrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineData#lines.: RipGrepLineTextrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineText# {
186 textrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineText#text.: " fn from_clap_and_git_config(\n".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(),
187 },
188 line_numberrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineData#line_number.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
189 absolute_offsetrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineData#absolute_offset.: 35837,
190 submatchesrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineData#submatches.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![RipGrepLineSubmatchrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineSubmatch# {
191 _matchrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineSubmatch#_match.: RipGrepLineTextrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineText# { textrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineText#text.: "fn".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().() },
192 startrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineSubmatch#start.: 4,
193 endrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineSubmatch#end.: 6
194 }]
195 }
196 }
197 )
198 }
199
200 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
201 fn test_deserialize_2rust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/tests/test_deserialize_2().() {
202 let line = r#"{"type":"match","data":{"path":{"text":"src/handlers/submodule.rs"},"lines":{"text":" .paint(minus_commit.chars().take(7).collect::<String>()),\n"},"line_number":41,"absolute_offset":1430,"submatches":[{"match":{"text":"("},"start":30,"end":31},{"match":{"text":"("},"start":49,"end":50},{"match":{"text":")"},"start":50,"end":51},{"match":{"text":"("},"start":56,"end":57},{"match":{"text":")"},"start":58,"end":59},{"match":{"text":"("},"start":77,"end":78},{"match":{"text":")"},"start":78,"end":79},{"match":{"text":")"},"start":79,"end":80}]}}"#;
203 let ripgrep_line: RipGrepLinerust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLine# = serde_jsonrust-analyzer cargo serde_json 1.0.111 crate/::from_strrust-analyzer cargo serde_json 1.0.111 de/from_str().(line).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
204 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
205 ripgrep_line,
206 RipGrepLinerust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLine# {
207 _typerust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLine#_type.: greprust-analyzer cargo git-delta 0.19.2 handlers/grep/::LineTyperust-analyzer cargo git-delta 0.19.2 handlers/grep/LineType#::Matchrust-analyzer cargo git-delta 0.19.2 handlers/grep/LineType#Match#,
208 datarust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLine#data.: RipGrepLineDatarust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineData# {
209 pathrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineData#path.: RipGrepLineTextrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineText# {
210 textrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineText#text.: "src/handlers/submodule.rs".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()
211 },
212 linesrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineData#lines.: RipGrepLineTextrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineText# {
213 textrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineText#text.: " .paint(minus_commit.chars().take(7).collect::<String>()),\n".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(),
214 },
215 line_numberrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineData#line_number.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(41),
216 absolute_offsetrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineData#absolute_offset.: 1430,
217 submatchesrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineData#submatches.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![
218 RipGrepLineSubmatchrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineSubmatch# {
219 _matchrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineSubmatch#_match.: RipGrepLineTextrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineText# { textrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineText#text.: "(".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().() },
220 startrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineSubmatch#start.: 30,
221 endrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineSubmatch#end.: 31
222 },
223 RipGrepLineSubmatchrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineSubmatch# {
224 _matchrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineSubmatch#_match.: RipGrepLineTextrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineText# { textrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineText#text.: "(".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().() },
225 startrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineSubmatch#start.: 49,
226 endrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineSubmatch#end.: 50
227 },
228 RipGrepLineSubmatchrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineSubmatch# {
229 _matchrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineSubmatch#_match.: RipGrepLineTextrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineText# { textrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineText#text.: ")".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().() },
230 startrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineSubmatch#start.: 50,
231 endrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineSubmatch#end.: 51
232 },
233 RipGrepLineSubmatchrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineSubmatch# {
234 _matchrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineSubmatch#_match.: RipGrepLineTextrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineText# { textrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineText#text.: "(".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().() },
235 startrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineSubmatch#start.: 56,
236 endrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineSubmatch#end.: 57
237 },
238 RipGrepLineSubmatchrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineSubmatch# {
239 _matchrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineSubmatch#_match.: RipGrepLineTextrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineText# { textrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineText#text.: ")".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().() },
240 startrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineSubmatch#start.: 58,
241 endrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineSubmatch#end.: 59
242 },
243 RipGrepLineSubmatchrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineSubmatch# {
244 _matchrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineSubmatch#_match.: RipGrepLineTextrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineText# { textrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineText#text.: "(".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().() },
245 startrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineSubmatch#start.: 77,
246 endrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineSubmatch#end.: 78
247 },
248 RipGrepLineSubmatchrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineSubmatch# {
249 _matchrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineSubmatch#_match.: RipGrepLineTextrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineText# { textrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineText#text.: ")".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().() },
250 startrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineSubmatch#start.: 78,
251 endrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineSubmatch#end.: 79
252 },
253 RipGrepLineSubmatchrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineSubmatch# {
254 _matchrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineSubmatch#_match.: RipGrepLineTextrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineText# { textrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineText#text.: ")".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().() },
255 startrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineSubmatch#start.: 79,
256 endrust-analyzer cargo git-delta 0.19.2 handlers/ripgrep_json/RipGrepLineSubmatch#end.: 80
257 },
258 ]
259 }
260 }
261 )
262 }
263 }