lspf 0.7.0

A Rust framework for building extensible LSP language servers
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
//! Standard LSP feature descriptors (ADR 0017).
//!
//! Each `features::*` constructor returns a descriptor implementing one of the
//! sealed traits [`FeatureSpec`] (request features) or
//! [`NotificationFeatureSpec`] (notification features). A descriptor fixes
//! three things at once: the `lsp_types` request or notification marker that
//! names the wire method and its typed parameters (and result, for requests),
//! the descriptor's public options, and the single deterministic contribution
//! the feature makes to the capability catalog.
//!
//! Both traits are sealed: downstream crates use these descriptors but cannot
//! implement either trait, so they cannot present a pseudo-standard feature
//! whose capability fragment lspf does not know how to merge. Custom methods
//! use [`request`](crate::ServerBuilder::request) and
//! [`notification`](crate::ServerBuilder::notification) instead and advertise
//! no capability.

use lsp_types::notification::{
    DidChangeWatchedFiles, DidCreateFiles, DidDeleteFiles, DidRenameFiles, Notification,
};
use lsp_types::request::{
    CallHierarchyIncomingCalls, CallHierarchyOutgoingCalls, CallHierarchyPrepare,
    CodeActionRequest, CodeActionResolveRequest, CodeLensRequest, CodeLensResolve,
    ColorPresentationRequest, Completion, DocumentColor, DocumentDiagnosticRequest,
    DocumentHighlightRequest, DocumentLinkRequest, DocumentLinkResolve, DocumentSymbolRequest,
    FoldingRangeRequest, Formatting, GotoDeclaration, GotoDefinition, GotoImplementation,
    GotoTypeDefinition, HoverRequest, InlayHintRequest, InlayHintResolveRequest,
    InlineValueRequest, LinkedEditingRange, MonikerRequest, OnTypeFormatting, PrepareRenameRequest,
    RangeFormatting, References, Rename, Request, ResolveCompletionItem, SelectionRangeRequest,
    SemanticTokensFullDeltaRequest, SemanticTokensFullRequest, SemanticTokensRangeRequest,
    SignatureHelpRequest, TypeHierarchyPrepare, TypeHierarchySubtypes, TypeHierarchySupertypes,
    WillCreateFiles, WillDeleteFiles, WillRenameFiles, WillSaveWaitUntil,
    WorkspaceDiagnosticRequest, WorkspaceSymbolRequest, WorkspaceSymbolResolve,
};
use lsp_types::{
    CallHierarchyOptions, CodeActionOptions, CodeLensOptions, ColorProviderOptions,
    CompletionOptions, DeclarationOptions, DefinitionOptions, DiagnosticOptions,
    DocumentFormattingOptions, DocumentHighlightOptions, DocumentLinkOptions,
    DocumentOnTypeFormattingOptions, DocumentRangeFormattingOptions, DocumentSymbolOptions,
    FileOperationRegistrationOptions, FoldingProviderOptions, InlayHintOptions, InlineValueOptions,
    LinkedEditingRangeOptions, MonikerOptions, ReferencesOptions, RenameOptions,
    SelectionRangeOptions, SemanticTokensOptions, SignatureHelpOptions,
    StaticTextDocumentRegistrationOptions, TypeHierarchyOptions, WorkspaceSymbolOptions,
};

use crate::capability::CapabilityBuilder;
use crate::error::BuildError;

pub(crate) mod sealed {
    use crate::capability::CapabilityBuilder;
    use crate::error::BuildError;

    /// The in-crate half of [`FeatureSpec`](super::FeatureSpec). Being only
    /// `pub(crate)` it both seals the public trait against downstream
    /// implementations and keeps the internal [`CapabilityBuilder`] out of the
    /// public API.
    ///
    /// `contribute` names the crate-private `CapabilityBuilder`, which the
    /// public `FeatureSpec` supertrait bound technically makes reachable. The
    /// leak is inert — `Sealed` cannot be implemented and `CapabilityBuilder`
    /// cannot be named or constructed outside the crate — so the lint is
    /// silenced deliberately.
    #[allow(private_interfaces)]
    pub trait Sealed {
        /// Record this feature's contribution to the capability catalog, or
        /// return a [`BuildError`] if it conflicts with an existing one.
        fn contribute(&self, caps: &mut CapabilityBuilder) -> Result<(), BuildError>;
    }
}

/// The sealed descriptor contract for a standard LSP feature (ADR 0017).
///
/// [`Marker`](Self::Marker) is the `lsp_types` request marker fixing the wire
/// method and the typed parameter and result types dispatch uses. The
/// capability contribution lives on the sealed in-crate supertrait, so this
/// trait is usable but not implementable downstream. Implemented only by the
/// descriptors returned from this module.
pub trait FeatureSpec: sealed::Sealed {
    /// The request marker this feature dispatches, fixing its method and its
    /// parameter and result types.
    type Marker: Request;
}

/// The sealed descriptor contract for a standard LSP notification feature
/// (ADR 0017).
///
/// The notification counterpart of [`FeatureSpec`]: [`Marker`](Self::Marker)
/// is the `lsp_types` notification marker fixing the wire method and the typed
/// parameter type dispatch uses. Registered through
/// [`ServerBuilder::feature_notification`](crate::ServerBuilder::feature_notification).
/// Implemented only by the descriptors returned from this module.
pub trait NotificationFeatureSpec: sealed::Sealed {
    /// The notification marker this feature dispatches, fixing its method and
    /// its parameter type.
    type Marker: Notification;
}

/// The `textDocument/willSaveWaitUntil` request feature descriptor.
pub struct WillSaveWaitUntilFeature(());

/// Describe the typed pre-save edit request. Its registration contributes
/// `willSaveWaitUntil: true` to the effective text-document sync options.
pub fn will_save_wait_until() -> WillSaveWaitUntilFeature {
    WillSaveWaitUntilFeature(())
}

#[allow(private_interfaces)]
impl sealed::Sealed for WillSaveWaitUntilFeature {
    fn contribute(&self, caps: &mut CapabilityBuilder) -> Result<(), BuildError> {
        caps.set_will_save_wait_until();
        Ok(())
    }
}
impl FeatureSpec for WillSaveWaitUntilFeature {
    type Marker = WillSaveWaitUntil;
}

/// The `textDocument/hover` feature descriptor. Construct it with [`hover`].
pub struct HoverFeature(());

/// Describe the standard hover feature: it dispatches
/// [`HoverParams`](lsp_types::HoverParams), returns
/// [`Option<Hover>`](lsp_types::Hover), and advertises `hoverProvider`.
pub fn hover() -> HoverFeature {
    HoverFeature(())
}

#[allow(private_interfaces)]
impl sealed::Sealed for HoverFeature {
    fn contribute(&self, caps: &mut CapabilityBuilder) -> Result<(), BuildError> {
        caps.set_hover()
    }
}
impl FeatureSpec for HoverFeature {
    type Marker = HoverRequest;
}

/// The `textDocument/signatureHelp` feature descriptor. Construct it with
/// [`signature_help`].
pub struct SignatureHelpFeature {
    options: SignatureHelpOptions,
}

/// Describe the standard signature-help feature: it dispatches the lsp-types
/// [`SignatureHelpRequest`] marker — typed
/// [`SignatureHelpParams`](lsp_types::SignatureHelpParams) in, optional
/// [`SignatureHelp`](lsp_types::SignatureHelp) out — and advertises the
/// supplied [`SignatureHelpOptions`] as `signatureHelpProvider`.
pub fn signature_help(options: SignatureHelpOptions) -> SignatureHelpFeature {
    SignatureHelpFeature { options }
}

#[allow(private_interfaces)]
impl sealed::Sealed for SignatureHelpFeature {
    fn contribute(&self, caps: &mut CapabilityBuilder) -> Result<(), BuildError> {
        caps.set_signature_help(self.options.clone())
    }
}
impl FeatureSpec for SignatureHelpFeature {
    type Marker = SignatureHelpRequest;
}

/// The `textDocument/declaration` feature descriptor. Construct it with
/// [`declaration`].
pub struct DeclarationFeature {
    options: DeclarationOptions,
}

/// Describe the standard declaration feature: it dispatches the lsp-types
/// [`GotoDeclaration`] marker and advertises the supplied [`DeclarationOptions`]
/// as the singular `declarationProvider` capability.
pub fn declaration(options: DeclarationOptions) -> DeclarationFeature {
    DeclarationFeature { options }
}

#[allow(private_interfaces)]
impl sealed::Sealed for DeclarationFeature {
    fn contribute(&self, caps: &mut CapabilityBuilder) -> Result<(), BuildError> {
        caps.set_declaration(self.options.clone())
    }
}
impl FeatureSpec for DeclarationFeature {
    type Marker = GotoDeclaration;
}

/// The `textDocument/definition` feature descriptor. Construct it with
/// [`definition`].
pub struct DefinitionFeature {
    options: DefinitionOptions,
}

/// Describe the standard definition feature: it dispatches the lsp-types
/// [`GotoDefinition`] marker and advertises the supplied [`DefinitionOptions`]
/// as the singular `definitionProvider` capability.
pub fn definition(options: DefinitionOptions) -> DefinitionFeature {
    DefinitionFeature { options }
}

#[allow(private_interfaces)]
impl sealed::Sealed for DefinitionFeature {
    fn contribute(&self, caps: &mut CapabilityBuilder) -> Result<(), BuildError> {
        caps.set_definition(self.options.clone())
    }
}
impl FeatureSpec for DefinitionFeature {
    type Marker = GotoDefinition;
}

/// The `textDocument/typeDefinition` feature descriptor. Construct it with
/// [`type_definition`].
pub struct TypeDefinitionFeature {
    options: StaticTextDocumentRegistrationOptions,
}

/// Describe the standard type-definition feature: it dispatches the lsp-types
/// [`GotoTypeDefinition`] marker and advertises the supplied
/// [`StaticTextDocumentRegistrationOptions`] as the singular
/// `typeDefinitionProvider` capability.
pub fn type_definition(options: StaticTextDocumentRegistrationOptions) -> TypeDefinitionFeature {
    TypeDefinitionFeature { options }
}

#[allow(private_interfaces)]
impl sealed::Sealed for TypeDefinitionFeature {
    fn contribute(&self, caps: &mut CapabilityBuilder) -> Result<(), BuildError> {
        caps.set_type_definition(self.options.clone())
    }
}
impl FeatureSpec for TypeDefinitionFeature {
    type Marker = GotoTypeDefinition;
}

/// The `textDocument/implementation` feature descriptor. Construct it with
/// [`implementation`].
pub struct ImplementationFeature {
    options: StaticTextDocumentRegistrationOptions,
}

/// Describe the standard implementation feature: it dispatches the lsp-types
/// [`GotoImplementation`] marker and advertises the supplied
/// [`StaticTextDocumentRegistrationOptions`] as the singular
/// `implementationProvider` capability.
pub fn implementation(options: StaticTextDocumentRegistrationOptions) -> ImplementationFeature {
    ImplementationFeature { options }
}

#[allow(private_interfaces)]
impl sealed::Sealed for ImplementationFeature {
    fn contribute(&self, caps: &mut CapabilityBuilder) -> Result<(), BuildError> {
        caps.set_implementation(self.options.clone())
    }
}
impl FeatureSpec for ImplementationFeature {
    type Marker = GotoImplementation;
}

/// The `textDocument/references` feature descriptor. Construct it with
/// [`references`].
pub struct ReferencesFeature {
    options: ReferencesOptions,
}

