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 (CreateBufferForPeer, Foreground),
54 (CreateChannel, Foreground),
55 (CreateChannelResponse, Foreground),
56 (CreateContext, Foreground),
57 (CreateContextResponse, Foreground),
58 (CreateProjectEntry, Foreground),
59 (CreateRoom, Foreground),
60 (CreateRoomResponse, Foreground),
61 (DeclineCall, Foreground),
62 (DeleteChannel, Foreground),
63 (DeleteNotification, Foreground),
64 (DeleteProjectEntry, Foreground),
65 (EndStream, Foreground),
66 (Error, Foreground),
67 (ExpandProjectEntry, Foreground),
68 (ExpandProjectEntryResponse, Foreground),
69 (FindSearchCandidatesResponse, Background),
70 (FindSearchCandidates, Background),
71 (FlushBufferedMessages, Foreground),
72 (ExpandAllForProjectEntry, Foreground),
73 (ExpandAllForProjectEntryResponse, Foreground),
74 (Follow, Foreground),
75 (FollowResponse, Foreground),
76 (ApplyCodeActionKind, Foreground),
77 (ApplyCodeActionKindResponse, Foreground),
78 (FormatBuffers, Foreground),
79 (FormatBuffersResponse, Foreground),
80 (FuzzySearchUsers, Foreground),
81 (GetChannelMembers, Foreground),
82 (GetChannelMembersResponse, Foreground),
83 (GetChannelMessages, Background),
84 (GetChannelMessagesById, Background),
85 (GetChannelMessagesResponse, Background),
86 (GetCodeActions, Background),
87 (GetCodeActionsResponse, Background),
88 (GetCompletions, Background),
89 (GetCompletionsResponse, Background),
90 (GetDeclaration, Background),
91 (GetDeclarationResponse, Background),
92 (GetDefinition, Background),
93 (GetDefinitionResponse, Background),
94 (GetDocumentHighlights, Background),
95 (GetDocumentHighlightsResponse, Background),
96 (GetDocumentSymbols, Background),
97 (GetDocumentSymbolsResponse, Background),
98 (GetHover, Background),
99 (GetHoverResponse, Background),
100 (GetNotifications, Foreground),
101 (GetNotificationsResponse, Foreground),
102 (GetPanicFiles, Background),
103 (GetPanicFilesResponse, Background),
104 (GetPathMetadata, Background),
105 (GetPathMetadataResponse, Background),
106 (GetPermalinkToLine, Foreground),
107 (GetPermalinkToLineResponse, Foreground),
108 (GetPrivateUserInfo, Foreground),
109 (GetPrivateUserInfoResponse, Foreground),
110 (GetProjectSymbols, Background),
111 (GetProjectSymbolsResponse, Background),
112 (GetReferences, Background),
113 (GetReferencesResponse, Background),
114 (GetSignatureHelp, Background),
115 (GetSignatureHelpResponse, Background),
116 (GetSupermavenApiKey, Background),
117 (GetSupermavenApiKeyResponse, Background),
118 (GetTypeDefinition, Background),
119 (GetTypeDefinitionResponse, Background),
120 (GetImplementation, Background),
121 (GetImplementationResponse, Background),
122 (GetLlmToken, Background),
123 (GetLlmTokenResponse, Background),
124 (LanguageServerIdForName, Background),
125 (LanguageServerIdForNameResponse, Background),
126 (OpenUnstagedDiff, Foreground),
127 (OpenUnstagedDiffResponse, Foreground),
128 (OpenUncommittedDiff, Foreground),
129 (OpenUncommittedDiffResponse, Foreground),
130 (GetUsers, Foreground),
131 (GitGetBranches, Background),
132 (GitBranchesResponse, Background),
133 (Hello, Foreground),
134 (HideToast, Background),
135 (IncomingCall, Foreground),
136 (InlayHints, Background),
137 (InlayHintsResponse, Background),
138 (InstallExtension, Background),
139 (InviteChannelMember, Foreground),
140 (JoinChannel, Foreground),
141 (JoinChannelBuffer, Foreground),
142 (JoinChannelBufferResponse, Foreground),
143 (JoinChannelChat, Foreground),
144 (JoinChannelChatResponse, Foreground),
145 (JoinProject, Foreground),
146 (JoinProjectResponse, Foreground),
147 (JoinRoom, Foreground),
148 (JoinRoomResponse, Foreground),
149 (LanguageServerLog, Foreground),
150 (LanguageServerPromptRequest, Foreground),
151 (LanguageServerPromptResponse, Foreground),
152 (LeaveChannelBuffer, Background),
153 (LeaveChannelChat, Foreground),
154 (LeaveProject, Foreground),
155 (LeaveRoom, Foreground),
156 (LinkedEditingRange, Background),
157 (LinkedEditingRangeResponse, Background),
158 (ListRemoteDirectory, Background),
159 (ListRemoteDirectoryResponse, Background),
160 (ListToolchains, Foreground),
161 (ListToolchainsResponse, Foreground),
162 (LoadCommitDiff, Foreground),
163 (LoadCommitDiffResponse, Foreground),
164 (LspExtExpandMacro, Background),
165 (LspExtExpandMacroResponse, Background),
166 (LspExtOpenDocs, Background),
167 (LspExtOpenDocsResponse, Background),
168 (LspExtRunnables, Background),
169 (LspExtRunnablesResponse, Background),
170 (LspExtSwitchSourceHeader, Background),
171 (LspExtSwitchSourceHeaderResponse, Background),
172 (LspExtGoToParentModule, Background),
173 (LspExtGoToParentModuleResponse, 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 (RunDebugLocators, Background),
304 (DebugRequest, 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 (RefreshInlayHints, Ack),
378 (RefreshCodeLens, Ack),
379 (RejoinChannelBuffers, RejoinChannelBuffersResponse),
380 (RejoinRoom, RejoinRoomResponse),
381 (ReloadBuffers, ReloadBuffersResponse),
382 (RemoveChannelMember, Ack),
383 (RemoveChannelMessage, Ack),
384 (UpdateChannelMessage, Ack),
385 (RemoveContact, Ack),
386 (RenameChannel, RenameChannelResponse),
387 (RenameProjectEntry, ProjectEntryResponse),
388 (RequestContact, Ack),
389 (
390 ResolveCompletionDocumentation,
391 ResolveCompletionDocumentationResponse
392 ),
393 (ResolveInlayHint, ResolveInlayHintResponse),
394 (RespondToChannelInvite, Ack),
395 (RespondToContactRequest, Ack),
396 (SaveBuffer, BufferSaved),
397 (Stage, Ack),
398 (FindSearchCandidates, FindSearchCandidatesResponse),
399 (SendChannelMessage, SendChannelMessageResponse),
400 (SetChannelMemberRole, Ack),
401 (SetChannelVisibility, Ack),
402 (ShareProject, ShareProjectResponse),
403 (SynchronizeBuffers, SynchronizeBuffersResponse),
404 (TaskContextForLocation, TaskContext),
405 (Test, Test),
406 (Unstage, Ack),
407 (UpdateBuffer, Ack),
408 (UpdateParticipantLocation, Ack),
409 (UpdateProject, Ack),
410 (UpdateWorktree, Ack),
411 (UpdateRepository, Ack),
412 (RemoveRepository, Ack),
413 (LanguageServerIdForName, LanguageServerIdForNameResponse),
414 (LspExtExpandMacro, LspExtExpandMacroResponse),
415 (LspExtOpenDocs, LspExtOpenDocsResponse),
416 (LspExtRunnables, LspExtRunnablesResponse),
417 (SetRoomParticipantRole, Ack),
418 (BlameBuffer, BlameBufferResponse),
419 (RejoinRemoteProjects, RejoinRemoteProjectsResponse),
420 (MultiLspQuery, MultiLspQueryResponse),
421 (RestartLanguageServers, Ack),
422 (StopLanguageServers, Ack),
423 (OpenContext, OpenContextResponse),
424 (CreateContext, CreateContextResponse),
425 (SynchronizeContexts, SynchronizeContextsResponse),
426 (LspExtSwitchSourceHeader, LspExtSwitchSourceHeaderResponse),
427 (LspExtGoToParentModule, LspExtGoToParentModuleResponse),
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 (RunDebugLocators, DebugRequest),
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 LspExtGoToParentModule,
551 LanguageServerLog,
552 Toast,
553 HideToast,
554 OpenServerSettings,
555 GetPermalinkToLine,
556 LanguageServerPromptRequest,
557 LanguageServerIdForName,
558 GitGetBranches,
559 UpdateGitBranch,
560 ListToolchains,
561 ActivateToolchain,
562 ActiveToolchain,
563 GetPathMetadata,
564 CancelLanguageServerWork,
565 RegisterBufferWithLanguageServers,
566 GitShow,
567 GitReset,
568 GitCheckoutFiles,
569 SetIndexText,
570
571 Push,
572 Fetch,
573 GetRemotes,
574 Pull,
575 AskPassRequest,
576 GitChangeBranch,
577 GitCreateBranch,
578 CheckForPushedCommits,
579 GitDiff,
580 GitInit,
581 BreakpointsForFile,
582 ToggleBreakpoint,
583 RunDebugLocators,
584 GetDebugAdapterBinary,
585);
586
587entity_messages!(
588 {channel_id, Channel},
589 ChannelMessageSent,
590 ChannelMessageUpdate,
591 RemoveChannelMessage,
592 UpdateChannelMessage,
593 UpdateChannelBuffer,
594 UpdateChannelBufferCollaborators,
595);
596
597impl From<Timestamp> for SystemTime {
598 fn from(val: Timestamp) -> Self {
599 UNIX_EPOCH
600 .checked_add(Duration::new(val.seconds, val.nanos))
601 .unwrap()
602 }
603}
604
605impl From<SystemTime> for Timestamp {
606 fn from(time: SystemTime) -> Self {
607 let duration = time.duration_since(UNIX_EPOCH).unwrap();
608 Self {
609 seconds: duration.as_secs(),
610 nanos: duration.subsec_nanos(),
611 }
612 }
613}
614
615impl From<u128> for Nonce {
616 fn from(nonce: u128) -> Self {
617 let upper_half = (nonce >> 64) as u64;
618 let lower_half = nonce as u64;
619 Self {
620 upper_half,
621 lower_half,
622 }
623 }
624}
625
626impl From<Nonce> for u128 {
627 fn from(nonce: Nonce) -> Self {
628 let upper_half = (nonce.upper_half as u128) << 64;
629 let lower_half = nonce.lower_half as u128;
630 upper_half | lower_half
631 }
632}
633
634#[cfg(any(test, feature = "test-support"))]
635pub const MAX_WORKTREE_UPDATE_MAX_CHUNK_SIZE: usize = 2;
636#[cfg(not(any(test, feature = "test-support")))]
637pub const MAX_WORKTREE_UPDATE_MAX_CHUNK_SIZE: usize = 256;
638
639pub fn split_worktree_update(mut message: UpdateWorktree) -> impl Iterator<Item = UpdateWorktree> {
640 let mut done = false;
641
642 iter::from_fn(move || {
643 if done {
644 return None;
645 }
646
647 let updated_entries_chunk_size = cmp::min(
648 message.updated_entries.len(),
649 MAX_WORKTREE_UPDATE_MAX_CHUNK_SIZE,
650 );
651 let updated_entries: Vec<_> = message
652 .updated_entries
653 .drain(..updated_entries_chunk_size)
654 .collect();
655
656 let removed_entries_chunk_size = cmp::min(
657 message.removed_entries.len(),
658 MAX_WORKTREE_UPDATE_MAX_CHUNK_SIZE,
659 );
660 let removed_entries = message
661 .removed_entries
662 .drain(..removed_entries_chunk_size)
663 .collect();
664
665 let mut updated_repositories = Vec::new();
666 let mut limit = MAX_WORKTREE_UPDATE_MAX_CHUNK_SIZE;
667 while let Some(repo) = message.updated_repositories.first_mut() {
668 let updated_statuses_limit = cmp::min(repo.updated_statuses.len(), limit);
669 let removed_statuses_limit = cmp::min(repo.removed_statuses.len(), limit);
670
671 updated_repositories.push(RepositoryEntry {
672 repository_id: repo.repository_id,
673 branch_summary: repo.branch_summary.clone(),
674 updated_statuses: repo
675 .updated_statuses
676 .drain(..updated_statuses_limit)
677 .collect(),
678 removed_statuses: repo
679 .removed_statuses
680 .drain(..removed_statuses_limit)
681 .collect(),
682 current_merge_conflicts: repo.current_merge_conflicts.clone(),
683 });
684 if repo.removed_statuses.is_empty() && repo.updated_statuses.is_empty() {
685 message.updated_repositories.remove(0);
686 }
687 limit = limit.saturating_sub(removed_statuses_limit + updated_statuses_limit);
688 if limit == 0 {
689 break;
690 }
691 }
692
693 done = message.updated_entries.is_empty()
694 && message.removed_entries.is_empty()
695 && message.updated_repositories.is_empty();
696
697 let removed_repositories = if done {
698 mem::take(&mut message.removed_repositories)
699 } else {
700 Default::default()
701 };
702
703 Some(UpdateWorktree {
704 project_id: message.project_id,
705 worktree_id: message.worktree_id,
706 root_name: message.root_name.clone(),
707 abs_path: message.abs_path.clone(),
708 updated_entries,
709 removed_entries,
710 scan_id: message.scan_id,
711 is_last_update: done && message.is_last_update,
712 updated_repositories,
713 removed_repositories,
714 })
715 })
716}
717
718pub fn split_repository_update(
719 mut update: UpdateRepository,
720) -> impl Iterator<Item = UpdateRepository> {
721 let mut updated_statuses_iter = mem::take(&mut update.updated_statuses).into_iter().fuse();
722 let mut removed_statuses_iter = mem::take(&mut update.removed_statuses).into_iter().fuse();
723 std::iter::from_fn({
724 let update = update.clone();
725 move || {
726 let updated_statuses = updated_statuses_iter
727 .by_ref()
728 .take(MAX_WORKTREE_UPDATE_MAX_CHUNK_SIZE)
729 .collect::<Vec<_>>();
730 let removed_statuses = removed_statuses_iter
731 .by_ref()
732 .take(MAX_WORKTREE_UPDATE_MAX_CHUNK_SIZE)
733 .collect::<Vec<_>>();
734 if updated_statuses.is_empty() && removed_statuses.is_empty() {
735 return None;
736 }
737 Some(UpdateRepository {
738 updated_statuses,
739 removed_statuses,
740 is_last_update: false,
741 ..update.clone()
742 })
743 }
744 })
745 .chain([UpdateRepository {
746 updated_statuses: Vec::new(),
747 removed_statuses: Vec::new(),
748 is_last_update: true,
749 ..update
750 }])
751}
752
753#[cfg(test)]
754mod tests {
755 use super::*;
756
757 #[test]
758 fn test_converting_peer_id_from_and_to_u64() {
759 let peer_id = PeerId {
760 owner_id: 10,
761 id: 3,
762 };
763 assert_eq!(PeerId::from_u64(peer_id.as_u64()), peer_id);
764 let peer_id = PeerId {
765 owner_id: u32::MAX,
766 id: 3,
767 };
768 assert_eq!(PeerId::from_u64(peer_id.as_u64()), peer_id);
769 let peer_id = PeerId {
770 owner_id: 10,
771 id: u32::MAX,
772 };
773 assert_eq!(PeerId::from_u64(peer_id.as_u64()), peer_id);
774 let peer_id = PeerId {
775 owner_id: u32::MAX,
776 id: u32::MAX,
777 };
778 assert_eq!(PeerId::from_u64(peer_id.as_u64()), peer_id);
779 }
780
781 #[test]
782 #[cfg(target_os = "windows")]
783 fn test_proto() {
784 use std::path::PathBuf;
785
786 fn generate_proto_path(path: PathBuf) -> PathBuf {
787 let proto = path.to_proto();
788 PathBuf::from_proto(proto)
789 }
790
791 let path = PathBuf::from("C:\\foo\\bar");
792 assert_eq!(path, generate_proto_path(path.clone()));
793
794 let path = PathBuf::from("C:/foo/bar/");
795 assert_eq!(path, generate_proto_path(path.clone()));
796
797 let path = PathBuf::from("C:/foo\\bar\\");
798 assert_eq!(path, generate_proto_path(path.clone()));
799 }
800}