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