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 (AllocateWorktreeId, Foreground),
36 (AllocateWorktreeIdResponse, Foreground),
37 (ApplyCodeAction, Background),
38 (ApplyCodeActionResponse, Background),
39 (ApplyCompletionAdditionalEdits, Background),
40 (ApplyCompletionAdditionalEditsResponse, Background),
41 (BlameBuffer, Foreground),
42 (BlameBufferResponse, Foreground),
43 (BufferReloaded, Foreground),
44 (BufferSaved, Foreground),
45 (Call, Foreground),
46 (CallCanceled, Foreground),
47 (CancelCall, Foreground),
48 (CancelLanguageServerWork, Foreground),
49 (ChannelMessageSent, Foreground),
50 (ChannelMessageUpdate, Foreground),
51 (CloseBuffer, Foreground),
52 (Commit, Background),
53 (RunGitHook, Background),
54 (CopyProjectEntry, Foreground),
55 (CreateBufferForPeer, Foreground),
56 (CreateImageForPeer, Foreground),
57 (CreateFileForPeer, Foreground),
58 (CreateChannel, Foreground),
59 (CreateChannelResponse, Foreground),
60 (CreateProjectEntry, Foreground),
61 (CreateRoom, Foreground),
62 (CreateRoomResponse, Foreground),
63 (DeclineCall, Foreground),
64 (DeleteChannel, Foreground),
65 (DeleteNotification, Foreground),
66 (DeleteProjectEntry, Foreground),
67 (DownloadFileByPath, Background),
68 (DownloadFileResponse, Background),
69 (EndStream, Foreground),
70 (Error, Foreground),
71 (ExpandProjectEntry, Foreground),
72 (ExpandProjectEntryResponse, Foreground),
73 (FindSearchCandidates, Background),
74 (FlushBufferedMessages, Foreground),
75 (ExpandAllForProjectEntry, Foreground),
76 (ExpandAllForProjectEntryResponse, Foreground),
77 (Follow, Foreground),
78 (FollowResponse, Foreground),
79 (ApplyCodeActionKind, Foreground),
80 (ApplyCodeActionKindResponse, Foreground),
81 (FormatBuffers, Foreground),
82 (FormatBuffersResponse, Foreground),
83 (FuzzySearchUsers, Foreground),
84 (GetChannelMembers, Foreground),
85 (GetChannelMembersResponse, Foreground),
86 (GetChannelMessages, Background),
87 (GetChannelMessagesById, Background),
88 (GetChannelMessagesResponse, Background),
89 (GetCodeActions, Background),
90 (GetCodeActionsResponse, Background),
91 (GetCompletions, Background),
92 (GetCompletionsResponse, Background),
93 (GetDeclaration, Background),
94 (GetDeclarationResponse, Background),
95 (GetDefinition, Background),
96 (GetDefinitionResponse, Background),
97 (GetDocumentHighlights, Background),
98 (GetDocumentHighlightsResponse, Background),
99 (GetDocumentSymbols, Background),
100 (GetDocumentSymbolsResponse, Background),
101 (GetHover, Background),
102 (GetHoverResponse, Background),
103 (GetNotifications, Foreground),
104 (GetNotificationsResponse, Foreground),
105 (GetCrashFiles, Background),
106 (GetCrashFilesResponse, Background),
107 (GetPathMetadata, Background),
108 (GetPathMetadataResponse, Background),
109 (GetPermalinkToLine, Foreground),
110 (GetProcesses, Background),
111 (GetProcessesResponse, Background),
112 (GetPermalinkToLineResponse, Foreground),
113 (GetProjectSymbols, Background),
114 (GetProjectSymbolsResponse, Background),
115 (GetReferences, Background),
116 (GetReferencesResponse, Background),
117 (GetSignatureHelp, Background),
118 (GetSignatureHelpResponse, 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 (SemanticTokens, Background),
136 (SemanticTokensResponse, Background),
137 (InstallExtension, Background),
138 (InviteChannelMember, Foreground),
139 (JoinChannel, Foreground),
140 (JoinChannelBuffer, Foreground),
141 (JoinChannelBufferResponse, Foreground),
142 (JoinChannelChat, Foreground),
143 (JoinChannelChatResponse, Foreground),
144 (JoinProject, Foreground),
145 (JoinProjectResponse, Foreground),
146 (JoinRoom, Foreground),
147 (JoinRoomResponse, Foreground),
148 (LanguageServerLog, Foreground),
149 (LanguageServerPromptRequest, Foreground),
150 (LanguageServerPromptResponse, Foreground),
151 (LeaveChannelBuffer, Background),
152 (LeaveChannelChat, Foreground),
153 (LeaveProject, Foreground),
154 (LeaveRoom, Foreground),
155 (LinkedEditingRange, Background),
156 (LinkedEditingRangeResponse, Background),
157 (ListRemoteDirectory, Background),
158 (ListRemoteDirectoryResponse, Background),
159 (ListToolchains, Foreground),
160 (ListToolchainsResponse, Foreground),
161 (LoadCommitDiff, Foreground),
162 (LoadCommitDiffResponse, Foreground),
163 (LspExtExpandMacro, Background),
164 (LspExtExpandMacroResponse, Background),
165 (LspExtOpenDocs, Background),
166 (LspExtOpenDocsResponse, Background),
167 (LspExtRunnables, Background),
168 (LspExtRunnablesResponse, Background),
169 (LspExtSwitchSourceHeader, Background),
170 (LspExtSwitchSourceHeaderResponse, Background),
171 (LspExtGoToParentModule, Background),
172 (LspExtGoToParentModuleResponse, Background),
173 (LspExtCancelFlycheck, Background),
174 (LspExtRunFlycheck, Background),
175 (LspExtClearFlycheck, Background),
176 (MarkNotificationRead, Foreground),
177 (MoveChannel, Foreground),
178 (ReorderChannel, Foreground),
179 (LspQuery, Background),
180 (LspQueryResponse, Background),
181 (OnTypeFormatting, Background),
182 (OnTypeFormattingResponse, Background),
183 (OpenBufferById, Background),
184 (OpenBufferByPath, Background),
185 (OpenImageByPath, Background),
186 (OpenBufferForSymbol, Background),
187 (OpenBufferForSymbolResponse, Background),
188 (OpenBufferResponse, Background),
189 (OpenImageResponse, Background),
190 (OpenCommitMessageBuffer, Background),
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, Background),
200 (RefreshSemanticTokens, Background),
201 (RegisterBufferWithLanguageServers, Background),
202 (RejoinChannelBuffers, Foreground),
203 (RejoinChannelBuffersResponse, Foreground),
204 (RejoinRemoteProjects, Foreground),
205 (RejoinRemoteProjectsResponse, Foreground),
206 (RejoinRoom, Foreground),
207 (RejoinRoomResponse, Foreground),
208 (ReloadBuffers, Foreground),
209 (ReloadBuffersResponse, Foreground),
210 (RemoveChannelMember, Foreground),
211 (RemoveChannelMessage, Foreground),
212 (RemoveContact, Foreground),
213 (RemoveProjectCollaborator, Foreground),
214 (RemoveWorktree, Foreground),
215 (RenameChannel, Foreground),
216 (RenameChannelResponse, Foreground),
217 (RenameProjectEntry, Foreground),
218 (RequestContact, Foreground),
219 (ResolveCompletionDocumentation, Background),
220 (ResolveCompletionDocumentationResponse, Background),
221 (ResolveInlayHint, Background),
222 (ResolveInlayHintResponse, Background),
223 (GetDocumentColor, Background),
224 (GetDocumentColorResponse, Background),
225 (GetColorPresentation, Background),
226 (GetColorPresentationResponse, Background),
227 (GetFoldingRanges, Background),
228 (GetFoldingRangesResponse, Background),
229 (RefreshCodeLens, Background),
230 (GetCodeLens, Background),
231 (GetCodeLensResponse, Background),
232 (RespondToChannelInvite, Foreground),
233 (RespondToContactRequest, Foreground),
234 (RestartLanguageServers, Foreground),
235 (StopLanguageServers, Background),
236 (RoomUpdated, Foreground),
237 (SaveBuffer, Foreground),
238 (SendChannelMessage, Background),
239 (SendChannelMessageResponse, Background),
240 (SetChannelMemberRole, Foreground),
241 (SetChannelVisibility, Foreground),
242 (SetRoomParticipantRole, Foreground),
243 (ShareProject, Foreground),
244 (ShareProjectResponse, Foreground),
245 (ShowContacts, Foreground),
246 (ShutdownRemoteServer, Foreground),
247 (Stage, Background),
248 (StartLanguageServer, Foreground),
249 (SubscribeToChannels, Foreground),
250 (SyncExtensions, Background),
251 (SyncExtensionsResponse, Background),
252 (BreakpointsForFile, Background),
253 (ToggleBreakpoint, Foreground),
254 (SynchronizeBuffers, Foreground),
255 (SynchronizeBuffersResponse, Foreground),
256 (TaskContext, Background),
257 (TaskContextForLocation, Background),
258 (Test, Foreground),
259 (Toast, Background),
260 (Unfollow, Foreground),
261 (UnshareProject, Foreground),
262 (Unstage, Background),
263 (Stash, Background),
264 (StashPop, Background),
265 (StashApply, Background),
266 (StashDrop, Background),
267 (UpdateBuffer, Foreground),
268 (UpdateBufferFile, Foreground),
269 (UpdateChannelBuffer, Foreground),
270 (UpdateChannelBufferCollaborators, Foreground),
271 (UpdateChannelMessage, Foreground),
272 (UpdateChannels, Foreground),
273 (UpdateContacts, Foreground),
274 (UpdateDiagnosticSummary, Foreground),
275 (UpdateDiffBases, Foreground),
276 (UpdateFollowers, Foreground),
277 (UpdateGitBranch, Background),
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 (GitDeleteBranch, Background),
292 (GitCheckoutFiles, Background),
293 (GitShow, Background),
294 (GitCommitDetails, Background),
295 (GitFileHistory, Background),
296 (GitFileHistoryResponse, Background),
297 (GitCreateCheckpoint, Background),
298 (GitCreateCheckpointResponse, Background),
299 (GitCreateArchiveCheckpoint, Background),
300 (GitCreateArchiveCheckpointResponse, Background),
301 (GitRestoreCheckpoint, Background),
302 (GitRestoreArchiveCheckpoint, Background),
303 (GitCompareCheckpoints, Background),
304 (GitCompareCheckpointsResponse, Background),
305 (GitDiffCheckpoints, Background),
306 (GitDiffCheckpointsResponse, Background),
307 (SetIndexText, Background),
308 (Push, Background),
309 (Fetch, Background),
310 (GetRemotes, Background),
311 (GetRemotesResponse, Background),
312 (Pull, Background),
313 (RemoteMessageResponse, Background),
314 (AskPassRequest, Background),
315 (AskPassResponse, Background),
316 (GitCreateRemote, Background),
317 (GitRemoveRemote, Background),
318 (GitCreateBranch, Background),
319 (GitChangeBranch, Background),
320 (GitRenameBranch, Background),
321 (TrustWorktrees, Background),
322 (RestrictWorktrees, Background),
323 (CheckForPushedCommits, Background),
324 (CheckForPushedCommitsResponse, Background),
325 (GitDiff, Background),
326 (GitDiffResponse, Background),
327 (GitInit, Background),
328 (GetDebugAdapterBinary, Background),
329 (DebugAdapterBinary, Background),
330 (RunDebugLocators, Background),
331 (DebugRequest, Background),
332 (LogToDebugConsole, Background),
333 (GetDocumentDiagnostics, Background),
334 (GetDocumentDiagnosticsResponse, Background),
335 (PullWorkspaceDiagnostics, Background),
336 (GetDefaultBranch, Background),
337 (GetDefaultBranchResponse, Background),
338 (GetTreeDiff, Background),
339 (GetTreeDiffResponse, Background),
340 (GetBlobContent, Background),
341 (GetBlobContentResponse, Background),
342 (GitClone, Background),
343 (GitCloneResponse, Background),
344 (ToggleLspLogs, Background),
345 (GetDirectoryEnvironment, Background),
346 (DirectoryEnvironment, Background),
347 (GetAgentServerCommand, Background),
348 (AgentServerCommand, Background),
349 (GetContextServerCommand, Background),
350 (ContextServerCommand, Background),
351 (ExternalAgentsUpdated, Background),
352 (ExternalExtensionAgentsUpdated, Background),
353 (ExternalAgentLoadingStatusUpdated, Background),
354 (NewExternalAgentVersionAvailable, Background),
355 (RemoteStarted, Background),
356 (GitGetWorktrees, Background),
357 (GitGetHeadSha, Background),
358 (GitGetHeadShaResponse, Background),
359 (GitEditRef, Background),
360 (GitRepairWorktrees, Background),
361 (GetCommitData, Background),
362 (GetCommitDataResponse, Background),
363 (GitWorktreesResponse, Background),
364 (GitCreateWorktree, Background),
365 (GitRemoveWorktree, Background),
366 (GitRenameWorktree, Background),
367 (ShareAgentThread, Foreground),
368 (GetSharedAgentThread, Foreground),
369 (GetSharedAgentThreadResponse, Foreground),
370 (FindSearchCandidatesChunk, Background),
371 (FindSearchCandidatesCancelled, Background),
372 (SpawnKernel, Background),
373 (SpawnKernelResponse, Background),
374 (KillKernel, Background),
375 (GetRemoteProfilingData, Background),
376 (GetRemoteProfilingDataResponse, Background),
377);
378
379request_messages!(
380 (AllocateWorktreeId, AllocateWorktreeIdResponse),
381 (ApplyCodeAction, ApplyCodeActionResponse),
382 (
383 ApplyCompletionAdditionalEdits,
384 ApplyCompletionAdditionalEditsResponse
385 ),
386 (Call, Ack),
387 (CancelCall, Ack),
388 (Commit, Ack),
389 (RunGitHook, Ack),
390 (CopyProjectEntry, ProjectEntryResponse),
391 (CreateChannel, CreateChannelResponse),
392 (CreateProjectEntry, ProjectEntryResponse),
393 (CreateRoom, CreateRoomResponse),
394 (DeclineCall, Ack),
395 (DeleteChannel, Ack),
396 (DeleteProjectEntry, ProjectEntryResponse),
397 (DownloadFileByPath, DownloadFileResponse),
398 (ExpandProjectEntry, ExpandProjectEntryResponse),
399 (ExpandAllForProjectEntry, ExpandAllForProjectEntryResponse),
400 (Follow, FollowResponse),
401 (ApplyCodeActionKind, ApplyCodeActionKindResponse),
402 (FormatBuffers, FormatBuffersResponse),
403 (FuzzySearchUsers, UsersResponse),
404 (GetChannelMembers, GetChannelMembersResponse),
405 (GetChannelMessages, GetChannelMessagesResponse),
406 (GetChannelMessagesById, GetChannelMessagesResponse),
407 (GetCodeActions, GetCodeActionsResponse),
408 (GetCompletions, GetCompletionsResponse),
409 (GetDefinition, GetDefinitionResponse),
410 (GetDeclaration, GetDeclarationResponse),
411 (GetImplementation, GetImplementationResponse),
412 (GetDocumentHighlights, GetDocumentHighlightsResponse),
413 (GetDocumentSymbols, GetDocumentSymbolsResponse),
414 (GetHover, GetHoverResponse),
415 (GetNotifications, GetNotificationsResponse),
416 (GetProjectSymbols, GetProjectSymbolsResponse),
417 (GetReferences, GetReferencesResponse),
418 (GetSignatureHelp, GetSignatureHelpResponse),
419 (OpenUnstagedDiff, OpenUnstagedDiffResponse),
420 (OpenUncommittedDiff, OpenUncommittedDiffResponse),
421 (GetTypeDefinition, GetTypeDefinitionResponse),
422 (LinkedEditingRange, LinkedEditingRangeResponse),
423 (ListRemoteDirectory, ListRemoteDirectoryResponse),
424 (GetUsers, UsersResponse),
425 (IncomingCall, Ack),
426 (InlayHints, InlayHintsResponse),
427 (SemanticTokens, SemanticTokensResponse),
428 (GetCodeLens, GetCodeLensResponse),
429 (InviteChannelMember, Ack),
430 (JoinChannel, JoinRoomResponse),
431 (JoinChannelBuffer, JoinChannelBufferResponse),
432 (JoinChannelChat, JoinChannelChatResponse),
433 (JoinProject, JoinProjectResponse),
434 (JoinRoom, JoinRoomResponse),
435 (LeaveChannelBuffer, Ack),
436 (LeaveRoom, Ack),
437 (LoadCommitDiff, LoadCommitDiffResponse),
438 (MarkNotificationRead, Ack),
439 (MoveChannel, Ack),
440 (OnTypeFormatting, OnTypeFormattingResponse),
441 (OpenBufferById, OpenBufferResponse),
442 (OpenBufferByPath, OpenBufferResponse),
443 (OpenImageByPath, OpenImageResponse),
444 (OpenBufferForSymbol, OpenBufferForSymbolResponse),
445 (OpenCommitMessageBuffer, OpenBufferResponse),
446 (OpenNewBuffer, OpenBufferResponse),
447 (PerformRename, PerformRenameResponse),
448 (Ping, Ack),
449 (PrepareRename, PrepareRenameResponse),
450 (RefreshInlayHints, Ack),
451 (RefreshSemanticTokens, Ack),
452 (RefreshCodeLens, Ack),
453 (RejoinChannelBuffers, RejoinChannelBuffersResponse),
454 (RejoinRoom, RejoinRoomResponse),
455 (ReloadBuffers, ReloadBuffersResponse),
456 (RemoveChannelMember, Ack),
457 (RemoveChannelMessage, Ack),
458 (UpdateChannelMessage, Ack),
459 (RemoveContact, Ack),
460 (RenameChannel, RenameChannelResponse),
461 (RenameProjectEntry, ProjectEntryResponse),
462 (ReorderChannel, Ack),
463 (RequestContact, Ack),
464 (
465 ResolveCompletionDocumentation,
466 ResolveCompletionDocumentationResponse
467 ),
468 (ResolveInlayHint, ResolveInlayHintResponse),
469 (GetDocumentColor, GetDocumentColorResponse),
470 (GetFoldingRanges, GetFoldingRangesResponse),
471 (GetColorPresentation, GetColorPresentationResponse),
472 (RespondToChannelInvite, Ack),
473 (RespondToContactRequest, Ack),
474 (SaveBuffer, BufferSaved),
475 (Stage, Ack),
476 (FindSearchCandidates, Ack),
477 (SendChannelMessage, SendChannelMessageResponse),
478 (SetChannelMemberRole, Ack),
479 (SetChannelVisibility, Ack),
480 (ShareAgentThread, Ack),
481 (GetSharedAgentThread, GetSharedAgentThreadResponse),
482 (ShareProject, ShareProjectResponse),
483 (SynchronizeBuffers, SynchronizeBuffersResponse),
484 (TaskContextForLocation, TaskContext),
485 (Test, Test),
486 (Unstage, Ack),
487 (Stash, Ack),
488 (StashPop, Ack),
489 (StashApply, Ack),
490 (StashDrop, Ack),
491 (UpdateBuffer, Ack),
492 (UpdateParticipantLocation, Ack),
493 (UpdateProject, Ack),
494 (UpdateWorktree, Ack),
495 (UpdateRepository, Ack),
496 (RemoveRepository, Ack),
497 (LspExtExpandMacro, LspExtExpandMacroResponse),
498 (LspExtOpenDocs, LspExtOpenDocsResponse),
499 (LspExtRunnables, LspExtRunnablesResponse),
500 (SetRoomParticipantRole, Ack),
501 (BlameBuffer, BlameBufferResponse),
502 (RejoinRemoteProjects, RejoinRemoteProjectsResponse),
503 (LspQuery, Ack),
504 (LspQueryResponse, Ack),
505 (RestartLanguageServers, Ack),
506 (StopLanguageServers, Ack),
507 (LspExtSwitchSourceHeader, LspExtSwitchSourceHeaderResponse),
508 (LspExtGoToParentModule, LspExtGoToParentModuleResponse),
509 (LspExtCancelFlycheck, Ack),
510 (LspExtRunFlycheck, Ack),
511 (LspExtClearFlycheck, Ack),
512 (AddWorktree, AddWorktreeResponse),
513 (ShutdownRemoteServer, Ack),
514 (RemoveWorktree, Ack),
515 (OpenServerSettings, OpenBufferResponse),
516 (GetPermalinkToLine, GetPermalinkToLineResponse),
517 (FlushBufferedMessages, Ack),
518 (LanguageServerPromptRequest, LanguageServerPromptResponse),
519 (GitGetBranches, GitBranchesResponse),
520 (UpdateGitBranch, Ack),
521 (ListToolchains, ListToolchainsResponse),
522 (ActivateToolchain, Ack),
523 (ActiveToolchain, ActiveToolchainResponse),
524 (ResolveToolchain, ResolveToolchainResponse),
525 (GetPathMetadata, GetPathMetadataResponse),
526 (GetCrashFiles, GetCrashFilesResponse),
527 (CancelLanguageServerWork, Ack),
528 (SyncExtensions, SyncExtensionsResponse),
529 (InstallExtension, Ack),
530 (RegisterBufferWithLanguageServers, Ack),
531 (GitShow, GitCommitDetails),
532 (GitFileHistory, GitFileHistoryResponse),
533 (GitCreateCheckpoint, GitCreateCheckpointResponse),
534 (
535 GitCreateArchiveCheckpoint,
536 GitCreateArchiveCheckpointResponse
537 ),
538 (GitRestoreCheckpoint, Ack),
539 (GitRestoreArchiveCheckpoint, Ack),
540 (GitCompareCheckpoints, GitCompareCheckpointsResponse),
541 (GitDiffCheckpoints, GitDiffCheckpointsResponse),
542 (GitReset, Ack),
543 (GitDeleteBranch, Ack),
544 (GitCheckoutFiles, Ack),
545 (SetIndexText, Ack),
546 (Push, RemoteMessageResponse),
547 (Fetch, RemoteMessageResponse),
548 (GetRemotes, GetRemotesResponse),
549 (Pull, RemoteMessageResponse),
550 (AskPassRequest, AskPassResponse),
551 (GitCreateRemote, Ack),
552 (GitRemoveRemote, Ack),
553 (GitCreateBranch, Ack),
554 (GitChangeBranch, Ack),
555 (GitRenameBranch, Ack),
556 (CheckForPushedCommits, CheckForPushedCommitsResponse),
557 (GitDiff, GitDiffResponse),
558 (GitInit, Ack),
559 (ToggleBreakpoint, Ack),
560 (GetDebugAdapterBinary, DebugAdapterBinary),
561 (RunDebugLocators, DebugRequest),
562 (GetDocumentDiagnostics, GetDocumentDiagnosticsResponse),
563 (PullWorkspaceDiagnostics, Ack),
564 (GetDefaultBranch, GetDefaultBranchResponse),
565 (GetBlobContent, GetBlobContentResponse),
566 (GetTreeDiff, GetTreeDiffResponse),
567 (GitClone, GitCloneResponse),
568 (ToggleLspLogs, Ack),
569 (GetDirectoryEnvironment, DirectoryEnvironment),
570 (GetProcesses, GetProcessesResponse),
571 (GetAgentServerCommand, AgentServerCommand),
572 (GetContextServerCommand, ContextServerCommand),
573 (RemoteStarted, Ack),
574 (GitGetWorktrees, GitWorktreesResponse),
575 (GitGetHeadSha, GitGetHeadShaResponse),
576 (GitEditRef, Ack),
577 (GitRepairWorktrees, Ack),
578 (GetCommitData, GetCommitDataResponse),
579 (GitCreateWorktree, Ack),
580 (GitRemoveWorktree, Ack),
581 (GitRenameWorktree, Ack),
582 (TrustWorktrees, Ack),
583 (RestrictWorktrees, Ack),
584 (FindSearchCandidatesChunk, Ack),
585 (SpawnKernel, SpawnKernelResponse),
586 (KillKernel, Ack),
587 (GetRemoteProfilingData, GetRemoteProfilingDataResponse),
588);
589
590lsp_messages!(
591 (GetReferences, GetReferencesResponse, true),
592 (GetDocumentColor, GetDocumentColorResponse, true),
593 (GetFoldingRanges, GetFoldingRangesResponse, true),
594 (GetDocumentSymbols, GetDocumentSymbolsResponse, true),
595 (GetHover, GetHoverResponse, true),
596 (GetCodeActions, GetCodeActionsResponse, true),
597 (GetSignatureHelp, GetSignatureHelpResponse, true),
598 (GetCodeLens, GetCodeLensResponse, true),
599 (GetDocumentDiagnostics, GetDocumentDiagnosticsResponse, true),
600 (GetDefinition, GetDefinitionResponse, true),
601 (GetDeclaration, GetDeclarationResponse, true),
602 (GetTypeDefinition, GetTypeDefinitionResponse, true),
603 (GetImplementation, GetImplementationResponse, true),
604 (InlayHints, InlayHintsResponse, false),
605 (SemanticTokens, SemanticTokensResponse, true)
606);
607
608entity_messages!(
609 {project_id, ShareProject},
610 AddProjectCollaborator,
611 AddWorktree,
612 AllocateWorktreeId,
613 ApplyCodeAction,
614 ApplyCompletionAdditionalEdits,
615 BlameBuffer,
616 BufferReloaded,
617 BufferSaved,
618 CloseBuffer,
619 Commit,
620 RunGitHook,
621 GetColorPresentation,
622 CopyProjectEntry,
623 CreateBufferForPeer,
624 CreateFileForPeer,
625 CreateImageForPeer,
626 CreateProjectEntry,
627 GetDocumentColor,
628 GetFoldingRanges,
629 DeleteProjectEntry,
630 ExpandProjectEntry,
631 ExpandAllForProjectEntry,
632 FindSearchCandidates,
633 ApplyCodeActionKind,
634 FormatBuffers,
635 GetCodeActions,
636 GetCodeLens,
637 GetCompletions,
638 GetDefinition,
639 GetDeclaration,
640 GetImplementation,
641 GetDocumentHighlights,
642 GetDocumentSymbols,
643 GetHover,
644 GetProjectSymbols,
645 GetReferences,
646 GetSignatureHelp,
647 OpenUnstagedDiff,
648 OpenUncommittedDiff,
649 GetTypeDefinition,
650 InlayHints,
651 SemanticTokens,
652 JoinProject,
653 LeaveProject,
654 SpawnKernel,
655 KillKernel,
656 LinkedEditingRange,
657 LoadCommitDiff,
658 LspQuery,
659 LspQueryResponse,
660 RestartLanguageServers,
661 StopLanguageServers,
662 OnTypeFormatting,
663 OpenNewBuffer,
664 OpenBufferById,
665 OpenBufferByPath,
666 OpenImageByPath,
667 OpenBufferForSymbol,
668 OpenCommitMessageBuffer,
669 PerformRename,
670 PrepareRename,
671 RefreshInlayHints,
672 RefreshSemanticTokens,
673 RefreshCodeLens,
674 ReloadBuffers,
675 RemoveProjectCollaborator,
676 RenameProjectEntry,
677 ResolveCompletionDocumentation,
678 ResolveInlayHint,
679 SaveBuffer,
680 Stage,
681 StartLanguageServer,
682 SynchronizeBuffers,
683 TaskContextForLocation,
684 UnshareProject,
685 Unstage,
686 Stash,
687 StashPop,
688 StashApply,
689 StashDrop,
690 UpdateBuffer,
691 UpdateBufferFile,
692 UpdateDiagnosticSummary,
693 UpdateDiffBases,
694 UpdateLanguageServer,
695 UpdateProject,
696 UpdateProjectCollaborator,
697 UpdateWorktree,
698 UpdateRepository,
699 RemoveRepository,
700 UpdateWorktreeSettings,
701 UpdateUserSettings,
702 LspExtExpandMacro,
703 LspExtOpenDocs,
704 LspExtRunnables,
705 LspExtSwitchSourceHeader,
706 LspExtGoToParentModule,
707 LspExtCancelFlycheck,
708 LspExtRunFlycheck,
709 LspExtClearFlycheck,
710 LanguageServerLog,
711 Toast,
712 HideToast,
713 OpenServerSettings,
714 GetPermalinkToLine,
715 LanguageServerPromptRequest,
716 GitGetBranches,
717 UpdateGitBranch,
718 ListToolchains,
719 ActivateToolchain,
720 ActiveToolchain,
721 ResolveToolchain,
722 GetPathMetadata,
723 GetProcesses,
724 CancelLanguageServerWork,
725 RegisterBufferWithLanguageServers,
726 GitShow,
727 GitFileHistory,
728 GitCreateCheckpoint,
729 GitRestoreCheckpoint,
730 GitCompareCheckpoints,
731 GitDiffCheckpoints,
732 GitReset,
733 GitDeleteBranch,
734 GitCheckoutFiles,
735 SetIndexText,
736 ToggleLspLogs,
737 GetDirectoryEnvironment,
738
739 Push,
740 Fetch,
741 GetRemotes,
742 Pull,
743 AskPassRequest,
744 GitChangeBranch,
745 GitRenameBranch,
746 GitCreateBranch,
747 GitCreateRemote,
748 GitRemoveRemote,
749 CheckForPushedCommits,
750 GitDiff,
751 GitInit,
752 BreakpointsForFile,
753 ToggleBreakpoint,
754 RunDebugLocators,
755 GetDebugAdapterBinary,
756 LogToDebugConsole,
757 GetDocumentDiagnostics,
758 PullWorkspaceDiagnostics,
759 GetDefaultBranch,
760 GetTreeDiff,
761 GetBlobContent,
762 GitClone,
763 GetAgentServerCommand,
764 GetContextServerCommand,
765 ExternalAgentsUpdated,
766 ExternalExtensionAgentsUpdated,
767 ExternalAgentLoadingStatusUpdated,
768 NewExternalAgentVersionAvailable,
769 GitGetWorktrees,
770 GitGetHeadSha,
771 GitEditRef,
772 GitRepairWorktrees,
773 GetCommitData,
774 GitCreateArchiveCheckpoint,
775 GitRestoreArchiveCheckpoint,
776 GitCreateWorktree,
777 GitRemoveWorktree,
778 GitRenameWorktree,
779 TrustWorktrees,
780 RestrictWorktrees,
781 FindSearchCandidatesChunk,
782 FindSearchCandidatesCancelled,
783 DownloadFileByPath,
784 GetRemoteProfilingData
785);
786
787entity_messages!(
788 {channel_id, Channel},
789 ChannelMessageSent,
790 ChannelMessageUpdate,
791 RemoveChannelMessage,
792 UpdateChannelMessage,
793 UpdateChannelBuffer,
794 UpdateChannelBufferCollaborators,
795);
796
797impl From<Timestamp> for SystemTime {
798 fn from(val: Timestamp) -> Self {
799 UNIX_EPOCH
800 .checked_add(Duration::new(val.seconds, val.nanos))
801 .unwrap()
802 }
803}
804
805impl From<SystemTime> for Timestamp {
806 fn from(time: SystemTime) -> Self {
807 let duration = time.duration_since(UNIX_EPOCH).unwrap_or_default();
808 Self {
809 seconds: duration.as_secs(),
810 nanos: duration.subsec_nanos(),
811 }
812 }
813}
814
815impl From<u128> for Nonce {
816 fn from(nonce: u128) -> Self {
817 let upper_half = (nonce >> 64) as u64;
818 let lower_half = nonce as u64;
819 Self {
820 upper_half,
821 lower_half,
822 }
823 }
824}
825
826impl From<Nonce> for u128 {
827 fn from(nonce: Nonce) -> Self {
828 let upper_half = (nonce.upper_half as u128) << 64;
829 let lower_half = nonce.lower_half as u128;
830 upper_half | lower_half
831 }
832}
833
834#[cfg(any(test, feature = "test-support"))]
835pub const MAX_WORKTREE_UPDATE_MAX_CHUNK_SIZE: usize = 2;
836#[cfg(not(any(test, feature = "test-support")))]
837pub const MAX_WORKTREE_UPDATE_MAX_CHUNK_SIZE: usize = 256;
838
839pub fn split_worktree_update(mut message: UpdateWorktree) -> impl Iterator<Item = UpdateWorktree> {
840 let mut done = false;
841
842 iter::from_fn(move || {
843 if done {
844 return None;
845 }
846
847 let updated_entries_chunk_size = cmp::min(
848 message.updated_entries.len(),
849 MAX_WORKTREE_UPDATE_MAX_CHUNK_SIZE,
850 );
851 let updated_entries: Vec<_> = message
852 .updated_entries
853 .drain(..updated_entries_chunk_size)
854 .collect();
855
856 let removed_entries_chunk_size = cmp::min(
857 message.removed_entries.len(),
858 MAX_WORKTREE_UPDATE_MAX_CHUNK_SIZE,
859 );
860 let removed_entries = message
861 .removed_entries
862 .drain(..removed_entries_chunk_size)
863 .collect();
864
865 let mut updated_repositories = Vec::new();
866 let mut limit = MAX_WORKTREE_UPDATE_MAX_CHUNK_SIZE;
867 while let Some(repo) = message.updated_repositories.first_mut() {
868 let updated_statuses_limit = cmp::min(repo.updated_statuses.len(), limit);
869 let removed_statuses_limit = cmp::min(repo.removed_statuses.len(), limit);
870
871 updated_repositories.push(RepositoryEntry {
872 repository_id: repo.repository_id,
873 branch_summary: repo.branch_summary.clone(),
874 updated_statuses: repo
875 .updated_statuses
876 .drain(..updated_statuses_limit)
877 .collect(),
878 removed_statuses: repo
879 .removed_statuses
880 .drain(..removed_statuses_limit)
881 .collect(),
882 current_merge_conflicts: repo.current_merge_conflicts.clone(),
883 });
884 if repo.removed_statuses.is_empty() && repo.updated_statuses.is_empty() {
885 message.updated_repositories.remove(0);
886 }
887 limit = limit.saturating_sub(removed_statuses_limit + updated_statuses_limit);
888 if limit == 0 {
889 break;
890 }
891 }
892
893 done = message.updated_entries.is_empty()
894 && message.removed_entries.is_empty()
895 && message.updated_repositories.is_empty();
896
897 let removed_repositories = if done {
898 mem::take(&mut message.removed_repositories)
899 } else {
900 Default::default()
901 };
902
903 Some(UpdateWorktree {
904 project_id: message.project_id,
905 worktree_id: message.worktree_id,
906 root_name: message.root_name.clone(),
907 abs_path: message.abs_path.clone(),
908 root_repo_common_dir: message.root_repo_common_dir.clone(),
909 updated_entries,
910 removed_entries,
911 scan_id: message.scan_id,
912 is_last_update: done && message.is_last_update,
913 updated_repositories,
914 removed_repositories,
915 })
916 })
917}
918
919pub fn split_repository_update(
920 mut update: UpdateRepository,
921) -> impl Iterator<Item = UpdateRepository> {
922 let mut updated_statuses_iter = mem::take(&mut update.updated_statuses).into_iter().fuse();
923 let mut removed_statuses_iter = mem::take(&mut update.removed_statuses).into_iter().fuse();
924 let branch_list = mem::take(&mut update.branch_list);
925 std::iter::from_fn({
926 let update = update.clone();
927 move || {
928 let updated_statuses = updated_statuses_iter
929 .by_ref()
930 .take(MAX_WORKTREE_UPDATE_MAX_CHUNK_SIZE)
931 .collect::<Vec<_>>();
932 let removed_statuses = removed_statuses_iter
933 .by_ref()
934 .take(MAX_WORKTREE_UPDATE_MAX_CHUNK_SIZE)
935 .collect::<Vec<_>>();
936 if updated_statuses.is_empty() && removed_statuses.is_empty() {
937 return None;
938 }
939 Some(UpdateRepository {
940 updated_statuses,
941 removed_statuses,
942 branch_list: Vec::new(),
943 is_last_update: false,
944 ..update.clone()
945 })
946 }
947 })
948 .chain([UpdateRepository {
949 updated_statuses: Vec::new(),
950 removed_statuses: Vec::new(),
951 branch_list,
952 is_last_update: true,
953 ..update
954 }])
955}
956
957impl LspQuery {
958 pub fn query_name_and_write_permissions(&self) -> (&str, bool) {
959 match self.request {
960 Some(lsp_query::Request::GetHover(_)) => ("GetHover", false),
961 Some(lsp_query::Request::GetCodeActions(_)) => ("GetCodeActions", true),
962 Some(lsp_query::Request::GetSignatureHelp(_)) => ("GetSignatureHelp", false),
963 Some(lsp_query::Request::GetCodeLens(_)) => ("GetCodeLens", true),
964 Some(lsp_query::Request::GetDocumentDiagnostics(_)) => {
965 ("GetDocumentDiagnostics", false)
966 }
967 Some(lsp_query::Request::GetDefinition(_)) => ("GetDefinition", false),
968 Some(lsp_query::Request::GetDeclaration(_)) => ("GetDeclaration", false),
969 Some(lsp_query::Request::GetTypeDefinition(_)) => ("GetTypeDefinition", false),
970 Some(lsp_query::Request::GetImplementation(_)) => ("GetImplementation", false),
971 Some(lsp_query::Request::GetReferences(_)) => ("GetReferences", false),
972 Some(lsp_query::Request::GetDocumentColor(_)) => ("GetDocumentColor", false),
973 Some(lsp_query::Request::GetFoldingRanges(_)) => ("GetFoldingRanges", false),
974 Some(lsp_query::Request::GetDocumentSymbols(_)) => ("GetDocumentSymbols", false),
975 Some(lsp_query::Request::InlayHints(_)) => ("InlayHints", false),
976 Some(lsp_query::Request::SemanticTokens(_)) => ("SemanticTokens", false),
977 None => ("<unknown>", true),
978 }
979 }
980}
981
982#[cfg(test)]
983mod tests {
984 use super::*;
985
986 #[test]
987 fn test_converting_peer_id_from_and_to_u64() {
988 let peer_id = PeerId {
989 owner_id: 10,
990 id: 3,
991 };
992 assert_eq!(PeerId::from_u64(peer_id.as_u64()), peer_id);
993 let peer_id = PeerId {
994 owner_id: u32::MAX,
995 id: 3,
996 };
997 assert_eq!(PeerId::from_u64(peer_id.as_u64()), peer_id);
998 let peer_id = PeerId {
999 owner_id: 10,
1000 id: u32::MAX,
1001 };
1002 assert_eq!(PeerId::from_u64(peer_id.as_u64()), peer_id);
1003 let peer_id = PeerId {
1004 owner_id: u32::MAX,
1005 id: u32::MAX,
1006 };
1007 assert_eq!(PeerId::from_u64(peer_id.as_u64()), peer_id);
1008 }
1009
1010 #[test]
1011 fn test_split_repository_update_keeps_branch_list_on_final_chunk() {
1012 let update = UpdateRepository {
1013 updated_statuses: vec![
1014 StatusEntry::default(),
1015 StatusEntry::default(),
1016 StatusEntry::default(),
1017 ],
1018 branch_list: vec![Branch {
1019 ref_name: "refs/heads/main".into(),
1020 ..Default::default()
1021 }],
1022 ..Default::default()
1023 };
1024
1025 let chunks = split_repository_update(update).collect::<Vec<_>>();
1026
1027 assert_eq!(chunks.len(), 3);
1028 assert!(chunks[0].branch_list.is_empty());
1029 assert!(chunks[1].branch_list.is_empty());
1030 assert_eq!(chunks[2].branch_list.len(), 1);
1031 assert_eq!(chunks[2].branch_list[0].ref_name, "refs/heads/main");
1032 assert!(!chunks[0].is_last_update);
1033 assert!(!chunks[1].is_last_update);
1034 assert!(chunks[2].is_last_update);
1035 }
1036}