1use std::sync::Arc;
8
9use derive_more::{Display, From};
10use serde::{Deserialize, Serialize};
11use serde_with::{DefaultOnError, VecSkipError, serde_as, skip_serializing_none};
12
13use crate::{IntoOption, SkipListener};
14
15use super::{Meta, SessionId};
16
17pub(crate) const NES_START_METHOD_NAME: &str = "nes/start";
21pub(crate) const NES_SUGGEST_METHOD_NAME: &str = "nes/suggest";
23pub(crate) const NES_ACCEPT_METHOD_NAME: &str = "nes/accept";
25pub(crate) const NES_REJECT_METHOD_NAME: &str = "nes/reject";
27pub(crate) const NES_CLOSE_METHOD_NAME: &str = "nes/close";
29pub(crate) const DOCUMENT_DID_OPEN_METHOD_NAME: &str = "document/didOpen";
31pub(crate) const DOCUMENT_DID_CHANGE_METHOD_NAME: &str = "document/didChange";
33pub(crate) const DOCUMENT_DID_CLOSE_METHOD_NAME: &str = "document/didClose";
35pub(crate) const DOCUMENT_DID_SAVE_METHOD_NAME: &str = "document/didSave";
37pub(crate) const DOCUMENT_DID_FOCUS_METHOD_NAME: &str = "document/didFocus";
39
40#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
42#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash, Display, From)]
43#[serde(transparent)]
44#[from(Arc<str>, String, &'static str)]
45#[non_exhaustive]
46pub struct NesSuggestionId(pub Arc<str>);
47
48impl NesSuggestionId {
49 #[must_use]
51 pub fn new(id: impl Into<Arc<str>>) -> Self {
52 Self(id.into())
53 }
54}
55
56#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
62#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
63#[non_exhaustive]
64pub enum PositionEncodingKind {
65 #[serde(rename = "utf-16")]
67 Utf16,
68 #[serde(rename = "utf-32")]
70 Utf32,
71 #[serde(rename = "utf-8")]
73 Utf8,
74}
75
76#[serde_as]
80#[skip_serializing_none]
81#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
82#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
83#[serde(rename_all = "camelCase")]
84#[non_exhaustive]
85pub struct Position {
86 pub line: u32,
88 pub character: u32,
90 #[serde_as(deserialize_as = "DefaultOnError")]
96 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
97 #[serde(default)]
98 #[serde(rename = "_meta")]
99 pub meta: Option<Meta>,
100}
101
102impl Position {
103 #[must_use]
105 pub fn new(line: u32, character: u32) -> Self {
106 Self {
107 line,
108 character,
109 meta: None,
110 }
111 }
112
113 #[must_use]
119 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
120 self.meta = meta.into_option();
121 self
122 }
123}
124
125#[serde_as]
127#[skip_serializing_none]
128#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
129#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
130#[serde(rename_all = "camelCase")]
131#[non_exhaustive]
132pub struct Range {
133 pub start: Position,
135 pub end: Position,
137 #[serde_as(deserialize_as = "DefaultOnError")]
143 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
144 #[serde(default)]
145 #[serde(rename = "_meta")]
146 pub meta: Option<Meta>,
147}
148
149impl Range {
150 #[must_use]
152 pub fn new(start: Position, end: Position) -> Self {
153 Self {
154 start,
155 end,
156 meta: None,
157 }
158 }
159
160 #[must_use]
166 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
167 self.meta = meta.into_option();
168 self
169 }
170}
171
172#[serde_as]
176#[skip_serializing_none]
177#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
178#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
179#[serde(rename_all = "camelCase")]
180#[non_exhaustive]
181pub struct NesCapabilities {
182 #[serde_as(deserialize_as = "DefaultOnError")]
184 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
185 #[serde(default)]
186 pub events: Option<NesEventCapabilities>,
187 #[serde_as(deserialize_as = "DefaultOnError")]
189 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
190 #[serde(default)]
191 pub context: Option<NesContextCapabilities>,
192 #[serde_as(deserialize_as = "DefaultOnError")]
198 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
199 #[serde(default)]
200 #[serde(rename = "_meta")]
201 pub meta: Option<Meta>,
202}
203
204impl NesCapabilities {
205 #[must_use]
207 pub fn new() -> Self {
208 Self::default()
209 }
210
211 #[must_use]
213 pub fn events(mut self, events: impl IntoOption<NesEventCapabilities>) -> Self {
214 self.events = events.into_option();
215 self
216 }
217
218 #[must_use]
220 pub fn context(mut self, context: impl IntoOption<NesContextCapabilities>) -> Self {
221 self.context = context.into_option();
222 self
223 }
224
225 #[must_use]
231 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
232 self.meta = meta.into_option();
233 self
234 }
235}
236
237#[serde_as]
239#[skip_serializing_none]
240#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
241#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
242#[serde(rename_all = "camelCase")]
243#[non_exhaustive]
244pub struct NesEventCapabilities {
245 #[serde_as(deserialize_as = "DefaultOnError")]
247 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
248 #[serde(default)]
249 pub document: Option<NesDocumentEventCapabilities>,
250 #[serde_as(deserialize_as = "DefaultOnError")]
256 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
257 #[serde(default)]
258 #[serde(rename = "_meta")]
259 pub meta: Option<Meta>,
260}
261
262impl NesEventCapabilities {
263 #[must_use]
265 pub fn new() -> Self {
266 Self::default()
267 }
268
269 #[must_use]
271 pub fn document(mut self, document: impl IntoOption<NesDocumentEventCapabilities>) -> Self {
272 self.document = document.into_option();
273 self
274 }
275
276 #[must_use]
282 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
283 self.meta = meta.into_option();
284 self
285 }
286}
287
288#[serde_as]
290#[skip_serializing_none]
291#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
292#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
293#[serde(rename_all = "camelCase")]
294#[non_exhaustive]
295pub struct NesDocumentEventCapabilities {
296 #[serde_as(deserialize_as = "DefaultOnError")]
298 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
299 #[serde(default)]
300 pub did_open: Option<NesDocumentDidOpenCapabilities>,
301 #[serde_as(deserialize_as = "DefaultOnError")]
303 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
304 #[serde(default)]
305 pub did_change: Option<NesDocumentDidChangeCapabilities>,
306 #[serde_as(deserialize_as = "DefaultOnError")]
308 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
309 #[serde(default)]
310 pub did_close: Option<NesDocumentDidCloseCapabilities>,
311 #[serde_as(deserialize_as = "DefaultOnError")]
313 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
314 #[serde(default)]
315 pub did_save: Option<NesDocumentDidSaveCapabilities>,
316 #[serde_as(deserialize_as = "DefaultOnError")]
318 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
319 #[serde(default)]
320 pub did_focus: Option<NesDocumentDidFocusCapabilities>,
321 #[serde_as(deserialize_as = "DefaultOnError")]
327 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
328 #[serde(default)]
329 #[serde(rename = "_meta")]
330 pub meta: Option<Meta>,
331}
332
333impl NesDocumentEventCapabilities {
334 #[must_use]
336 pub fn new() -> Self {
337 Self::default()
338 }
339
340 #[must_use]
342 pub fn did_open(mut self, did_open: impl IntoOption<NesDocumentDidOpenCapabilities>) -> Self {
343 self.did_open = did_open.into_option();
344 self
345 }
346
347 #[must_use]
349 pub fn did_change(
350 mut self,
351 did_change: impl IntoOption<NesDocumentDidChangeCapabilities>,
352 ) -> Self {
353 self.did_change = did_change.into_option();
354 self
355 }
356
357 #[must_use]
359 pub fn did_close(
360 mut self,
361 did_close: impl IntoOption<NesDocumentDidCloseCapabilities>,
362 ) -> Self {
363 self.did_close = did_close.into_option();
364 self
365 }
366
367 #[must_use]
369 pub fn did_save(mut self, did_save: impl IntoOption<NesDocumentDidSaveCapabilities>) -> Self {
370 self.did_save = did_save.into_option();
371 self
372 }
373
374 #[must_use]
376 pub fn did_focus(
377 mut self,
378 did_focus: impl IntoOption<NesDocumentDidFocusCapabilities>,
379 ) -> Self {
380 self.did_focus = did_focus.into_option();
381 self
382 }
383
384 #[must_use]
390 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
391 self.meta = meta.into_option();
392 self
393 }
394}
395
396#[serde_as]
398#[skip_serializing_none]
399#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
400#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
401#[serde(rename_all = "camelCase")]
402#[non_exhaustive]
403pub struct NesDocumentDidOpenCapabilities {
404 #[serde_as(deserialize_as = "DefaultOnError")]
410 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
411 #[serde(default)]
412 #[serde(rename = "_meta")]
413 pub meta: Option<Meta>,
414}
415
416impl NesDocumentDidOpenCapabilities {
417 #[must_use]
419 pub fn new() -> Self {
420 Self::default()
421 }
422}
423
424#[serde_as]
426#[skip_serializing_none]
427#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
428#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
429#[serde(rename_all = "camelCase")]
430#[non_exhaustive]
431pub struct NesDocumentDidChangeCapabilities {
432 pub sync_kind: TextDocumentSyncKind,
434 #[serde_as(deserialize_as = "DefaultOnError")]
440 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
441 #[serde(default)]
442 #[serde(rename = "_meta")]
443 pub meta: Option<Meta>,
444}
445
446impl NesDocumentDidChangeCapabilities {
447 #[must_use]
449 pub fn new(sync_kind: TextDocumentSyncKind) -> Self {
450 Self {
451 sync_kind,
452 meta: None,
453 }
454 }
455
456 #[must_use]
462 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
463 self.meta = meta.into_option();
464 self
465 }
466}
467
468#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
470#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
471#[non_exhaustive]
472pub enum TextDocumentSyncKind {
473 #[serde(rename = "full")]
475 Full,
476 #[serde(rename = "incremental")]
478 Incremental,
479}
480
481#[serde_as]
483#[skip_serializing_none]
484#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
485#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
486#[serde(rename_all = "camelCase")]
487#[non_exhaustive]
488pub struct NesDocumentDidCloseCapabilities {
489 #[serde_as(deserialize_as = "DefaultOnError")]
495 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
496 #[serde(default)]
497 #[serde(rename = "_meta")]
498 pub meta: Option<Meta>,
499}
500
501impl NesDocumentDidCloseCapabilities {
502 #[must_use]
504 pub fn new() -> Self {
505 Self::default()
506 }
507}
508
509#[serde_as]
511#[skip_serializing_none]
512#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
513#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
514#[serde(rename_all = "camelCase")]
515#[non_exhaustive]
516pub struct NesDocumentDidSaveCapabilities {
517 #[serde_as(deserialize_as = "DefaultOnError")]
523 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
524 #[serde(default)]
525 #[serde(rename = "_meta")]
526 pub meta: Option<Meta>,
527}
528
529impl NesDocumentDidSaveCapabilities {
530 #[must_use]
532 pub fn new() -> Self {
533 Self::default()
534 }
535}
536
537#[serde_as]
539#[skip_serializing_none]
540#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
541#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
542#[serde(rename_all = "camelCase")]
543#[non_exhaustive]
544pub struct NesDocumentDidFocusCapabilities {
545 #[serde_as(deserialize_as = "DefaultOnError")]
551 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
552 #[serde(default)]
553 #[serde(rename = "_meta")]
554 pub meta: Option<Meta>,
555}
556
557impl NesDocumentDidFocusCapabilities {
558 #[must_use]
560 pub fn new() -> Self {
561 Self::default()
562 }
563}
564
565#[serde_as]
567#[skip_serializing_none]
568#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
569#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
570#[serde(rename_all = "camelCase")]
571#[non_exhaustive]
572pub struct NesContextCapabilities {
573 #[serde_as(deserialize_as = "DefaultOnError")]
575 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
576 #[serde(default)]
577 pub recent_files: Option<NesRecentFilesCapabilities>,
578 #[serde_as(deserialize_as = "DefaultOnError")]
580 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
581 #[serde(default)]
582 pub related_snippets: Option<NesRelatedSnippetsCapabilities>,
583 #[serde_as(deserialize_as = "DefaultOnError")]
585 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
586 #[serde(default)]
587 pub edit_history: Option<NesEditHistoryCapabilities>,
588 #[serde_as(deserialize_as = "DefaultOnError")]
590 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
591 #[serde(default)]
592 pub user_actions: Option<NesUserActionsCapabilities>,
593 #[serde_as(deserialize_as = "DefaultOnError")]
595 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
596 #[serde(default)]
597 pub open_files: Option<NesOpenFilesCapabilities>,
598 #[serde_as(deserialize_as = "DefaultOnError")]
600 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
601 #[serde(default)]
602 pub diagnostics: Option<NesDiagnosticsCapabilities>,
603 #[serde_as(deserialize_as = "DefaultOnError")]
609 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
610 #[serde(default)]
611 #[serde(rename = "_meta")]
612 pub meta: Option<Meta>,
613}
614
615impl NesContextCapabilities {
616 #[must_use]
618 pub fn new() -> Self {
619 Self::default()
620 }
621
622 #[must_use]
624 pub fn recent_files(
625 mut self,
626 recent_files: impl IntoOption<NesRecentFilesCapabilities>,
627 ) -> Self {
628 self.recent_files = recent_files.into_option();
629 self
630 }
631
632 #[must_use]
634 pub fn related_snippets(
635 mut self,
636 related_snippets: impl IntoOption<NesRelatedSnippetsCapabilities>,
637 ) -> Self {
638 self.related_snippets = related_snippets.into_option();
639 self
640 }
641
642 #[must_use]
644 pub fn edit_history(
645 mut self,
646 edit_history: impl IntoOption<NesEditHistoryCapabilities>,
647 ) -> Self {
648 self.edit_history = edit_history.into_option();
649 self
650 }
651
652 #[must_use]
654 pub fn user_actions(
655 mut self,
656 user_actions: impl IntoOption<NesUserActionsCapabilities>,
657 ) -> Self {
658 self.user_actions = user_actions.into_option();
659 self
660 }
661
662 #[must_use]
664 pub fn open_files(mut self, open_files: impl IntoOption<NesOpenFilesCapabilities>) -> Self {
665 self.open_files = open_files.into_option();
666 self
667 }
668
669 #[must_use]
671 pub fn diagnostics(mut self, diagnostics: impl IntoOption<NesDiagnosticsCapabilities>) -> Self {
672 self.diagnostics = diagnostics.into_option();
673 self
674 }
675
676 #[must_use]
682 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
683 self.meta = meta.into_option();
684 self
685 }
686}
687
688#[serde_as]
690#[skip_serializing_none]
691#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
692#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
693#[serde(rename_all = "camelCase")]
694#[non_exhaustive]
695pub struct NesRecentFilesCapabilities {
696 #[serde_as(deserialize_as = "DefaultOnError")]
698 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
699 #[serde(default)]
700 pub max_count: Option<u32>,
701 #[serde_as(deserialize_as = "DefaultOnError")]
707 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
708 #[serde(default)]
709 #[serde(rename = "_meta")]
710 pub meta: Option<Meta>,
711}
712
713impl NesRecentFilesCapabilities {
714 #[must_use]
716 pub fn new() -> Self {
717 Self::default()
718 }
719}
720
721#[serde_as]
723#[skip_serializing_none]
724#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
725#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
726#[serde(rename_all = "camelCase")]
727#[non_exhaustive]
728pub struct NesRelatedSnippetsCapabilities {
729 #[serde_as(deserialize_as = "DefaultOnError")]
735 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
736 #[serde(default)]
737 #[serde(rename = "_meta")]
738 pub meta: Option<Meta>,
739}
740
741impl NesRelatedSnippetsCapabilities {
742 #[must_use]
744 pub fn new() -> Self {
745 Self::default()
746 }
747}
748
749#[serde_as]
751#[skip_serializing_none]
752#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
753#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
754#[serde(rename_all = "camelCase")]
755#[non_exhaustive]
756pub struct NesEditHistoryCapabilities {
757 #[serde_as(deserialize_as = "DefaultOnError")]
759 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
760 #[serde(default)]
761 pub max_count: Option<u32>,
762 #[serde_as(deserialize_as = "DefaultOnError")]
768 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
769 #[serde(default)]
770 #[serde(rename = "_meta")]
771 pub meta: Option<Meta>,
772}
773
774impl NesEditHistoryCapabilities {
775 #[must_use]
777 pub fn new() -> Self {
778 Self::default()
779 }
780}
781
782#[serde_as]
784#[skip_serializing_none]
785#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
786#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
787#[serde(rename_all = "camelCase")]
788#[non_exhaustive]
789pub struct NesUserActionsCapabilities {
790 #[serde_as(deserialize_as = "DefaultOnError")]
792 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
793 #[serde(default)]
794 pub max_count: Option<u32>,
795 #[serde_as(deserialize_as = "DefaultOnError")]
801 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
802 #[serde(default)]
803 #[serde(rename = "_meta")]
804 pub meta: Option<Meta>,
805}
806
807impl NesUserActionsCapabilities {
808 #[must_use]
810 pub fn new() -> Self {
811 Self::default()
812 }
813}
814
815#[serde_as]
817#[skip_serializing_none]
818#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
819#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
820#[serde(rename_all = "camelCase")]
821#[non_exhaustive]
822pub struct NesOpenFilesCapabilities {
823 #[serde_as(deserialize_as = "DefaultOnError")]
829 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
830 #[serde(default)]
831 #[serde(rename = "_meta")]
832 pub meta: Option<Meta>,
833}
834
835impl NesOpenFilesCapabilities {
836 #[must_use]
838 pub fn new() -> Self {
839 Self::default()
840 }
841}
842
843#[serde_as]
845#[skip_serializing_none]
846#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
847#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
848#[serde(rename_all = "camelCase")]
849#[non_exhaustive]
850pub struct NesDiagnosticsCapabilities {
851 #[serde_as(deserialize_as = "DefaultOnError")]
857 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
858 #[serde(default)]
859 #[serde(rename = "_meta")]
860 pub meta: Option<Meta>,
861}
862
863impl NesDiagnosticsCapabilities {
864 #[must_use]
866 pub fn new() -> Self {
867 Self::default()
868 }
869}
870
871#[serde_as]
875#[skip_serializing_none]
876#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
877#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
878#[serde(rename_all = "camelCase")]
879#[non_exhaustive]
880pub struct ClientNesCapabilities {
881 #[serde_as(deserialize_as = "DefaultOnError")]
883 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
884 #[serde(default)]
885 pub jump: Option<NesJumpCapabilities>,
886 #[serde_as(deserialize_as = "DefaultOnError")]
888 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
889 #[serde(default)]
890 pub rename: Option<NesRenameCapabilities>,
891 #[serde_as(deserialize_as = "DefaultOnError")]
893 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
894 #[serde(default)]
895 pub search_and_replace: Option<NesSearchAndReplaceCapabilities>,
896 #[serde_as(deserialize_as = "DefaultOnError")]
902 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
903 #[serde(default)]
904 #[serde(rename = "_meta")]
905 pub meta: Option<Meta>,
906}
907
908impl ClientNesCapabilities {
909 #[must_use]
911 pub fn new() -> Self {
912 Self::default()
913 }
914
915 #[must_use]
917 pub fn jump(mut self, jump: impl IntoOption<NesJumpCapabilities>) -> Self {
918 self.jump = jump.into_option();
919 self
920 }
921
922 #[must_use]
924 pub fn rename(mut self, rename: impl IntoOption<NesRenameCapabilities>) -> Self {
925 self.rename = rename.into_option();
926 self
927 }
928
929 #[must_use]
931 pub fn search_and_replace(
932 mut self,
933 search_and_replace: impl IntoOption<NesSearchAndReplaceCapabilities>,
934 ) -> Self {
935 self.search_and_replace = search_and_replace.into_option();
936 self
937 }
938
939 #[must_use]
945 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
946 self.meta = meta.into_option();
947 self
948 }
949}
950
951#[serde_as]
953#[skip_serializing_none]
954#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
955#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
956#[serde(rename_all = "camelCase")]
957#[non_exhaustive]
958pub struct NesJumpCapabilities {
959 #[serde_as(deserialize_as = "DefaultOnError")]
965 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
966 #[serde(default)]
967 #[serde(rename = "_meta")]
968 pub meta: Option<Meta>,
969}
970
971impl NesJumpCapabilities {
972 #[must_use]
974 pub fn new() -> Self {
975 Self::default()
976 }
977}
978
979#[serde_as]
981#[skip_serializing_none]
982#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
983#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
984#[serde(rename_all = "camelCase")]
985#[non_exhaustive]
986pub struct NesRenameCapabilities {
987 #[serde_as(deserialize_as = "DefaultOnError")]
993 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
994 #[serde(default)]
995 #[serde(rename = "_meta")]
996 pub meta: Option<Meta>,
997}
998
999impl NesRenameCapabilities {
1000 #[must_use]
1002 pub fn new() -> Self {
1003 Self::default()
1004 }
1005}
1006
1007#[serde_as]
1009#[skip_serializing_none]
1010#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
1011#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
1012#[serde(rename_all = "camelCase")]
1013#[non_exhaustive]
1014pub struct NesSearchAndReplaceCapabilities {
1015 #[serde_as(deserialize_as = "DefaultOnError")]
1021 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
1022 #[serde(default)]
1023 #[serde(rename = "_meta")]
1024 pub meta: Option<Meta>,
1025}
1026
1027impl NesSearchAndReplaceCapabilities {
1028 #[must_use]
1030 pub fn new() -> Self {
1031 Self::default()
1032 }
1033}
1034
1035#[serde_as]
1039#[skip_serializing_none]
1040#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
1041#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
1042#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = DOCUMENT_DID_OPEN_METHOD_NAME)))]
1043#[serde(rename_all = "camelCase")]
1044#[non_exhaustive]
1045pub struct DidOpenDocumentNotification {
1046 pub session_id: SessionId,
1048 pub uri: String,
1050 pub language_id: String,
1052 pub version: i64,
1054 pub text: String,
1056 #[serde_as(deserialize_as = "DefaultOnError")]
1062 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
1063 #[serde(default)]
1064 #[serde(rename = "_meta")]
1065 pub meta: Option<Meta>,
1066}
1067
1068impl DidOpenDocumentNotification {
1069 #[must_use]
1071 pub fn new(
1072 session_id: impl Into<SessionId>,
1073 uri: impl Into<String>,
1074 language_id: impl Into<String>,
1075 version: i64,
1076 text: impl Into<String>,
1077 ) -> Self {
1078 Self {
1079 session_id: session_id.into(),
1080 uri: uri.into(),
1081 language_id: language_id.into(),
1082 version,
1083 text: text.into(),
1084 meta: None,
1085 }
1086 }
1087
1088 #[must_use]
1094 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
1095 self.meta = meta.into_option();
1096 self
1097 }
1098}
1099
1100#[serde_as]
1102#[skip_serializing_none]
1103#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
1104#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
1105#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = DOCUMENT_DID_CHANGE_METHOD_NAME)))]
1106#[serde(rename_all = "camelCase")]
1107#[non_exhaustive]
1108pub struct DidChangeDocumentNotification {
1109 pub session_id: SessionId,
1111 pub uri: String,
1113 pub version: i64,
1115 #[serde_as(deserialize_as = "DefaultOnError<VecSkipError<_, SkipListener>>")]
1117 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true, "x-deserialize-skip-invalid-items" = true)))]
1118 pub content_changes: Vec<TextDocumentContentChangeEvent>,
1119 #[serde_as(deserialize_as = "DefaultOnError")]
1125 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
1126 #[serde(default)]
1127 #[serde(rename = "_meta")]
1128 pub meta: Option<Meta>,
1129}
1130
1131impl DidChangeDocumentNotification {
1132 #[must_use]
1134 pub fn new(
1135 session_id: impl Into<SessionId>,
1136 uri: impl Into<String>,
1137 version: i64,
1138 content_changes: Vec<TextDocumentContentChangeEvent>,
1139 ) -> Self {
1140 Self {
1141 session_id: session_id.into(),
1142 uri: uri.into(),
1143 version,
1144 content_changes,
1145 meta: None,
1146 }
1147 }
1148
1149 #[must_use]
1155 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
1156 self.meta = meta.into_option();
1157 self
1158 }
1159}
1160
1161#[serde_as]
1166#[skip_serializing_none]
1167#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
1168#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
1169#[serde(rename_all = "camelCase")]
1170#[non_exhaustive]
1171pub struct TextDocumentContentChangeEvent {
1172 #[serde(default)]
1174 pub range: Option<Range>,
1175 pub text: String,
1177 #[serde_as(deserialize_as = "DefaultOnError")]
1183 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
1184 #[serde(default)]
1185 #[serde(rename = "_meta")]
1186 pub meta: Option<Meta>,
1187}
1188
1189impl TextDocumentContentChangeEvent {
1190 #[must_use]
1192 pub fn full(text: impl Into<String>) -> Self {
1193 Self {
1194 range: None,
1195 text: text.into(),
1196 meta: None,
1197 }
1198 }
1199
1200 #[must_use]
1202 pub fn incremental(range: Range, text: impl Into<String>) -> Self {
1203 Self {
1204 range: Some(range),
1205 text: text.into(),
1206 meta: None,
1207 }
1208 }
1209
1210 #[must_use]
1216 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
1217 self.meta = meta.into_option();
1218 self
1219 }
1220}
1221
1222#[serde_as]
1224#[skip_serializing_none]
1225#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
1226#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
1227#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = DOCUMENT_DID_CLOSE_METHOD_NAME)))]
1228#[serde(rename_all = "camelCase")]
1229#[non_exhaustive]
1230pub struct DidCloseDocumentNotification {
1231 pub session_id: SessionId,
1233 pub uri: String,
1235 #[serde_as(deserialize_as = "DefaultOnError")]
1241 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
1242 #[serde(default)]
1243 #[serde(rename = "_meta")]
1244 pub meta: Option<Meta>,
1245}
1246
1247impl DidCloseDocumentNotification {
1248 #[must_use]
1250 pub fn new(session_id: impl Into<SessionId>, uri: impl Into<String>) -> Self {
1251 Self {
1252 session_id: session_id.into(),
1253 uri: uri.into(),
1254 meta: None,
1255 }
1256 }
1257
1258 #[must_use]
1264 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
1265 self.meta = meta.into_option();
1266 self
1267 }
1268}
1269
1270#[serde_as]
1272#[skip_serializing_none]
1273#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
1274#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
1275#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = DOCUMENT_DID_SAVE_METHOD_NAME)))]
1276#[serde(rename_all = "camelCase")]
1277#[non_exhaustive]
1278pub struct DidSaveDocumentNotification {
1279 pub session_id: SessionId,
1281 pub uri: String,
1283 #[serde_as(deserialize_as = "DefaultOnError")]
1289 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
1290 #[serde(default)]
1291 #[serde(rename = "_meta")]
1292 pub meta: Option<Meta>,
1293}
1294
1295impl DidSaveDocumentNotification {
1296 #[must_use]
1298 pub fn new(session_id: impl Into<SessionId>, uri: impl Into<String>) -> Self {
1299 Self {
1300 session_id: session_id.into(),
1301 uri: uri.into(),
1302 meta: None,
1303 }
1304 }
1305
1306 #[must_use]
1312 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
1313 self.meta = meta.into_option();
1314 self
1315 }
1316}
1317
1318#[serde_as]
1320#[skip_serializing_none]
1321#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
1322#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
1323#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = DOCUMENT_DID_FOCUS_METHOD_NAME)))]
1324#[serde(rename_all = "camelCase")]
1325#[non_exhaustive]
1326pub struct DidFocusDocumentNotification {
1327 pub session_id: SessionId,
1329 pub uri: String,
1331 pub version: i64,
1333 pub position: Position,
1335 pub visible_range: Range,
1337 #[serde_as(deserialize_as = "DefaultOnError")]
1343 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
1344 #[serde(default)]
1345 #[serde(rename = "_meta")]
1346 pub meta: Option<Meta>,
1347}
1348
1349impl DidFocusDocumentNotification {
1350 #[must_use]
1352 pub fn new(
1353 session_id: impl Into<SessionId>,
1354 uri: impl Into<String>,
1355 version: i64,
1356 position: Position,
1357 visible_range: Range,
1358 ) -> Self {
1359 Self {
1360 session_id: session_id.into(),
1361 uri: uri.into(),
1362 version,
1363 position,
1364 visible_range,
1365 meta: None,
1366 }
1367 }
1368
1369 #[must_use]
1375 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
1376 self.meta = meta.into_option();
1377 self
1378 }
1379}
1380
1381crate::serde_util::default_on_null! {
1384 #[serde_as]
1386 #[skip_serializing_none]
1387 #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
1388 #[derive(Debug, Clone, Serialize, PartialEq, Eq)]
1389 #[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = NES_START_METHOD_NAME)))]
1390 #[serde(rename_all = "camelCase")]
1391 #[non_exhaustive]
1392 pub struct StartNesRequest {
1393 #[serde_as(deserialize_as = "DefaultOnError")]
1395 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
1396 #[serde(default)]
1397 pub workspace_uri: Option<String>,
1398 #[serde(default)]
1400 pub workspace_folders: Option<Vec<WorkspaceFolder>>,
1401 #[serde_as(deserialize_as = "DefaultOnError")]
1403 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
1404 #[serde(default)]
1405 pub repository: Option<NesRepository>,
1406 #[serde_as(deserialize_as = "DefaultOnError")]
1412 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
1413 #[serde(default)]
1414 #[serde(rename = "_meta")]
1415 pub meta: Option<Meta>,
1416 }
1417}
1418
1419impl StartNesRequest {
1420 #[must_use]
1422 pub fn new() -> Self {
1423 Self {
1424 workspace_uri: None,
1425 workspace_folders: None,
1426 repository: None,
1427 meta: None,
1428 }
1429 }
1430
1431 #[must_use]
1433 pub fn workspace_uri(mut self, workspace_uri: impl IntoOption<String>) -> Self {
1434 self.workspace_uri = workspace_uri.into_option();
1435 self
1436 }
1437
1438 #[must_use]
1440 pub fn workspace_folders(
1441 mut self,
1442 workspace_folders: impl IntoOption<Vec<WorkspaceFolder>>,
1443 ) -> Self {
1444 self.workspace_folders = workspace_folders.into_option();
1445 self
1446 }
1447
1448 #[must_use]
1450 pub fn repository(mut self, repository: impl IntoOption<NesRepository>) -> Self {
1451 self.repository = repository.into_option();
1452 self
1453 }
1454
1455 #[must_use]
1461 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
1462 self.meta = meta.into_option();
1463 self
1464 }
1465}
1466
1467impl Default for StartNesRequest {
1468 fn default() -> Self {
1469 Self::new()
1470 }
1471}
1472
1473#[serde_as]
1475#[skip_serializing_none]
1476#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
1477#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
1478#[serde(rename_all = "camelCase")]
1479#[non_exhaustive]
1480pub struct WorkspaceFolder {
1481 pub uri: String,
1483 pub name: String,
1485 #[serde_as(deserialize_as = "DefaultOnError")]
1491 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
1492 #[serde(default)]
1493 #[serde(rename = "_meta")]
1494 pub meta: Option<Meta>,
1495}
1496
1497impl WorkspaceFolder {
1498 #[must_use]
1500 pub fn new(uri: impl Into<String>, name: impl Into<String>) -> Self {
1501 Self {
1502 uri: uri.into(),
1503 name: name.into(),
1504 meta: None,
1505 }
1506 }
1507
1508 #[must_use]
1514 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
1515 self.meta = meta.into_option();
1516 self
1517 }
1518}
1519
1520#[serde_as]
1522#[skip_serializing_none]
1523#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
1524#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
1525#[serde(rename_all = "camelCase")]
1526#[non_exhaustive]
1527pub struct NesRepository {
1528 pub name: String,
1530 pub owner: String,
1532 pub remote_url: String,
1534 #[serde_as(deserialize_as = "DefaultOnError")]
1540 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
1541 #[serde(default)]
1542 #[serde(rename = "_meta")]
1543 pub meta: Option<Meta>,
1544}
1545
1546impl NesRepository {
1547 #[must_use]
1549 pub fn new(
1550 name: impl Into<String>,
1551 owner: impl Into<String>,
1552 remote_url: impl Into<String>,
1553 ) -> Self {
1554 Self {
1555 name: name.into(),
1556 owner: owner.into(),
1557 remote_url: remote_url.into(),
1558 meta: None,
1559 }
1560 }
1561
1562 #[must_use]
1568 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
1569 self.meta = meta.into_option();
1570 self
1571 }
1572}
1573
1574#[serde_as]
1576#[skip_serializing_none]
1577#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
1578#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
1579#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = NES_START_METHOD_NAME)))]
1580#[serde(rename_all = "camelCase")]
1581#[non_exhaustive]
1582pub struct StartNesResponse {
1583 pub session_id: SessionId,
1585 #[serde_as(deserialize_as = "DefaultOnError")]
1591 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
1592 #[serde(default)]
1593 #[serde(rename = "_meta")]
1594 pub meta: Option<Meta>,
1595}
1596
1597impl StartNesResponse {
1598 #[must_use]
1600 pub fn new(session_id: impl Into<SessionId>) -> Self {
1601 Self {
1602 session_id: session_id.into(),
1603 meta: None,
1604 }
1605 }
1606
1607 #[must_use]
1613 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
1614 self.meta = meta.into_option();
1615 self
1616 }
1617}
1618
1619#[serde_as]
1626#[skip_serializing_none]
1627#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
1628#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
1629#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = NES_CLOSE_METHOD_NAME)))]
1630#[serde(rename_all = "camelCase")]
1631#[non_exhaustive]
1632pub struct CloseNesRequest {
1633 pub session_id: SessionId,
1635 #[serde_as(deserialize_as = "DefaultOnError")]
1641 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
1642 #[serde(default)]
1643 #[serde(rename = "_meta")]
1644 pub meta: Option<Meta>,
1645}
1646
1647impl CloseNesRequest {
1648 #[must_use]
1650 pub fn new(session_id: impl Into<SessionId>) -> Self {
1651 Self {
1652 session_id: session_id.into(),
1653 meta: None,
1654 }
1655 }
1656
1657 #[must_use]
1663 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
1664 self.meta = meta.into_option();
1665 self
1666 }
1667}
1668
1669crate::serde_util::default_on_null! {
1670 #[serde_as]
1672 #[skip_serializing_none]
1673 #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
1674 #[derive(Default, Debug, Clone, Serialize, PartialEq, Eq)]
1675 #[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = NES_CLOSE_METHOD_NAME)))]
1676 #[serde(rename_all = "camelCase")]
1677 #[non_exhaustive]
1678 pub struct CloseNesResponse {
1679 #[serde_as(deserialize_as = "DefaultOnError")]
1685 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
1686 #[serde(default)]
1687 #[serde(rename = "_meta")]
1688 pub meta: Option<Meta>,
1689 }
1690}
1691
1692impl CloseNesResponse {
1693 #[must_use]
1695 pub fn new() -> Self {
1696 Self::default()
1697 }
1698
1699 #[must_use]
1705 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
1706 self.meta = meta.into_option();
1707 self
1708 }
1709}
1710
1711#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
1715#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
1716#[non_exhaustive]
1717pub enum NesTriggerKind {
1718 #[serde(rename = "automatic")]
1720 Automatic,
1721 #[serde(rename = "diagnostic")]
1723 Diagnostic,
1724 #[serde(rename = "manual")]
1726 Manual,
1727}
1728
1729#[serde_as]
1731#[skip_serializing_none]
1732#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
1733#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
1734#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = NES_SUGGEST_METHOD_NAME)))]
1735#[serde(rename_all = "camelCase")]
1736#[non_exhaustive]
1737pub struct SuggestNesRequest {
1738 pub session_id: SessionId,
1740 pub uri: String,
1742 pub version: i64,
1744 pub position: Position,
1746 #[serde(default)]
1748 pub selection: Option<Range>,
1749 pub trigger_kind: NesTriggerKind,
1751 #[serde(default)]
1753 pub context: Option<NesSuggestContext>,
1754 #[serde_as(deserialize_as = "DefaultOnError")]
1760 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
1761 #[serde(default)]
1762 #[serde(rename = "_meta")]
1763 pub meta: Option<Meta>,
1764}
1765
1766impl SuggestNesRequest {
1767 #[must_use]
1769 pub fn new(
1770 session_id: impl Into<SessionId>,
1771 uri: impl Into<String>,
1772 version: i64,
1773 position: Position,
1774 trigger_kind: NesTriggerKind,
1775 ) -> Self {
1776 Self {
1777 session_id: session_id.into(),
1778 uri: uri.into(),
1779 version,
1780 position,
1781 selection: None,
1782 trigger_kind,
1783 context: None,
1784 meta: None,
1785 }
1786 }
1787
1788 #[must_use]
1790 pub fn selection(mut self, selection: impl IntoOption<Range>) -> Self {
1791 self.selection = selection.into_option();
1792 self
1793 }
1794
1795 #[must_use]
1797 pub fn context(mut self, context: impl IntoOption<NesSuggestContext>) -> Self {
1798 self.context = context.into_option();
1799 self
1800 }
1801
1802 #[must_use]
1808 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
1809 self.meta = meta.into_option();
1810 self
1811 }
1812}
1813
1814#[serde_as]
1816#[skip_serializing_none]
1817#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
1818#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
1819#[serde(rename_all = "camelCase")]
1820#[non_exhaustive]
1821pub struct NesSuggestContext {
1822 #[serde(default)]
1824 pub recent_files: Option<Vec<NesRecentFile>>,
1825 #[serde(default)]
1827 pub related_snippets: Option<Vec<NesRelatedSnippet>>,
1828 #[serde(default)]
1830 pub edit_history: Option<Vec<NesEditHistoryEntry>>,
1831 #[serde(default)]
1833 pub user_actions: Option<Vec<NesUserAction>>,
1834 #[serde(default)]
1836 pub open_files: Option<Vec<NesOpenFile>>,
1837 #[serde(default)]
1839 pub diagnostics: Option<Vec<NesDiagnostic>>,
1840 #[serde_as(deserialize_as = "DefaultOnError")]
1846 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
1847 #[serde(default)]
1848 #[serde(rename = "_meta")]
1849 pub meta: Option<Meta>,
1850}
1851
1852impl NesSuggestContext {
1853 #[must_use]
1855 pub fn new() -> Self {
1856 Self::default()
1857 }
1858
1859 #[must_use]
1861 pub fn recent_files(mut self, recent_files: impl IntoOption<Vec<NesRecentFile>>) -> Self {
1862 self.recent_files = recent_files.into_option();
1863 self
1864 }
1865
1866 #[must_use]
1868 pub fn related_snippets(
1869 mut self,
1870 related_snippets: impl IntoOption<Vec<NesRelatedSnippet>>,
1871 ) -> Self {
1872 self.related_snippets = related_snippets.into_option();
1873 self
1874 }
1875
1876 #[must_use]
1878 pub fn edit_history(mut self, edit_history: impl IntoOption<Vec<NesEditHistoryEntry>>) -> Self {
1879 self.edit_history = edit_history.into_option();
1880 self
1881 }
1882
1883 #[must_use]
1885 pub fn user_actions(mut self, user_actions: impl IntoOption<Vec<NesUserAction>>) -> Self {
1886 self.user_actions = user_actions.into_option();
1887 self
1888 }
1889
1890 #[must_use]
1892 pub fn open_files(mut self, open_files: impl IntoOption<Vec<NesOpenFile>>) -> Self {
1893 self.open_files = open_files.into_option();
1894 self
1895 }
1896
1897 #[must_use]
1899 pub fn diagnostics(mut self, diagnostics: impl IntoOption<Vec<NesDiagnostic>>) -> Self {
1900 self.diagnostics = diagnostics.into_option();
1901 self
1902 }
1903
1904 #[must_use]
1910 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
1911 self.meta = meta.into_option();
1912 self
1913 }
1914}
1915
1916#[serde_as]
1918#[skip_serializing_none]
1919#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
1920#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
1921#[serde(rename_all = "camelCase")]
1922#[non_exhaustive]
1923pub struct NesRecentFile {
1924 pub uri: String,
1926 pub language_id: String,
1928 pub text: String,
1930 #[serde_as(deserialize_as = "DefaultOnError")]
1936 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
1937 #[serde(default)]
1938 #[serde(rename = "_meta")]
1939 pub meta: Option<Meta>,
1940}
1941
1942impl NesRecentFile {
1943 #[must_use]
1945 pub fn new(
1946 uri: impl Into<String>,
1947 language_id: impl Into<String>,
1948 text: impl Into<String>,
1949 ) -> Self {
1950 Self {
1951 uri: uri.into(),
1952 language_id: language_id.into(),
1953 text: text.into(),
1954 meta: None,
1955 }
1956 }
1957
1958 #[must_use]
1964 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
1965 self.meta = meta.into_option();
1966 self
1967 }
1968}
1969
1970#[serde_as]
1972#[skip_serializing_none]
1973#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
1974#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
1975#[serde(rename_all = "camelCase")]
1976#[non_exhaustive]
1977pub struct NesRelatedSnippet {
1978 pub uri: String,
1980 pub excerpts: Vec<NesExcerpt>,
1982 #[serde_as(deserialize_as = "DefaultOnError")]
1988 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
1989 #[serde(default)]
1990 #[serde(rename = "_meta")]
1991 pub meta: Option<Meta>,
1992}
1993
1994impl NesRelatedSnippet {
1995 #[must_use]
1997 pub fn new(uri: impl Into<String>, excerpts: Vec<NesExcerpt>) -> Self {
1998 Self {
1999 uri: uri.into(),
2000 excerpts,
2001 meta: None,
2002 }
2003 }
2004
2005 #[must_use]
2011 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
2012 self.meta = meta.into_option();
2013 self
2014 }
2015}
2016
2017#[serde_as]
2019#[skip_serializing_none]
2020#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
2021#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
2022#[serde(rename_all = "camelCase")]
2023#[non_exhaustive]
2024pub struct NesExcerpt {
2025 pub start_line: u32,
2027 pub end_line: u32,
2029 pub text: String,
2031 #[serde_as(deserialize_as = "DefaultOnError")]
2037 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
2038 #[serde(default)]
2039 #[serde(rename = "_meta")]
2040 pub meta: Option<Meta>,
2041}
2042
2043impl NesExcerpt {
2044 #[must_use]
2046 pub fn new(start_line: u32, end_line: u32, text: impl Into<String>) -> Self {
2047 Self {
2048 start_line,
2049 end_line,
2050 text: text.into(),
2051 meta: None,
2052 }
2053 }
2054
2055 #[must_use]
2061 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
2062 self.meta = meta.into_option();
2063 self
2064 }
2065}
2066
2067#[serde_as]
2069#[skip_serializing_none]
2070#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
2071#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
2072#[serde(rename_all = "camelCase")]
2073#[non_exhaustive]
2074pub struct NesEditHistoryEntry {
2075 pub uri: String,
2077 pub diff: String,
2079 #[serde_as(deserialize_as = "DefaultOnError")]
2085 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
2086 #[serde(default)]
2087 #[serde(rename = "_meta")]
2088 pub meta: Option<Meta>,
2089}
2090
2091impl NesEditHistoryEntry {
2092 #[must_use]
2094 pub fn new(uri: impl Into<String>, diff: impl Into<String>) -> Self {
2095 Self {
2096 uri: uri.into(),
2097 diff: diff.into(),
2098 meta: None,
2099 }
2100 }
2101
2102 #[must_use]
2108 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
2109 self.meta = meta.into_option();
2110 self
2111 }
2112}
2113
2114#[serde_as]
2116#[skip_serializing_none]
2117#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
2118#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
2119#[serde(rename_all = "camelCase")]
2120#[non_exhaustive]
2121pub struct NesUserAction {
2122 pub action: String,
2124 pub uri: String,
2126 pub position: Position,
2128 pub timestamp_ms: u64,
2130 #[serde_as(deserialize_as = "DefaultOnError")]
2136 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
2137 #[serde(default)]
2138 #[serde(rename = "_meta")]
2139 pub meta: Option<Meta>,
2140}
2141
2142impl NesUserAction {
2143 #[must_use]
2145 pub fn new(
2146 action: impl Into<String>,
2147 uri: impl Into<String>,
2148 position: Position,
2149 timestamp_ms: u64,
2150 ) -> Self {
2151 Self {
2152 action: action.into(),
2153 uri: uri.into(),
2154 position,
2155 timestamp_ms,
2156 meta: None,
2157 }
2158 }
2159
2160 #[must_use]
2166 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
2167 self.meta = meta.into_option();
2168 self
2169 }
2170}
2171
2172#[serde_as]
2174#[skip_serializing_none]
2175#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
2176#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
2177#[serde(rename_all = "camelCase")]
2178#[non_exhaustive]
2179pub struct NesOpenFile {
2180 pub uri: String,
2182 pub language_id: String,
2184 #[serde_as(deserialize_as = "DefaultOnError")]
2186 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
2187 #[serde(default)]
2188 pub visible_range: Option<Range>,
2189 #[serde_as(deserialize_as = "DefaultOnError")]
2191 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
2192 #[serde(default)]
2193 pub last_focused_ms: Option<u64>,
2194 #[serde_as(deserialize_as = "DefaultOnError")]
2200 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
2201 #[serde(default)]
2202 #[serde(rename = "_meta")]
2203 pub meta: Option<Meta>,
2204}
2205
2206impl NesOpenFile {
2207 #[must_use]
2209 pub fn new(uri: impl Into<String>, language_id: impl Into<String>) -> Self {
2210 Self {
2211 uri: uri.into(),
2212 language_id: language_id.into(),
2213 visible_range: None,
2214 last_focused_ms: None,
2215 meta: None,
2216 }
2217 }
2218
2219 #[must_use]
2221 pub fn visible_range(mut self, visible_range: impl IntoOption<Range>) -> Self {
2222 self.visible_range = visible_range.into_option();
2223 self
2224 }
2225
2226 #[must_use]
2228 pub fn last_focused_ms(mut self, last_focused_ms: impl IntoOption<u64>) -> Self {
2229 self.last_focused_ms = last_focused_ms.into_option();
2230 self
2231 }
2232
2233 #[must_use]
2239 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
2240 self.meta = meta.into_option();
2241 self
2242 }
2243}
2244
2245#[serde_as]
2247#[skip_serializing_none]
2248#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
2249#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
2250#[serde(rename_all = "camelCase")]
2251#[non_exhaustive]
2252pub struct NesDiagnostic {
2253 pub uri: String,
2255 pub range: Range,
2257 pub severity: NesDiagnosticSeverity,
2259 pub message: String,
2261 #[serde_as(deserialize_as = "DefaultOnError")]
2267 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
2268 #[serde(default)]
2269 #[serde(rename = "_meta")]
2270 pub meta: Option<Meta>,
2271}
2272
2273impl NesDiagnostic {
2274 #[must_use]
2276 pub fn new(
2277 uri: impl Into<String>,
2278 range: Range,
2279 severity: NesDiagnosticSeverity,
2280 message: impl Into<String>,
2281 ) -> Self {
2282 Self {
2283 uri: uri.into(),
2284 range,
2285 severity,
2286 message: message.into(),
2287 meta: None,
2288 }
2289 }
2290
2291 #[must_use]
2297 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
2298 self.meta = meta.into_option();
2299 self
2300 }
2301}
2302
2303#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
2305#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
2306#[non_exhaustive]
2307pub enum NesDiagnosticSeverity {
2308 #[serde(rename = "error")]
2310 Error,
2311 #[serde(rename = "warning")]
2313 Warning,
2314 #[serde(rename = "information")]
2316 Information,
2317 #[serde(rename = "hint")]
2319 Hint,
2320}
2321
2322#[serde_as]
2326#[skip_serializing_none]
2327#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
2328#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
2329#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = NES_SUGGEST_METHOD_NAME)))]
2330#[serde(rename_all = "camelCase")]
2331#[non_exhaustive]
2332pub struct SuggestNesResponse {
2333 pub suggestions: Vec<NesSuggestion>,
2335 #[serde_as(deserialize_as = "DefaultOnError")]
2341 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
2342 #[serde(default)]
2343 #[serde(rename = "_meta")]
2344 pub meta: Option<Meta>,
2345}
2346
2347impl SuggestNesResponse {
2348 #[must_use]
2350 pub fn new(suggestions: Vec<NesSuggestion>) -> Self {
2351 Self {
2352 suggestions,
2353 meta: None,
2354 }
2355 }
2356
2357 #[must_use]
2363 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
2364 self.meta = meta.into_option();
2365 self
2366 }
2367}
2368
2369#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
2371#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
2372#[serde(tag = "kind", rename_all = "camelCase")]
2373#[cfg_attr(feature = "schemars", schemars(extend("discriminator" = {"propertyName": "kind"})))]
2374#[non_exhaustive]
2375pub enum NesSuggestion {
2376 Edit(NesEditSuggestion),
2378 Jump(NesJumpSuggestion),
2380 Rename(NesRenameSuggestion),
2382 SearchAndReplace(NesSearchAndReplaceSuggestion),
2384}
2385
2386#[serde_as]
2388#[skip_serializing_none]
2389#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
2390#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
2391#[serde(rename_all = "camelCase")]
2392#[non_exhaustive]
2393pub struct NesEditSuggestion {
2394 pub id: NesSuggestionId,
2396 pub uri: String,
2398 pub edits: Vec<NesTextEdit>,
2400 #[serde_as(deserialize_as = "DefaultOnError")]
2402 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
2403 #[serde(default)]
2404 pub cursor_position: Option<Position>,
2405 #[serde_as(deserialize_as = "DefaultOnError")]
2411 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
2412 #[serde(default)]
2413 #[serde(rename = "_meta")]
2414 pub meta: Option<Meta>,
2415}
2416
2417impl NesEditSuggestion {
2418 #[must_use]
2420 pub fn new(
2421 id: impl Into<NesSuggestionId>,
2422 uri: impl Into<String>,
2423 edits: Vec<NesTextEdit>,
2424 ) -> Self {
2425 Self {
2426 id: id.into(),
2427 uri: uri.into(),
2428 edits,
2429 cursor_position: None,
2430 meta: None,
2431 }
2432 }
2433
2434 #[must_use]
2436 pub fn cursor_position(mut self, cursor_position: impl IntoOption<Position>) -> Self {
2437 self.cursor_position = cursor_position.into_option();
2438 self
2439 }
2440
2441 #[must_use]
2447 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
2448 self.meta = meta.into_option();
2449 self
2450 }
2451}
2452
2453#[serde_as]
2455#[skip_serializing_none]
2456#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
2457#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
2458#[serde(rename_all = "camelCase")]
2459#[non_exhaustive]
2460pub struct NesTextEdit {
2461 pub range: Range,
2463 pub new_text: String,
2465 #[serde_as(deserialize_as = "DefaultOnError")]
2471 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
2472 #[serde(default)]
2473 #[serde(rename = "_meta")]
2474 pub meta: Option<Meta>,
2475}
2476
2477impl NesTextEdit {
2478 #[must_use]
2480 pub fn new(range: Range, new_text: impl Into<String>) -> Self {
2481 Self {
2482 range,
2483 new_text: new_text.into(),
2484 meta: None,
2485 }
2486 }
2487
2488 #[must_use]
2494 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
2495 self.meta = meta.into_option();
2496 self
2497 }
2498}
2499
2500#[serde_as]
2502#[skip_serializing_none]
2503#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
2504#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
2505#[serde(rename_all = "camelCase")]
2506#[non_exhaustive]
2507pub struct NesJumpSuggestion {
2508 pub id: NesSuggestionId,
2510 pub uri: String,
2512 pub position: Position,
2514 #[serde_as(deserialize_as = "DefaultOnError")]
2520 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
2521 #[serde(default)]
2522 #[serde(rename = "_meta")]
2523 pub meta: Option<Meta>,
2524}
2525
2526impl NesJumpSuggestion {
2527 #[must_use]
2529 pub fn new(id: impl Into<NesSuggestionId>, uri: impl Into<String>, position: Position) -> Self {
2530 Self {
2531 id: id.into(),
2532 uri: uri.into(),
2533 position,
2534 meta: None,
2535 }
2536 }
2537
2538 #[must_use]
2544 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
2545 self.meta = meta.into_option();
2546 self
2547 }
2548}
2549
2550#[serde_as]
2552#[skip_serializing_none]
2553#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
2554#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
2555#[serde(rename_all = "camelCase")]
2556#[non_exhaustive]
2557pub struct NesRenameSuggestion {
2558 pub id: NesSuggestionId,
2560 pub uri: String,
2562 pub position: Position,
2564 pub new_name: String,
2566 #[serde_as(deserialize_as = "DefaultOnError")]
2572 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
2573 #[serde(default)]
2574 #[serde(rename = "_meta")]
2575 pub meta: Option<Meta>,
2576}
2577
2578impl NesRenameSuggestion {
2579 #[must_use]
2581 pub fn new(
2582 id: impl Into<NesSuggestionId>,
2583 uri: impl Into<String>,
2584 position: Position,
2585 new_name: impl Into<String>,
2586 ) -> Self {
2587 Self {
2588 id: id.into(),
2589 uri: uri.into(),
2590 position,
2591 new_name: new_name.into(),
2592 meta: None,
2593 }
2594 }
2595
2596 #[must_use]
2602 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
2603 self.meta = meta.into_option();
2604 self
2605 }
2606}
2607
2608#[serde_as]
2610#[skip_serializing_none]
2611#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
2612#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
2613#[serde(rename_all = "camelCase")]
2614#[non_exhaustive]
2615pub struct NesSearchAndReplaceSuggestion {
2616 pub id: NesSuggestionId,
2618 pub uri: String,
2620 pub search: String,
2622 pub replace: String,
2624 #[serde(default)]
2626 pub is_regex: Option<bool>,
2627 #[serde_as(deserialize_as = "DefaultOnError")]
2633 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
2634 #[serde(default)]
2635 #[serde(rename = "_meta")]
2636 pub meta: Option<Meta>,
2637}
2638
2639impl NesSearchAndReplaceSuggestion {
2640 #[must_use]
2642 pub fn new(
2643 id: impl Into<NesSuggestionId>,
2644 uri: impl Into<String>,
2645 search: impl Into<String>,
2646 replace: impl Into<String>,
2647 ) -> Self {
2648 Self {
2649 id: id.into(),
2650 uri: uri.into(),
2651 search: search.into(),
2652 replace: replace.into(),
2653 is_regex: None,
2654 meta: None,
2655 }
2656 }
2657
2658 #[must_use]
2660 pub fn is_regex(mut self, is_regex: impl IntoOption<bool>) -> Self {
2661 self.is_regex = is_regex.into_option();
2662 self
2663 }
2664
2665 #[must_use]
2671 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
2672 self.meta = meta.into_option();
2673 self
2674 }
2675}
2676
2677#[serde_as]
2681#[skip_serializing_none]
2682#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
2683#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
2684#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = NES_ACCEPT_METHOD_NAME)))]
2685#[serde(rename_all = "camelCase")]
2686#[non_exhaustive]
2687pub struct AcceptNesNotification {
2688 pub session_id: SessionId,
2690 pub id: NesSuggestionId,
2692 #[serde_as(deserialize_as = "DefaultOnError")]
2698 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
2699 #[serde(default)]
2700 #[serde(rename = "_meta")]
2701 pub meta: Option<Meta>,
2702}
2703
2704impl AcceptNesNotification {
2705 #[must_use]
2707 pub fn new(session_id: impl Into<SessionId>, id: impl Into<NesSuggestionId>) -> Self {
2708 Self {
2709 session_id: session_id.into(),
2710 id: id.into(),
2711 meta: None,
2712 }
2713 }
2714
2715 #[must_use]
2721 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
2722 self.meta = meta.into_option();
2723 self
2724 }
2725}
2726
2727#[serde_as]
2729#[skip_serializing_none]
2730#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
2731#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
2732#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = NES_REJECT_METHOD_NAME)))]
2733#[serde(rename_all = "camelCase")]
2734#[non_exhaustive]
2735pub struct RejectNesNotification {
2736 pub session_id: SessionId,
2738 pub id: NesSuggestionId,
2740 #[serde_as(deserialize_as = "DefaultOnError")]
2742 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
2743 #[serde(default)]
2744 pub reason: Option<NesRejectReason>,
2745 #[serde_as(deserialize_as = "DefaultOnError")]
2751 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
2752 #[serde(default)]
2753 #[serde(rename = "_meta")]
2754 pub meta: Option<Meta>,
2755}
2756
2757impl RejectNesNotification {
2758 #[must_use]
2760 pub fn new(session_id: impl Into<SessionId>, id: impl Into<NesSuggestionId>) -> Self {
2761 Self {
2762 session_id: session_id.into(),
2763 id: id.into(),
2764 reason: None,
2765 meta: None,
2766 }
2767 }
2768
2769 #[must_use]
2771 pub fn reason(mut self, reason: impl IntoOption<NesRejectReason>) -> Self {
2772 self.reason = reason.into_option();
2773 self
2774 }
2775
2776 #[must_use]
2782 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
2783 self.meta = meta.into_option();
2784 self
2785 }
2786}
2787
2788#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
2790#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
2791#[non_exhaustive]
2792pub enum NesRejectReason {
2793 #[serde(rename = "rejected")]
2795 Rejected,
2796 #[serde(rename = "ignored")]
2798 Ignored,
2799 #[serde(rename = "replaced")]
2801 Replaced,
2802 #[serde(rename = "cancelled")]
2804 Cancelled,
2805}
2806
2807#[cfg(test)]
2808mod tests {
2809 use super::*;
2810 use serde_json::json;
2811
2812 #[test]
2813 fn test_position_encoding_kind_serialization() {
2814 assert_eq!(
2815 serde_json::to_value(&PositionEncodingKind::Utf16).unwrap(),
2816 json!("utf-16")
2817 );
2818 assert_eq!(
2819 serde_json::to_value(&PositionEncodingKind::Utf32).unwrap(),
2820 json!("utf-32")
2821 );
2822 assert_eq!(
2823 serde_json::to_value(&PositionEncodingKind::Utf8).unwrap(),
2824 json!("utf-8")
2825 );
2826
2827 assert_eq!(
2828 serde_json::from_value::<PositionEncodingKind>(json!("utf-16")).unwrap(),
2829 PositionEncodingKind::Utf16
2830 );
2831 assert_eq!(
2832 serde_json::from_value::<PositionEncodingKind>(json!("utf-32")).unwrap(),
2833 PositionEncodingKind::Utf32
2834 );
2835 assert_eq!(
2836 serde_json::from_value::<PositionEncodingKind>(json!("utf-8")).unwrap(),
2837 PositionEncodingKind::Utf8
2838 );
2839 }
2840
2841 #[test]
2842 fn test_agent_nes_capabilities_serialization() {
2843 let caps = NesCapabilities::new()
2844 .events(
2845 NesEventCapabilities::new().document(
2846 NesDocumentEventCapabilities::new()
2847 .did_open(NesDocumentDidOpenCapabilities::default())
2848 .did_change(NesDocumentDidChangeCapabilities::new(
2849 TextDocumentSyncKind::Incremental,
2850 ))
2851 .did_close(NesDocumentDidCloseCapabilities::default())
2852 .did_save(NesDocumentDidSaveCapabilities::default())
2853 .did_focus(NesDocumentDidFocusCapabilities::default()),
2854 ),
2855 )
2856 .context(
2857 NesContextCapabilities::new()
2858 .recent_files(NesRecentFilesCapabilities {
2859 max_count: Some(10),
2860 meta: None,
2861 })
2862 .related_snippets(NesRelatedSnippetsCapabilities::default())
2863 .edit_history(NesEditHistoryCapabilities {
2864 max_count: Some(6),
2865 meta: None,
2866 })
2867 .user_actions(NesUserActionsCapabilities {
2868 max_count: Some(16),
2869 meta: None,
2870 })
2871 .open_files(NesOpenFilesCapabilities::default())
2872 .diagnostics(NesDiagnosticsCapabilities::default()),
2873 );
2874
2875 let json = serde_json::to_value(&caps).unwrap();
2876 assert_eq!(
2877 json,
2878 json!({
2879 "events": {
2880 "document": {
2881 "didOpen": {},
2882 "didChange": {
2883 "syncKind": "incremental"
2884 },
2885 "didClose": {},
2886 "didSave": {},
2887 "didFocus": {}
2888 }
2889 },
2890 "context": {
2891 "recentFiles": {
2892 "maxCount": 10
2893 },
2894 "relatedSnippets": {},
2895 "editHistory": {
2896 "maxCount": 6
2897 },
2898 "userActions": {
2899 "maxCount": 16
2900 },
2901 "openFiles": {},
2902 "diagnostics": {}
2903 }
2904 })
2905 );
2906
2907 let deserialized: NesCapabilities = serde_json::from_value(json).unwrap();
2909 assert_eq!(deserialized, caps);
2910 }
2911
2912 #[test]
2913 fn test_client_nes_capabilities_serialization() {
2914 let caps = ClientNesCapabilities::new()
2915 .jump(NesJumpCapabilities::default())
2916 .rename(NesRenameCapabilities::default())
2917 .search_and_replace(NesSearchAndReplaceCapabilities::default());
2918
2919 let json = serde_json::to_value(&caps).unwrap();
2920 assert_eq!(
2921 json,
2922 json!({
2923 "jump": {},
2924 "rename": {},
2925 "searchAndReplace": {}
2926 })
2927 );
2928
2929 let deserialized: ClientNesCapabilities = serde_json::from_value(json).unwrap();
2930 assert_eq!(deserialized, caps);
2931 }
2932
2933 #[test]
2934 fn test_document_did_open_serialization() {
2935 let notification = DidOpenDocumentNotification::new(
2936 "session_123",
2937 "file:///path/to/file.rs",
2938 "rust",
2939 1,
2940 "fn main() {\n println!(\"hello\");\n}\n",
2941 );
2942
2943 let json = serde_json::to_value(¬ification).unwrap();
2944 assert_eq!(
2945 json,
2946 json!({
2947 "sessionId": "session_123",
2948 "uri": "file:///path/to/file.rs",
2949 "languageId": "rust",
2950 "version": 1,
2951 "text": "fn main() {\n println!(\"hello\");\n}\n"
2952 })
2953 );
2954
2955 let deserialized: DidOpenDocumentNotification = serde_json::from_value(json).unwrap();
2956 assert_eq!(deserialized, notification);
2957 }
2958
2959 #[test]
2960 fn test_document_did_change_incremental_serialization() {
2961 let notification = DidChangeDocumentNotification::new(
2962 "session_123",
2963 "file:///path/to/file.rs",
2964 2,
2965 vec![TextDocumentContentChangeEvent::incremental(
2966 Range::new(Position::new(1, 4), Position::new(1, 4)),
2967 "let x = 42;\n ",
2968 )],
2969 );
2970
2971 let json = serde_json::to_value(¬ification).unwrap();
2972 assert_eq!(
2973 json,
2974 json!({
2975 "sessionId": "session_123",
2976 "uri": "file:///path/to/file.rs",
2977 "version": 2,
2978 "contentChanges": [
2979 {
2980 "range": {
2981 "start": { "line": 1, "character": 4 },
2982 "end": { "line": 1, "character": 4 }
2983 },
2984 "text": "let x = 42;\n "
2985 }
2986 ]
2987 })
2988 );
2989 }
2990
2991 #[test]
2992 fn test_document_did_change_full_serialization() {
2993 let notification = DidChangeDocumentNotification::new(
2994 "session_123",
2995 "file:///path/to/file.rs",
2996 2,
2997 vec![TextDocumentContentChangeEvent::full(
2998 "fn main() {\n let x = 42;\n println!(\"hello\");\n}\n",
2999 )],
3000 );
3001
3002 let json = serde_json::to_value(¬ification).unwrap();
3003 assert_eq!(
3004 json,
3005 json!({
3006 "sessionId": "session_123",
3007 "uri": "file:///path/to/file.rs",
3008 "version": 2,
3009 "contentChanges": [
3010 {
3011 "text": "fn main() {\n let x = 42;\n println!(\"hello\");\n}\n"
3012 }
3013 ]
3014 })
3015 );
3016 }
3017
3018 #[test]
3019 fn test_document_did_close_serialization() {
3020 let notification =
3021 DidCloseDocumentNotification::new("session_123", "file:///path/to/file.rs");
3022 let json = serde_json::to_value(¬ification).unwrap();
3023 assert_eq!(
3024 json,
3025 json!({ "sessionId": "session_123", "uri": "file:///path/to/file.rs" })
3026 );
3027 }
3028
3029 #[test]
3030 fn test_document_did_save_serialization() {
3031 let notification =
3032 DidSaveDocumentNotification::new("session_123", "file:///path/to/file.rs");
3033 let json = serde_json::to_value(¬ification).unwrap();
3034 assert_eq!(
3035 json,
3036 json!({ "sessionId": "session_123", "uri": "file:///path/to/file.rs" })
3037 );
3038 }
3039
3040 #[test]
3041 fn test_document_did_focus_serialization() {
3042 let notification = DidFocusDocumentNotification::new(
3043 "session_123",
3044 "file:///path/to/file.rs",
3045 2,
3046 Position::new(5, 12),
3047 Range::new(Position::new(0, 0), Position::new(45, 0)),
3048 );
3049
3050 let json = serde_json::to_value(¬ification).unwrap();
3051 assert_eq!(
3052 json,
3053 json!({
3054 "sessionId": "session_123",
3055 "uri": "file:///path/to/file.rs",
3056 "version": 2,
3057 "position": { "line": 5, "character": 12 },
3058 "visibleRange": {
3059 "start": { "line": 0, "character": 0 },
3060 "end": { "line": 45, "character": 0 }
3061 }
3062 })
3063 );
3064 }
3065
3066 #[test]
3067 fn test_nes_suggestion_edit_serialization() {
3068 let suggestion = NesSuggestion::Edit(
3069 NesEditSuggestion::new(
3070 "sugg_001",
3071 "file:///path/to/other_file.rs",
3072 vec![NesTextEdit::new(
3073 Range::new(Position::new(5, 0), Position::new(5, 10)),
3074 "let result = helper();",
3075 )],
3076 )
3077 .cursor_position(Position::new(5, 22)),
3078 );
3079
3080 let json = serde_json::to_value(&suggestion).unwrap();
3081 assert_eq!(
3082 json,
3083 json!({
3084 "kind": "edit",
3085 "id": "sugg_001",
3086 "uri": "file:///path/to/other_file.rs",
3087 "edits": [
3088 {
3089 "range": {
3090 "start": { "line": 5, "character": 0 },
3091 "end": { "line": 5, "character": 10 }
3092 },
3093 "newText": "let result = helper();"
3094 }
3095 ],
3096 "cursorPosition": { "line": 5, "character": 22 }
3097 })
3098 );
3099
3100 let deserialized: NesSuggestion = serde_json::from_value(json).unwrap();
3101 assert_eq!(deserialized, suggestion);
3102 }
3103
3104 #[test]
3105 fn test_nes_suggestion_jump_serialization() {
3106 let suggestion = NesSuggestion::Jump(NesJumpSuggestion::new(
3107 "sugg_002",
3108 "file:///path/to/other_file.rs",
3109 Position::new(15, 4),
3110 ));
3111
3112 let json = serde_json::to_value(&suggestion).unwrap();
3113 assert_eq!(
3114 json,
3115 json!({
3116 "kind": "jump",
3117 "id": "sugg_002",
3118 "uri": "file:///path/to/other_file.rs",
3119 "position": { "line": 15, "character": 4 }
3120 })
3121 );
3122
3123 let deserialized: NesSuggestion = serde_json::from_value(json).unwrap();
3124 assert_eq!(deserialized, suggestion);
3125 }
3126
3127 #[test]
3128 fn test_nes_suggestion_rename_serialization() {
3129 let suggestion = NesSuggestion::Rename(NesRenameSuggestion::new(
3130 "sugg_003",
3131 "file:///path/to/file.rs",
3132 Position::new(5, 10),
3133 "calculateTotal",
3134 ));
3135
3136 let json = serde_json::to_value(&suggestion).unwrap();
3137 assert_eq!(
3138 json,
3139 json!({
3140 "kind": "rename",
3141 "id": "sugg_003",
3142 "uri": "file:///path/to/file.rs",
3143 "position": { "line": 5, "character": 10 },
3144 "newName": "calculateTotal"
3145 })
3146 );
3147
3148 let deserialized: NesSuggestion = serde_json::from_value(json).unwrap();
3149 assert_eq!(deserialized, suggestion);
3150 }
3151
3152 #[test]
3153 fn test_nes_suggestion_search_and_replace_serialization() {
3154 let suggestion = NesSuggestion::SearchAndReplace(
3155 NesSearchAndReplaceSuggestion::new(
3156 "sugg_004",
3157 "file:///path/to/file.rs",
3158 "oldFunction",
3159 "newFunction",
3160 )
3161 .is_regex(false),
3162 );
3163
3164 let json = serde_json::to_value(&suggestion).unwrap();
3165 assert_eq!(
3166 json,
3167 json!({
3168 "kind": "searchAndReplace",
3169 "id": "sugg_004",
3170 "uri": "file:///path/to/file.rs",
3171 "search": "oldFunction",
3172 "replace": "newFunction",
3173 "isRegex": false
3174 })
3175 );
3176
3177 let deserialized: NesSuggestion = serde_json::from_value(json).unwrap();
3178 assert_eq!(deserialized, suggestion);
3179 }
3180
3181 #[test]
3182 fn test_nes_start_request_serialization() {
3183 let request = StartNesRequest::new()
3184 .workspace_uri("file:///Users/alice/projects/my-app")
3185 .workspace_folders(vec![WorkspaceFolder::new(
3186 "file:///Users/alice/projects/my-app",
3187 "my-app",
3188 )])
3189 .repository(NesRepository::new(
3190 "my-app",
3191 "alice",
3192 "https://github.com/alice/my-app.git",
3193 ));
3194
3195 let json = serde_json::to_value(&request).unwrap();
3196 assert_eq!(
3197 json,
3198 json!({
3199 "workspaceUri": "file:///Users/alice/projects/my-app",
3200 "workspaceFolders": [
3201 {
3202 "uri": "file:///Users/alice/projects/my-app",
3203 "name": "my-app"
3204 }
3205 ],
3206 "repository": {
3207 "name": "my-app",
3208 "owner": "alice",
3209 "remoteUrl": "https://github.com/alice/my-app.git"
3210 }
3211 })
3212 );
3213 }
3214
3215 #[test]
3216 fn test_nes_start_response_serialization() {
3217 let response = StartNesResponse::new("session_abc123");
3218 let json = serde_json::to_value(&response).unwrap();
3219 assert_eq!(json, json!({ "sessionId": "session_abc123" }));
3220 }
3221
3222 #[test]
3223 fn test_nes_trigger_kind_serialization() {
3224 assert_eq!(
3225 serde_json::to_value(&NesTriggerKind::Automatic).unwrap(),
3226 json!("automatic")
3227 );
3228 assert_eq!(
3229 serde_json::to_value(&NesTriggerKind::Diagnostic).unwrap(),
3230 json!("diagnostic")
3231 );
3232 assert_eq!(
3233 serde_json::to_value(&NesTriggerKind::Manual).unwrap(),
3234 json!("manual")
3235 );
3236 }
3237
3238 #[test]
3239 fn test_nes_reject_reason_serialization() {
3240 assert_eq!(
3241 serde_json::to_value(&NesRejectReason::Rejected).unwrap(),
3242 json!("rejected")
3243 );
3244 assert_eq!(
3245 serde_json::to_value(&NesRejectReason::Ignored).unwrap(),
3246 json!("ignored")
3247 );
3248 assert_eq!(
3249 serde_json::to_value(&NesRejectReason::Replaced).unwrap(),
3250 json!("replaced")
3251 );
3252 assert_eq!(
3253 serde_json::to_value(&NesRejectReason::Cancelled).unwrap(),
3254 json!("cancelled")
3255 );
3256 }
3257
3258 #[test]
3259 fn test_nes_accept_notification_serialization() {
3260 let notification = AcceptNesNotification::new("session_123", "sugg_001");
3261 let json = serde_json::to_value(¬ification).unwrap();
3262 assert_eq!(
3263 json,
3264 json!({ "sessionId": "session_123", "id": "sugg_001" })
3265 );
3266 }
3267
3268 #[test]
3269 fn test_nes_reject_notification_serialization() {
3270 let notification =
3271 RejectNesNotification::new("session_123", "sugg_001").reason(NesRejectReason::Rejected);
3272 let json = serde_json::to_value(¬ification).unwrap();
3273 assert_eq!(
3274 json,
3275 json!({ "sessionId": "session_123", "id": "sugg_001", "reason": "rejected" })
3276 );
3277 }
3278
3279 #[test]
3280 fn test_nes_suggest_request_with_context_serialization() {
3281 let request = SuggestNesRequest::new(
3282 "session_123",
3283 "file:///path/to/file.rs",
3284 2,
3285 Position::new(5, 12),
3286 NesTriggerKind::Automatic,
3287 )
3288 .selection(Range::new(Position::new(5, 4), Position::new(5, 12)))
3289 .context(
3290 NesSuggestContext::new()
3291 .recent_files(vec![NesRecentFile::new(
3292 "file:///path/to/utils.rs",
3293 "rust",
3294 "pub fn helper() -> i32 { 42 }\n",
3295 )])
3296 .diagnostics(vec![NesDiagnostic::new(
3297 "file:///path/to/file.rs",
3298 Range::new(Position::new(5, 0), Position::new(5, 10)),
3299 NesDiagnosticSeverity::Error,
3300 "cannot find value `foo` in this scope",
3301 )]),
3302 );
3303
3304 let json = serde_json::to_value(&request).unwrap();
3305 assert_eq!(json["sessionId"], "session_123");
3306 assert_eq!(json["uri"], "file:///path/to/file.rs");
3307 assert_eq!(json["version"], 2);
3308 assert_eq!(json["triggerKind"], "automatic");
3309 assert_eq!(
3310 json["context"]["recentFiles"][0]["uri"],
3311 "file:///path/to/utils.rs"
3312 );
3313 assert_eq!(json["context"]["diagnostics"][0]["severity"], "error");
3314 }
3315
3316 #[test]
3317 fn test_text_document_sync_kind_serialization() {
3318 assert_eq!(
3319 serde_json::to_value(&TextDocumentSyncKind::Full).unwrap(),
3320 json!("full")
3321 );
3322 assert_eq!(
3323 serde_json::to_value(&TextDocumentSyncKind::Incremental).unwrap(),
3324 json!("incremental")
3325 );
3326 }
3327
3328 #[test]
3329 fn test_document_did_change_capabilities_requires_sync_kind() {
3330 assert!(serde_json::from_value::<NesDocumentDidChangeCapabilities>(json!({})).is_err());
3331 }
3332
3333 #[test]
3334 fn test_nes_suggest_response_serialization() {
3335 let response = SuggestNesResponse::new(vec![
3336 NesSuggestion::Edit(NesEditSuggestion::new(
3337 "sugg_001",
3338 "file:///path/to/file.rs",
3339 vec![NesTextEdit::new(
3340 Range::new(Position::new(5, 0), Position::new(5, 10)),
3341 "let result = helper();",
3342 )],
3343 )),
3344 NesSuggestion::Jump(NesJumpSuggestion::new(
3345 "sugg_002",
3346 "file:///path/to/other.rs",
3347 Position::new(10, 0),
3348 )),
3349 ]);
3350
3351 let json = serde_json::to_value(&response).unwrap();
3352 assert_eq!(json["suggestions"].as_array().unwrap().len(), 2);
3353 assert_eq!(json["suggestions"][0]["kind"], "edit");
3354 assert_eq!(json["suggestions"][1]["kind"], "jump");
3355 }
3356}