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

Show changes relative to VCS in diagnostics #467

Closed
wants to merge 3 commits into from

Conversation

luctius
Copy link
Contributor

@luctius luctius commented Jul 18, 2021

Because I'm lazy it is for git only for now, and it is only updated when the file is saved.

WIP because my children wake too early and I'm tired.

@kirawi
Copy link
Member

kirawi commented Jul 18, 2021

It would be better to have it as a plugin: #227
Maybe you could look at #455 to help figure out the API needed for this kind of thing.

Comment on lines 19 to 22
LineChange::Added => &"+",
LineChange::RemovedAbove => &"-",
LineChange::RemovedBelow => &"_",
LineChange::Modified => &"~",
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should just use the for add and modify and for blocks removed. UTF-8 characters will look better. And we can make use of colors, like green for added, yellow/orange for modified, red for removed.

Copy link
Member

Choose a reason for hiding this comment

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

I personally prefer:


let g:gitgutter_sign_added = '▌'
let g:gitgutter_sign_removed = '▖'
let g:gitgutter_sign_removed_first_line = '▘'
let g:gitgutter_sign_modified = '▐'
let g:gitgutter_sign_modified_removed = '▞'

with
diff.plus #35BF86
diff.minus #F22C86
diff.delta #6F44F0

Copy link
Contributor Author

Choose a reason for hiding this comment

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

While I like those glyphs, I'm not sure if they are very discoverable to unfamiliar users. That said, I am planning to make them them theme configurable in a separate PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

is confusing, I prefer - or line like for removed, at least it's clearer.

Copy link
Member

Choose a reason for hiding this comment

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

You need to see how it looks visually. is specifically when an area is both deleted and then modified.

Copy link
Member

Choose a reason for hiding this comment

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

Screenshot 2021-07-19 at 23 23 59

In the first purple area, one line was deleted and replaced with a single line. In the second area, multiple lines were deleted and replaced with a single line.

Copy link
Contributor

Choose a reason for hiding this comment

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

Without you explaning, I won't understand what that means.

@pickfire
Copy link
Contributor

It would be good as a plugin but I think this plugin should be bundled by default, since git is very widely used.

@archseer
Copy link
Member

I wonder if https://github.com/Byron/gitoxide might be a better fit to avoid needing to link against openssl/libssh/libz.

@pickfire
Copy link
Contributor

pickfire commented Jul 19, 2021

Can gitoxide do a line diff for file yet? Oh, maybe it can. https://docs.rs/git-diff/0.3.0/git_diff/tree/index.html

@luctius
Copy link
Contributor Author

luctius commented Jul 19, 2021

I will look at gitoxide later; I hadn't realized it provided a goo diff alternative yet. That said; we probably won't need openssh since we don't need to make connections. (I did however forget to disable it... ;-))

@luctius luctius force-pushed the features/git-diff branch from 667d30f to c07e7ef Compare July 19, 2021 12:35
theme.toml Outdated Show resolved Hide resolved
@luctius luctius force-pushed the features/git-diff branch from c07e7ef to d1c25e5 Compare July 19, 2021 13:50
Luctius added 2 commits July 19, 2021 15:59
In this case git, but others are easily added.
@luctius luctius force-pushed the features/git-diff branch from ab6ce71 to 4c4ec7b Compare July 19, 2021 13:59
@luctius luctius changed the title WIP - Show changes relative to VCS in diagnostics Show changes relative to VCS in diagnostics Jul 19, 2021
@luctius luctius marked this pull request as ready for review July 19, 2021 14:05
@luctius
Copy link
Contributor Author

luctius commented Jul 19, 2021

I took a look at gitoxide, but that is still heavily in development; case in point, if I wanted to use git-repository, I had to use the git repo, and I had a conflict with libc when using git-repository, git-diff and chrono.

My suggestion is to take another look after a couple of months and see if things are more stable.

theme.toml Outdated Show resolved Hide resolved
@pickfire
Copy link
Contributor

Why are all of them blue by default?

Screenshot_20210720_131457

Copy link
Contributor

@pickfire pickfire left a comment

Choose a reason for hiding this comment

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

Tested, seemed to show something but default colors seemed to be off. All of them is blue.

The diff also showed out too late, it will only show the current diff after two saves rather than instant after save.

