search: use heuristic signal choose pattern interpretation
Created by: rvantonder
Stacked on #11059.
Long description because these are changes around complex behaviors that need a trail :-) Feel free to skip to the one inline comment to see why this PR exists.
This PR uses the heuristic signals to fix a regression introduced in https://github.com/sourcegraph/sourcegraph/pull/9846. What happened is that we originally applied a heuristic to treat a pattern like foo() or bar()
literally even in regexp mode, similar to how we do this heuristic today for foo()
(note that normally, ()
would imply empty string in regexp syntax). #9846 added the logic to interpret quoted strings as literal patterns and regexp otherwise for and/or queries, similar to the behavior we have today. Except, this introduced behavior where we would interpret syntactically valid regexp strings like foo()
as regexp still (i.e., the fact that we applied the heuristic was thrown away at the point we converted this value).
This PR uses that knowledge to mimic exactly what we do today. I was particular about how to do this by tracking heuristic signals. The alternative hack could have been to set Quoted: true
when this heuristic fires, but:
-
Quoted: true
is intended to mean (only) "quoted is true iff the search pattern was quoted", which drives logic to treat it literally in certain context - Thus, I don't want to entangle (abuse) the above to say "this heuristic implies this pattern should be treated literally, so let's quote it to get that behavior".