proto.rs

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