Commit 94e4b8e
committed
printer: fix --vimgrep for multi-line mode
It turned out that --vimgrep wasn't quite getting the column of each
match correctly. Instead of printing column numbers relative to the
current line, it was printing column numbers as byte offsets relative to
where the match began. To fix this, we simply subtract the offset of the
line number from the beginning of the match. If the beginning of the
match came before the start of the current line, then there's really
nothing sensible we can do other than to use a column number of 1, which
we now document.
Interestingly, existing tests were checking that the previous behavior
was intended. My only defense is that I somehow tricked myself into
thinking it was a byte offset instead of a column number.
Kudos to @bfrg for calling this out in #1866:
#1866 (comment)1 parent 2af7724 commit 94e4b8e
File tree
4 files changed
+30
-8
lines changed- crates/printer/src
- tests
4 files changed
+30
-8
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
| 25 | + | |
24 | 26 | | |
25 | 27 | | |
26 | 28 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
222 | 222 | | |
223 | 223 | | |
224 | 224 | | |
225 | | - | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
226 | 228 | | |
227 | 229 | | |
228 | 230 | | |
| |||
1090 | 1092 | | |
1091 | 1093 | | |
1092 | 1094 | | |
1093 | | - | |
| 1095 | + | |
1094 | 1096 | | |
1095 | 1097 | | |
1096 | 1098 | | |
| |||
2990 | 2992 | | |
2991 | 2993 | | |
2992 | 2994 | | |
2993 | | - | |
| 2995 | + | |
2994 | 2996 | | |
2995 | | - | |
| 2997 | + | |
2996 | 2998 | | |
2997 | 2999 | | |
2998 | 3000 | | |
| |||
3019 | 3021 | | |
3020 | 3022 | | |
3021 | 3023 | | |
3022 | | - | |
3023 | | - | |
3024 | | - | |
| 3024 | + | |
| 3025 | + | |
| 3026 | + | |
3025 | 3027 | | |
3026 | 3028 | | |
3027 | 3029 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
80 | | - | |
| 80 | + | |
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
864 | 864 | | |
865 | 865 | | |
866 | 866 | | |
| 867 | + | |
| 868 | + | |
| 869 | + | |
| 870 | + | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
| 884 | + | |
0 commit comments