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