/// Describe the standard references feature: it dispatches the lsp-types
/// [`References`] marker and advertises the supplied [`ReferencesOptions`] as
/// the singular `referencesProvider` capability.
pub fn references(options: ReferencesOptions) -> ReferencesFeature {
    ReferencesFeature { options }
}

#[allow(private_interfaces)]
impl sealed::Sealed for ReferencesFeature {
    fn contribute(&self, caps: &mut CapabilityBuilder) -> Result<(), BuildError> {
        caps.set_references(self.options.clone())
    }
}
impl FeatureSpec for ReferencesFeature {
    type Marker = References;
}

/// The `textDocument/documentHighlight` feature descriptor. Construct it with
/// [`document_highlight`].
pub struct DocumentHighlightFeature {
    options: DocumentHighlightOptions,
}

/// Describe the standard document-highlight feature: it dispatches the
/// lsp-types [`DocumentHighlightRequest`] marker and advertises the supplied
/// [`DocumentHighlightOptions`] as the singular `documentHighlightProvider`
/// capability.
pub fn document_highlight(options: DocumentHighlightOptions) -> DocumentHighlightFeature {
    DocumentHighlightFeature { options }
}

#[allow(private_interfaces)]
impl sealed::Sealed for DocumentHighlightFeature {
    fn contribute(&self, caps: &mut CapabilityBuilder) -> Result<(), BuildError> {
        caps.set_document_highlight(self.options.clone())
    }
}
impl FeatureSpec for DocumentHighlightFeature {
    type Marker = DocumentHighlightRequest;
}

/// The `textDocument/documentSymbol` feature descriptor. Construct it with
/// [`document_symbol`].
pub struct DocumentSymbolFeature {
    options: DocumentSymbolOptions,
}

/// Describe the standard document-symbol feature: it dispatches the lsp-types
/// [`DocumentSymbolRequest`] marker and advertises the supplied
/// [`DocumentSymbolOptions`] as the singular `documentSymbolProvider`
/// capability.
pub fn document_symbol(options: DocumentSymbolOptions) -> DocumentSymbolFeature {
    DocumentSymbolFeature { options }
}

#[allow(private_interfaces)]
impl sealed::Sealed for DocumentSymbolFeature {
    fn contribute(&self, caps: &mut CapabilityBuilder) -> Result<(), BuildError> {
        caps.set_document_symbol(self.options.clone())
    }
}
impl FeatureSpec for DocumentSymbolFeature {
    type Marker = DocumentSymbolRequest;
}

/// The `textDocument/linkedEditingRange` feature descriptor. Construct it with
/// [`linked_editing_range`].
pub struct LinkedEditingRangeFeature {
    options: LinkedEditingRangeOptions,
}

/// Describe the standard linked-editing-range feature: it dispatches the
/// lsp-types [`LinkedEditingRange`] marker and advertises the supplied
/// [`LinkedEditingRangeOptions`] as the singular `linkedEditingRangeProvider`
/// capability.
pub fn linked_editing_range(options: LinkedEditingRangeOptions) -> LinkedEditingRangeFeature {
    LinkedEditingRangeFeature { options }
}

#[allow(private_interfaces)]
impl sealed::Sealed for LinkedEditingRangeFeature {
    fn contribute(&self, caps: &mut CapabilityBuilder) -> Result<(), BuildError> {
        caps.set_linked_editing_range(self.options.clone())
    }
}
impl FeatureSpec for LinkedEditingRangeFeature {
    type Marker = LinkedEditingRange;
}

/// The `textDocument/moniker` feature descriptor. Construct it with
/// [`moniker`].
pub struct MonikerFeature {
    options: MonikerOptions,
}

/// Describe the standard moniker feature: it dispatches the lsp-types
/// [`MonikerRequest`] marker and advertises the supplied [`MonikerOptions`] as
/// the singular `monikerProvider` capability.
pub fn moniker(options: MonikerOptions) -> MonikerFeature {
    MonikerFeature { options }
}

#[allow(private_interfaces)]
impl sealed::Sealed for MonikerFeature {
    fn contribute(&self, caps: &mut CapabilityBuilder) -> Result<(), BuildError> {
        caps.set_moniker(self.options.clone())
    }
}
impl FeatureSpec for MonikerFeature {
    type Marker = MonikerRequest;
}

/// The `textDocument/formatting` feature descriptor.
pub struct DocumentFormattingFeature {
    options: DocumentFormattingOptions,
}

/// Describe whole-document formatting and its provider options.
pub fn document_formatting(options: DocumentFormattingOptions) -> DocumentFormattingFeature {
    DocumentFormattingFeature { options }
}

#[allow(private_interfaces)]
impl sealed::Sealed for DocumentFormattingFeature {
    fn contribute(&self, caps: &mut CapabilityBuilder) -> Result<(), BuildError> {
        caps.set_document_formatting(self.options.clone())
    }
}
impl FeatureSpec for DocumentFormattingFeature {
    type Marker = Formatting;
}

/// The `textDocument/rangeFormatting` feature descriptor.
pub struct RangeFormattingFeature {
    options: DocumentRangeFormattingOptions,
}

/// Describe range formatting and its provider options.
pub fn range_formatting(options: DocumentRangeFormattingOptions) -> RangeFormattingFeature {
    RangeFormattingFeature { options }
}

#[allow(private_interfaces)]
impl sealed::Sealed for RangeFormattingFeature {
    fn contribute(&self, caps: &mut CapabilityBuilder) -> Result<(), BuildError> {
        caps.set_range_formatting(self.options.clone())
    }
}
impl FeatureSpec for RangeFormattingFeature {
    type Marker = RangeFormatting;
}

/// The `textDocument/onTypeFormatting` feature descriptor.
pub struct OnTypeFormattingFeature {
    options: DocumentOnTypeFormattingOptions,
}

/// Describe on-type formatting and its trigger-character options.
pub fn on_type_formatting(options: DocumentOnTypeFormattingOptions) -> OnTypeFormattingFeature {
    OnTypeFormattingFeature { options }
}

#[allow(private_interfaces)]
impl sealed::Sealed for OnTypeFormattingFeature {
    fn contribute(&self, caps: &mut CapabilityBuilder) -> Result<(), BuildError> {
        caps.set_on_type_formatting(self.options.clone())
    }
}
impl FeatureSpec for OnTypeFormattingFeature {
    type Marker = OnTypeFormatting;
}

/// The `textDocument/documentColor` feature descriptor.
pub struct DocumentColorFeature {
    options: ColorProviderOptions,
}

/// Describe document-color discovery and the shared color provider.
pub fn document_color(options: ColorProviderOptions) -> DocumentColorFeature {
    DocumentColorFeature { options }
}

#[allow(private_interfaces)]
impl sealed::Sealed for DocumentColorFeature {
    fn contribute(&self, caps: &mut CapabilityBuilder) -> Result<(), BuildError> {
        caps.set_document_color(self.options.clone())
    }
}
impl FeatureSpec for DocumentColorFeature {
    type Marker = DocumentColor;
}

/// The `textDocument/colorPresentation` feature descriptor.
pub struct ColorPresentationFeature(());

/// Describe color presentation, the subordinate route of `colorProvider`.
pub fn color_presentation() -> ColorPresentationFeature {
    ColorPresentationFeature(())
}

#[allow(private_interfaces)]
impl sealed::Sealed for ColorPresentationFeature {
    fn contribute(&self, caps: &mut CapabilityBuilder) -> Result<(), BuildError> {
        caps.set_color_presentation();
        Ok(())
    }
}
impl FeatureSpec for ColorPresentationFeature {
    type Marker = ColorPresentationRequest;
}

/// The `textDocument/foldingRange` feature descriptor.
pub struct FoldingRangeFeature {
    options: FoldingProviderOptions,
}

/// Describe folding-range discovery and its provider options.
pub fn folding_range(options: FoldingProviderOptions) -> FoldingRangeFeature {
    FoldingRangeFeature { options }
}

#[allow(private_interfaces)]
impl sealed::Sealed for FoldingRangeFeature {
    fn contribute(&self, caps: &mut CapabilityBuilder) -> Result<(), BuildError> {
        caps.set_folding_range(self.options.clone())
    }
}
impl FeatureSpec for FoldingRangeFeature {
    type Marker = FoldingRangeRequest;
}

/// The `textDocument/selectionRange` feature descriptor.
pub struct SelectionRangeFeature {
    options: SelectionRangeOptions,
}

/// Describe selection-range discovery and its provider options.
pub fn selection_range(options: SelectionRangeOptions) -> SelectionRangeFeature {
    SelectionRangeFeature { options }
}

#[allow(private_interfaces)]
impl sealed::Sealed for SelectionRangeFeature {
    fn contribute(&self, caps: &mut CapabilityBuilder) -> Result<(), BuildError> {
        caps.set_selection_range(self.options.clone())
    }
}
impl FeatureSpec for SelectionRangeFeature {
    type Marker = SelectionRangeRequest;
}

/// The `textDocument/inlineValue` feature descriptor.
pub struct InlineValueFeature {
    options: InlineValueOptions,
}

/// Describe inline-value calculation and its provider options.
pub fn inline_value(options: InlineValueOptions) -> InlineValueFeature {
    InlineValueFeature { options }
}

#[allow(private_interfaces)]
impl sealed::Sealed for InlineValueFeature {
    fn contribute(&self, caps: &mut CapabilityBuilder) -> Result<(), BuildError> {
        caps.set_inline_value(self.options.clone())
    }
}
impl FeatureSpec for InlineValueFeature {
    type Marker = InlineValueRequest;
}

/// The `textDocument/prepareCallHierarchy` feature descriptor.
pub struct CallHierarchyPrepareFeature {
    options: CallHierarchyOptions,
}

/// Describe the call-hierarchy prepare feature and its single provider
/// capability. Incoming and outgoing call routes depend on this feature.
pub fn call_hierarchy_prepare(options: CallHierarchyOptions) -> CallHierarchyPrepareFeature {
    CallHierarchyPrepareFeature { options }
}

#[allow(private_interfaces)]
impl sealed::Sealed for CallHierarchyPrepareFeature {
    fn contribute(&self, caps: &mut CapabilityBuilder) -> Result<(), BuildError> {
        caps.set_call_hierarchy(self.options)
    }
}
impl FeatureSpec for CallHierarchyPrepareFeature {
    type Marker = CallHierarchyPrepare;
}

/// The `callHierarchy/incomingCalls` feature descriptor.
pub struct CallHierarchyIncomingCallsFeature(());

/// Describe the incoming-call route. It contributes membership to the
/// call-hierarchy family without emitting a second provider capability.
pub fn call_hierarchy_incoming_calls() -> CallHierarchyIncomingCallsFeature {
    CallHierarchyIncomingCallsFeature(())
}

#[allow(private_interfaces)]
impl sealed::Sealed for CallHierarchyIncomingCallsFeature {
    fn contribute(&self, caps: &mut CapabilityBuilder) -> Result<(), BuildError> {
        caps.set_call_hierarchy_incoming_calls();
        Ok(())
    }
}
impl FeatureSpec for CallHierarchyIncomingCallsFeature {
    type Marker = CallHierarchyIncomingCalls;
}

/// The `callHierarchy/outgoingCalls` feature descriptor.
pub struct CallHierarchyOutgoingCallsFeature(());

/// Describe the outgoing-call route. It contributes membership to the
/// call-hierarchy family without emitting a second provider capability.
pub fn call_hierarchy_outgoing_calls() -> CallHierarchyOutgoingCallsFeature {
    CallHierarchyOutgoingCallsFeature(())
}

