Skip to content

Add inline blame (like in VSCode) #66

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

Merged
merged 8 commits into from
Jun 6, 2021
Merged

Conversation

biozz
Copy link
Contributor

@biozz biozz commented Jun 3, 2021

Closes #24.

This is basically a rewrite of #27 with a couple of minor changes:

  • I didn't add multiline support as @psykzz did, because this is not how GitLens works (it always shows blame on one line)
  • Added threading with a configurable timer delay, which fixes the annoyance of blinking blame while typing
  • Added global setting to enable/disable this feature (enabled by default)

There are also several caveats, some of which were discussed in previous issues and PRs:

  • Weird behavior of phantoms on an empty line is not fixed, I just skip those
  • There is still some cursor jumping when adding text on empty lines
  • I was not able to add summary to the output, because I think get_blame_textfirst needs a major rewrite without regex and use -P flag of git blame (I am willing to contribute here as well)
  • The text color is hard-coded in, so it will work properly only for dark color schemes

Things I want to improve after the general idea is accepted:

  • Add pretty date formatting, like in vscode, ex. "3 days ago" instead of "2021-05-01 10:00:12+0300"
  • Add buttons to phantoms to show full blame or mimic hover effect like in vscode

I am open to any discussion and willing to change the names of the variables as maintainers feel more comfortable with. I was not sure about the code style, because I didn't find any guides, but I can reformat as you wish.

inline_blame

PS: because of the file structure of the plugin it was very inconvenient to develop, I had to move code around and restart sublime text. Was this a deliberate decision? Sorry for the rant.

@todo
Copy link

todo bot commented Jun 3, 2021

add pretty format of the date, like "3 days ago"

# TODO: add pretty format of the date, like "3 days ago"
date=blame['date'],
time=blame['time'] + blame['timezone'],
# TODO: add first line of the commit here, but
# it requires porcelain format of git blame
# and further refactoring of BaseBlame


This comment was generated by todo based on a TODO comment in 43887f5 in #66. cc @biozz.

@todo
Copy link

todo bot commented Jun 3, 2021

add first line of the commit here, but

# TODO: add first line of the commit here, but
# it requires porcelain format of git blame
# and further refactoring of BaseBlame
)
phantom = sublime.Phantom(anchor, body, sublime.LAYOUT_INLINE)
phantoms.append(phantom)


This comment was generated by todo based on a TODO comment in 43887f5 in #66. cc @biozz.

@frou
Copy link
Owner

frou commented Jun 3, 2021

Thanks for this. I will give it a try and get back to you. Just to answer the two questions:

I am open to any discussion and willing to change the names of the variables as maintainers feel more comfortable with. I was not sure about the code style, because I didn't find any guides, but I can reformat as you wish.

You could format it with black but it's not essential.

PS: because of the file structure of the plugin it was very inconvenient to develop, I had to move code around and restart sublime text. Was this a deliberate decision? Sorry for the rant.

The source files are organised like this so that there is only a single "plugin" in Sublime terms (boot.py) and the rest of the code is effectively a library for use by that plugin. The AutomaticPackageReloader takes care of reloading code (in proper dependency order) when any .py file is modified. Indeed I should mention that it's recommended somewhere.

Repository owner deleted a comment from todo bot Jun 3, 2021
@biozz
Copy link
Contributor Author

biozz commented Jun 4, 2021

@frou AtomicPackageReloader works like a charm, thank you for the suggestion!

If you want, I can push another PR explaining how to set up a local development environment for this plugin.

Repository owner deleted a comment from todo bot Jun 4, 2021
@frou
Copy link
Owner

frou commented Jun 4, 2021

After trying this some more, the main thing I notice is due to the fact that on_selection_modified gets ran in 2 different (but related) situations:

  • (A) When the cursor/caret is moved using the arrow keys or mouse.
  • (B) When the cursor/caret is moved because the user is writing or deleting text.

Situation (A) is useful and expected. But I don't think the Inline Blame should be shown in situation (B), both because it's distracting, and because it shows incorrect information. For example, in your GIF, it shows me as being the committer of asdfafsadf, but that was never committed by anyone.

