zed-industries / zed

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
https://zed.dev
Other
45.38k stars 2.48k forks source link

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

Open jaydenseric opened 2 months ago

jaydenseric commented 2 months ago

Check for existing issues

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

osiewicz commented 2 months ago

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.

jaydenseric commented 2 months ago

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:

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.

exalted commented 2 months ago

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 commented 1 month ago

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 commented 1 month ago

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 commented 2 weeks ago

This is definitely a basic function needed.