1#![allow(non_snake_case)]
2
3pub mod error;
4mod macros;
5mod typed_envelope;
6
7pub use error::*;
8pub use prost::{DecodeError, Message};
9use std::{
10 cmp,
11 fmt::Debug,
12 iter, mem,
13 time::{Duration, SystemTime, UNIX_EPOCH},
14};
15pub use typed_envelope::*;
16
17include!(concat!(env!("OUT_DIR"), "/zed.messages.rs"));
18
19pub const SSH_PEER_ID: PeerId = PeerId { owner_id: 0, id: 0 };
20pub const SSH_PROJECT_ID: u64 = 0;
21
22messages!(
23 (AcceptTermsOfService, Foreground),
24 (AcceptTermsOfServiceResponse, Foreground),
25 (Ack, Foreground),
26 (AckBufferOperation, Background),
27 (AckChannelMessage, Background),
28 (ActivateToolchain, Foreground),
29 (ActiveToolchain, Foreground),
30 (ActiveToolchainResponse, Foreground),
31 (AddNotification, Foreground),
32 (AddProjectCollaborator, Foreground),
33 (AddWorktree, Foreground),
34 (AddWorktreeResponse, Foreground),
35 (AdvertiseContexts, Foreground),
36 (ApplyCodeAction, Background),
37 (ApplyCodeActionResponse, Background),
38 (ApplyCompletionAdditionalEdits, Background),
39 (ApplyCompletionAdditionalEditsResponse, Background),
40 (BlameBuffer, Foreground),
41 (BlameBufferResponse, Foreground),
42 (BufferReloaded, Foreground),
43 (BufferSaved, Foreground),
44 (Call, Foreground),
45 (CallCanceled, Foreground),
46 (CancelCall, Foreground),
47 (CancelLanguageServerWork, Foreground),
48 (ChannelMessageSent, Foreground),
49 (ChannelMessageUpdate, Foreground),
50 (CloseBuffer, Foreground),
51 (Commit, Background),
52 (CopyProjectEntry, Foreground),
53 (CountLanguageModelTokens, Background),
54 (CountLanguageModelTokensResponse, Background),
55 (CreateBufferForPeer, Foreground),
56 (CreateChannel, Foreground),
57 (CreateChannelResponse, Foreground),
58 (CreateContext, Foreground),
59 (CreateContextResponse, Foreground),
60 (CreateProjectEntry, Foreground),
61 (CreateRoom, Foreground),
62 (CreateRoomResponse, Foreground),
63 (DeclineCall, Foreground),
64 (DeleteChannel, Foreground),
65 (DeleteNotification, Foreground),
66 (DeleteProjectEntry, Foreground),
67 (EndStream, Foreground),
68 (Error, Foreground),
69 (ExpandProjectEntry, Foreground),
70 (ExpandProjectEntryResponse, Foreground),
71 (FindSearchCandidatesResponse, Background),
72 (FindSearchCandidates, Background),
73 (FlushBufferedMessages, Foreground),
74 (ExpandAllForProjectEntry, Foreground),
75 (ExpandAllForProjectEntryResponse, Foreground),
76 (Follow, Foreground),
77 (FollowResponse, Foreground),
78 (ApplyCodeActionKind, Foreground),
79 (ApplyCodeActionKindResponse, Foreground),
80 (FormatBuffers, Foreground),
81 (FormatBuffersResponse, Foreground),
82 (FuzzySearchUsers, Foreground),
83 (GetChannelMembers, Foreground),
84 (GetChannelMembersResponse, Foreground),
85 (GetChannelMessages, Background),
86 (GetChannelMessagesById, Background),
87 (GetChannelMessagesResponse, Background),
88 (GetCodeActions, Background),
89 (GetCodeActionsResponse, Background),
90 (GetCompletions, Background),
91 (GetCompletionsResponse, Background),
92 (GetDeclaration, Background),
93 (GetDeclarationResponse, Background),
94 (GetDefinition, Background),
95 (GetDefinitionResponse, Background),
96 (GetDocumentHighlights, Background),
97 (GetDocumentHighlightsResponse, Background),
98 (GetDocumentSymbols, Background),
99 (GetDocumentSymbolsResponse, Background),
100 (GetHover, Background),
101 (GetHoverResponse, Background),
102 (GetNotifications, Foreground),
103 (GetNotificationsResponse, Foreground),
104 (GetPanicFiles, Background),
105 (GetPanicFilesResponse, Background),
106 (GetPathMetadata, Background),
107 (GetPathMetadataResponse, Background),
108 (GetPermalinkToLine, Foreground),
109 (GetPermalinkToLineResponse, Foreground),
110 (GetPrivateUserInfo, Foreground),
111 (GetPrivateUserInfoResponse, Foreground),
112 (GetProjectSymbols, Background),
113 (GetProjectSymbolsResponse, Background),
114 (GetReferences, Background),
115 (GetReferencesResponse, Background),
116 (GetSignatureHelp, Background),
117 (GetSignatureHelpResponse, Background),
118 (GetSupermavenApiKey, Background),
119 (GetSupermavenApiKeyResponse, Background),
120 (GetTypeDefinition, Background),
121 (GetTypeDefinitionResponse, Background),
122 (GetImplementation, Background),
123 (GetImplementationResponse, Background),
124 (GetLlmToken, Background),
125 (GetLlmTokenResponse, Background),
126 (LanguageServerIdForName, Background),
127 (LanguageServerIdForNameResponse, Background),
128 (OpenUnstagedDiff, Foreground),
129 (OpenUnstagedDiffResponse, Foreground),
130 (OpenUncommittedDiff, Foreground),
131 (OpenUncommittedDiffResponse, Foreground),
132 (GetUsers, Foreground),
133 (GitGetBranches, Background),
134 (GitBranchesResponse, Background),
135 (Hello, Foreground),
136 (HideToast, Background),
137 (IncomingCall, Foreground),
138 (InlayHints, Background),
139 (InlayHintsResponse, Background),
140 (InstallExtension, Background),
141 (InviteChannelMember, Foreground),
142 (JoinChannel, Foreground),
143 (JoinChannelBuffer, Foreground),
144 (JoinChannelBufferResponse, Foreground),
145 (JoinChannelChat, Foreground),
146 (JoinChannelChatResponse, Foreground),
147 (JoinProject, Foreground),
148 (JoinProjectResponse, Foreground),
149 (JoinRoom, Foreground),
150 (JoinRoomResponse, Foreground),
151 (LanguageServerLog, Foreground),
152 (LanguageServerPromptRequest, Foreground),
153 (LanguageServerPromptResponse, Foreground),
154 (LeaveChannelBuffer, Background),
155 (LeaveChannelChat, Foreground),
156 (LeaveProject, Foreground),
157 (LeaveRoom, Foreground),
158 (LinkedEditingRange, Background),
159 (LinkedEditingRangeResponse, Background),
160 (ListRemoteDirectory, Background),
161 (ListRemoteDirectoryResponse, Background),
162 (ListToolchains, Foreground),
163 (ListToolchainsResponse, Foreground),
164 (LoadCommitDiff, Foreground),
165 (LoadCommitDiffResponse, Foreground),
166 (LspExtExpandMacro, Background),
167 (LspExtExpandMacroResponse, Background),
168 (LspExtOpenDocs, Background),
169 (LspExtOpenDocsResponse, Background),
170 (LspExtRunnables, Background),
171 (LspExtRunnablesResponse, Background),
172 (LspExtSwitchSourceHeader, Background),
173 (LspExtSwitchSourceHeaderResponse, Background),
174 (MarkNotificationRead, Foreground),
175 (MoveChannel, Foreground),
176 (MultiLspQuery, Background),
177 (MultiLspQueryResponse, Background),
178 (OnTypeFormatting, Background),
179 (OnTypeFormattingResponse, Background),
180 (OpenBufferById, Background),
181 (OpenBufferByPath, Background),
182 (OpenBufferForSymbol, Background),
183 (OpenBufferForSymbolResponse, Background),
184 (OpenBufferResponse, Background),
185 (OpenCommitMessageBuffer, Background),
186 (OpenContext, Foreground),
187 (OpenContextResponse, Foreground),
188 (OpenNewBuffer, Foreground),
189 (OpenServerSettings, Foreground),
190 (PerformRename, Background),
191 (PerformRenameResponse, Background),
192 (Ping, Foreground),
193 (PrepareRename, Background),
194 (PrepareRenameResponse, Background),
195 (ProjectEntryResponse, Foreground),
196 (RefreshInlayHints, Foreground),
197 (RefreshLlmToken, Background),
198 (RegisterBufferWithLanguageServers, Background),
199 (RejoinChannelBuffers, Foreground),
200 (RejoinChannelBuffersResponse, Foreground),
201 (RejoinRemoteProjects, Foreground),
202 (RejoinRemoteProjectsResponse, Foreground),
203 (RejoinRoom, Foreground),
204 (RejoinRoomResponse, Foreground),
205 (ReloadBuffers, Foreground),
206 (ReloadBuffersResponse, Foreground),
207 (RemoveChannelMember, Foreground),
208 (RemoveChannelMessage, Foreground),
209 (RemoveContact, Foreground),
210 (RemoveProjectCollaborator, Foreground),
211 (RemoveWorktree, Foreground),
212 (RenameChannel, Foreground),
213 (RenameChannelResponse, Foreground),
214 (RenameProjectEntry, Foreground),
215 (RequestContact, Foreground),
216 (ResolveCompletionDocumentation, Background),
217 (ResolveCompletionDocumentationResponse, Background),
218 (ResolveInlayHint, Background),
219 (ResolveInlayHintResponse, Background),
220 (RefreshCodeLens, Background),
221 (GetCodeLens, Background),
222 (GetCodeLensResponse, Background),
223 (RespondToChannelInvite, Foreground),
224 (RespondToContactRequest, Foreground),
225 (RestartLanguageServers, Foreground),
226 (StopLanguageServers, Background),
227 (RoomUpdated, Foreground),
228 (SaveBuffer, Foreground),
229 (SendChannelMessage, Background),
230 (SendChannelMessageResponse, Background),
231 (SetChannelMemberRole, Foreground),
232 (SetChannelVisibility, Foreground),
233 (SetRoomParticipantRole, Foreground),
234 (ShareProject, Foreground),
235 (ShareProjectResponse, Foreground),
236 (ShowContacts, Foreground),
237 (ShutdownRemoteServer, Foreground),
238 (Stage, Background),
239 (StartLanguageServer, Foreground),
240 (SubscribeToChannels, Foreground),
241 (SyncExtensions, Background),
242 (SyncExtensionsResponse, Background),
243 (BreakpointsForFile, Background),
244 (ToggleBreakpoint, Foreground),
245 (SynchronizeBuffers, Foreground),
246 (SynchronizeBuffersResponse, Foreground),
247 (SynchronizeContexts, Foreground),
248 (SynchronizeContextsResponse, Foreground),
249 (TaskContext, Background),
250 (TaskContextForLocation, Background),
251 (Test, Foreground),
252 (Toast, Background),
253 (Unfollow, Foreground),
254 (UnshareProject, Foreground),
255 (Unstage, Background),
256 (UpdateBuffer, Foreground),
257 (UpdateBufferFile, Foreground),
258 (UpdateChannelBuffer, Foreground),
259 (UpdateChannelBufferCollaborators, Foreground),
260 (UpdateChannelMessage, Foreground),
261 (UpdateChannels, Foreground),
262 (UpdateContacts, Foreground),
263 (UpdateContext, Foreground),
264 (UpdateDiagnosticSummary, Foreground),
265 (UpdateDiffBases, Foreground),
266 (UpdateFollowers, Foreground),
267 (UpdateGitBranch, Background),
268 (UpdateInviteInfo, Foreground),
269 (UpdateLanguageServer, Foreground),
270 (UpdateNotification, Foreground),
271 (UpdateParticipantLocation, Foreground),
272 (UpdateProject, Foreground),
273 (UpdateProjectCollaborator, Foreground),
274 (UpdateUserChannels, Foreground),
275 (UpdateUserPlan, Foreground),
276 (UpdateWorktree, Foreground),
277 (UpdateWorktreeSettings, Foreground),
278 (UpdateRepository, Foreground),
279 (RemoveRepository, Foreground),
280 (UsersResponse, Foreground),
281 (GitReset, Background),
282 (GitCheckoutFiles, Background),
283 (GitShow, Background),
284 (GitCommitDetails, Background),
285 (SetIndexText, Background),
286 (Push, Background),
287 (Fetch, Background),
288 (GetRemotes, Background),
289 (GetRemotesResponse, Background),
290 (Pull, Background),
291 (RemoteMessageResponse, Background),
292 (AskPassRequest, Background),
293 (AskPassResponse, Background),
294 (GitCreateBranch, Background),
295 (GitChangeBranch, Background),
296 (CheckForPushedCommits, Background),
297 (CheckForPushedCommitsResponse, Background),
298 (GitDiff, Background),
299 (GitDiffResponse, Background),
300 (GitInit, Background),
301 (GetDebugAdapterBinary, Background),
302 (DebugAdapterBinary, Background),
303 (RunDebugLocator, Background),
304 (DebugTaskDefinition, Background),
305);
306
307request_messages!(
308 (AcceptTermsOfService, AcceptTermsOfServiceResponse),
309 (ApplyCodeAction, ApplyCodeActionResponse),
310 (
311 ApplyCompletionAdditionalEdits,
312 ApplyCompletionAdditionalEditsResponse
313 ),
314 (Call, Ack),
315 (CancelCall, Ack),
316 (Commit, Ack),
317 (CopyProjectEntry, ProjectEntryResponse),
318 (CreateChannel, CreateChannelResponse),
319 (CreateProjectEntry, ProjectEntryResponse),
320 (CreateRoom, CreateRoomResponse),
321 (DeclineCall, Ack),
322 (DeleteChannel, Ack),
323 (DeleteProjectEntry, ProjectEntryResponse),
324 (ExpandProjectEntry, ExpandProjectEntryResponse),
325 (ExpandAllForProjectEntry, ExpandAllForProjectEntryResponse),
326 (Follow, FollowResponse),
327 (ApplyCodeActionKind, ApplyCodeActionKindResponse),
328 (FormatBuffers, FormatBuffersResponse),
329 (FuzzySearchUsers, UsersResponse),
330 (GetChannelMembers, GetChannelMembersResponse),
331 (GetChannelMessages, GetChannelMessagesResponse),
332 (GetChannelMessagesById, GetChannelMessagesResponse),
333 (GetCodeActions, GetCodeActionsResponse),
334 (GetCompletions, GetCompletionsResponse),
335 (GetDefinition, GetDefinitionResponse),
336 (GetDeclaration, GetDeclarationResponse),
337 (GetImplementation, GetImplementationResponse),
338 (GetDocumentHighlights, GetDocumentHighlightsResponse),
339 (GetDocumentSymbols, GetDocumentSymbolsResponse),
340 (GetHover, GetHoverResponse),
341 (GetLlmToken, GetLlmTokenResponse),
342 (GetNotifications, GetNotificationsResponse),
343 (GetPrivateUserInfo, GetPrivateUserInfoResponse),
344 (GetProjectSymbols, GetProjectSymbolsResponse),
345 (GetReferences, GetReferencesResponse),
346 (GetSignatureHelp, GetSignatureHelpResponse),
347 (OpenUnstagedDiff, OpenUnstagedDiffResponse),
348 (OpenUncommittedDiff, OpenUncommittedDiffResponse),
349 (GetSupermavenApiKey, GetSupermavenApiKeyResponse),
350 (GetTypeDefinition, GetTypeDefinitionResponse),
351 (LinkedEditingRange, LinkedEditingRangeResponse),
352 (ListRemoteDirectory, ListRemoteDirectoryResponse),
353 (GetUsers, UsersResponse),
354 (IncomingCall, Ack),
355 (InlayHints, InlayHintsResponse),
356 (GetCodeLens, GetCodeLensResponse),
357 (InviteChannelMember, Ack),
358 (JoinChannel, JoinRoomResponse),
359 (JoinChannelBuffer, JoinChannelBufferResponse),
360 (JoinChannelChat, JoinChannelChatResponse),
361 (JoinProject, JoinProjectResponse),
362 (JoinRoom, JoinRoomResponse),
363 (LeaveChannelBuffer, Ack),
364 (LeaveRoom, Ack),
365 (LoadCommitDiff, LoadCommitDiffResponse),
366 (MarkNotificationRead, Ack),
367 (MoveChannel, Ack),
368 (OnTypeFormatting, OnTypeFormattingResponse),
369 (OpenBufferById, OpenBufferResponse),
370 (OpenBufferByPath, OpenBufferResponse),
371 (OpenBufferForSymbol, OpenBufferForSymbolResponse),
372 (OpenCommitMessageBuffer, OpenBufferResponse),
373 (OpenNewBuffer, OpenBufferResponse),
374 (PerformRename, PerformRenameResponse),
375 (Ping, Ack),
376 (PrepareRename, PrepareRenameResponse),
377 (CountLanguageModelTokens, CountLanguageModelTokensResponse),
378 (RefreshInlayHints, Ack),
379 (RefreshCodeLens, Ack),
380 (RejoinChannelBuffers, RejoinChannelBuffersResponse),
381 (RejoinRoom, RejoinRoomResponse),
382 (ReloadBuffers, ReloadBuffersResponse),
383 (RemoveChannelMember, Ack),
384 (RemoveChannelMessage, Ack),
385 (UpdateChannelMessage, Ack),
386 (RemoveContact, Ack),
387 (RenameChannel, RenameChannelResponse),
388 (RenameProjectEntry, ProjectEntryResponse),
389 (RequestContact, Ack),
390 (
391 ResolveCompletionDocumentation,
392 ResolveCompletionDocumentationResponse
393 ),
394 (ResolveInlayHint, ResolveInlayHintResponse),
395 (RespondToChannelInvite, Ack),
396 (RespondToContactRequest, Ack),
397 (SaveBuffer, BufferSaved),
398 (Stage, Ack),
399 (FindSearchCandidates, FindSearchCandidatesResponse),
400 (SendChannelMessage, SendChannelMessageResponse),
401 (SetChannelMemberRole, Ack),
402 (SetChannelVisibility, Ack),
403 (ShareProject, ShareProjectResponse),
404 (SynchronizeBuffers, SynchronizeBuffersResponse),
405 (TaskContextForLocation, TaskContext),
406 (Test, Test),
407 (Unstage, Ack),
408 (UpdateBuffer, Ack),
409 (UpdateParticipantLocation, Ack),
410 (UpdateProject, Ack),
411 (UpdateWorktree, Ack),
412 (UpdateRepository, Ack),
413 (RemoveRepository, Ack),
414 (LanguageServerIdForName, LanguageServerIdForNameResponse),
415 (LspExtExpandMacro, LspExtExpandMacroResponse),
416 (LspExtOpenDocs, LspExtOpenDocsResponse),
417 (LspExtRunnables, LspExtRunnablesResponse),
418 (SetRoomParticipantRole, Ack),
419 (BlameBuffer, BlameBufferResponse),
420 (RejoinRemoteProjects, RejoinRemoteProjectsResponse),
421 (MultiLspQuery, MultiLspQueryResponse),
422 (RestartLanguageServers, Ack),
423 (StopLanguageServers, Ack),
424 (OpenContext, OpenContextResponse),
425 (CreateContext, CreateContextResponse),
426 (SynchronizeContexts, SynchronizeContextsResponse),
427 (LspExtSwitchSourceHeader, LspExtSwitchSourceHeaderResponse),
428 (AddWorktree, AddWorktreeResponse),
429 (ShutdownRemoteServer, Ack),
430 (RemoveWorktree, Ack),
431 (OpenServerSettings, OpenBufferResponse),
432 (GetPermalinkToLine, GetPermalinkToLineResponse),
433 (FlushBufferedMessages, Ack),
434 (LanguageServerPromptRequest, LanguageServerPromptResponse),
435 (GitGetBranches, GitBranchesResponse),
436 (UpdateGitBranch, Ack),
437 (ListToolchains, ListToolchainsResponse),
438 (ActivateToolchain, Ack),
439 (ActiveToolchain, ActiveToolchainResponse),
440 (GetPathMetadata, GetPathMetadataResponse),
441 (GetPanicFiles, GetPanicFilesResponse),
442 (CancelLanguageServerWork, Ack),
443 (SyncExtensions, SyncExtensionsResponse),
444 (InstallExtension, Ack),
445 (RegisterBufferWithLanguageServers, Ack),
446 (GitShow, GitCommitDetails),
447 (GitReset, Ack),
448 (GitCheckoutFiles, Ack),
449 (SetIndexText, Ack),
450 (Push, RemoteMessageResponse),
451 (Fetch, RemoteMessageResponse),
452 (GetRemotes, GetRemotesResponse),
453 (Pull, RemoteMessageResponse),
454 (AskPassRequest, AskPassResponse),
455 (GitCreateBranch, Ack),
456 (GitChangeBranch, Ack),
457 (CheckForPushedCommits, CheckForPushedCommitsResponse),
458 (GitDiff, GitDiffResponse),
459 (GitInit, Ack),
460 (ToggleBreakpoint, Ack),
461 (GetDebugAdapterBinary, DebugAdapterBinary),
462 (RunDebugLocator, DebugTaskDefinition),
463);
464
465entity_messages!(
466 {project_id, ShareProject},
467 AddProjectCollaborator,
468 AddWorktree,
469 ApplyCodeAction,
470 ApplyCompletionAdditionalEdits,
471 BlameBuffer,
472 BufferReloaded,
473 BufferSaved,
474 CloseBuffer,
475 Commit,
476 CopyProjectEntry,
477 CreateBufferForPeer,
478 CreateProjectEntry,
479 DeleteProjectEntry,
480 ExpandProjectEntry,
481 ExpandAllForProjectEntry,
482 FindSearchCandidates,
483 ApplyCodeActionKind,
484 FormatBuffers,
485 GetCodeActions,
486 GetCodeLens,
487 GetCompletions,
488 GetDefinition,
489 GetDeclaration,
490 GetImplementation,
491 GetDocumentHighlights,
492 GetDocumentSymbols,
493 GetHover,
494 GetProjectSymbols,
495 GetReferences,
496 GetSignatureHelp,
497 OpenUnstagedDiff,
498 OpenUncommittedDiff,
499 GetTypeDefinition,
500 InlayHints,
501 JoinProject,
502 LeaveProject,
503 LinkedEditingRange,
504 LoadCommitDiff,
505 MultiLspQuery,
506 RestartLanguageServers,
507 StopLanguageServers,
508 OnTypeFormatting,
509 OpenNewBuffer,
510 OpenBufferById,
511 OpenBufferByPath,
512 OpenBufferForSymbol,
513 OpenCommitMessageBuffer,
514 PerformRename,
515 PrepareRename,
516 RefreshInlayHints,
517 RefreshCodeLens,
518 ReloadBuffers,
519 RemoveProjectCollaborator,
520 RenameProjectEntry,
521 ResolveCompletionDocumentation,
522 ResolveInlayHint,
523 SaveBuffer,
524 Stage,
525 StartLanguageServer,
526 SynchronizeBuffers,
527 TaskContextForLocation,
528 UnshareProject,
529 Unstage,
530 UpdateBuffer,
531 UpdateBufferFile,
532 UpdateDiagnosticSummary,
533 UpdateDiffBases,
534 UpdateLanguageServer,
535 UpdateProject,
536 UpdateProjectCollaborator,
537 UpdateWorktree,
538 UpdateRepository,
539 RemoveRepository,
540 UpdateWorktreeSettings,
541 LspExtExpandMacro,
542 LspExtOpenDocs,
543 LspExtRunnables,
544 AdvertiseContexts,
545 OpenContext,
546 CreateContext,
547 UpdateContext,
548 SynchronizeContexts,
549 LspExtSwitchSourceHeader,
550 LanguageServerLog,
551 Toast,
552 HideToast,
553 OpenServerSettings,
554 GetPermalinkToLine,
555 LanguageServerPromptRequest,
556 LanguageServerIdForName,
557 GitGetBranches,
558 UpdateGitBranch,
559 ListToolchains,
560 ActivateToolchain,
561 ActiveToolchain,
562 GetPathMetadata,
563 CancelLanguageServerWork,
564 RegisterBufferWithLanguageServers,
565 GitShow,
566 GitReset,
567 GitCheckoutFiles,
568 SetIndexText,
569
570 Push,
571 Fetch,
572 GetRemotes,
573 Pull,
574 AskPassRequest,
575 GitChangeBranch,
576 GitCreateBranch,
577 CheckForPushedCommits,
578 GitDiff,
579 GitInit,
580 BreakpointsForFile,
581 ToggleBreakpoint,
582 RunDebugLocator,
583 GetDebugAdapterBinary,
584);
585
586entity_messages!(
587 {channel_id, Channel},
588 ChannelMessageSent,
589 ChannelMessageUpdate,
590 RemoveChannelMessage,
591 UpdateChannelMessage,
592 UpdateChannelBuffer,
593 UpdateChannelBufferCollaborators,
594);
595
596impl From<Timestamp> for SystemTime {
597 fn from(val: Timestamp) -> Self {
598 UNIX_EPOCH
599 .checked_add(Duration::new(val.seconds, val.nanos))
600 .unwrap()
601 }
602}
603
604impl From<SystemTime> for Timestamp {
605 fn from(time: SystemTime) -> Self {
606 let duration = time.duration_since(UNIX_EPOCH).unwrap();
607 Self {
608 seconds: duration.as_secs(),
609 nanos: duration.subsec_nanos(),
610 }
611 }
612}
613
614impl From<u128> for Nonce {
615 fn from(nonce: u128) -> Self {
616 let upper_half = (nonce >> 64) as u64;
617 let lower_half = nonce as u64;
618 Self {
619 upper_half,
620 lower_half,
621 }
622 }
623}
624
625impl From<Nonce> for u128 {
626 fn from(nonce: Nonce) -> Self {
627 let upper_half = (nonce.upper_half as u128) << 64;
628 let lower_half = nonce.lower_half as u128;
629 upper_half | lower_half
630 }
631}
632
633#[cfg(any(test, feature = "test-support"))]
634pub const MAX_WORKTREE_UPDATE_MAX_CHUNK_SIZE: usize = 2;
635#[cfg(not(any(test, feature = "test-support")))]
636pub const MAX_WORKTREE_UPDATE_MAX_CHUNK_SIZE: usize = 256;
637
638pub fn split_worktree_update(mut message: UpdateWorktree) -> impl Iterator<Item = UpdateWorktree> {
639 let mut done = false;
640
641 iter::from_fn(move || {
642 if done {
643 return None;
644 }
645
646 let updated_entries_chunk_size = cmp::min(
647 message.updated_entries.len(),
648 MAX_WORKTREE_UPDATE_MAX_CHUNK_SIZE,
649 );
650 let updated_entries: Vec<_> = message
651 .updated_entries
652 .drain(..updated_entries_chunk_size)
653 .collect();
654
655 let removed_entries_chunk_size = cmp::min(
656 message.removed_entries.len(),
657 MAX_WORKTREE_UPDATE_MAX_CHUNK_SIZE,
658 );
659 let removed_entries = message
660 .removed_entries
661 .drain(..removed_entries_chunk_size)
662 .collect();
663
664 let mut updated_repositories = Vec::new();
665 let mut limit = MAX_WORKTREE_UPDATE_MAX_CHUNK_SIZE;
666 while let Some(repo) = message.updated_repositories.first_mut() {
667 let updated_statuses_limit = cmp::min(repo.updated_statuses.len(), limit);
668 let removed_statuses_limit = cmp::min(repo.removed_statuses.len(), limit);
669
670 updated_repositories.push(RepositoryEntry {
671 repository_id: repo.repository_id,
672 branch_summary: repo.branch_summary.clone(),
673 updated_statuses: repo
674 .updated_statuses
675 .drain(..updated_statuses_limit)
676 .collect(),
677 removed_statuses: repo
678 .removed_statuses
679 .drain(..removed_statuses_limit)
680 .collect(),
681 current_merge_conflicts: repo.current_merge_conflicts.clone(),
682 });
683 if repo.removed_statuses.is_empty() && repo.updated_statuses.is_empty() {
684 message.updated_repositories.remove(0);
685 }
686 limit = limit.saturating_sub(removed_statuses_limit + updated_statuses_limit);
687 if limit == 0 {
688 break;
689 }
690 }
691
692 done = message.updated_entries.is_empty()
693 && message.removed_entries.is_empty()
694 && message.updated_repositories.is_empty();
695
696 let removed_repositories = if done {
697 mem::take(&mut message.removed_repositories)
698 } else {
699 Default::default()
700 };
701
702 Some(UpdateWorktree {
703 project_id: message.project_id,
704 worktree_id: message.worktree_id,
705 root_name: message.root_name.clone(),
706 abs_path: message.abs_path.clone(),
707 updated_entries,
708 removed_entries,
709 scan_id: message.scan_id,
710 is_last_update: done && message.is_last_update,
711 updated_repositories,
712 removed_repositories,
713 })
714 })
715}
716
717pub fn split_repository_update(
718 mut update: UpdateRepository,
719) -> impl Iterator<Item = UpdateRepository> {
720 let mut updated_statuses_iter = mem::take(&mut update.updated_statuses).into_iter().fuse();
721 let mut removed_statuses_iter = mem::take(&mut update.removed_statuses).into_iter().fuse();
722 std::iter::from_fn({
723 let update = update.clone();
724 move || {
725 let updated_statuses = updated_statuses_iter
726 .by_ref()
727 .take(MAX_WORKTREE_UPDATE_MAX_CHUNK_SIZE)
728 .collect::<Vec<_>>();
729 let removed_statuses = removed_statuses_iter
730 .by_ref()
731 .take(MAX_WORKTREE_UPDATE_MAX_CHUNK_SIZE)
732 .collect::<Vec<_>>();
733 if updated_statuses.is_empty() && removed_statuses.is_empty() {
734 return None;
735 }
736 Some(UpdateRepository {
737 updated_statuses,
738 removed_statuses,
739 is_last_update: false,
740 ..update.clone()
741 })
742 }
743 })
744 .chain([UpdateRepository {
745 updated_statuses: Vec::new(),
746 removed_statuses: Vec::new(),
747 is_last_update: true,
748 ..update
749 }])
750}
751
752#[cfg(test)]
753mod tests {
754 use super::*;
755
756 #[test]
757 fn test_converting_peer_id_from_and_to_u64() {
758 let peer_id = PeerId {
759 owner_id: 10,
760 id: 3,
761 };
762 assert_eq!(PeerId::from_u64(peer_id.as_u64()), peer_id);
763 let peer_id = PeerId {
764 owner_id: u32::MAX,
765 id: 3,
766 };
767 assert_eq!(PeerId::from_u64(peer_id.as_u64()), peer_id);
768 let peer_id = PeerId {
769 owner_id: 10,
770 id: u32::MAX,
771 };
772 assert_eq!(PeerId::from_u64(peer_id.as_u64()), peer_id);
773 let peer_id = PeerId {
774 owner_id: u32::MAX,
775 id: u32::MAX,
776 };
777 assert_eq!(PeerId::from_u64(peer_id.as_u64()), peer_id);
778 }
779
780 #[test]
781 #[cfg(target_os = "windows")]
782 fn test_proto() {
783 use std::path::PathBuf;
784
785 fn generate_proto_path(path: PathBuf) -> PathBuf {
786 let proto = path.to_proto();
787 PathBuf::from_proto(proto)
788 }
789
790 let path = PathBuf::from("C:\\foo\\bar");
791 assert_eq!(path, generate_proto_path(path.clone()));
792
793 let path = PathBuf::from("C:/foo/bar/");
794 assert_eq!(path, generate_proto_path(path.clone()));
795
796 let path = PathBuf::from("C:/foo\\bar\\");
797 assert_eq!(path, generate_proto_path(path.clone()));
798 }
799}