Comment on lines +564 to +566
if let Some(vcs) = &mut self.version_control {
vcs.diff();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the bug that the diff showed out too late is probably because save_impl is asynchronous and this does not triggers render after it is finished.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Any suggestions on how to fix this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I see now that the diff occurs before the async save call, which means it occurs before the file is actually written.
I'm not sure how to fix it in an elegant way yet, but there is progress.

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, forgot to comment here, I think the way to go would be to .and_then the save future, in that closure schedule another callback (using something similar as cx.callback) and modify the document in there.

I'm planning on making this a bit easier to do by introducing hooks, so saving would trigger a hook::DOCUMENT_SAVED and schedule jobs like these.

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 had some time to look at it again.

From what I can see, we need some way to have a job queue with access to the document and which the document can access.

I'm thinking of giving document a jobs queue. This would be similar to how Compositor polls it's layers, now Editor will poll the documents for any jobs.

This would allow us to move several other functions to async, like possibly open and format.

Copy link
Member

Choose a reason for hiding this comment

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

I think we could maybe make the existing jobs queue accessible globally, and in the callback you can simply use a passed in id to find the document (editor.documents[id])

Copy link
Member

Choose a reason for hiding this comment

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

Format already uses the callback system after some of the recent PRs, it receives the changes in a job then applies them to the doc: #285

@archseer
Copy link
Member

The blue is because the scope names don't match anymore I guess. The code will use #0000FF if a scope is missing so you can see something is wrong:

.unwrap_or_else(|| Style::default().fg(Color::Rgb(0, 0, 255)))

(Maybe we should make that bright yellow/red/pink to make it more obvious)

theme.toml Outdated Show resolved Hide resolved
theme.toml Outdated Show resolved Hide resolved
@luctius luctius force-pushed the features/git-diff branch from 5c5ad45 to b67c35e Compare July 20, 2021 06:53
@gbaranski
Copy link
Contributor

wouldn't it be better to make another column for displaying git changes? diagnostics column is very wide. here's how it could look like:
gitsigns_actions
source: https://github.com/lewis6991/gitsigns.nvim

Copy link
Contributor

@pickfire pickfire left a comment

Choose a reason for hiding this comment

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

There are color now but the issue that the displayed vcs is still one save old is still there.

for (i, line) in (view.first_line..last_line).enumerate() {
use helix_core::diagnostic::Severity;
if let Some(line_changes) = doc.vcs_line_changes() {
Copy link
Member

Choose a reason for hiding this comment

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

To address #405, maybe here we could abstract it to simply be doc.line_changes() . It doesn't need to be done in this PR however.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, though I agree that it is probably outside of the scope of this PR.

@luctius
Copy link
Contributor Author

luctius commented Aug 7, 2021

There are color now but the issue that the displayed vcs is still one save old is still there.

As I mentioned above, I am still working this out.

I had some time to look at it again.

From what I can see, we need some way to have a job queue with access to the document and which the document can access.

I'm thinking of giving document a jobs queue. This would be similar to how Compositor polls it's layers, now Editor will poll the documents for any jobs.

This would allow us to move several other functions to async, like possibly open and format.

@pickfire pickfire marked this pull request as draft August 9, 2021 10:38
@zetashift
Copy link
Contributor

I also find the column a bit too wide for my taste, however I'm glad the functionality is being worked on!

@kirawi
Copy link
Member

kirawi commented Oct 31, 2021

There are color now but the issue that the displayed vcs is still one save old is still there.

As I mentioned above, I am still working this out.

I had some time to look at it again.
From what I can see, we need some way to have a job queue with access to the document and which the document can access.
I'm thinking of giving document a jobs queue. This would be similar to how Compositor polls it's layers, now Editor will poll the documents for any jobs.
This would allow us to move several other functions to async, like possibly open and format.

I don't know if you found out or not, but we indeed already have this functionality:

Some(callback) = self.jobs.futures.next() => {
self.jobs.handle_callback(&mut self.editor, &mut self.compositor, callback);
self.render();
}
Some(callback) = self.jobs.wait_futures.next() => {
self.jobs.handle_callback(&mut self.editor, &mut self.compositor, callback);
self.render();
}
_ = &mut self.editor.idle_timer => {
// idle timeout
self.editor.clear_idle_timer();
self.handle_idle_timeout();
}

We already use it for opening and maybe formatting, e.g.

fn write_impl<P: AsRef<Path>>(
cx: &mut compositor::Context,
path: Option<P>,
) -> anyhow::Result<()> {
let jobs = &mut cx.jobs;
let (_, doc) = current!(cx.editor);
if let Some(path) = path {
doc.set_path(Some(path.as_ref()))
.context("invalid filepath")?;
}
if doc.path().is_none() {
bail!("cannot write a buffer without a filename");
}
let fmt = doc.auto_format().map(|fmt| {
let shared = fmt.shared();
let callback = make_format_callback(
doc.id(),
doc.version(),
Modified::SetUnmodified,
shared.clone(),
);
jobs.callback(callback);
shared
});
let future = doc.format_and_save(fmt);
cx.jobs.add(Job::new(future).wait_before_exiting());
Ok(())
}

@archseer archseer mentioned this pull request Nov 25, 2021
@Nehliin
Copy link
Contributor

Nehliin commented Nov 28, 2021

Anyone working on this? I'd really like this functionality pre plugins since the plugin system seems a bit far off. I'd be happy to help on this.

@pickfire
Copy link
Contributor

@Nehliin Seemed like @luctius is not so active lately. Maybe you can take his current patch and rebase it to master and fix the bugs that mentioned here, that can help on this patch.

@Nehliin
Copy link
Contributor

Nehliin commented Nov 29, 2021

I'll take a look then 👍

@the-mikedavis
Copy link
Member

Should we close in favor of #1623?

@the-mikedavis the-mikedavis added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label May 18, 2022
@luctius luctius closed this May 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants