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