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