#[allow(private_interfaces)]
impl sealed::Sealed for CallHierarchyOutgoingCallsFeature {
    fn contribute(&self, caps: &mut CapabilityBuilder) -> Result<(), BuildError> {
        caps.set_call_hierarchy_outgoing_calls();
        Ok(())
    }
}
impl FeatureSpec for CallHierarchyOutgoingCallsFeature {
    type Marker = CallHierarchyOutgoingCalls;
}

/// The `textDocument/prepareTypeHierarchy` feature descriptor.
pub struct TypeHierarchyPrepareFeature {
    options: TypeHierarchyOptions,
}

/// Describe the type-hierarchy prepare feature and its single provider
/// capability. Supertype and subtype routes depend on this feature.
pub fn type_hierarchy_prepare(options: TypeHierarchyOptions) -> TypeHierarchyPrepareFeature {
    TypeHierarchyPrepareFeature { options }
}

#[allow(private_interfaces)]
impl sealed::Sealed for TypeHierarchyPrepareFeature {
    fn contribute(&self, caps: &mut CapabilityBuilder) -> Result<(), BuildError> {
        caps.set_type_hierarchy(self.options.clone())
    }
}
impl FeatureSpec for TypeHierarchyPrepareFeature {
    type Marker = TypeHierarchyPrepare;
}

/// The `typeHierarchy/supertypes` feature descriptor.
pub struct TypeHierarchySupertypesFeature(());

/// Describe the supertype route without emitting another prepare capability.
pub fn type_hierarchy_supertypes() -> TypeHierarchySupertypesFeature {
    TypeHierarchySupertypesFeature(())
}

#[allow(private_interfaces)]
impl sealed::Sealed for TypeHierarchySupertypesFeature {
    fn contribute(&self, caps: &mut CapabilityBuilder) -> Result<(), BuildError> {
        caps.set_type_hierarchy_supertypes();
        Ok(())
    }
}
impl FeatureSpec for TypeHierarchySupertypesFeature {
    type Marker = TypeHierarchySupertypes;
}

/// The `typeHierarchy/subtypes` feature descriptor.
pub struct TypeHierarchySubtypesFeature(());

/// Describe the subtype route without emitting another prepare capability.
pub fn type_hierarchy_subtypes() -> TypeHierarchySubtypesFeature {
    TypeHierarchySubtypesFeature(())
}

#[allow(private_interfaces)]
impl sealed::Sealed for TypeHierarchySubtypesFeature {
    fn contribute(&self, caps: &mut CapabilityBuilder) -> Result<(), BuildError> {
        caps.set_type_hierarchy_subtypes();
        Ok(())
    }
}
impl FeatureSpec for TypeHierarchySubtypesFeature {
    type Marker = TypeHierarchySubtypes;
}

/// The `textDocument/semanticTokens/full` feature descriptor.
pub struct SemanticTokensFullFeature {
    options: SemanticTokensOptions,
}

/// Describe full-document semantic tokens. All semantic-token descriptors in
/// one family must agree on their legend and shared options.
pub fn semantic_tokens_full(options: SemanticTokensOptions) -> SemanticTokensFullFeature {
    SemanticTokensFullFeature { options }
}

#[allow(private_interfaces)]
impl sealed::Sealed for SemanticTokensFullFeature {
    fn contribute(&self, caps: &mut CapabilityBuilder) -> Result<(), BuildError> {
        caps.set_semantic_tokens_full(self.options.clone())
    }
}
impl FeatureSpec for SemanticTokensFullFeature {
    type Marker = SemanticTokensFullRequest;
}

/// The `textDocument/semanticTokens/full/delta` feature descriptor.
pub struct SemanticTokensFullDeltaFeature {
    options: SemanticTokensOptions,
}

/// Describe semantic-token deltas, which depend on the full-document route.
pub fn semantic_tokens_full_delta(
    options: SemanticTokensOptions,
) -> SemanticTokensFullDeltaFeature {
    SemanticTokensFullDeltaFeature { options }
}

#[allow(private_interfaces)]
impl sealed::Sealed for SemanticTokensFullDeltaFeature {
    fn contribute(&self, caps: &mut CapabilityBuilder) -> Result<(), BuildError> {
        caps.set_semantic_tokens_full_delta(self.options.clone())
    }
}
impl FeatureSpec for SemanticTokensFullDeltaFeature {
    type Marker = SemanticTokensFullDeltaRequest;
}

/// The `textDocument/semanticTokens/range` feature descriptor.
pub struct SemanticTokensRangeFeature {
    options: SemanticTokensOptions,
}

/// Describe range semantic tokens and merge them into the family's one
/// provider capability.
pub fn semantic_tokens_range(options: SemanticTokensOptions) -> SemanticTokensRangeFeature {
    SemanticTokensRangeFeature { options }
}

#[allow(private_interfaces)]
impl sealed::Sealed for SemanticTokensRangeFeature {
    fn contribute(&self, caps: &mut CapabilityBuilder) -> Result<(), BuildError> {
        caps.set_semantic_tokens_range(self.options.clone())
    }
}
impl FeatureSpec for SemanticTokensRangeFeature {
    type Marker = SemanticTokensRangeRequest;
}

/// The `textDocument/completion` feature descriptor. Construct it with
/// [`completion`].
pub struct CompletionFeature {
    options: CompletionOptions,
}

/// Describe the standard completion feature: it dispatches the lsp-types
/// [`Completion`] marker and advertises the supplied [`CompletionOptions`] as
/// `completionProvider`.
pub fn completion(options: CompletionOptions) -> CompletionFeature {
    CompletionFeature { options }
}

#[allow(private_interfaces)]
impl sealed::Sealed for CompletionFeature {
    fn contribute(&self, caps: &mut CapabilityBuilder) -> Result<(), BuildError> {
        caps.set_completion(self.options.clone())
    }
}
impl FeatureSpec for CompletionFeature {
    type Marker = Completion;
}

/// The `completionItem/resolve` feature descriptor. Construct it with
/// [`completion_resolve`].
pub struct CompletionResolveFeature(());

/// Describe the standard completion-item resolve feature: it dispatches the
/// lsp-types [`ResolveCompletionItem`] marker — a typed
/// [`CompletionItem`](lsp_types::CompletionItem) in and out — and augments
/// the completion family's capability with `resolveProvider`.
///
/// Resolve is a dependent feature: registering it without the base
/// [`completion`] feature fails validation with
/// [`BuildError::ConflictingCapability`]
/// rather than advertising a dangling `resolveProvider`.
pub fn completion_resolve() -> CompletionResolveFeature {
    CompletionResolveFeature(())
}

#[allow(private_interfaces)]
impl sealed::Sealed for CompletionResolveFeature {
    fn contribute(&self, caps: &mut CapabilityBuilder) -> Result<(), BuildError> {
        caps.set_completion_resolve();
        Ok(())
    }
}
impl FeatureSpec for CompletionResolveFeature {
    type Marker = ResolveCompletionItem;
}

/// The `textDocument/diagnostic` feature descriptor. Construct it with
/// [`document_diagnostic`].
pub struct DocumentDiagnosticFeature {
    options: DiagnosticOptions,
}

/// Describe document diagnostics with the shared pull-diagnostics provider
/// options and the exact [`DocumentDiagnosticRequest`] wire contract.
pub fn document_diagnostic(options: DiagnosticOptions) -> DocumentDiagnosticFeature {
    DocumentDiagnosticFeature { options }
}

#[allow(private_interfaces)]
impl sealed::Sealed for DocumentDiagnosticFeature {
    fn contribute(&self, caps: &mut CapabilityBuilder) -> Result<(), BuildError> {
        caps.set_diagnostics(self.options.clone())
    }
}
impl FeatureSpec for DocumentDiagnosticFeature {
    type Marker = DocumentDiagnosticRequest;
}

/// The `workspace/diagnostic` feature descriptor. Construct it with
/// [`workspace_diagnostic`].
pub struct WorkspaceDiagnosticFeature {
    options: DiagnosticOptions,
}

/// Describe workspace diagnostics with the shared pull-diagnostics provider
/// options and the exact [`WorkspaceDiagnosticRequest`] wire contract.
pub fn workspace_diagnostic(options: DiagnosticOptions) -> WorkspaceDiagnosticFeature {
    WorkspaceDiagnosticFeature { options }
}

#[allow(private_interfaces)]
impl sealed::Sealed for WorkspaceDiagnosticFeature {
    fn contribute(&self, caps: &mut CapabilityBuilder) -> Result<(), BuildError> {
        caps.set_diagnostics(self.options.clone())
    }
}
impl FeatureSpec for WorkspaceDiagnosticFeature {
    type Marker = WorkspaceDiagnosticRequest;
}

/// The `workspace/symbol` feature descriptor. Construct it with
/// [`workspace_symbol`].
pub struct WorkspaceSymbolFeature {
    options: WorkspaceSymbolOptions,
}

/// Describe the standard workspace-symbol feature: it dispatches the
/// lsp-types [`WorkspaceSymbolRequest`] marker and advertises the supplied
/// [`WorkspaceSymbolOptions`] as the base of the `workspaceSymbolProvider`
/// capability family.
pub fn workspace_symbol(options: WorkspaceSymbolOptions) -> WorkspaceSymbolFeature {
    WorkspaceSymbolFeature { options }
}

#[allow(private_interfaces)]
impl sealed::Sealed for WorkspaceSymbolFeature {
    fn contribute(&self, caps: &mut CapabilityBuilder) -> Result<(), BuildError> {
        caps.set_workspace_symbol(self.options.clone())
    }
}
impl FeatureSpec for WorkspaceSymbolFeature {
    type Marker = WorkspaceSymbolRequest;
}

/// The `workspaceSymbol/resolve` feature descriptor. Construct it with
/// [`workspace_symbol_resolve`].
pub struct WorkspaceSymbolResolveFeature(());

/// Describe the standard workspace-symbol resolve feature: it dispatches the
/// lsp-types [`WorkspaceSymbolResolve`] marker — a typed
/// [`WorkspaceSymbol`](lsp_types::WorkspaceSymbol) in and out — and augments
/// the workspace-symbol family's capability with `resolveProvider`.
///
/// Resolve is a dependent feature: registering it without the base
/// [`workspace_symbol`] feature fails validation with
/// [`BuildError::ConflictingCapability`]
/// rather than advertising a dangling `resolveProvider`.
pub fn workspace_symbol_resolve() -> WorkspaceSymbolResolveFeature {
    WorkspaceSymbolResolveFeature(())
}

#[allow(private_interfaces)]
impl sealed::Sealed for WorkspaceSymbolResolveFeature {
    fn contribute(&self, caps: &mut CapabilityBuilder) -> Result<(), BuildError> {
        caps.set_workspace_symbol_resolve();
        Ok(())
    }
}
impl FeatureSpec for WorkspaceSymbolResolveFeature {
    type Marker = WorkspaceSymbolResolve;
}

/// The `textDocument/rename` feature descriptor. Construct it with [`rename`].
pub struct RenameFeature {
    options: RenameOptions,
}

/// Describe the standard rename feature: it dispatches the lsp-types
/// [`Rename`] marker and advertises the supplied [`RenameOptions`] as the base
/// of the `renameProvider` capability family.
pub fn rename(options: RenameOptions) -> RenameFeature {
    RenameFeature { options }
}

