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