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