#[allow(private_interfaces)]
impl sealed::Sealed for RenameFeature {
    fn contribute(&self, caps: &mut CapabilityBuilder) -> Result<(), BuildError> {
        caps.set_rename(self.options.clone())
    }
}
impl FeatureSpec for RenameFeature {
    type Marker = Rename;
}

/// The `textDocument/prepareRename` feature descriptor. Construct it with
/// [`prepare_rename`].
pub struct PrepareRenameFeature(());

/// Describe the standard prepare-rename feature: it dispatches the lsp-types
/// [`PrepareRenameRequest`] marker and augments the rename family's capability
/// with `prepareProvider`.
///
/// Prepare rename is a dependent feature: registering it without the base
/// [`rename`] feature fails validation with
/// [`BuildError::ConflictingCapability`]
/// rather than advertising a dangling `prepareProvider`.
pub fn prepare_rename() -> PrepareRenameFeature {
    PrepareRenameFeature(())
}

#[allow(private_interfaces)]
impl sealed::Sealed for PrepareRenameFeature {
    fn contribute(&self, caps: &mut CapabilityBuilder) -> Result<(), BuildError> {
        caps.set_prepare_rename();
        Ok(())
    }
}
impl FeatureSpec for PrepareRenameFeature {
    type Marker = PrepareRenameRequest;
}

/// The `textDocument/codeAction` feature descriptor. Construct it with
/// [`code_action`].
pub struct CodeActionFeature {
    options: CodeActionOptions,
}

/// Describe the standard code-action feature: it dispatches the lsp-types
/// [`CodeActionRequest`] marker and advertises the supplied
/// [`CodeActionOptions`] as the base of the `codeActionProvider` capability
/// family.
pub fn code_action(options: CodeActionOptions) -> CodeActionFeature {
    CodeActionFeature { options }
}

#[allow(private_interfaces)]
impl sealed::Sealed for CodeActionFeature {
    fn contribute(&self, caps: &mut CapabilityBuilder) -> Result<(), BuildError> {
        caps.set_code_action(self.options.clone())
    }
}
impl FeatureSpec for CodeActionFeature {
    type Marker = CodeActionRequest;
}

/// The `codeAction/resolve` feature descriptor. Construct it with
/// [`code_action_resolve`].
pub struct CodeActionResolveFeature(());

/// Describe the standard code-action resolve feature: it dispatches the
/// lsp-types [`CodeActionResolveRequest`] marker — a typed
/// [`CodeAction`](lsp_types::CodeAction) in and out — and augments the
/// code-action family's capability with `resolveProvider`.
///
/// Resolve is a dependent feature: registering it without the base
/// [`code_action`] feature fails validation with
/// [`BuildError::ConflictingCapability`]
/// rather than advertising a dangling `resolveProvider`.
pub fn code_action_resolve() -> CodeActionResolveFeature {
    CodeActionResolveFeature(())
}

#[allow(private_interfaces)]
impl sealed::Sealed for CodeActionResolveFeature {
    fn contribute(&self, caps: &mut CapabilityBuilder) -> Result<(), BuildError> {
        caps.set_code_action_resolve();
        Ok(())
    }
}
impl FeatureSpec for CodeActionResolveFeature {
    type Marker = CodeActionResolveRequest;
}

/// The `textDocument/codeLens` feature descriptor. Construct it with
/// [`code_lens`].
pub struct CodeLensFeature {
    options: CodeLensOptions,
}

/// Describe the standard code-lens feature: it dispatches the lsp-types
/// [`CodeLensRequest`] marker and advertises the supplied [`CodeLensOptions`]
/// as the base of the `codeLensProvider` capability family.
pub fn code_lens(options: CodeLensOptions) -> CodeLensFeature {
    CodeLensFeature { options }
}

#[allow(private_interfaces)]
impl sealed::Sealed for CodeLensFeature {
    fn contribute(&self, caps: &mut CapabilityBuilder) -> Result<(), BuildError> {
        caps.set_code_lens(self.options)
    }
}
impl FeatureSpec for CodeLensFeature {
    type Marker = CodeLensRequest;
}

/// The `codeLens/resolve` feature descriptor. Construct it with
/// [`code_lens_resolve`].
pub struct CodeLensResolveFeature(());

/// Describe the standard code-lens resolve feature: it dispatches the
/// lsp-types [`CodeLensResolve`] marker — a typed
/// [`CodeLens`](lsp_types::CodeLens) in and out — and augments the code-lens
/// family's capability with `resolveProvider`.
///
/// Resolve is a dependent feature: registering it without the base
/// [`code_lens`] feature fails validation with
/// [`BuildError::ConflictingCapability`]
/// rather than advertising a dangling `resolveProvider`.
pub fn code_lens_resolve() -> CodeLensResolveFeature {
    CodeLensResolveFeature(())
}

#[allow(private_interfaces)]
impl sealed::Sealed for CodeLensResolveFeature {
    fn contribute(&self, caps: &mut CapabilityBuilder) -> Result<(), BuildError> {
        caps.set_code_lens_resolve();
        Ok(())
    }
}
impl FeatureSpec for CodeLensResolveFeature {
    type Marker = CodeLensResolve;
}

/// The `textDocument/documentLink` feature descriptor. Construct it with
/// [`document_link`].
pub struct DocumentLinkFeature {
    options: DocumentLinkOptions,
}

/// Describe the standard document-link feature: it dispatches the lsp-types
/// [`DocumentLinkRequest`] marker and advertises the supplied
/// [`DocumentLinkOptions`] as the base of the `documentLinkProvider`
/// capability family.
pub fn document_link(options: DocumentLinkOptions) -> DocumentLinkFeature {
    DocumentLinkFeature { options }
}

#[allow(private_interfaces)]
impl sealed::Sealed for DocumentLinkFeature {
    fn contribute(&self, caps: &mut CapabilityBuilder) -> Result<(), BuildError> {
        caps.set_document_link(self.options.clone())
    }
}
impl FeatureSpec for DocumentLinkFeature {
    type Marker = DocumentLinkRequest;
}

/// The `documentLink/resolve` feature descriptor. Construct it with
/// [`document_link_resolve`].
pub struct DocumentLinkResolveFeature(());

/// Describe the standard document-link resolve feature: it dispatches the
/// lsp-types [`DocumentLinkResolve`] marker — a typed
/// [`DocumentLink`](lsp_types::DocumentLink) in and out — and augments the
/// document-link family's capability with `resolveProvider`.
///
/// Resolve is a dependent feature: registering it without the base
/// [`document_link`] feature fails validation with
/// [`BuildError::ConflictingCapability`]
/// rather than advertising a dangling `resolveProvider`.
pub fn document_link_resolve() -> DocumentLinkResolveFeature {
    DocumentLinkResolveFeature(())
}

#[allow(private_interfaces)]
impl sealed::Sealed for DocumentLinkResolveFeature {
    fn contribute(&self, caps: &mut CapabilityBuilder) -> Result<(), BuildError> {
        caps.set_document_link_resolve();
        Ok(())
    }
}
impl FeatureSpec for DocumentLinkResolveFeature {
    type Marker = DocumentLinkResolve;
}

/// The `textDocument/inlayHint` feature descriptor. Construct it with
/// [`inlay_hint`].
pub struct InlayHintFeature {
    options: InlayHintOptions,
}

/// Describe the standard inlay-hint feature: it dispatches the lsp-types
/// [`InlayHintRequest`] marker and advertises the supplied [`InlayHintOptions`]
/// as the base of the `inlayHintProvider` capability family.
pub fn inlay_hint(options: InlayHintOptions) -> InlayHintFeature {
    InlayHintFeature { options }
}

#[allow(private_interfaces)]
impl sealed::Sealed for InlayHintFeature {
    fn contribute(&self, caps: &mut CapabilityBuilder) -> Result<(), BuildError> {
        caps.set_inlay_hint(self.options.clone())
    }
}
impl FeatureSpec for InlayHintFeature {
    type Marker = InlayHintRequest;
}

/// The `inlayHint/resolve` feature descriptor. Construct it with
/// [`inlay_hint_resolve`].
pub struct InlayHintResolveFeature(());

/// Describe the standard inlay-hint resolve feature: it dispatches the
/// lsp-types [`InlayHintResolveRequest`] marker — a typed
/// [`InlayHint`](lsp_types::InlayHint) in and out — and augments the
/// inlay-hint family's capability with `resolveProvider`.
///
/// Resolve is a dependent feature: registering it without the base
/// [`inlay_hint`] feature fails validation with
/// [`BuildError::ConflictingCapability`]
/// rather than advertising a dangling `resolveProvider`.
pub fn inlay_hint_resolve() -> InlayHintResolveFeature {
    InlayHintResolveFeature(())
}

#[allow(private_interfaces)]
impl sealed::Sealed for InlayHintResolveFeature {
    fn contribute(&self, caps: &mut CapabilityBuilder) -> Result<(), BuildError> {
        caps.set_inlay_hint_resolve();
        Ok(())
    }
}
impl FeatureSpec for InlayHintResolveFeature {
    type Marker = InlayHintResolveRequest;
}

/// The `workspace/willCreateFiles` feature descriptor. Construct it with
/// [`will_create_files`].
pub struct WillCreateFilesFeature {
    options: FileOperationRegistrationOptions,
}

/// Describe the standard will-create-files request: it dispatches the
/// lsp-types [`WillCreateFiles`] marker and contributes the supplied
/// [`FileOperationRegistrationOptions`] to the create file-operation family,
/// whose shared filters the family's capability advertises.
///
/// The create family is shared with [`did_create_files`]: both sides must
/// contribute identical filters, or the build fails with
/// [`BuildError::ConflictingCapability`].
pub fn will_create_files(options: FileOperationRegistrationOptions) -> WillCreateFilesFeature {
    WillCreateFilesFeature { options }
}

#[allow(private_interfaces)]
impl sealed::Sealed for WillCreateFilesFeature {
    fn contribute(&self, caps: &mut CapabilityBuilder) -> Result<(), BuildError> {
        caps.set_will_create(self.options.clone())
    }
}
impl FeatureSpec for WillCreateFilesFeature {
    type Marker = WillCreateFiles;
}

/// The `workspace/willRenameFiles` feature descriptor. Construct it with
/// [`will_rename_files`].
pub struct WillRenameFilesFeature {
    options: FileOperationRegistrationOptions,
}

/// Describe the standard will-rename-files request: it dispatches the
/// lsp-types [`WillRenameFiles`] marker and contributes the supplied
/// [`FileOperationRegistrationOptions`] to the rename file-operation family,
/// whose shared filters the family's capability advertises.
///
/// The rename family is shared with [`did_rename_files`]: both sides must
/// contribute identical filters, or the build fails with
/// [`BuildError::ConflictingCapability`].
pub fn will_rename_files(options: FileOperationRegistrationOptions) -> WillRenameFilesFeature {
    WillRenameFilesFeature { options }
}

#[allow(private_interfaces)]
impl sealed::Sealed for WillRenameFilesFeature {
    fn contribute(&self, caps: &mut CapabilityBuilder) -> Result<(), BuildError> {
        caps.set_will_rename(self.options.clone())
    }
}
impl FeatureSpec for WillRenameFilesFeature {
    type Marker = WillRenameFiles;
}

/// The `workspace/willDeleteFiles` feature descriptor. Construct it with
/// [`will_delete_files`].
pub struct WillDeleteFilesFeature {
    options: FileOperationRegistrationOptions,
}