More generally, we can say that that it doesn't make sense to show any blame information while the file has unsaved edits. This already came up with the existing blame modes.

Please give my latest commit a try. Basically, whenever the file has unsaved edits, you need to save it to disk before you'll be shown any Inline Blame.

If you want, I can push another PR explaining how to set up a local development environment for this plugin.

That's alright - I'll do something about that later

Repository owner deleted a comment from todo bot Jun 4, 2021
@todo
Copy link

todo bot commented Jun 4, 2021

add pretty format of the date, like "3 days ago"

# TODO: add pretty format of the date, like "3 days ago"
date=blame["date"],
time=blame["time"] + blame["timezone"],
# TODO: add first line of the commit here, but
# it requires porcelain format of git blame
# and further refactoring of BaseBlame


This comment was generated by todo based on a TODO comment in 8702020 in #66. cc @biozz.

@biozz
Copy link
Contributor Author

biozz commented Jun 4, 2021

I was actually struggling with fixing this behavior, but you did it and looks good.

I tried it and noticed that after I save the file the blame doesn't show, but VSCode does show it. And I think the user also expects it to appear after save. So I added another signal and moved common logic to a separate method.

@frou
Copy link
Owner

frou commented Jun 4, 2021

Ah, good catch.

Another improvement might be to detect the string "Not Committed Yet" and suppress the phantom then too. Because the lines in the gutter (the "mini_diff" indicators) are already sufficient.

About the colour of the inline blame text... the hex twiddling is fun, but how about instead just going for a variation on blue, like this the rest of this package's UI already does? Something like color: color(var(--bluish) blend(var(--background) 60%));

p.s. Sorry for the todo[bot] misbehaving. The actual purpose of that bot is to turn any todo that is committed on master into its own Issue.

@todo
Copy link

todo bot commented Jun 4, 2021

add pretty format of the date, like "3 days ago"

# TODO: add pretty format of the date, like "3 days ago"
date=blame["date"],
time=blame["time"] + blame["timezone"],
# TODO: add first line of the commit here, but
# it requires porcelain format of git blame
# and further refactoring of BaseBlame


This comment was generated by todo based on a TODO comment in 36bf31b in #66. cc @biozz.

@biozz
Copy link
Contributor Author

biozz commented Jun 4, 2021

how about instead just going for a variation on blue, like this the rest of this package's UI already does?

Sure

detect the string "Not Committed Yet" and suppress the phantom

This depends on the purpose. If we want this plugin to mimic VSCodes', then it should always show. But if you insist, the condition is simple enough (I would rather compare with sha equals to zeros).

@frou
Copy link
Owner

frou commented Jun 4, 2021

Nah, I don't feel strongly about that.

I'm happy to merge this (perhaps with some more of the refinements you mentioned in the OP).

I don't think I would leave Inline Blame enabled by default though. Because this package already has (AFAIK) thousands of users who are accustomed to the "unobtrusive" mode of operation, and we know how people get angry if the UI of their software changes significantly. Still, all the users can be told about the new feature in the package update message, and encouraged to try it by editing their settings.

@biozz
Copy link
Contributor Author

biozz commented Jun 5, 2021

This last commit had me move code around quite a bit. Sorry for the growing diff!

  • Added relative date to inline blames

For this I had to duplicate the parser and replace date parts with relative date. This not very pretty, as I rely on ago string, which should do 99% of the time, but there is also in the future, and I am not sure how other languages are going to work. But in these cases it will just gracefully fallback to an empty string.

My original plan to use porcelain format would require to add a copy of the pretty date formatter, so I think extra regex is a good trade-of here.

  • Added summary to inline blames

Because clickable URLs inside the phantom should be the same, I moved handle_phantom_button callback into the base class. I tried to keep the naming of href elements style as close to the original as possible.

And that's about it, all of my original ideas are implemented. Please feel free to add any final touches.

@frou frou merged commit f4dc2aa into frou:master Jun 6, 2021
@frou
Copy link
Owner

frou commented Jun 6, 2021

Thanks for your work on this. I will probably tweak this (and some other stuff) a bit, and make sure everything still works on ST3, etc. So the new release of the package won't come for a little while.

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.

GitLens like functionality
2 participants