Open Terrance opened 1 year ago
Testing again now on a different machine, it seems the incorrect matches don't show with multiple candidate files open. If no files are open, candidates from all files are shown. With one file open, candidates from that file are shown but not the others.
What version of vscode does this other machine use? Did this only start happening today with the update?
I can check in the morning, but I did try on this computer before updating and it was still happening then, so probably safe to say it wasn't introduced in the latest update.
The other machine is on 1.75.1, so hasn't gained the update yet.
Here is another reproducer.
Foo
PrefixFoo
FooSuffix
Bar
PrefixBar
BarSuffix
Foo|Bar
with Match Whole Word & Use Regular Expression options.\b(Foo|Bar)\b
regexp:
\bFoo|Bar\b
regexp where Foo is only constrained to start the word, and Bar only to end it:
Bar|Foo
search is run, it gives different unexpected matches, apparently equivalent to \bBar|Foo\b
regexp:
(In all cases, there were other clean "foo" and "bar" matches in other files; I didn't test the more complex interactions between files that Terrance reports...)
This also reproduced on 1.76.0. I now re-tested #112401 (originally reported in 2020) and found that presently its behavior too depends on whether the candidate file has an open editor.
Weirdly, the theory on #112401 suggests the Whole Word constraint being applied after the regexp engine is done searching, resulting in behavior that has no equivalent regexp — whereas my theory of \bFoo|Bar\b
vs. \b(Foo|Bar)\b
here relies on it translating to a regexp. :man_shrugging:
Looking more into this, I don't believe this is a new issue. The find when files are open seems to handle matching a whole word differently than how the ripgrep engine does when files are closed.
In-file find uses a more complicated way of using word separators when we want a whole-word match: https://github.com/microsoft/vscode/blob/3059063b805ed0ac10a6d9539e213386bfcfb852/src/vs/editor/common/model/pieceTreeTextBuffer/pieceTreeBase.ts#L799
Whereas our parsing into ripgrep has a simpler approach" https://github.com/microsoft/vscode/blob/5ca7a333e12b313eda4092bf4d1ca60e365ec416/src/vs/base/common/strings.ts#L183-L188
Might be related to https://github.com/microsoft/vscode/issues/170529 (but here, the whole world toggle over-matches instead)
Does this issue occur when all extensions are disabled?: Yes
Steps to Reproduce:
As an example, looking for method calls with an argument:
Initially I did a whole-word regex search for
target\([^)]
, which matched all the calls providing at least one argument (i.e.two
andthree
here).Spread across multiple files, I found that after selecting a match in the search result list to open one file, and then selecting one in a different file, the first result disappeared from the search results. This is presumably because with whole-word enabled, these shouldn't actually match unless the argument is a single character, which for
arg
here is not the case.Testing again now on a different machine, it seems the incorrect matches don't show with multiple candidate files open. If no files are open, candidates from all files are shown. With one file open, candidates from that file are shown but not the others.
Whole-word matching does appear to apply correctly in other cases (e.g. here,
target
is correctly matched whole-word so that the likes ofothertarget
don't match).