proto.rs

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