/// Describe the standard will-delete-files request: it dispatches the
/// lsp-types [`WillDeleteFiles`] marker and contributes the supplied
/// [`FileOperationRegistrationOptions`] to the delete file-operation family,
/// whose shared filters the family's capability advertises.
///
/// The delete family is shared with [`did_delete_files`]: both sides must
/// contribute identical filters, or the build fails with
/// [`BuildError::ConflictingCapability`].
pub fn will_delete_files(options: FileOperationRegistrationOptions) -> WillDeleteFilesFeature {
    WillDeleteFilesFeature { options }
}

#[allow(private_interfaces)]
impl sealed::Sealed for WillDeleteFilesFeature {
    fn contribute(&self, caps: &mut CapabilityBuilder) -> Result<(), BuildError> {
        caps.set_will_delete(self.options.clone())
    }
}
impl FeatureSpec for WillDeleteFilesFeature {
    type Marker = WillDeleteFiles;
}

/// The `workspace/didChangeWatchedFiles` notification feature descriptor.
/// Construct it with [`did_change_watched_files`].
pub struct DidChangeWatchedFilesFeature(());

/// Describe the standard watched-files notification feature: it dispatches
/// the lsp-types [`DidChangeWatchedFiles`] marker with typed
/// [`DidChangeWatchedFilesParams`](lsp_types::DidChangeWatchedFilesParams).
///
/// LSP 3.17 has no server capability field for watched files — a server
/// subscribes through dynamic registration — so this descriptor contributes
/// nothing to the capability catalog. Registering through the descriptor
/// rather than [`notification`](crate::ServerBuilder::notification) keeps the
/// registration inside the sealed catalog.
pub fn did_change_watched_files() -> DidChangeWatchedFilesFeature {
    DidChangeWatchedFilesFeature(())
}

#[allow(private_interfaces)]
impl sealed::Sealed for DidChangeWatchedFilesFeature {
    fn contribute(&self, _caps: &mut CapabilityBuilder) -> Result<(), BuildError> {
        Ok(())
    }
}
impl NotificationFeatureSpec for DidChangeWatchedFilesFeature {
    type Marker = DidChangeWatchedFiles;
}

/// The `workspace/didCreateFiles` notification feature descriptor. Construct
/// it with [`did_create_files`].
pub struct DidCreateFilesFeature {
    options: FileOperationRegistrationOptions,
}

/// Describe the standard did-create-files notification feature: it dispatches
/// the lsp-types [`DidCreateFiles`] marker and contributes the supplied
/// [`FileOperationRegistrationOptions`] to the create file-operation family,
/// whose shared filters the family's capability advertises.
///
/// The create family is shared with [`will_create_files`]: both sides must
/// contribute identical filters, or the build fails with
/// [`BuildError::ConflictingCapability`].
pub fn did_create_files(options: FileOperationRegistrationOptions) -> DidCreateFilesFeature {
    DidCreateFilesFeature { options }
}

#[allow(private_interfaces)]
impl sealed::Sealed for DidCreateFilesFeature {
    fn contribute(&self, caps: &mut CapabilityBuilder) -> Result<(), BuildError> {
        caps.set_did_create(self.options.clone())
    }
}
impl NotificationFeatureSpec for DidCreateFilesFeature {
    type Marker = DidCreateFiles;
}

/// The `workspace/didRenameFiles` notification feature descriptor. Construct
/// it with [`did_rename_files`].
pub struct DidRenameFilesFeature {
    options: FileOperationRegistrationOptions,
}

/// Describe the standard did-rename-files notification feature: it dispatches
/// the lsp-types [`DidRenameFiles`] marker and contributes the supplied
/// [`FileOperationRegistrationOptions`] to the rename file-operation family,
/// whose shared filters the family's capability advertises.
///
/// The rename family is shared with [`will_rename_files`]: both sides must
/// contribute identical filters, or the build fails with
/// [`BuildError::ConflictingCapability`].
pub fn did_rename_files(options: FileOperationRegistrationOptions) -> DidRenameFilesFeature {
    DidRenameFilesFeature { options }
}

#[allow(private_interfaces)]
impl sealed::Sealed for DidRenameFilesFeature {
    fn contribute(&self, caps: &mut CapabilityBuilder) -> Result<(), BuildError> {
        caps.set_did_rename(self.options.clone())
    }
}
impl NotificationFeatureSpec for DidRenameFilesFeature {
    type Marker = DidRenameFiles;
}

/// The `workspace/didDeleteFiles` notification feature descriptor. Construct
/// it with [`did_delete_files`].
pub struct DidDeleteFilesFeature {
    options: FileOperationRegistrationOptions,
}

/// Describe the standard did-delete-files notification feature: it dispatches
/// the lsp-types [`DidDeleteFiles`] marker and contributes the supplied
/// [`FileOperationRegistrationOptions`] to the delete file-operation family,
/// whose shared filters the family's capability advertises.
///
/// The delete family is shared with [`will_delete_files`]: both sides must
/// contribute identical filters, or the build fails with
/// [`BuildError::ConflictingCapability`].
pub fn did_delete_files(options: FileOperationRegistrationOptions) -> DidDeleteFilesFeature {
    DidDeleteFilesFeature { options }
}

#[allow(private_interfaces)]
impl sealed::Sealed for DidDeleteFilesFeature {
    fn contribute(&self, caps: &mut CapabilityBuilder) -> Result<(), BuildError> {
        caps.set_did_delete(self.options.clone())
    }
}
impl NotificationFeatureSpec for DidDeleteFilesFeature {
    type Marker = DidDeleteFiles;
}

#[cfg(test)]
mod tests {
    use super::*;
    use lsp_types::notification::{DidChangeWatchedFiles, DidCreateFiles};
    use lsp_types::request::{
        CallHierarchyIncomingCalls, CallHierarchyOutgoingCalls, CallHierarchyPrepare,
        CodeActionRequest, CodeActionResolveRequest, CodeLensRequest, CodeLensResolve,
        ColorPresentationRequest, DocumentColor, DocumentDiagnosticRequest,
        DocumentHighlightRequest, DocumentLinkRequest, DocumentLinkResolve, DocumentSymbolRequest,
        FoldingRangeRequest, Formatting, GotoDeclaration, GotoDeclarationParams,
        GotoDeclarationResponse, GotoDefinition, GotoImplementation, GotoImplementationParams,
        GotoImplementationResponse, GotoTypeDefinition, GotoTypeDefinitionParams,
        GotoTypeDefinitionResponse, InlayHintRequest, InlayHintResolveRequest, InlineValueRequest,
        LinkedEditingRange, MonikerRequest, OnTypeFormatting, PrepareRenameRequest,
        RangeFormatting, References, Rename, SelectionRangeRequest, SemanticTokensFullDeltaRequest,
        SemanticTokensFullRequest, SemanticTokensRangeRequest, SignatureHelpRequest,
        TypeHierarchyPrepare, TypeHierarchySubtypes, TypeHierarchySupertypes,
        WorkspaceDiagnosticRequest,
    };
    use lsp_types::{
        CallHierarchyIncomingCall, CallHierarchyIncomingCallsParams, CallHierarchyItem,
        CallHierarchyOutgoingCall, CallHierarchyOutgoingCallsParams, CallHierarchyPrepareParams,
        CodeAction, CodeActionOptions, CodeActionParams, CodeActionResponse, CodeLens,
        CodeLensOptions, CodeLensParams, ColorInformation, ColorPresentation,
        ColorPresentationParams, ColorProviderOptions, CreateFilesParams, DeclarationOptions,
        DefinitionOptions, DeleteFilesParams, DiagnosticOptions, DidChangeWatchedFilesParams,
        DocumentColorParams, DocumentDiagnosticParams, DocumentDiagnosticReportResult,
        DocumentFormattingOptions, DocumentFormattingParams, DocumentHighlight,
        DocumentHighlightOptions, DocumentHighlightParams, DocumentLink, DocumentLinkOptions,
        DocumentLinkParams, DocumentOnTypeFormattingOptions, DocumentOnTypeFormattingParams,
        DocumentRangeFormattingOptions, DocumentRangeFormattingParams, DocumentSymbolOptions,
        DocumentSymbolParams, DocumentSymbolResponse, FoldingProviderOptions, FoldingRange,
        FoldingRangeParams, GotoDefinitionParams, GotoDefinitionResponse, InlayHint,
        InlayHintOptions, InlayHintParams, InlineValue, InlineValueOptions, InlineValueParams,
        LinkedEditingRangeOptions, LinkedEditingRangeParams, LinkedEditingRanges, Location,
        Moniker, MonikerOptions, MonikerParams, PrepareRenameResponse, ReferenceParams,
        ReferencesOptions, RenameFilesParams, RenameOptions, RenameParams, SelectionRange,
        SelectionRangeOptions, SelectionRangeParams, SemanticTokensDeltaParams,
        SemanticTokensFullDeltaResult, SemanticTokensParams, SemanticTokensRangeParams,
        SemanticTokensRangeResult, SemanticTokensResult, SignatureHelp, SignatureHelpOptions,
        SignatureHelpParams, StaticTextDocumentRegistrationOptions, TextDocumentPositionParams,
        TextEdit, TypeHierarchyItem, TypeHierarchyPrepareParams, TypeHierarchySubtypesParams,
        TypeHierarchySupertypesParams, WorkspaceDiagnosticParams, WorkspaceDiagnosticReportResult,
        WorkspaceEdit, WorkspaceSymbol, WorkspaceSymbolParams, WorkspaceSymbolResponse,
    };

    fn assert_formatting_descriptor<F: FeatureSpec<Marker = Formatting>>(_: F) {}
    fn assert_range_formatting_descriptor<F: FeatureSpec<Marker = RangeFormatting>>(_: F) {}
    fn assert_on_type_formatting_descriptor<F: FeatureSpec<Marker = OnTypeFormatting>>(_: F) {}

    fn assert_formatting_contract<R>()
    where
        R: Request<Params = DocumentFormattingParams, Result = Option<Vec<TextEdit>>>,
    {
    }

    fn assert_range_formatting_contract<R>()
    where
        R: Request<Params = DocumentRangeFormattingParams, Result = Option<Vec<TextEdit>>>,
    {
    }

    fn assert_on_type_formatting_contract<R>()
    where
        R: Request<Params = DocumentOnTypeFormattingParams, Result = Option<Vec<TextEdit>>>,
    {
    }

    #[test]
    fn formatting_descriptors_fix_the_exact_lsp_types_contracts() {
        assert_formatting_descriptor(document_formatting(DocumentFormattingOptions::default()));
        assert_range_formatting_descriptor(range_formatting(DocumentRangeFormattingOptions {
            work_done_progress_options: Default::default(),
        }));
        assert_on_type_formatting_descriptor(on_type_formatting(
            DocumentOnTypeFormattingOptions::default(),
        ));
        assert_formatting_contract::<Formatting>();
        assert_range_formatting_contract::<RangeFormatting>();
        assert_on_type_formatting_contract::<OnTypeFormatting>();
        assert_eq!(<Formatting as Request>::METHOD, "textDocument/formatting");
        assert_eq!(
            <RangeFormatting as Request>::METHOD,
            "textDocument/rangeFormatting"
        );
        assert_eq!(
            <OnTypeFormatting as Request>::METHOD,
            "textDocument/onTypeFormatting"
        );
    }

