Add git blame (#8889)

This adds a new action to the editor: `editor: toggle git blame`. When
used it turns on a sidebar containing `git blame` information for the
currently open buffer.

The git blame information is updated when the buffer changes. It handles
additions, deletions, modifications, changes to the underlying git data
(new commits, changed commits, ...), file saves. It also handles folding
and wrapping lines correctly.

When the user hovers over a commit, a tooltip displays information for
the commit that introduced the line. If the repository has a remote with
the name `origin` configured, then clicking on a blame entry opens the
permalink to the commit on the code host.

Users can right-click on a blame entry to get a context menu which
allows them to copy the SHA of the commit.

The feature also works on shared projects, e.g. when collaborating a
peer can request `git blame` data.

As of this PR, Zed now comes bundled with a `git` binary so that users
don't have to have `git` installed locally to use this feature.

### Screenshots

![screenshot-2024-03-28-13 57
43@2x](https://github.com/zed-industries/zed/assets/1185253/ee8ec55d-3b5e-4d63-a85a-852da914f5ba)

![screenshot-2024-03-28-14 01
23@2x](https://github.com/zed-industries/zed/assets/1185253/2ba8efd7-e887-4076-a87a-587a732b9e9a)
![screenshot-2024-03-28-14 01
32@2x](https://github.com/zed-industries/zed/assets/1185253/496f4a06-b189-4881-b427-2289ae6e6075)

### TODOs

- [x] Bundling `git` binary

### Release Notes

Release Notes:

- Added `editor: toggle git blame` command that toggles a sidebar with
git blame information for the current buffer.

---------

Co-authored-by: Antonio <antonio@zed.dev>
Co-authored-by: Piotr <piotr@zed.dev>
Co-authored-by: Bennet <bennetbo@gmx.de>
Co-authored-by: Mikayla <mikayla@zed.dev>
This commit is contained in:
Thorsten Ball 2024-03-28 18:32:11 +01:00 committed by GitHub
parent e2d6b0deba
commit 7f54935324
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
39 changed files with 3760 additions and 157 deletions

View file

@ -205,7 +205,10 @@ message Envelope {
CountTokensWithLanguageModel count_tokens_with_language_model = 168;
CountTokensResponse count_tokens_response = 169;
UpdateChannelMessage update_channel_message = 170;
ChannelMessageUpdate channel_message_update = 171; // current max
ChannelMessageUpdate channel_message_update = 171;
BlameBuffer blame_buffer = 172;
BlameBufferResponse blame_buffer_response = 173; // Current max
}
reserved 158 to 161;
@ -1784,3 +1787,48 @@ message CountTokensWithLanguageModel {
message CountTokensResponse {
uint32 token_count = 1;
}
message BlameBuffer {
uint64 project_id = 1;
uint64 buffer_id = 2;
repeated VectorClockEntry version = 3;
}
message BlameEntry {
bytes sha = 1;
uint32 start_line = 2;
uint32 end_line = 3;
uint32 original_line_number = 4;
optional string author = 5;
optional string author_mail = 6;
optional int64 author_time = 7;
optional string author_tz = 8;
optional string committer = 9;
optional string committer_mail = 10;
optional int64 committer_time = 11;
optional string committer_tz = 12;
optional string summary = 13;
optional string previous = 14;
string filename = 15;
}
message CommitMessage {
bytes oid = 1;
string message = 2;
}
message CommitPermalink {
bytes oid = 1;
string permalink = 2;
}
message BlameBufferResponse {
repeated BlameEntry entries = 1;
repeated CommitMessage messages = 2;
repeated CommitPermalink permalinks = 3;
}

View file

@ -296,6 +296,8 @@ messages!(
(LspExtExpandMacro, Background),
(LspExtExpandMacroResponse, Background),
(SetRoomParticipantRole, Foreground),
(BlameBuffer, Foreground),
(BlameBufferResponse, Foreground),
);
request_messages!(
@ -386,6 +388,7 @@ request_messages!(
(UpdateWorktree, Ack),
(LspExtExpandMacro, LspExtExpandMacroResponse),
(SetRoomParticipantRole, Ack),
(BlameBuffer, BlameBufferResponse),
);
entity_messages!(
@ -393,6 +396,7 @@ entity_messages!(
AddProjectCollaborator,
ApplyCodeAction,
ApplyCompletionAdditionalEdits,
BlameBuffer,
BufferReloaded,
BufferSaved,
CopyProjectEntry,