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