    fn assert_document_color_descriptor<F: FeatureSpec<Marker = DocumentColor>>(_: F) {}
    fn assert_color_presentation_descriptor<F: FeatureSpec<Marker = ColorPresentationRequest>>(
        _: F,
    ) {
    }
    fn assert_folding_range_descriptor<F: FeatureSpec<Marker = FoldingRangeRequest>>(_: F) {}
    fn assert_selection_range_descriptor<F: FeatureSpec<Marker = SelectionRangeRequest>>(_: F) {}
    fn assert_inline_value_descriptor<F: FeatureSpec<Marker = InlineValueRequest>>(_: F) {}

    fn assert_document_color_contract<R>()
    where
        R: Request<Params = DocumentColorParams, Result = Vec<ColorInformation>>,
    {
    }

    fn assert_color_presentation_contract<R>()
    where
        R: Request<Params = ColorPresentationParams, Result = Vec<ColorPresentation>>,
    {
    }

    fn assert_folding_range_contract<R>()
    where
        R: Request<Params = FoldingRangeParams, Result = Option<Vec<FoldingRange>>>,
    {
    }

    fn assert_selection_range_contract<R>()
    where
        R: Request<Params = SelectionRangeParams, Result = Option<Vec<SelectionRange>>>,
    {
    }

    fn assert_inline_value_contract<R>()
    where
        R: Request<Params = InlineValueParams, Result = Option<Vec<InlineValue>>>,
    {
    }

    #[test]
    fn presentation_descriptors_fix_the_exact_lsp_types_contracts() {
        assert_document_color_descriptor(document_color(ColorProviderOptions {}));
        assert_color_presentation_descriptor(color_presentation());
        assert_folding_range_descriptor(folding_range(FoldingProviderOptions {}));
        assert_selection_range_descriptor(selection_range(SelectionRangeOptions::default()));
        assert_inline_value_descriptor(inline_value(InlineValueOptions::default()));
        assert_document_color_contract::<DocumentColor>();
        assert_color_presentation_contract::<ColorPresentationRequest>();
        assert_folding_range_contract::<FoldingRangeRequest>();
        assert_selection_range_contract::<SelectionRangeRequest>();
        assert_inline_value_contract::<InlineValueRequest>();
        assert_eq!(
            <DocumentColor as Request>::METHOD,
            "textDocument/documentColor"
        );
        assert_eq!(
            <ColorPresentationRequest as Request>::METHOD,
            "textDocument/colorPresentation"
        );
        assert_eq!(
            <FoldingRangeRequest as Request>::METHOD,
            "textDocument/foldingRange"
        );
        assert_eq!(
            <SelectionRangeRequest as Request>::METHOD,
            "textDocument/selectionRange"
        );
        assert_eq!(
            <InlineValueRequest as Request>::METHOD,
            "textDocument/inlineValue"
        );
    }

    #[test]
    fn editing_and_presentation_descriptors_contribute_only_their_capabilities() {
        let formatting = DocumentFormattingOptions::default();
        let range = DocumentRangeFormattingOptions {
            work_done_progress_options: Default::default(),
        };
        let on_type = DocumentOnTypeFormattingOptions {
            first_trigger_character: "}".to_string(),
            more_trigger_character: Some(vec![";".to_string()]),
        };
        let selection = SelectionRangeOptions::default();
        let inline = InlineValueOptions::default();
        let mut caps = CapabilityBuilder::default();

        sealed::Sealed::contribute(&document_formatting(formatting.clone()), &mut caps).unwrap();
        sealed::Sealed::contribute(&range_formatting(range.clone()), &mut caps).unwrap();
        sealed::Sealed::contribute(&on_type_formatting(on_type.clone()), &mut caps).unwrap();
        sealed::Sealed::contribute(&document_color(ColorProviderOptions {}), &mut caps).unwrap();
        sealed::Sealed::contribute(&color_presentation(), &mut caps).unwrap();
        sealed::Sealed::contribute(&folding_range(FoldingProviderOptions {}), &mut caps).unwrap();
        sealed::Sealed::contribute(&selection_range(selection.clone()), &mut caps).unwrap();
        sealed::Sealed::contribute(&inline_value(inline.clone()), &mut caps).unwrap();
        caps.validate().unwrap();

        assert_eq!(
            caps.finish(),
            lsp_types::ServerCapabilities {
                document_formatting_provider: Some(lsp_types::OneOf::Right(formatting)),
                document_range_formatting_provider: Some(lsp_types::OneOf::Right(range)),
                document_on_type_formatting_provider: Some(on_type),
                color_provider: Some(lsp_types::ColorProviderCapability::ColorProvider(
                    ColorProviderOptions {},
                )),
                folding_range_provider: Some(
                    lsp_types::FoldingRangeProviderCapability::FoldingProvider(
                        FoldingProviderOptions {},
                    ),
                ),
                selection_range_provider: Some(
                    lsp_types::SelectionRangeProviderCapability::Options(selection),
                ),
                inline_value_provider: Some(lsp_types::OneOf::Right(
                    lsp_types::InlineValueServerCapabilities::Options(inline),
                )),
                ..lsp_types::ServerCapabilities::default()
            }
        );
    }

    fn assert_call_prepare_descriptor<F: FeatureSpec<Marker = CallHierarchyPrepare>>(_: F) {}
    fn assert_call_incoming_descriptor<F: FeatureSpec<Marker = CallHierarchyIncomingCalls>>(_: F) {}
    fn assert_call_outgoing_descriptor<F: FeatureSpec<Marker = CallHierarchyOutgoingCalls>>(_: F) {}

    fn assert_call_prepare_contract<R>()
    where
        R: Request<Params = CallHierarchyPrepareParams, Result = Option<Vec<CallHierarchyItem>>>,
    {
    }

    fn assert_call_incoming_contract<R>()
    where
        R: Request<
                Params = CallHierarchyIncomingCallsParams,
                Result = Option<Vec<CallHierarchyIncomingCall>>,
            >,
    {
    }

    fn assert_call_outgoing_contract<R>()
    where
        R: Request<
                Params = CallHierarchyOutgoingCallsParams,
                Result = Option<Vec<CallHierarchyOutgoingCall>>,
            >,
    {
    }

    #[test]
    fn call_hierarchy_descriptors_fix_the_exact_lsp_types_contracts() {
        assert_call_prepare_descriptor(call_hierarchy_prepare(CallHierarchyOptions::default()));
        assert_call_incoming_descriptor(call_hierarchy_incoming_calls());
        assert_call_outgoing_descriptor(call_hierarchy_outgoing_calls());
        assert_call_prepare_contract::<CallHierarchyPrepare>();
        assert_call_incoming_contract::<CallHierarchyIncomingCalls>();
        assert_call_outgoing_contract::<CallHierarchyOutgoingCalls>();
        assert_eq!(
            <CallHierarchyPrepare as Request>::METHOD,
            "textDocument/prepareCallHierarchy"
        );
        assert_eq!(
            <CallHierarchyIncomingCalls as Request>::METHOD,
            "callHierarchy/incomingCalls"
        );
        assert_eq!(
            <CallHierarchyOutgoingCalls as Request>::METHOD,
            "callHierarchy/outgoingCalls"
        );
    }

    fn assert_type_prepare_descriptor<F: FeatureSpec<Marker = TypeHierarchyPrepare>>(_: F) {}
    fn assert_type_supertypes_descriptor<F: FeatureSpec<Marker = TypeHierarchySupertypes>>(_: F) {}
    fn assert_type_subtypes_descriptor<F: FeatureSpec<Marker = TypeHierarchySubtypes>>(_: F) {}

    fn assert_type_prepare_contract<R>()
    where
        R: Request<Params = TypeHierarchyPrepareParams, Result = Option<Vec<TypeHierarchyItem>>>,
    {
    }

    fn assert_type_supertypes_contract<R>()
    where
        R: Request<Params = TypeHierarchySupertypesParams, Result = Option<Vec<TypeHierarchyItem>>>,
    {
    }

    fn assert_type_subtypes_contract<R>()
    where
        R: Request<Params = TypeHierarchySubtypesParams, Result = Option<Vec<TypeHierarchyItem>>>,
    {
    }

    #[test]
    fn type_hierarchy_descriptors_fix_the_exact_lsp_types_contracts() {
        assert_type_prepare_descriptor(type_hierarchy_prepare(TypeHierarchyOptions::default()));
        assert_type_supertypes_descriptor(type_hierarchy_supertypes());
        assert_type_subtypes_descriptor(type_hierarchy_subtypes());
        assert_type_prepare_contract::<TypeHierarchyPrepare>();
        assert_type_supertypes_contract::<TypeHierarchySupertypes>();
        assert_type_subtypes_contract::<TypeHierarchySubtypes>();
        assert_eq!(
            <TypeHierarchyPrepare as Request>::METHOD,
            "textDocument/prepareTypeHierarchy"
        );
        assert_eq!(
            <TypeHierarchySupertypes as Request>::METHOD,
            "typeHierarchy/supertypes"
        );
        assert_eq!(
            <TypeHierarchySubtypes as Request>::METHOD,
            "typeHierarchy/subtypes"
        );
    }

    fn assert_semantic_full_descriptor<F: FeatureSpec<Marker = SemanticTokensFullRequest>>(_: F) {}
    fn assert_semantic_delta_descriptor<F: FeatureSpec<Marker = SemanticTokensFullDeltaRequest>>(
        _: F,
    ) {
    }
    fn assert_semantic_range_descriptor<F: FeatureSpec<Marker = SemanticTokensRangeRequest>>(_: F) {
    }

    fn assert_semantic_full_contract<R>()
    where
        R: Request<Params = SemanticTokensParams, Result = Option<SemanticTokensResult>>,
    {
    }

    fn assert_semantic_delta_contract<R>()
    where
        R: Request<
                Params = SemanticTokensDeltaParams,
                Result = Option<SemanticTokensFullDeltaResult>,
            >,
    {
    }

    fn assert_semantic_range_contract<R>()
    where
        R: Request<Params = SemanticTokensRangeParams, Result = Option<SemanticTokensRangeResult>>,
    {
    }

    #[test]
    fn semantic_token_descriptors_fix_the_exact_lsp_types_contracts() {
        let options = SemanticTokensOptions::default();
        assert_semantic_full_descriptor(semantic_tokens_full(options.clone()));
        assert_semantic_delta_descriptor(semantic_tokens_full_delta(options.clone()));
        assert_semantic_range_descriptor(semantic_tokens_range(options));
        assert_semantic_full_contract::<SemanticTokensFullRequest>();
        assert_semantic_delta_contract::<SemanticTokensFullDeltaRequest>();
        assert_semantic_range_contract::<SemanticTokensRangeRequest>();
        assert_eq!(
            <SemanticTokensFullRequest as Request>::METHOD,
            "textDocument/semanticTokens/full"
        );
        assert_eq!(
            <SemanticTokensFullDeltaRequest as Request>::METHOD,
            "textDocument/semanticTokens/full/delta"
        );
        assert_eq!(
            <SemanticTokensRangeRequest as Request>::METHOD,
            "textDocument/semanticTokens/range"
        );
    }

    fn assert_document_descriptor<F: FeatureSpec<Marker = DocumentDiagnosticRequest>>(_: F) {}

    fn assert_will_save_wait_until_descriptor<F: FeatureSpec<Marker = WillSaveWaitUntil>>(_: F) {}

    #[test]
    fn will_save_wait_until_descriptor_fixes_the_typed_request_contract() {
        assert_will_save_wait_until_descriptor(will_save_wait_until());
        assert_eq!(
            <WillSaveWaitUntil as Request>::METHOD,
            "textDocument/willSaveWaitUntil"
        );
    }
    fn assert_workspace_descriptor<F: FeatureSpec<Marker = WorkspaceDiagnosticRequest>>(_: F) {}

    fn assert_document_contract<R>()
    where
        R: Request<Params = DocumentDiagnosticParams, Result = DocumentDiagnosticReportResult>,
    {
    }

    fn assert_workspace_contract<R>()
    where
        R: Request<Params = WorkspaceDiagnosticParams, Result = WorkspaceDiagnosticReportResult>,
    {
    }

    #[test]
    fn diagnostic_descriptors_fix_the_exact_lsp_types_contracts() {
        assert_document_descriptor(document_diagnostic(DiagnosticOptions::default()));
        assert_workspace_descriptor(workspace_diagnostic(DiagnosticOptions::default()));
        assert_document_contract::<DocumentDiagnosticRequest>();
        assert_workspace_contract::<WorkspaceDiagnosticRequest>();
        assert_eq!(
            <DocumentDiagnosticRequest as Request>::METHOD,
            "textDocument/diagnostic"
        );
        assert_eq!(
            <WorkspaceDiagnosticRequest as Request>::METHOD,
            "workspace/diagnostic"
        );
    }

    fn assert_workspace_symbol_descriptor<F: FeatureSpec<Marker = WorkspaceSymbolRequest>>(_: F) {}
    fn assert_workspace_symbol_resolve_descriptor<
        F: FeatureSpec<Marker = WorkspaceSymbolResolve>,
    >(
        _: F,
    ) {
    }
    fn assert_will_create_descriptor<F: FeatureSpec<Marker = WillCreateFiles>>(_: F) {}
    fn assert_will_rename_descriptor<F: FeatureSpec<Marker = WillRenameFiles>>(_: F) {}
    fn assert_will_delete_descriptor<F: FeatureSpec<Marker = WillDeleteFiles>>(_: F) {}
    fn assert_did_change_watched_descriptor<
        F: NotificationFeatureSpec<Marker = DidChangeWatchedFiles>,
    >(
        _: F,
    ) {
    }
    fn assert_did_create_descriptor<F: NotificationFeatureSpec<Marker = DidCreateFiles>>(_: F) {}

    fn assert_workspace_symbol_contract<R>()
    where
        R: Request<Params = WorkspaceSymbolParams, Result = Option<WorkspaceSymbolResponse>>,
    {
    }

    fn assert_workspace_symbol_resolve_contract<R>()
    where
        R: Request<Params = WorkspaceSymbol, Result = WorkspaceSymbol>,
    {
    }

    fn assert_will_create_contract<R>()
    where
        R: Request<Params = CreateFilesParams, Result = Option<WorkspaceEdit>>,
    {
    }

    fn assert_will_rename_contract<R>()
    where
        R: Request<Params = RenameFilesParams, Result = Option<WorkspaceEdit>>,
    {
    }

    fn assert_will_delete_contract<R>()
    where
        R: Request<Params = DeleteFilesParams, Result = Option<WorkspaceEdit>>,
    {
    }

    fn assert_did_change_watched_contract<N>()
    where
        N: Notification<Params = DidChangeWatchedFilesParams>,
    {
    }

    fn assert_did_create_contract<N>()
    where
        N: Notification<Params = CreateFilesParams>,
    {
    }

    fn workspace_symbol_options() -> WorkspaceSymbolOptions {
        WorkspaceSymbolOptions {
            work_done_progress_options: Default::default(),
            resolve_provider: None,
        }
    }

    #[test]
    fn workspace_symbol_descriptors_fix_the_exact_lsp_types_contracts() {
        assert_workspace_symbol_descriptor(workspace_symbol(workspace_symbol_options()));
        assert_workspace_symbol_resolve_descriptor(workspace_symbol_resolve());
        assert_workspace_symbol_contract::<WorkspaceSymbolRequest>();
        assert_workspace_symbol_resolve_contract::<WorkspaceSymbolResolve>();
        assert_eq!(
            <WorkspaceSymbolRequest as Request>::METHOD,
            "workspace/symbol"
        );
        assert_eq!(
            <WorkspaceSymbolResolve as Request>::METHOD,
            "workspaceSymbol/resolve"
        );
    }

    #[test]
    fn file_operation_descriptors_fix_the_exact_lsp_types_contracts() {
        let options = || FileOperationRegistrationOptions::default();
        assert_will_create_descriptor(will_create_files(options()));
        assert_will_rename_descriptor(will_rename_files(options()));
        assert_will_delete_descriptor(will_delete_files(options()));
        assert_did_change_watched_descriptor(did_change_watched_files());
        assert_did_create_descriptor(did_create_files(options()));
        assert_will_create_contract::<WillCreateFiles>();
        assert_will_rename_contract::<WillRenameFiles>();
        assert_will_delete_contract::<WillDeleteFiles>();
        assert_did_change_watched_contract::<DidChangeWatchedFiles>();
        assert_did_create_contract::<DidCreateFiles>();
        assert_eq!(
            <WillCreateFiles as Request>::METHOD,
            "workspace/willCreateFiles"
        );
        assert_eq!(
            <WillRenameFiles as Request>::METHOD,
            "workspace/willRenameFiles"
        );
        assert_eq!(
            <WillDeleteFiles as Request>::METHOD,
            "workspace/willDeleteFiles"
        );
        assert_eq!(
            <DidChangeWatchedFiles as Notification>::METHOD,
            "workspace/didChangeWatchedFiles"
        );
        assert_eq!(
            <DidCreateFiles as Notification>::METHOD,
            "workspace/didCreateFiles"
        );
        assert_eq!(
            <DidRenameFiles as Notification>::METHOD,
            "workspace/didRenameFiles"
        );
        assert_eq!(
            <DidDeleteFiles as Notification>::METHOD,
            "workspace/didDeleteFiles"
        );
    }

    fn assert_rename_descriptor<F: FeatureSpec<Marker = Rename>>(_: F) {}
    fn assert_prepare_rename_descriptor<F: FeatureSpec<Marker = PrepareRenameRequest>>(_: F) {}

    fn assert_rename_contract<R>()
    where
        R: Request<Params = RenameParams, Result = Option<WorkspaceEdit>>,
    {
    }

    fn assert_prepare_rename_contract<R>()
    where
        R: Request<Params = TextDocumentPositionParams, Result = Option<PrepareRenameResponse>>,
    {
    }

    #[test]
    fn rename_descriptors_fix_the_exact_lsp_types_contracts() {
        assert_rename_descriptor(rename(RenameOptions {
            prepare_provider: None,
            work_done_progress_options: Default::default(),
        }));
        assert_prepare_rename_descriptor(prepare_rename());
        assert_rename_contract::<Rename>();
        assert_prepare_rename_contract::<PrepareRenameRequest>();
        assert_eq!(<Rename as Request>::METHOD, "textDocument/rename");
        assert_eq!(
            <PrepareRenameRequest as Request>::METHOD,
            "textDocument/prepareRename"
        );
    }

    fn assert_code_action_descriptor<F: FeatureSpec<Marker = CodeActionRequest>>(_: F) {}
    fn assert_code_action_resolve_descriptor<F: FeatureSpec<Marker = CodeActionResolveRequest>>(
        _: F,
    ) {
    }

    fn assert_code_action_contract<R>()
    where
        R: Request<Params = CodeActionParams, Result = Option<CodeActionResponse>>,
    {
    }

    fn assert_code_action_resolve_contract<R>()
    where
        R: Request<Params = CodeAction, Result = CodeAction>,
    {
    }

    #[test]
    fn code_action_descriptors_fix_the_exact_lsp_types_contracts() {
        assert_code_action_descriptor(code_action(CodeActionOptions::default()));
        assert_code_action_resolve_descriptor(code_action_resolve());
        assert_code_action_contract::<CodeActionRequest>();
        assert_code_action_resolve_contract::<CodeActionResolveRequest>();
        assert_eq!(
            <CodeActionRequest as Request>::METHOD,
            "textDocument/codeAction"
        );
        assert_eq!(
            <CodeActionResolveRequest as Request>::METHOD,
            "codeAction/resolve"
        );
    }

    fn assert_code_lens_descriptor<F: FeatureSpec<Marker = CodeLensRequest>>(_: F) {}
    fn assert_code_lens_resolve_descriptor<F: FeatureSpec<Marker = CodeLensResolve>>(_: F) {}

    fn assert_code_lens_contract<R>()
    where
        R: Request<Params = CodeLensParams, Result = Option<Vec<CodeLens>>>,
    {
    }

    fn assert_code_lens_resolve_contract<R>()
    where
        R: Request<Params = CodeLens, Result = CodeLens>,
    {
    }

    #[test]
    fn code_lens_descriptors_fix_the_exact_lsp_types_contracts() {
        assert_code_lens_descriptor(code_lens(CodeLensOptions {
            resolve_provider: None,
        }));
        assert_code_lens_resolve_descriptor(code_lens_resolve());
        assert_code_lens_contract::<CodeLensRequest>();
        assert_code_lens_resolve_contract::<CodeLensResolve>();
        assert_eq!(
            <CodeLensRequest as Request>::METHOD,
            "textDocument/codeLens"
        );
        assert_eq!(<CodeLensResolve as Request>::METHOD, "codeLens/resolve");
    }

    fn assert_document_link_descriptor<F: FeatureSpec<Marker = DocumentLinkRequest>>(_: F) {}
    fn assert_document_link_resolve_descriptor<F: FeatureSpec<Marker = DocumentLinkResolve>>(_: F) {
    }

    fn assert_document_link_contract<R>()
    where
        R: Request<Params = DocumentLinkParams, Result = Option<Vec<DocumentLink>>>,
    {
    }

    fn assert_document_link_resolve_contract<R>()
    where
        R: Request<Params = DocumentLink, Result = DocumentLink>,
    {
    }

    #[test]
    fn document_link_descriptors_fix_the_exact_lsp_types_contracts() {
        assert_document_link_descriptor(document_link(DocumentLinkOptions {
            resolve_provider: None,
            work_done_progress_options: Default::default(),
        }));
        assert_document_link_resolve_descriptor(document_link_resolve());
        assert_document_link_contract::<DocumentLinkRequest>();
        assert_document_link_resolve_contract::<DocumentLinkResolve>();
        assert_eq!(
            <DocumentLinkRequest as Request>::METHOD,
            "textDocument/documentLink"
        );
        assert_eq!(
            <DocumentLinkResolve as Request>::METHOD,
            "documentLink/resolve"
        );
    }

    fn assert_inlay_hint_descriptor<F: FeatureSpec<Marker = InlayHintRequest>>(_: F) {}
    fn assert_inlay_hint_resolve_descriptor<F: FeatureSpec<Marker = InlayHintResolveRequest>>(
        _: F,
    ) {
    }

    fn assert_inlay_hint_contract<R>()
    where
        R: Request<Params = InlayHintParams, Result = Option<Vec<InlayHint>>>,
    {
    }

    fn assert_inlay_hint_resolve_contract<R>()
    where
        R: Request<Params = InlayHint, Result = InlayHint>,
    {
    }

    #[test]
    fn inlay_hint_descriptors_fix_the_exact_lsp_types_contracts() {
        assert_inlay_hint_descriptor(inlay_hint(InlayHintOptions::default()));
        assert_inlay_hint_resolve_descriptor(inlay_hint_resolve());
        assert_inlay_hint_contract::<InlayHintRequest>();
        assert_inlay_hint_resolve_contract::<InlayHintResolveRequest>();
        assert_eq!(
            <InlayHintRequest as Request>::METHOD,
            "textDocument/inlayHint"
        );
        assert_eq!(
            <InlayHintResolveRequest as Request>::METHOD,
            "inlayHint/resolve"
        );
    }

