-
Notifications
You must be signed in to change notification settings - Fork 29k
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
Ctrl+Shift+F with regex show wrong results #131507
Comments
BurntSushi/ripgrep#1983 (comment) |
Well... I've been thinking about this again while looking at #65281 and so on, and it's a problem that not only clear \n but also all negative matches like [^a] are hit, so it's not good to try to automatically decide whether to search in multiline mode on the VSCode side... At the very least, it seems to me that this issue would be resolved if VSCode did not try to search in multiline mode on its own, regardless of the user's intentions. |
You are right that our current handling will not be totally correct and an explicit button would be better. We try really hard not to add buttons for every single feature because people also value a minimal UI. So this is a tough one. |
Based on that policy, I think the following is a more accurate (at least better than the current VSCode) way to determine if the regular expression should be searched in multiline mode.
|
Uh... sorry, there's a bug in the code. if (chCode === CharCode.OpenSquareBracket) {
// move to next char
i++;
if (i >= len) {
// string ends with a [
break;
}
const nextChCode = searchString.charCodeAt(i);
if (nextChCode === CharCode.Caret) {
return true;
}
// roll back the forward reading
i--;
} |
Ah... I forgot to mention another method that is quite the opposite of the previous addition. (it doesn't bring pain to the user who intends the negation to work in single-line mode). |
Is there any news on this? With a search it is a pity that it does not search correctly here, but who replaces text at the same time, gets serious problems here. For me hundreds of files are destroyed. Fortunately I had made a backup before replacing multiple files. If you test the code beforehand in the search CTRL+F and Regex101 and it works, you do not assume that VSCode fails when replacing multiple files with the same pattern. |
Sorry for the noise, the error was sitting in front of the keyboard. Solution: Original "Issue": Not working example in VS Code 1.70.2:
Correct results: lines 5+6, 8+9, 15+16 Current workaround:
Second my opinions about multi-line regex and
|
Same thing here, I'm cleaning up hundreds of HTML files with thousands of replaces per regex: I lost a couple of days of work because I have no idea how many files I corrupted with multiple search/replace actions involving I'd love to help fix this but I have no clue where to start. Can anyone give me some pointers? And why would the bug only show up for unopened buffers? |
Sorry for the trouble. This issue describes the upstream change in ripgrep: BurntSushi/ripgrep#1983. Here is where we process results from ripgrep:
I'm not sure where in the process it falls apart. Something is not handling multiple submatches correctly. You can trace the model through from that code to the search tree and and see where it goes wrong. |
#1
To avoid having #2 |
I found the cause and fixed the bug: see PR #160665. The RipGrep parser was not converting the absolute position submatches to correct (line number, column number) pairs, which lead to wrong display in the search widget and wrong replacements. Once I fixed it, examples from both #160005 and my issue #159733 replaced properly. @roblourens I looked into writing tests for this function, but since it's a private function and there are no tests for the class itself, what's the best approach here? |
* Fix wrong matches in multiline file search When multiple consecutive lines match a regular expression, RipGrep will return them as one match with multiple submatches. The parser that converts the absolute positions of the submatches to (line number, column number) pairs was not taking into account that `inBetweenChars` may contain newlines, leading to wrong matches, and search/replace actions that gave unexpected results. Fixes #131507 * Add tests for multiple submatches from ripgrep
Issue Type: Bug
main.cpp
:#include\s*<\w+>
, show the following result which is wrong:main.cpp
and search again, show correct result:VS Code version: Code 1.59.1 (3866c35, 2021-08-19T11:56:46.957Z)
OS version: Windows_NT x64 10.0.19042
Restricted Mode: No
System Info
gpu_compositing: enabled
multiple_raster_threads: enabled_on
oop_rasterization: enabled
opengl: enabled_on
rasterization: enabled
skia_renderer: enabled_on
video_decode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
test.mp4
The text was updated successfully, but these errors were encountered: