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

printer: implement --max-columns-preview-before #2683

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

kkocdko
Copy link

@kkocdko kkocdko commented Dec 11, 2023

See #1352 .

@kkocdko
Copy link
Author

kkocdko commented Dec 11, 2023

Currently:

rg --max-columns 30 --max-columns-preview --max-columns-preview-before 10 --per-match '=require\('

screenshot_0

Should we reduce the tips text length? And replace the "0 more matches" with "[... omitted end of long line]" when per-match enabled?

@@ -3768,6 +3770,53 @@ fn test_max_columns_preview() {
assert_eq!(false, args.max_columns_preview);
}

/// --max-columns-preview-before
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a better name?

@@ -65,6 +65,7 @@ pub(crate) struct HiArgs {
line_number: bool,
max_columns: Option<u64>,
max_columns_preview: bool,
max_columns_preview_before: Option<u64>,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can combine this to max_columns_preview: Option<u64>, but will cause breaking changes. Is this acceptable?

@@ -5335,6 +5384,42 @@ fn test_pcre2_version() {
assert_eq!(Some(SpecialMode::VersionPCRE2), args.special);
}

/// --per-match
Copy link
Author

@kkocdko kkocdko Dec 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expose this to cli.

self.write(b"[... omitted start of long line] ")?;
line = line.with_start(start);
}
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Compare to the full --column-context-before + --column-context-after support that needs to modify everywhere, the implementation code here is quiet simple.

@kkocdko
Copy link
Author

kkocdko commented Jan 14, 2024

Hi, @BurntSushi , what is your opinion about this design? Many people work on JavaScript bundler and web reverse engineering rely on this feature because we needs to deal with very long line and many huge files.

It's fine if you don't like this. I will still maintenance this patch for my friends.

@BurntSushi
Copy link
Owner

Dunno. I haven't reviewed this yet. I find the flag name long and overall unwieldy to use IMO. And I'm immediately skeptical of exposing per-match due to the problems with --vimgrep. (The size of the output is worst case quadratic in the size of the input.)

I don't have any timeline on when I'll review this, sorry.

To be clear, I'm open to adding some kind of feature for this functionality.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants