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

feat: adding mini.diff module as inline diff mechanism #210

Merged
merged 7 commits into from
Sep 13, 2024

Conversation

bassamsdata
Copy link
Contributor

Description

Adding the Mini.diff module as an option for the inline feature, offering an alternative to Neovim's original diff mode, which works between two buffers. With this, the diff will appear inline in the same buffer.

Related Issue(s)

The initial discussion happened here: #154
The PR is not finished yet; this is just a starting point. I placed the module in a new file due to its size, making it easier to maintain.

Currently, this PR has the following issues that aren’t working properly:

  • The diff starts but seems to use the wrong original text. It appears the variable original_buffer_content doesn’t capture the correct buffer to compare against (possibly can be retrieved from self.context.lines).
  • As a result, the accept and reject functions don’t work as expected.

Checklist

Copy link
Owner

Choose a reason for hiding this comment

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

I think we should give users the choice of a provider i.e. default or mini_diff. I think we should hardcode the revert_delay in too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a setting called config.display.inline.diff.diff_method that can be set to either default or mini_diff. I'm not sure if this is what you asking for.

I also removed the revert_delay setting and replaced it with a hardcoded value.

@olimorris
Copy link
Owner

This looks really promising. Very exciting to have in the plugin.

Once you're happy with the PR I'll merge into main and then at some point in the future refactor to a Diff class and ensure both the default provider and mini_diff implement the same methods.

@bassamsdata
Copy link
Contributor Author

This PR is ready unless there're other reviews. Here are some notes:

  1. All features like diff against LLMs, gr or ga for reject and accept, work perfectly.
  2. I've added some APIs, like force_git and force_codecompanion, and an API for the statusline diff source (Readme updated).
  3. I've added comments to make the code easier to understand, as well as Lua annotations.

at some point in the future refactor to a Diff class and ensure both the default provider and mini_diff implement the same methods.

  1. I agree. In the future, this module should be more integrated into the plugin. (I've already started a refactor but it will take some time).
  2. I'll be adding the mini.nvim module because some people use the entire mega plugin. (This will be in a separate PR since we need it for mini.pick as well.)

Thank you!

@S1M0N38
Copy link
Contributor

S1M0N38 commented Sep 13, 2024

Great work!

However, I am wondering why CodeCompanion decides to define custom keymaps for reject and accept (gr and ga) instead of using the default ones for operating with diff, i.e. do and dp.

dp does not reject a suggestion but updates the suggestion with the content of the original buffer. This is a way to update the chat context and sync it to the content of the user buffer, so that future requests are based on the correct file content.

Thoughts?

@olimorris
Copy link
Owner

@bassamsdata this look's awesome. Only non-value add ask is if we can rename references such as miniDiff to mini_diff for consistency reasons?

@S1M0N38 haha because the author has absolutely no idea about using diff's in Neovim 😆.

@bassamsdata
Copy link
Contributor Author

if we can rename references such as miniDiff to mini_diff for consistency reasons?

Sure, I made the change right away. I'm juggling multiple things at the moment, including Python, R, Golang, and Lua, so my brain got a bit mixed up since each language prefers a different naming convention. My bad!
So now, everything related to this module is named mini_diff. I kept the mini.diff plugin as MiniDiff since it's part of the plugin’s internal structure, and to help distinguish it from this module.

@S1M0N38 This is cool! I’ve been using Neovim for 2 years, but I haven’t really done any diffing in the editor. It feels like there’s always something new to learn in Neovim.

@olimorris olimorris merged commit a33d4ae into olimorris:main Sep 13, 2024
4 checks passed
@olimorris
Copy link
Owner

@bassamsdata thanks so much. I'll merge now. I've been using Neovim for the best part of 4 years and never even knew diffing could be done natively until I saw @S1M0N38's dante plugin the other week 😆.

@olimorris
Copy link
Owner

Hey @bassamsdata...I've reworked how we handle diff's in version 3.0.0 of the plugin...the result is I've broken your mini_diff integration so I will endeavor to fix that in the coming days!

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.

3 participants