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