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