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