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