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