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