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