    fn assert_signature_help_descriptor<F: FeatureSpec<Marker = SignatureHelpRequest>>(_: F) {}
    fn assert_declaration_descriptor<F: FeatureSpec<Marker = GotoDeclaration>>(_: F) {}
    fn assert_definition_descriptor<F: FeatureSpec<Marker = GotoDefinition>>(_: F) {}
    fn assert_type_definition_descriptor<F: FeatureSpec<Marker = GotoTypeDefinition>>(_: F) {}
    fn assert_implementation_descriptor<F: FeatureSpec<Marker = GotoImplementation>>(_: F) {}
    fn assert_references_descriptor<F: FeatureSpec<Marker = References>>(_: F) {}
    fn assert_document_highlight_descriptor<F: FeatureSpec<Marker = DocumentHighlightRequest>>(
        _: F,
    ) {
    }
    fn assert_document_symbol_descriptor<F: FeatureSpec<Marker = DocumentSymbolRequest>>(_: F) {}
    fn assert_linked_editing_range_descriptor<F: FeatureSpec<Marker = LinkedEditingRange>>(_: F) {}
    fn assert_moniker_descriptor<F: FeatureSpec<Marker = MonikerRequest>>(_: F) {}

    fn assert_signature_help_contract<R>()
    where
        R: Request<Params = SignatureHelpParams, Result = Option<SignatureHelp>>,
    {
    }

    fn assert_declaration_contract<R>()
    where
        R: Request<Params = GotoDeclarationParams, Result = Option<GotoDeclarationResponse>>,
    {
    }

    fn assert_definition_contract<R>()
    where
        R: Request<Params = GotoDefinitionParams, Result = Option<GotoDefinitionResponse>>,
    {
    }

    fn assert_type_definition_contract<R>()
    where
        R: Request<Params = GotoTypeDefinitionParams, Result = Option<GotoTypeDefinitionResponse>>,
    {
    }

    fn assert_implementation_contract<R>()
    where
        R: Request<Params = GotoImplementationParams, Result = Option<GotoImplementationResponse>>,
    {
    }

    fn assert_references_contract<R>()
    where
        R: Request<Params = ReferenceParams, Result = Option<Vec<Location>>>,
    {
    }

    fn assert_document_highlight_contract<R>()
    where
        R: Request<Params = DocumentHighlightParams, Result = Option<Vec<DocumentHighlight>>>,
    {
    }

    fn assert_document_symbol_contract<R>()
    where
        R: Request<Params = DocumentSymbolParams, Result = Option<DocumentSymbolResponse>>,
    {
    }

    fn assert_linked_editing_range_contract<R>()
    where
        R: Request<Params = LinkedEditingRangeParams, Result = Option<LinkedEditingRanges>>,
    {
    }

    fn assert_moniker_contract<R>()
    where
        R: Request<Params = MonikerParams, Result = Option<Vec<Moniker>>>,
    {
    }

    fn progress(value: Option<bool>) -> lsp_types::WorkDoneProgressOptions {
        lsp_types::WorkDoneProgressOptions {
            work_done_progress: value,
        }
    }

    fn static_text_document_registration_options() -> StaticTextDocumentRegistrationOptions {
        StaticTextDocumentRegistrationOptions {
            document_selector: None,
            id: Some("nav".to_string()),
        }
    }

    #[test]
    fn navigation_and_lookup_descriptors_fix_the_exact_lsp_types_contracts() {
        assert_signature_help_descriptor(signature_help(SignatureHelpOptions::default()));
        assert_declaration_descriptor(declaration(DeclarationOptions {
            work_done_progress_options: progress(Some(true)),
        }));
        assert_definition_descriptor(definition(DefinitionOptions {
            work_done_progress_options: progress(Some(true)),
        }));
        assert_type_definition_descriptor(type_definition(
            static_text_document_registration_options(),
        ));
        assert_implementation_descriptor(implementation(
            static_text_document_registration_options(),
        ));
        assert_references_descriptor(references(ReferencesOptions {
            work_done_progress_options: progress(Some(true)),
        }));
        assert_document_highlight_descriptor(document_highlight(DocumentHighlightOptions {
            work_done_progress_options: progress(Some(true)),
        }));
        assert_document_symbol_descriptor(document_symbol(DocumentSymbolOptions {
            label: Some("outline".to_string()),
            work_done_progress_options: progress(Some(true)),
        }));
        assert_linked_editing_range_descriptor(linked_editing_range(LinkedEditingRangeOptions {
            work_done_progress_options: progress(Some(true)),
        }));
        assert_moniker_descriptor(moniker(MonikerOptions {
            work_done_progress_options: progress(Some(true)),
        }));
        assert_signature_help_contract::<SignatureHelpRequest>();
        assert_declaration_contract::<GotoDeclaration>();
        assert_definition_contract::<GotoDefinition>();
        assert_type_definition_contract::<GotoTypeDefinition>();
        assert_implementation_contract::<GotoImplementation>();
        assert_references_contract::<References>();
        assert_document_highlight_contract::<DocumentHighlightRequest>();
        assert_document_symbol_contract::<DocumentSymbolRequest>();
        assert_linked_editing_range_contract::<LinkedEditingRange>();
        assert_moniker_contract::<MonikerRequest>();
        assert_eq!(
            <SignatureHelpRequest as Request>::METHOD,
            "textDocument/signatureHelp"
        );
        assert_eq!(
            <GotoDeclaration as Request>::METHOD,
            "textDocument/declaration"
        );
        assert_eq!(
            <GotoDefinition as Request>::METHOD,
            "textDocument/definition"
        );
        assert_eq!(
            <GotoTypeDefinition as Request>::METHOD,
            "textDocument/typeDefinition"
        );
        assert_eq!(
            <GotoImplementation as Request>::METHOD,
            "textDocument/implementation"
        );
        assert_eq!(<References as Request>::METHOD, "textDocument/references");
        assert_eq!(
            <DocumentHighlightRequest as Request>::METHOD,
            "textDocument/documentHighlight"
        );
        assert_eq!(
            <DocumentSymbolRequest as Request>::METHOD,
            "textDocument/documentSymbol"
        );
        assert_eq!(
            <LinkedEditingRange as Request>::METHOD,
            "textDocument/linkedEditingRange"
        );
        assert_eq!(<MonikerRequest as Request>::METHOD, "textDocument/moniker");
    }

    #[test]
    fn navigation_and_lookup_descriptors_contribute_only_their_capabilities() {
        let signature_options = SignatureHelpOptions {
            trigger_characters: Some(vec!["(".to_string()]),
            retrigger_characters: None,
            work_done_progress_options: Default::default(),
        };
        let declaration_options = DeclarationOptions {
            work_done_progress_options: progress(Some(true)),
        };
        let definition_options = DefinitionOptions {
            work_done_progress_options: progress(Some(true)),
        };
        let type_definition_options = static_text_document_registration_options();
        let implementation_options = static_text_document_registration_options();
        let references_options = ReferencesOptions {
            work_done_progress_options: progress(Some(true)),
        };
        let highlight_options = DocumentHighlightOptions {
            work_done_progress_options: progress(Some(true)),
        };
        let symbols_options = DocumentSymbolOptions {
            label: Some("outline".to_string()),
            work_done_progress_options: progress(Some(true)),
        };
        let linked_options = LinkedEditingRangeOptions {
            work_done_progress_options: progress(Some(true)),
        };
        let moniker_options = MonikerOptions {
            work_done_progress_options: progress(Some(true)),
        };
        let mut caps = CapabilityBuilder::default();

        sealed::Sealed::contribute(&signature_help(signature_options.clone()), &mut caps).unwrap();
        sealed::Sealed::contribute(&declaration(declaration_options.clone()), &mut caps).unwrap();
        sealed::Sealed::contribute(&definition(definition_options.clone()), &mut caps).unwrap();
        sealed::Sealed::contribute(&type_definition(type_definition_options.clone()), &mut caps)
            .unwrap();
        sealed::Sealed::contribute(&implementation(implementation_options.clone()), &mut caps)
            .unwrap();
        sealed::Sealed::contribute(&references(references_options.clone()), &mut caps).unwrap();
        sealed::Sealed::contribute(&document_highlight(highlight_options.clone()), &mut caps)
            .unwrap();
        sealed::Sealed::contribute(&document_symbol(symbols_options.clone()), &mut caps).unwrap();
        sealed::Sealed::contribute(&linked_editing_range(linked_options.clone()), &mut caps)
            .unwrap();
        sealed::Sealed::contribute(&moniker(moniker_options.clone()), &mut caps).unwrap();
        caps.validate().unwrap();

        assert_eq!(
            caps.finish(),
            lsp_types::ServerCapabilities {
                signature_help_provider: Some(signature_options),
                declaration_provider: Some(lsp_types::DeclarationCapability::Options(
                    declaration_options
                )),
                definition_provider: Some(lsp_types::OneOf::Right(definition_options)),
                type_definition_provider: Some(
                    lsp_types::TypeDefinitionProviderCapability::Options(type_definition_options)
                ),
                implementation_provider: Some(
                    lsp_types::ImplementationProviderCapability::Options(implementation_options)
                ),
                references_provider: Some(lsp_types::OneOf::Right(references_options)),
                document_highlight_provider: Some(lsp_types::OneOf::Right(highlight_options)),
                document_symbol_provider: Some(lsp_types::OneOf::Right(symbols_options)),
                linked_editing_range_provider: Some(
                    lsp_types::LinkedEditingRangeServerCapabilities::Options(linked_options),
                ),
                moniker_provider: Some(lsp_types::OneOf::Right(
                    lsp_types::MonikerServerCapabilities::Options(moniker_options),
                )),
                ..lsp_types::ServerCapabilities::default()
            }
        );
    }

    #[test]
    fn no_request_descriptor_fixes_the_execute_command_method() {
        // `workspace/executeCommand` is reserved for the Command registry
        // (ADR 0022). The enforcement is structural — `FeatureSpec` is sealed,
        // so no descriptor for it can ever be added downstream — and this pins
        // the in-crate catalog to that rule.
        for method in [
            <HoverRequest as Request>::METHOD,
            <Completion as Request>::METHOD,
            <ResolveCompletionItem as Request>::METHOD,
            <DocumentDiagnosticRequest as Request>::METHOD,
            <WorkspaceDiagnosticRequest as Request>::METHOD,
            <WorkspaceSymbolRequest as Request>::METHOD,
            <WorkspaceSymbolResolve as Request>::METHOD,
            <Rename as Request>::METHOD,
            <PrepareRenameRequest as Request>::METHOD,
            <CodeActionRequest as Request>::METHOD,
            <CodeActionResolveRequest as Request>::METHOD,
            <CodeLensRequest as Request>::METHOD,
            <CodeLensResolve as Request>::METHOD,
            <DocumentLinkRequest as Request>::METHOD,
            <DocumentLinkResolve as Request>::METHOD,
            <InlayHintRequest as Request>::METHOD,
            <InlayHintResolveRequest as Request>::METHOD,
            <WillCreateFiles as Request>::METHOD,
            <WillRenameFiles as Request>::METHOD,
            <WillDeleteFiles as Request>::METHOD,
        ] {
            assert_ne!(method, "workspace/executeCommand");
        }
    }
}