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