Skip to content

Commit c000632

Browse files
authored
Merge pull request #24 from mbarbin/grep-show-sexp-locations
Grep show sexp locations
2 parents aa5152c + d71df76 commit c000632

File tree

3 files changed

+53
-14
lines changed

3 files changed

+53
-14
lines changed

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
### Changed
88

9+
- Include locations in the output of `crs grep --sexp` (#24, @mbarbin).
910
- Reduce dependencies and replace `re2` by `ocaml-re` (#17, @mbarbin).
1011
- Reduce dependencies and replace `shexp` by `spawn` (#16, @mbarbin).
1112
- Make `crs grep` output in a pager when able (#16, @mbarbin).
@@ -14,6 +15,7 @@
1415

1516
### Fixed
1617

18+
- Fix position mismatch in tests shown by `ocaml-ci` (#23, @mbarbin).
1719
- Disable failing build with 5.4 alpha release (#19, @mbarbin).
1820
- Adapt grep implementation for portability to MacOS (#19, @mbarbin).
1921

lib/crs_cli/src/cmd__grep.ml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,9 @@ let main =
6767
let oc = Git_pager.write_end git_pager in
6868
if sexp
6969
then
70-
List.iter crs ~f:(fun cr ->
71-
Out_channel.output_line oc (Sexp.to_string_hum [%sexp (cr : Cr_comment.t)]))
70+
Ref.set_temporarily Loc.include_sexp_of_locs true ~f:(fun () ->
71+
List.iter crs ~f:(fun cr ->
72+
Out_channel.output_line oc (Sexp.to_string_hum [%sexp (cr : Cr_comment.t)])))
7273
else if summary
7374
then (
7475
let by_type =

test/cram/grep.t

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -75,38 +75,74 @@ Now let's grep for the CRs.
7575
A basic [sexp] output is available.
7676

7777
$ crs grep --sexp
78-
((path foo/a.txt) (whole_loc _)
79-
(header (Ok ((kind XCR) (due Now) (reported_by user1) (for_ ()))))
78+
((path foo/a.txt) (whole_loc ((start foo/a.txt:2:0) (stop foo/a.txt:2:38)))
79+
(header
80+
(Ok
81+
((kind ((txt XCR) (loc ((start foo/a.txt:2:3) (stop foo/a.txt:2:6)))))
82+
(due ((txt Now) (loc ((start foo/a.txt:2:3) (stop foo/a.txt:2:6)))))
83+
(reported_by
84+
((txt user1) (loc ((start foo/a.txt:2:7) (stop foo/a.txt:2:12)))))
85+
(for_ ()))))
8086
(digest_of_condensed_content 9dce8eceb787a95abf3fccb037d164ea)
8187
(content "XCR user1: Fix this. Edit: Done."))
82-
((path foo/b.txt) (whole_loc _)
83-
(header (Ok ((kind CR) (due Someday) (reported_by user1) (for_ ()))))
88+
((path foo/b.txt) (whole_loc ((start foo/b.txt:1:0) (stop foo/b.txt:1:71)))
89+
(header
90+
(Ok
91+
((kind ((txt CR) (loc ((start foo/b.txt:1:3) (stop foo/b.txt:1:5)))))
92+
(due ((txt Someday) (loc ((start foo/b.txt:1:6) (stop foo/b.txt:1:13)))))
93+
(reported_by
94+
((txt user1) (loc ((start foo/b.txt:1:14) (stop foo/b.txt:1:19)))))
95+
(for_ ()))))
8496
(digest_of_condensed_content 22722b7a3948f75ec004a651d97d02bb)
8597
(content
8698
"CR-someday user1: Reconsider if/when updating to the new version."))
87-
((path foo/bar/b.txt) (whole_loc _)
88-
(header (Ok ((kind CR) (due Soon) (reported_by user1) (for_ ()))))
99+
((path foo/bar/b.txt)
100+
(whole_loc ((start foo/bar/b.txt:2:0) (stop foo/bar/b.txt:2:55)))
101+
(header
102+
(Ok
103+
((kind
104+
((txt CR) (loc ((start foo/bar/b.txt:2:3) (stop foo/bar/b.txt:2:5)))))
105+
(due
106+
((txt Soon) (loc ((start foo/bar/b.txt:2:6) (stop foo/bar/b.txt:2:10)))))
107+
(reported_by
108+
((txt user1)
109+
(loc ((start foo/bar/b.txt:2:11) (stop foo/bar/b.txt:2:16)))))
110+
(for_ ()))))
89111
(digest_of_condensed_content 8b683d9bff5df08ee3642df3cf2426ce)
90112
(content "CR-soon user1: Hey, this is a code review comment"))
91-
((path foo/bar/c.txt) (whole_loc _)
113+
((path foo/bar/c.txt)
114+
(whole_loc ((start foo/bar/c.txt:1:0) (stop foo/bar/c.txt:1:52)))
92115
(header
93116
(Error
94117
("Invalid CR comment" "CR-user: Hey, I'm trying to use CR, it's cool!")))
95118
(digest_of_condensed_content 49a84095611ebd8cb3f83e4546e67533)
96119
(content "CR-user: Hey, I'm trying to use CR, it's cool!"))
97-
((path foo/bar/d.txt) (whole_loc _)
120+
((path foo/bar/d.txt)
121+
(whole_loc ((start foo/bar/d.txt:1:0) (stop foo/bar/d.txt:1:67)))
98122
(header
99123
(Error
100124
("Invalid CR comment"
101125
"CR : Hey, this comment look like a CR but it's not quite one.")))
102126
(digest_of_condensed_content d8a25b0acac6d3a23ff4f4c1e4c990a3)
103127
(content "CR : Hey, this comment look like a CR but it's not quite one."))
104-
((path foo/foo.c) (whole_loc _)
105-
(header (Ok ((kind CR) (due Now) (reported_by user1) (for_ (user3)))))
128+
((path foo/foo.c) (whole_loc ((start foo/foo.c:1:0) (stop foo/foo.c:1:60)))
129+
(header
130+
(Ok
131+
((kind ((txt CR) (loc ((start foo/foo.c:1:3) (stop foo/foo.c:1:5)))))
132+
(due ((txt Now) (loc ((start foo/foo.c:1:3) (stop foo/foo.c:1:5)))))
133+
(reported_by
134+
((txt user1) (loc ((start foo/foo.c:1:6) (stop foo/foo.c:1:11)))))
135+
(for_
136+
(((txt user3) (loc ((start foo/foo.c:1:16) (stop foo/foo.c:1:21)))))))))
106137
(digest_of_condensed_content 4721a5c5f8a37bdcb9e065268bbd0153)
107138
(content "CR user1 for user3: Hey, this is a code review comment"))
108-
((path hello) (whole_loc _)
109-
(header (Ok ((kind CR) (due Now) (reported_by user1) (for_ (user2)))))
139+
((path hello) (whole_loc ((start hello:2:0) (stop hello:2:60)))
140+
(header
141+
(Ok
142+
((kind ((txt CR) (loc ((start hello:2:3) (stop hello:2:5)))))
143+
(due ((txt Now) (loc ((start hello:2:3) (stop hello:2:5)))))
144+
(reported_by ((txt user1) (loc ((start hello:2:6) (stop hello:2:11)))))
145+
(for_ (((txt user2) (loc ((start hello:2:16) (stop hello:2:21)))))))))
110146
(digest_of_condensed_content 970aabfe0c3d4ec5707918edd3f01a8a)
111147
(content "CR user1 for user2: Hey, this is a code review comment"))
112148

0 commit comments

Comments
 (0)