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 REMOTE_SERVER_PEER_ID: PeerId = PeerId { owner_id: 0, id: 0 };
20pub const REMOTE_SERVER_PROJECT_ID: u64 = 0;
21
22messages!(
23 (Ack, Foreground),
24 (AckBufferOperation, Background),
25 (AckChannelMessage, Background),
26 (ActivateToolchain, Foreground),
27 (ActiveToolchain, Foreground),
28 (ActiveToolchainResponse, Foreground),
29 (ResolveToolchain, Background),
30 (ResolveToolchainResponse, Background),
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 (RunGitHook, Background),
53 (CopyProjectEntry, Foreground),
54 (CreateBufferForPeer, Foreground),
55 (CreateImageForPeer, Foreground),
56 (CreateChannel, Foreground),
57 (CreateChannelResponse, Foreground),
58 (CreateContext, Foreground),
59 (CreateContextResponse, Foreground),
60 (CreateProjectEntry, Foreground),
61 (CreateRoom, Foreground),
62 (CreateRoomResponse, Foreground),
63 (DeclineCall, Foreground),
64 (DeleteChannel, Foreground),
65 (DeleteNotification, Foreground),
66 (DeleteProjectEntry, Foreground),
67 (EndStream, Foreground),
68 (Error, Foreground),
69 (ExpandProjectEntry, Foreground),
70 (ExpandProjectEntryResponse, Foreground),
71 (FindSearchCandidatesResponse, Background),
72 (FindSearchCandidates, Background),
73 (FlushBufferedMessages, Foreground),
74 (ExpandAllForProjectEntry, Foreground),
75 (ExpandAllForProjectEntryResponse, Foreground),
76 (Follow, Foreground),
77 (FollowResponse, Foreground),
78 (ApplyCodeActionKind, Foreground),
79 (ApplyCodeActionKindResponse, Foreground),
80 (FormatBuffers, Foreground),
81 (FormatBuffersResponse, Foreground),
82 (FuzzySearchUsers, Foreground),
83 (GetChannelMembers, Foreground),
84 (GetChannelMembersResponse, Foreground),
85 (GetChannelMessages, Background),
86 (GetChannelMessagesById, Background),
87 (GetChannelMessagesResponse, Background),
88 (GetCodeActions, Background),
89 (GetCodeActionsResponse, Background),
90 (GetCompletions, Background),
91 (GetCompletionsResponse, Background),
92 (GetDeclaration, Background),
93 (GetDeclarationResponse, Background),
94 (GetDefinition, Background),
95 (GetDefinitionResponse, Background),
96 (GetDocumentHighlights, Background),
97 (GetDocumentHighlightsResponse, Background),
98 (GetDocumentSymbols, Background),
99 (GetDocumentSymbolsResponse, Background),
100 (GetHover, Background),
101 (GetHoverResponse, Background),
102 (GetNotifications, Foreground),
103 (GetNotificationsResponse, Foreground),
104 (GetCrashFiles, Background),
105 (GetCrashFilesResponse, Background),
106 (GetPathMetadata, Background),
107 (GetPathMetadataResponse, Background),
108 (GetPermalinkToLine, Foreground),
109 (GetProcesses, Background),
110 (GetProcessesResponse, Background),
111 (GetPermalinkToLineResponse, Foreground),
112 (GetProjectSymbols, Background),
113 (GetProjectSymbolsResponse, Background),
114 (GetReferences, Background),
115 (GetReferencesResponse, Background),
116 (GetSignatureHelp, Background),
117 (GetSignatureHelpResponse, Background),
118 (GetTypeDefinition, Background),
119 (GetTypeDefinitionResponse, Background),
120 (GetImplementation, Background),
121 (GetImplementationResponse, Background),
122 (OpenUnstagedDiff, Foreground),
123 (OpenUnstagedDiffResponse, Foreground),
124 (OpenUncommittedDiff, Foreground),
125 (OpenUncommittedDiffResponse, Foreground),
126 (GetUsers, Foreground),
127 (GitGetBranches, Background),
128 (GitBranchesResponse, Background),
129 (Hello, Foreground),
130 (HideToast, Background),
131 (IncomingCall, Foreground),
132 (InlayHints, Background),
133 (InlayHintsResponse, Background),
134 (InstallExtension, Background),
135 (InviteChannelMember, Foreground),
136 (JoinChannel, Foreground),
137 (JoinChannelBuffer, Foreground),
138 (JoinChannelBufferResponse, Foreground),
139 (JoinChannelChat, Foreground),
140 (JoinChannelChatResponse, Foreground),
141 (JoinProject, Foreground),
142 (JoinProjectResponse, Foreground),
143 (JoinRoom, Foreground),
144 (JoinRoomResponse, Foreground),
145 (LanguageServerLog, Foreground),
146 (LanguageServerPromptRequest, Foreground),
147 (LanguageServerPromptResponse, Foreground),
148 (LeaveChannelBuffer, Background),
149 (LeaveChannelChat, Foreground),
150 (LeaveProject, Foreground),
151 (LeaveRoom, Foreground),
152 (LinkedEditingRange, Background),
153 (LinkedEditingRangeResponse, Background),
154 (ListRemoteDirectory, Background),
155 (ListRemoteDirectoryResponse, Background),
156 (ListToolchains, Foreground),
157 (ListToolchainsResponse, Foreground),
158 (LoadCommitDiff, Foreground),
159 (LoadCommitDiffResponse, Foreground),
160 (LspExtExpandMacro, Background),
161 (LspExtExpandMacroResponse, Background),
162 (LspExtOpenDocs, Background),
163 (LspExtOpenDocsResponse, Background),
164 (LspExtRunnables, Background),
165 (LspExtRunnablesResponse, Background),
166 (LspExtSwitchSourceHeader, Background),
167 (LspExtSwitchSourceHeaderResponse, Background),
168 (LspExtGoToParentModule, Background),
169 (LspExtGoToParentModuleResponse, Background),
170 (LspExtCancelFlycheck, Background),
171 (LspExtRunFlycheck, Background),
172 (LspExtClearFlycheck, Background),
173 (MarkNotificationRead, Foreground),
174 (MoveChannel, Foreground),
175 (ReorderChannel, Foreground),
176 (LspQuery, Background),
177 (LspQueryResponse, Background),
178 (OnTypeFormatting, Background),
179 (OnTypeFormattingResponse, Background),
180 (OpenBufferById, Background),
181 (OpenBufferByPath, Background),
182 (OpenImageByPath, Background),
183 (OpenBufferForSymbol, Background),
184 (OpenBufferForSymbolResponse, Background),
185 (OpenBufferResponse, Background),
186 (OpenImageResponse, Background),
187 (OpenCommitMessageBuffer, Background),
188 (OpenContext, Foreground),
189 (OpenContextResponse, Foreground),
190 (OpenNewBuffer, Foreground),
191 (OpenServerSettings, Foreground),
192 (PerformRename, Background),
193 (PerformRenameResponse, Background),
194 (Ping, Foreground),
195 (PrepareRename, Background),
196 (PrepareRenameResponse, Background),
197 (ProjectEntryResponse, Foreground),
198 (RefreshInlayHints, Foreground),
199 (RegisterBufferWithLanguageServers, Background),
200 (RejoinChannelBuffers, Foreground),
201 (RejoinChannelBuffersResponse, Foreground),
202 (RejoinRemoteProjects, Foreground),
203 (RejoinRemoteProjectsResponse, Foreground),
204 (RejoinRoom, Foreground),
205 (RejoinRoomResponse, Foreground),
206 (ReloadBuffers, Foreground),
207 (ReloadBuffersResponse, Foreground),
208 (RemoveChannelMember, Foreground),
209 (RemoveChannelMessage, Foreground),
210 (RemoveContact, Foreground),
211 (RemoveProjectCollaborator, Foreground),
212 (RemoveWorktree, Foreground),
213 (RenameChannel, Foreground),
214 (RenameChannelResponse, Foreground),
215 (RenameProjectEntry, Foreground),
216 (RequestContact, Foreground),
217 (ResolveCompletionDocumentation, Background),
218 (ResolveCompletionDocumentationResponse, Background),
219 (ResolveInlayHint, Background),
220 (ResolveInlayHintResponse, Background),
221 (GetDocumentColor, Background),
222 (GetDocumentColorResponse, Background),
223 (GetColorPresentation, Background),
224 (GetColorPresentationResponse, Background),
225 (RefreshCodeLens, Background),
226 (GetCodeLens, Background),
227 (GetCodeLensResponse, Background),
228 (RespondToChannelInvite, Foreground),
229 (RespondToContactRequest, Foreground),
230 (RestartLanguageServers, Foreground),
231 (StopLanguageServers, Background),
232 (RoomUpdated, Foreground),
233 (SaveBuffer, Foreground),
234 (SendChannelMessage, Background),
235 (SendChannelMessageResponse, Background),
236 (SetChannelMemberRole, Foreground),
237 (SetChannelVisibility, Foreground),
238 (SetRoomParticipantRole, Foreground),
239 (ShareProject, Foreground),
240 (ShareProjectResponse, Foreground),
241 (ShowContacts, Foreground),
242 (ShutdownRemoteServer, Foreground),
243 (Stage, Background),
244 (StartLanguageServer, Foreground),
245 (SubscribeToChannels, Foreground),
246 (SyncExtensions, Background),
247 (SyncExtensionsResponse, Background),
248 (BreakpointsForFile, Background),
249 (ToggleBreakpoint, Foreground),
250 (SynchronizeBuffers, Foreground),
251 (SynchronizeBuffersResponse, Foreground),
252 (SynchronizeContexts, Foreground),
253 (SynchronizeContextsResponse, Foreground),
254 (TaskContext, Background),
255 (TaskContextForLocation, Background),
256 (Test, Foreground),
257 (Toast, Background),
258 (Unfollow, Foreground),
259 (UnshareProject, Foreground),
260 (Unstage, Background),
261 (Stash, Background),
262 (StashPop, Background),
263 (StashApply, Background),
264 (StashDrop, Background),
265 (UpdateBuffer, Foreground),
266 (UpdateBufferFile, Foreground),
267 (UpdateChannelBuffer, Foreground),
268 (UpdateChannelBufferCollaborators, Foreground),
269 (UpdateChannelMessage, Foreground),
270 (UpdateChannels, Foreground),
271 (UpdateContacts, Foreground),
272 (UpdateContext, Foreground),
273 (UpdateDiagnosticSummary, Foreground),
274 (UpdateDiffBases, Foreground),
275 (UpdateFollowers, Foreground),
276 (UpdateGitBranch, Background),
277 (UpdateLanguageServer, Foreground),
278 (UpdateNotification, Foreground),
279 (UpdateParticipantLocation, Foreground),
280 (UpdateProject, Foreground),
281 (UpdateProjectCollaborator, Foreground),
282 (UpdateUserChannels, Foreground),
283 (UpdateWorktree, Foreground),
284 (UpdateWorktreeSettings, Foreground),
285 (UpdateUserSettings, Background),
286 (UpdateRepository, Foreground),
287 (RemoveRepository, Foreground),
288 (UsersResponse, Foreground),
289 (GitReset, Background),
290 (GitDeleteBranch, Background),
291 (GitCheckoutFiles, Background),
292 (GitShow, Background),
293 (GitCommitDetails, Background),
294 (GitFileHistory, Background),
295 (GitFileHistoryResponse, Background),
296 (SetIndexText, Background),
297 (Push, Background),
298 (Fetch, Background),
299 (GetRemotes, Background),
300 (GetRemotesResponse, Background),
301 (Pull, Background),
302 (RemoteMessageResponse, Background),
303 (AskPassRequest, Background),
304 (AskPassResponse, Background),
305 (GitCreateRemote, Background),
306 (GitRemoveRemote, Background),
307 (GitCreateBranch, Background),
308 (GitChangeBranch, Background),
309 (GitRenameBranch, Background),
310 (TrustWorktrees, Background),
311 (RestrictWorktrees, Background),
312 (CheckForPushedCommits, Background),
313 (CheckForPushedCommitsResponse, Background),
314 (GitDiff, Background),
315 (GitDiffResponse, Background),
316 (GitInit, Background),
317 (GetDebugAdapterBinary, Background),
318 (DebugAdapterBinary, Background),
319 (RunDebugLocators, Background),
320 (DebugRequest, Background),
321 (LogToDebugConsole, Background),
322 (GetDocumentDiagnostics, Background),
323 (GetDocumentDiagnosticsResponse, Background),
324 (PullWorkspaceDiagnostics, Background),
325 (GetDefaultBranch, Background),
326 (GetDefaultBranchResponse, Background),
327 (GetTreeDiff, Background),
328 (GetTreeDiffResponse, Background),
329 (GetBlobContent, Background),
330 (GetBlobContentResponse, Background),
331 (GitClone, Background),
332 (GitCloneResponse, Background),
333 (ToggleLspLogs, Background),
334 (GetDirectoryEnvironment, Background),
335 (DirectoryEnvironment, Background),
336 (GetAgentServerCommand, Background),
337 (AgentServerCommand, Background),
338 (ExternalAgentsUpdated, Background),
339 (ExternalExtensionAgentsUpdated, Background),
340 (ExternalAgentLoadingStatusUpdated, Background),
341 (NewExternalAgentVersionAvailable, Background),
342 (RemoteStarted, Background),
343 (GitGetWorktrees, Background),
344 (GitWorktreesResponse, Background),
345 (GitCreateWorktree, Background)
346);
347
348request_messages!(
349 (ApplyCodeAction, ApplyCodeActionResponse),
350 (
351 ApplyCompletionAdditionalEdits,
352 ApplyCompletionAdditionalEditsResponse
353 ),
354 (Call, Ack),
355 (CancelCall, Ack),
356 (Commit, Ack),
357 (RunGitHook, Ack),
358 (CopyProjectEntry, ProjectEntryResponse),
359 (CreateChannel, CreateChannelResponse),
360 (CreateProjectEntry, ProjectEntryResponse),
361 (CreateRoom, CreateRoomResponse),
362 (DeclineCall, Ack),
363 (DeleteChannel, Ack),
364 (DeleteProjectEntry, ProjectEntryResponse),
365 (ExpandProjectEntry, ExpandProjectEntryResponse),
366 (ExpandAllForProjectEntry, ExpandAllForProjectEntryResponse),
367 (Follow, FollowResponse),
368 (ApplyCodeActionKind, ApplyCodeActionKindResponse),
369 (FormatBuffers, FormatBuffersResponse),
370 (FuzzySearchUsers, UsersResponse),
371 (GetChannelMembers, GetChannelMembersResponse),
372 (GetChannelMessages, GetChannelMessagesResponse),
373 (GetChannelMessagesById, GetChannelMessagesResponse),
374 (GetCodeActions, GetCodeActionsResponse),
375 (GetCompletions, GetCompletionsResponse),
376 (GetDefinition, GetDefinitionResponse),
377 (GetDeclaration, GetDeclarationResponse),
378 (GetImplementation, GetImplementationResponse),
379 (GetDocumentHighlights, GetDocumentHighlightsResponse),
380 (GetDocumentSymbols, GetDocumentSymbolsResponse),
381 (GetHover, GetHoverResponse),
382 (GetNotifications, GetNotificationsResponse),
383 (GetProjectSymbols, GetProjectSymbolsResponse),
384 (GetReferences, GetReferencesResponse),
385 (GetSignatureHelp, GetSignatureHelpResponse),
386 (OpenUnstagedDiff, OpenUnstagedDiffResponse),
387 (OpenUncommittedDiff, OpenUncommittedDiffResponse),
388 (GetTypeDefinition, GetTypeDefinitionResponse),
389 (LinkedEditingRange, LinkedEditingRangeResponse),
390 (ListRemoteDirectory, ListRemoteDirectoryResponse),
391 (GetUsers, UsersResponse),
392 (IncomingCall, Ack),
393 (InlayHints, InlayHintsResponse),
394 (GetCodeLens, GetCodeLensResponse),
395 (InviteChannelMember, Ack),
396 (JoinChannel, JoinRoomResponse),
397 (JoinChannelBuffer, JoinChannelBufferResponse),
398 (JoinChannelChat, JoinChannelChatResponse),
399 (JoinProject, JoinProjectResponse),
400 (JoinRoom, JoinRoomResponse),
401 (LeaveChannelBuffer, Ack),
402 (LeaveRoom, Ack),
403 (LoadCommitDiff, LoadCommitDiffResponse),
404 (MarkNotificationRead, Ack),
405 (MoveChannel, Ack),
406 (OnTypeFormatting, OnTypeFormattingResponse),
407 (OpenBufferById, OpenBufferResponse),
408 (OpenBufferByPath, OpenBufferResponse),
409 (OpenImageByPath, OpenImageResponse),
410 (OpenBufferForSymbol, OpenBufferForSymbolResponse),
411 (OpenCommitMessageBuffer, OpenBufferResponse),
412 (OpenNewBuffer, OpenBufferResponse),
413 (PerformRename, PerformRenameResponse),
414 (Ping, Ack),
415 (PrepareRename, PrepareRenameResponse),
416 (RefreshInlayHints, Ack),
417 (RefreshCodeLens, Ack),
418 (RejoinChannelBuffers, RejoinChannelBuffersResponse),
419 (RejoinRoom, RejoinRoomResponse),
420 (ReloadBuffers, ReloadBuffersResponse),
421 (RemoveChannelMember, Ack),
422 (RemoveChannelMessage, Ack),
423 (UpdateChannelMessage, Ack),
424 (RemoveContact, Ack),
425 (RenameChannel, RenameChannelResponse),
426 (RenameProjectEntry, ProjectEntryResponse),
427 (ReorderChannel, Ack),
428 (RequestContact, Ack),
429 (
430 ResolveCompletionDocumentation,
431 ResolveCompletionDocumentationResponse
432 ),
433 (ResolveInlayHint, ResolveInlayHintResponse),
434 (GetDocumentColor, GetDocumentColorResponse),
435 (GetColorPresentation, GetColorPresentationResponse),
436 (RespondToChannelInvite, Ack),
437 (RespondToContactRequest, Ack),
438 (SaveBuffer, BufferSaved),
439 (Stage, Ack),
440 (FindSearchCandidates, FindSearchCandidatesResponse),
441 (SendChannelMessage, SendChannelMessageResponse),
442 (SetChannelMemberRole, Ack),
443 (SetChannelVisibility, Ack),
444 (ShareProject, ShareProjectResponse),
445 (SynchronizeBuffers, SynchronizeBuffersResponse),
446 (TaskContextForLocation, TaskContext),
447 (Test, Test),
448 (Unstage, Ack),
449 (Stash, Ack),
450 (StashPop, Ack),
451 (StashApply, Ack),
452 (StashDrop, Ack),
453 (UpdateBuffer, Ack),
454 (UpdateParticipantLocation, Ack),
455 (UpdateProject, Ack),
456 (UpdateWorktree, Ack),
457 (UpdateRepository, Ack),
458 (RemoveRepository, Ack),
459 (LspExtExpandMacro, LspExtExpandMacroResponse),
460 (LspExtOpenDocs, LspExtOpenDocsResponse),
461 (LspExtRunnables, LspExtRunnablesResponse),
462 (SetRoomParticipantRole, Ack),
463 (BlameBuffer, BlameBufferResponse),
464 (RejoinRemoteProjects, RejoinRemoteProjectsResponse),
465 (LspQuery, Ack),
466 (LspQueryResponse, Ack),
467 (RestartLanguageServers, Ack),
468 (StopLanguageServers, Ack),
469 (OpenContext, OpenContextResponse),
470 (CreateContext, CreateContextResponse),
471 (SynchronizeContexts, SynchronizeContextsResponse),
472 (LspExtSwitchSourceHeader, LspExtSwitchSourceHeaderResponse),
473 (LspExtGoToParentModule, LspExtGoToParentModuleResponse),
474 (LspExtCancelFlycheck, Ack),
475 (LspExtRunFlycheck, Ack),
476 (LspExtClearFlycheck, Ack),
477 (AddWorktree, AddWorktreeResponse),
478 (ShutdownRemoteServer, Ack),
479 (RemoveWorktree, Ack),
480 (OpenServerSettings, OpenBufferResponse),
481 (GetPermalinkToLine, GetPermalinkToLineResponse),
482 (FlushBufferedMessages, Ack),
483 (LanguageServerPromptRequest, LanguageServerPromptResponse),
484 (GitGetBranches, GitBranchesResponse),
485 (UpdateGitBranch, Ack),
486 (ListToolchains, ListToolchainsResponse),
487 (ActivateToolchain, Ack),
488 (ActiveToolchain, ActiveToolchainResponse),
489 (ResolveToolchain, ResolveToolchainResponse),
490 (GetPathMetadata, GetPathMetadataResponse),
491 (GetCrashFiles, GetCrashFilesResponse),
492 (CancelLanguageServerWork, Ack),
493 (SyncExtensions, SyncExtensionsResponse),
494 (InstallExtension, Ack),
495 (RegisterBufferWithLanguageServers, Ack),
496 (GitShow, GitCommitDetails),
497 (GitFileHistory, GitFileHistoryResponse),
498 (GitReset, Ack),
499 (GitDeleteBranch, Ack),
500 (GitCheckoutFiles, Ack),
501 (SetIndexText, Ack),
502 (Push, RemoteMessageResponse),
503 (Fetch, RemoteMessageResponse),
504 (GetRemotes, GetRemotesResponse),
505 (Pull, RemoteMessageResponse),
506 (AskPassRequest, AskPassResponse),
507 (GitCreateRemote, Ack),
508 (GitRemoveRemote, Ack),
509 (GitCreateBranch, Ack),
510 (GitChangeBranch, Ack),
511 (GitRenameBranch, Ack),
512 (CheckForPushedCommits, CheckForPushedCommitsResponse),
513 (GitDiff, GitDiffResponse),
514 (GitInit, Ack),
515 (ToggleBreakpoint, Ack),
516 (GetDebugAdapterBinary, DebugAdapterBinary),
517 (RunDebugLocators, DebugRequest),
518 (GetDocumentDiagnostics, GetDocumentDiagnosticsResponse),
519 (PullWorkspaceDiagnostics, Ack),
520 (GetDefaultBranch, GetDefaultBranchResponse),
521 (GetBlobContent, GetBlobContentResponse),
522 (GetTreeDiff, GetTreeDiffResponse),
523 (GitClone, GitCloneResponse),
524 (ToggleLspLogs, Ack),
525 (GetDirectoryEnvironment, DirectoryEnvironment),
526 (GetProcesses, GetProcessesResponse),
527 (GetAgentServerCommand, AgentServerCommand),
528 (RemoteStarted, Ack),
529 (GitGetWorktrees, GitWorktreesResponse),
530 (GitCreateWorktree, Ack),
531 (TrustWorktrees, Ack),
532 (RestrictWorktrees, Ack),
533);
534
535lsp_messages!(
536 (GetReferences, GetReferencesResponse, true),
537 (GetDocumentColor, GetDocumentColorResponse, true),
538 (GetHover, GetHoverResponse, true),
539 (GetCodeActions, GetCodeActionsResponse, true),
540 (GetSignatureHelp, GetSignatureHelpResponse, true),
541 (GetCodeLens, GetCodeLensResponse, true),
542 (GetDocumentDiagnostics, GetDocumentDiagnosticsResponse, true),
543 (GetDefinition, GetDefinitionResponse, true),
544 (GetDeclaration, GetDeclarationResponse, true),
545 (GetTypeDefinition, GetTypeDefinitionResponse, true),
546 (GetImplementation, GetImplementationResponse, true),
547 (InlayHints, InlayHintsResponse, false),
548);
549
550entity_messages!(
551 {project_id, ShareProject},
552 AddProjectCollaborator,
553 AddWorktree,
554 ApplyCodeAction,
555 ApplyCompletionAdditionalEdits,
556 BlameBuffer,
557 BufferReloaded,
558 BufferSaved,
559 CloseBuffer,
560 Commit,
561 RunGitHook,
562 GetColorPresentation,
563 CopyProjectEntry,
564 CreateBufferForPeer,
565 CreateImageForPeer,
566 CreateProjectEntry,
567 GetDocumentColor,
568 DeleteProjectEntry,
569 ExpandProjectEntry,
570 ExpandAllForProjectEntry,
571 FindSearchCandidates,
572 ApplyCodeActionKind,
573 FormatBuffers,
574 GetCodeActions,
575 GetCodeLens,
576 GetCompletions,
577 GetDefinition,
578 GetDeclaration,
579 GetImplementation,
580 GetDocumentHighlights,
581 GetDocumentSymbols,
582 GetHover,
583 GetProjectSymbols,
584 GetReferences,
585 GetSignatureHelp,
586 OpenUnstagedDiff,
587 OpenUncommittedDiff,
588 GetTypeDefinition,
589 InlayHints,
590 JoinProject,
591 LeaveProject,
592 LinkedEditingRange,
593 LoadCommitDiff,
594 LspQuery,
595 LspQueryResponse,
596 RestartLanguageServers,
597 StopLanguageServers,
598 OnTypeFormatting,
599 OpenNewBuffer,
600 OpenBufferById,
601 OpenBufferByPath,
602 OpenImageByPath,
603 OpenBufferForSymbol,
604 OpenCommitMessageBuffer,
605 PerformRename,
606 PrepareRename,
607 RefreshInlayHints,
608 RefreshCodeLens,
609 ReloadBuffers,
610 RemoveProjectCollaborator,
611 RenameProjectEntry,
612 ResolveCompletionDocumentation,
613 ResolveInlayHint,
614 SaveBuffer,
615 Stage,
616 StartLanguageServer,
617 SynchronizeBuffers,
618 TaskContextForLocation,
619 UnshareProject,
620 Unstage,
621 Stash,
622 StashPop,
623 StashApply,
624 StashDrop,
625 UpdateBuffer,
626 UpdateBufferFile,
627 UpdateDiagnosticSummary,
628 UpdateDiffBases,
629 UpdateLanguageServer,
630 UpdateProject,
631 UpdateProjectCollaborator,
632 UpdateWorktree,
633 UpdateRepository,
634 RemoveRepository,
635 UpdateWorktreeSettings,
636 UpdateUserSettings,
637 LspExtExpandMacro,
638 LspExtOpenDocs,
639 LspExtRunnables,
640 AdvertiseContexts,
641 OpenContext,
642 CreateContext,
643 UpdateContext,
644 SynchronizeContexts,
645 LspExtSwitchSourceHeader,
646 LspExtGoToParentModule,
647 LspExtCancelFlycheck,
648 LspExtRunFlycheck,
649 LspExtClearFlycheck,
650 LanguageServerLog,
651 Toast,
652 HideToast,
653 OpenServerSettings,
654 GetPermalinkToLine,
655 LanguageServerPromptRequest,
656 GitGetBranches,
657 UpdateGitBranch,
658 ListToolchains,
659 ActivateToolchain,
660 ActiveToolchain,
661 ResolveToolchain,
662 GetPathMetadata,
663 GetProcesses,
664 CancelLanguageServerWork,
665 RegisterBufferWithLanguageServers,
666 GitShow,
667 GitFileHistory,
668 GitReset,
669 GitDeleteBranch,
670 GitCheckoutFiles,
671 SetIndexText,
672 ToggleLspLogs,
673 GetDirectoryEnvironment,
674
675 Push,
676 Fetch,
677 GetRemotes,
678 Pull,
679 AskPassRequest,
680 GitChangeBranch,
681 GitRenameBranch,
682 GitCreateBranch,
683 GitCreateRemote,
684 GitRemoveRemote,
685 CheckForPushedCommits,
686 GitDiff,
687 GitInit,
688 BreakpointsForFile,
689 ToggleBreakpoint,
690 RunDebugLocators,
691 GetDebugAdapterBinary,
692 LogToDebugConsole,
693 GetDocumentDiagnostics,
694 PullWorkspaceDiagnostics,
695 GetDefaultBranch,
696 GetTreeDiff,
697 GetBlobContent,
698 GitClone,
699 GetAgentServerCommand,
700 ExternalAgentsUpdated,
701 ExternalExtensionAgentsUpdated,
702 ExternalAgentLoadingStatusUpdated,
703 NewExternalAgentVersionAvailable,
704 GitGetWorktrees,
705 GitCreateWorktree,
706 TrustWorktrees,
707 RestrictWorktrees,
708);
709
710entity_messages!(
711 {channel_id, Channel},
712 ChannelMessageSent,
713 ChannelMessageUpdate,
714 RemoveChannelMessage,
715 UpdateChannelMessage,
716 UpdateChannelBuffer,
717 UpdateChannelBufferCollaborators,
718);
719
720impl From<Timestamp> for SystemTime {
721 fn from(val: Timestamp) -> Self {
722 UNIX_EPOCH
723 .checked_add(Duration::new(val.seconds, val.nanos))
724 .unwrap()
725 }
726}
727
728impl From<SystemTime> for Timestamp {
729 fn from(time: SystemTime) -> Self {
730 let duration = time.duration_since(UNIX_EPOCH).unwrap_or_default();
731 Self {
732 seconds: duration.as_secs(),
733 nanos: duration.subsec_nanos(),
734 }
735 }
736}
737
738impl From<u128> for Nonce {
739 fn from(nonce: u128) -> Self {
740 let upper_half = (nonce >> 64) as u64;
741 let lower_half = nonce as u64;
742 Self {
743 upper_half,
744 lower_half,
745 }
746 }
747}
748
749impl From<Nonce> for u128 {
750 fn from(nonce: Nonce) -> Self {
751 let upper_half = (nonce.upper_half as u128) << 64;
752 let lower_half = nonce.lower_half as u128;
753 upper_half | lower_half
754 }
755}
756
757#[cfg(any(test, feature = "test-support"))]
758pub const MAX_WORKTREE_UPDATE_MAX_CHUNK_SIZE: usize = 2;
759#[cfg(not(any(test, feature = "test-support")))]
760pub const MAX_WORKTREE_UPDATE_MAX_CHUNK_SIZE: usize = 256;
761
762pub fn split_worktree_update(mut message: UpdateWorktree) -> impl Iterator<Item = UpdateWorktree> {
763 let mut done = false;
764
765 iter::from_fn(move || {
766 if done {
767 return None;
768 }
769
770 let updated_entries_chunk_size = cmp::min(
771 message.updated_entries.len(),
772 MAX_WORKTREE_UPDATE_MAX_CHUNK_SIZE,
773 );
774 let updated_entries: Vec<_> = message
775 .updated_entries
776 .drain(..updated_entries_chunk_size)
777 .collect();
778
779 let removed_entries_chunk_size = cmp::min(
780 message.removed_entries.len(),
781 MAX_WORKTREE_UPDATE_MAX_CHUNK_SIZE,
782 );
783 let removed_entries = message
784 .removed_entries
785 .drain(..removed_entries_chunk_size)
786 .collect();
787
788 let mut updated_repositories = Vec::new();
789 let mut limit = MAX_WORKTREE_UPDATE_MAX_CHUNK_SIZE;
790 while let Some(repo) = message.updated_repositories.first_mut() {
791 let updated_statuses_limit = cmp::min(repo.updated_statuses.len(), limit);
792 let removed_statuses_limit = cmp::min(repo.removed_statuses.len(), limit);
793
794 updated_repositories.push(RepositoryEntry {
795 repository_id: repo.repository_id,
796 branch_summary: repo.branch_summary.clone(),
797 updated_statuses: repo
798 .updated_statuses
799 .drain(..updated_statuses_limit)
800 .collect(),
801 removed_statuses: repo
802 .removed_statuses
803 .drain(..removed_statuses_limit)
804 .collect(),
805 current_merge_conflicts: repo.current_merge_conflicts.clone(),
806 });
807 if repo.removed_statuses.is_empty() && repo.updated_statuses.is_empty() {
808 message.updated_repositories.remove(0);
809 }
810 limit = limit.saturating_sub(removed_statuses_limit + updated_statuses_limit);
811 if limit == 0 {
812 break;
813 }
814 }
815
816 done = message.updated_entries.is_empty()
817 && message.removed_entries.is_empty()
818 && message.updated_repositories.is_empty();
819
820 let removed_repositories = if done {
821 mem::take(&mut message.removed_repositories)
822 } else {
823 Default::default()
824 };
825
826 Some(UpdateWorktree {
827 project_id: message.project_id,
828 worktree_id: message.worktree_id,
829 root_name: message.root_name.clone(),
830 abs_path: message.abs_path.clone(),
831 updated_entries,
832 removed_entries,
833 scan_id: message.scan_id,
834 is_last_update: done && message.is_last_update,
835 updated_repositories,
836 removed_repositories,
837 })
838 })
839}
840
841pub fn split_repository_update(
842 mut update: UpdateRepository,
843) -> impl Iterator<Item = UpdateRepository> {
844 let mut updated_statuses_iter = mem::take(&mut update.updated_statuses).into_iter().fuse();
845 let mut removed_statuses_iter = mem::take(&mut update.removed_statuses).into_iter().fuse();
846 std::iter::from_fn({
847 let update = update.clone();
848 move || {
849 let updated_statuses = updated_statuses_iter
850 .by_ref()
851 .take(MAX_WORKTREE_UPDATE_MAX_CHUNK_SIZE)
852 .collect::<Vec<_>>();
853 let removed_statuses = removed_statuses_iter
854 .by_ref()
855 .take(MAX_WORKTREE_UPDATE_MAX_CHUNK_SIZE)
856 .collect::<Vec<_>>();
857 if updated_statuses.is_empty() && removed_statuses.is_empty() {
858 return None;
859 }
860 Some(UpdateRepository {
861 updated_statuses,
862 removed_statuses,
863 is_last_update: false,
864 ..update.clone()
865 })
866 }
867 })
868 .chain([UpdateRepository {
869 updated_statuses: Vec::new(),
870 removed_statuses: Vec::new(),
871 is_last_update: true,
872 ..update
873 }])
874}
875
876impl LspQuery {
877 pub fn query_name_and_write_permissions(&self) -> (&str, bool) {
878 match self.request {
879 Some(lsp_query::Request::GetHover(_)) => ("GetHover", false),
880 Some(lsp_query::Request::GetCodeActions(_)) => ("GetCodeActions", true),
881 Some(lsp_query::Request::GetSignatureHelp(_)) => ("GetSignatureHelp", false),
882 Some(lsp_query::Request::GetCodeLens(_)) => ("GetCodeLens", true),
883 Some(lsp_query::Request::GetDocumentDiagnostics(_)) => {
884 ("GetDocumentDiagnostics", false)
885 }
886 Some(lsp_query::Request::GetDefinition(_)) => ("GetDefinition", false),
887 Some(lsp_query::Request::GetDeclaration(_)) => ("GetDeclaration", false),
888 Some(lsp_query::Request::GetTypeDefinition(_)) => ("GetTypeDefinition", false),
889 Some(lsp_query::Request::GetImplementation(_)) => ("GetImplementation", false),
890 Some(lsp_query::Request::GetReferences(_)) => ("GetReferences", false),
891 Some(lsp_query::Request::GetDocumentColor(_)) => ("GetDocumentColor", false),
892 Some(lsp_query::Request::InlayHints(_)) => ("InlayHints", false),
893 None => ("<unknown>", true),
894 }
895 }
896}
897
898#[cfg(test)]
899mod tests {
900 use super::*;
901
902 #[test]
903 fn test_converting_peer_id_from_and_to_u64() {
904 let peer_id = PeerId {
905 owner_id: 10,
906 id: 3,
907 };
908 assert_eq!(PeerId::from_u64(peer_id.as_u64()), peer_id);
909 let peer_id = PeerId {
910 owner_id: u32::MAX,
911 id: 3,
912 };
913 assert_eq!(PeerId::from_u64(peer_id.as_u64()), peer_id);
914 let peer_id = PeerId {
915 owner_id: 10,
916 id: u32::MAX,
917 };
918 assert_eq!(PeerId::from_u64(peer_id.as_u64()), peer_id);
919 let peer_id = PeerId {
920 owner_id: u32::MAX,
921 id: u32::MAX,
922 };
923 assert_eq!(PeerId::from_u64(peer_id.as_u64()), peer_id);
924 }
925}