Skip to content
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

Project search breaks on regex lookbehind/lookahead group constructs #13486

Open
1 task done
jaydenseric opened this issue Jun 25, 2024 · 9 comments · May be fixed by #20308
Open
1 task done

Project search breaks on regex lookbehind/lookahead group constructs #13486

jaydenseric opened this issue Jun 25, 2024 · 9 comments · May be fixed by #20308
Assignees
Labels
bug [core label] search / project search Feedback for in-file search, multi-buffer global search, etc

Comments

@jaydenseric
Copy link
Contributor

Check for existing issues

  • Completed

Describe the bug / provide steps to reproduce it

With this sort of regex search query using negative lookbehind:

(?<!user|tenant)RecordId = randomUUID\(\);

I would expect to be able to match in the last two lines:

const tenantRecordId = randomUUID();
const userRecordId = randomUUID();
const fooRecordId = randomUUID();
const barRecordId = randomUUID();

But the Zed search input becomes red, and refuses to search when there is regex negative lookbehind syntax in the search query:

Screenshot 2024-06-25 at 1 32 01 PM

It's super useful to be able to use regex lookbehind/lookahead group constructs when project searching while refactoring.

Environment

Zed: v0.141.2 (Zed Preview)
OS: macOS 14.5.0
Memory: 64 GiB
Architecture: aarch64

If applicable, add mockups / screenshots to help explain present your vision of the feature

No response

If applicable, attach your ~/Library/Logs/Zed/Zed.log file to this issue.

No response

@jaydenseric jaydenseric added admin read Pending admin review bug [core label] triage Maintainer needs to classify the issue labels Jun 25, 2024
@osiewicz
Copy link
Contributor

osiewicz commented Jun 25, 2024

Hey,
We don't support lookbehind at the moment. We're using https://docs.rs/regex/latest/regex/ under the hood, and it's docs explicitly state:

The regex syntax supported by this crate is similar to other regex engines, but it lacks several features that are not known how to implement efficiently. This includes, but is not limited to, look-around and backreferences. In exchange, all regex searches in this crate have worst case O(m * n) time complexity, where m is proportional to the size of the regex and n is proportional to the size of the string being searched.

I know you're asking for some feature in general (and not for solving a specific use case), but we do support running searches in a selection now. This should allow you to select the last 2 lines in a file and run your query on just these lines.

@osiewicz osiewicz closed this as not planned Won't fix, can't repro, duplicate, stale Jun 25, 2024
@jaydenseric
Copy link
Contributor Author

I don't understand why you are closing this as not planned. There are multiple ways to do better here than just close the issue:

  • Use a more capable rust crate for doing regex with lookaheads/lookbehinds. They exist, e.g. https://crates.io/crates/fancy-regex .
  • Update the UI so that if a search regex is valid regex, but it's using regex features that Zed doesn't support yet, instead of just making the input an invalid red state, show a validation message explaining what is wrong so the user can stop attempting to debug their regex syntax which is actually perfectly valid.

As an anecdotal sample, In the last couple of weeks, both me and my immediate colleague have been using regex searches with lookbehind/lookahead group constructs to do find and replace refactoring in projects with hundreds of modules. It's not an edge case thing; today I had to fire up VS Code and use its regex find and replace because Zed doesn't have the capability.

@osiewicz osiewicz reopened this Jun 25, 2024
@notpeter notpeter added search / project search Feedback for in-file search, multi-buffer global search, etc and removed triage Maintainer needs to classify the issue admin read Pending admin review labels Jun 25, 2024
@exalted
Copy link
Contributor

exalted commented Jun 26, 2024

I, too, would like to see "look ahead" and "look behind" support in the search.

This issue would be a UX defect/bug/issue. However, there is also a feature request here. I hope we can capture both intents.

@christian-gama
Copy link

The lack of information about my Regex being "wrong" was driving me nuts. I thought I was doing something wrong when trying to create a lookbehind regex, because Zed was giving me a red box, indicating that the regex is wrong, but its not actually wrong, its not supported. It should have this information in the docs or an actual UI message telling that this is not supported (maybe another color, such as orange/yellow).

@crepantherx
Copy link

crepantherx commented Jul 26, 2024

please, we also want to fully switch to zed, but hickups like (notebook not supported, and regex don't work even as sublime) these are holding that to happen, now I am on a verge to uninstall it, as I am just carrying it's installation in my PC without using it(waiting for it to support) things which are really necessary.

and it's not really me, every zed user have same issues

Please release a version where we can switch ASAP

@zerolincku
Copy link

This is definitely a basic function needed.

@marcospb19
Copy link

marcospb19 commented Aug 31, 2024

fancy-regex (the crate which supports look-arounds) and regex (the crate Zed currently uses) both depend on the same regex-automata engine and regex-syntax parser, so, it's possible to have both without adding "bloat".

A possible solution for user-given patterns is: always use regex, but fallback to fancy-regex if the pattern compilation fails.

(I'm assuming that regex can be faster even for a pattern that compiles in both crates)

Keeping regex usage in the rest of the editor should be a sane decision tho.

@nicolasembleton
Copy link

It would be really nice to have this feature. It's very powerful for mass search / replace. A bit "niche" in terms of addressable user base, but definitely an important power-feature.

@tknx
Copy link

tknx commented Oct 15, 2024

Came here to find this... Do I care if an algorithm is "inefficient" for a computer when the alternate is it being very inefficient for me to manually do stuff? Not one bit. Please reconsider.

@github-actions github-actions bot added admin read Pending admin review triage Maintainer needs to classify the issue labels Nov 5, 2024
@notpeter notpeter removed triage Maintainer needs to classify the issue admin read Pending admin review labels Nov 5, 2024
@wbbradley wbbradley self-assigned this Nov 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug [core label] search / project search Feedback for in-file search, multi-buffer global search, etc
Projects