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

Rewrap not working on git commits #24987

Closed
dlight opened this issue Feb 16, 2025 · 7 comments · Fixed by #25260
Closed

Rewrap not working on git commits #24987

dlight opened this issue Feb 16, 2025 · 7 comments · Fixed by #25260

Comments

@dlight
Copy link

dlight commented Feb 16, 2025

Summary

Rewrap doesn't work if the language is set to Git Commit.

Steps to trigger the problem:

  1. Open a git commit (typically by running something like GIT_EDITOR='zeditor -w' git commit --amend)

  2. Run the command editor::Rewrap (typically by Pressing ctrl+k q or ctrl+k ctrl+q)

  3. See that lines don't rewrap. (Some styles enforce a maximum line width on git commits, a common value is 72 chars)

  4. In despair, change the language with Ctrl+K M (language_selector::Toggle) and select "Plain Text". Now the text rewraps fine (albeit at 80 lines - I can't find a way to configure line widths per-language, which is a separate issue but relatively minor)

Actual Behavior:

Lines don't rewrap with the language is "Git Commit"

Expected Behavior:

Lines should rewrap for git commits. A bonus feature is to make 72 chars the default for git commits specifically (but let the user configure)

Zed Version and System Specs

Zed: v0.173.9 (Zed)
OS: Linux X11 arch unknown
Memory: 18.9 GiB
Architecture: x86_64
GPU: AMD Radeon Graphics (RADV RENOIR) || radv || Mesa 24.3.4-arch1.1

@dlight
Copy link
Author

dlight commented Feb 16, 2025

I want to fix this if possible! But I can't find what part of the code controls or influences whether a give language will rewrap properly or not.

I can find this directory that defines the Git Commit language, that was merged just 2 weeks ago in #24274 (ping @SomeoneToIgnore maybe? Sorry if that's not appropriate), and I see it uses a tree sitter grammar from here. And I think that rewrap is implemented here. But, I'm not sure how to investigate this issue further.

@SomeoneToIgnore
Copy link
Contributor

Sorry, I have no clue on how rewrap in Zed works and why language selection might influence that.

And I think that rewrap is implemented here.

That place is quite deep into the impl and might not be the culprit.
I would suggest starting from the very top, in the editor,

pub fn rewrap_impl(&mut self, is_vim_mode: IsVimMode, cx: &mut Context<Self>) {

and debug that further and see why things are not working for this case.
should_rewrap is something worth checking specifically, as it seems that it could be false for this case for some reason (which we might want to check).

@marcospb19
Copy link
Contributor

I found this language-specific setting:

/// The column at which to soft-wrap lines, for buffers where soft-wrap
/// is enabled.
pub preferred_line_length: u32,

The docs say it's wired to soft wrap but it ideally would be wired to the rewrap too, I guess.

@SomeoneToIgnore
Copy link
Contributor

#25173 seems very related.

@maxdeviant
Copy link
Member

#25173 seems very related.

Indeed, it is quite related!

Once #25173 makes its way into a release you'll be able to add the following to your settings to enable rewrapping in buffers using the "Git Commit" language:

{
  "languages": {
    "Git Commit": {
      "allow_rewrap": "anywhere"
    }
  }
}

@marcospb19
Copy link
Contributor

marcospb19 commented Feb 19, 2025

@maxdeviant shouldn't that be the default?

@dlight
Copy link
Author

dlight commented Feb 20, 2025

Indeed

The global default is in_comment, as it is the most conservative option and allows rewrapping comments without risking breaking other syntax.

The Markdown and Plain Text languages default to anywhere, which mirrors the previous behavior for those language that was hard-coded into the rewrap implementation.

It seems that Git Commit should also enable "anywhere" by default, using the same rationale as "Plain Text" and "Markdown"

maxdeviant added a commit that referenced this issue Feb 20, 2025
…25260)

This PR makes `"allow_rewrap": "anywhere"` the default for "Git Commit"
files.

Closes #24987.

Release Notes:

- N/A
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 a pull request may close this issue.

4 participants