jaclang 0.0.5__py3-none-any.whl → 0.0.8__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of jaclang might be problematic. Click here for more details.

Files changed (94) hide show
  1. jaclang/__init__.py +2 -1
  2. jaclang/cli/__jac_gen__/__init__.py +0 -0
  3. jaclang/cli/__jac_gen__/cli.py +175 -0
  4. jaclang/cli/__jac_gen__/cmds.py +132 -0
  5. jaclang/cli/cli.jac +2 -2
  6. jaclang/cli/cmds.jac +8 -2
  7. jaclang/cli/impl/__jac_gen__/__init__.py +0 -0
  8. jaclang/cli/impl/__jac_gen__/cli_impl.py +16 -0
  9. jaclang/cli/impl/__jac_gen__/cmds_impl.py +26 -0
  10. jaclang/cli/impl/cli_impl.jac +25 -8
  11. jaclang/cli/impl/cmds_impl.jac +35 -6
  12. jaclang/core/__jac_gen__/__init__.py +0 -0
  13. jaclang/core/__jac_gen__/primitives.py +567 -0
  14. jaclang/core/impl/__jac_gen__/__init__.py +0 -0
  15. jaclang/core/impl/__jac_gen__/arch_impl.py +24 -0
  16. jaclang/core/impl/__jac_gen__/element_impl.py +26 -0
  17. jaclang/core/impl/__jac_gen__/exec_ctx_impl.py +12 -0
  18. jaclang/core/impl/__jac_gen__/memory_impl.py +14 -0
  19. jaclang/core/impl/element_impl.jac +3 -3
  20. jaclang/core/impl/exec_ctx_impl.jac +3 -6
  21. jaclang/core/primitives.jac +4 -3
  22. jaclang/jac/absyntree.py +555 -180
  23. jaclang/jac/constant.py +6 -0
  24. jaclang/jac/importer.py +34 -56
  25. jaclang/jac/langserve.py +26 -0
  26. jaclang/jac/lexer.py +35 -3
  27. jaclang/jac/parser.py +146 -115
  28. jaclang/jac/passes/blue/__init__.py +8 -3
  29. jaclang/jac/passes/blue/ast_build_pass.py +454 -305
  30. jaclang/jac/passes/blue/blue_pygen_pass.py +112 -74
  31. jaclang/jac/passes/blue/decl_def_match_pass.py +49 -277
  32. jaclang/jac/passes/blue/import_pass.py +1 -1
  33. jaclang/jac/passes/blue/pyout_pass.py +74 -0
  34. jaclang/jac/passes/blue/semantic_check_pass.py +37 -0
  35. jaclang/jac/passes/blue/sym_tab_build_pass.py +1045 -0
  36. jaclang/jac/passes/blue/tests/test_ast_build_pass.py +2 -2
  37. jaclang/jac/passes/blue/tests/test_blue_pygen_pass.py +9 -28
  38. jaclang/jac/passes/blue/tests/test_decl_def_match_pass.py +13 -22
  39. jaclang/jac/passes/blue/tests/test_sym_tab_build_pass.py +22 -0
  40. jaclang/jac/passes/ir_pass.py +8 -6
  41. jaclang/jac/passes/purple/__jac_gen__/__init__.py +0 -0
  42. jaclang/jac/passes/purple/__jac_gen__/analyze_pass.py +37 -0
  43. jaclang/jac/passes/purple/__jac_gen__/purple_pygen_pass.py +305 -0
  44. jaclang/jac/passes/purple/impl/__jac_gen__/__init__.py +0 -0
  45. jaclang/jac/passes/purple/impl/__jac_gen__/purple_pygen_pass_impl.py +23 -0
  46. jaclang/jac/passes/purple/impl/purple_pygen_pass_impl.jac +2 -5
  47. jaclang/jac/symtable.py +154 -0
  48. jaclang/jac/tests/fixtures/__jac_gen__/__init__.py +0 -0
  49. jaclang/jac/tests/fixtures/__jac_gen__/hello_world.py +16 -0
  50. jaclang/jac/tests/fixtures/fam.jac +7 -8
  51. jaclang/jac/tests/fixtures/mod_doc_test.jac +1 -0
  52. jaclang/jac/tests/test_parser.py +8 -0
  53. jaclang/jac/transform.py +41 -14
  54. jaclang/jac/transpiler.py +18 -9
  55. jaclang/utils/fstring_parser.py +2 -2
  56. jaclang/utils/helpers.py +41 -0
  57. jaclang/utils/lang_tools.py +12 -2
  58. jaclang/utils/test.py +41 -0
  59. jaclang/vendor/__init__.py +1 -0
  60. jaclang/vendor/pygls/__init__.py +25 -0
  61. jaclang/vendor/pygls/capabilities.py +502 -0
  62. jaclang/vendor/pygls/client.py +176 -0
  63. jaclang/vendor/pygls/constants.py +26 -0
  64. jaclang/vendor/pygls/exceptions.py +220 -0
  65. jaclang/vendor/pygls/feature_manager.py +241 -0
  66. jaclang/vendor/pygls/lsp/__init__.py +139 -0
  67. jaclang/vendor/pygls/lsp/client.py +2224 -0
  68. jaclang/vendor/pygls/lsprotocol/__init__.py +2 -0
  69. jaclang/vendor/pygls/lsprotocol/_hooks.py +1233 -0
  70. jaclang/vendor/pygls/lsprotocol/converters.py +17 -0
  71. jaclang/vendor/pygls/lsprotocol/types.py +12820 -0
  72. jaclang/vendor/pygls/lsprotocol/validators.py +47 -0
  73. jaclang/vendor/pygls/progress.py +79 -0
  74. jaclang/vendor/pygls/protocol.py +1184 -0
  75. jaclang/vendor/pygls/server.py +620 -0
  76. jaclang/vendor/pygls/uris.py +184 -0
  77. jaclang/vendor/pygls/workspace/__init__.py +81 -0
  78. jaclang/vendor/pygls/workspace/position.py +204 -0
  79. jaclang/vendor/pygls/workspace/text_document.py +234 -0
  80. jaclang/vendor/pygls/workspace/workspace.py +311 -0
  81. {jaclang-0.0.5.dist-info → jaclang-0.0.8.dist-info}/METADATA +1 -1
  82. jaclang-0.0.8.dist-info/RECORD +118 -0
  83. jaclang/core/jaclang.jac +0 -62
  84. jaclang/jac/passes/blue/tests/test_type_analyze_pass.py +0 -53
  85. jaclang/jac/passes/blue/type_analyze_pass.py +0 -728
  86. jaclang/jac/sym_table.py +0 -127
  87. jaclang-0.0.5.dist-info/RECORD +0 -73
  88. /jaclang/{utils → vendor}/sly/__init__.py +0 -0
  89. /jaclang/{utils → vendor}/sly/docparse.py +0 -0
  90. /jaclang/{utils → vendor}/sly/lex.py +0 -0
  91. /jaclang/{utils → vendor}/sly/yacc.py +0 -0
  92. {jaclang-0.0.5.dist-info → jaclang-0.0.8.dist-info}/WHEEL +0 -0
  93. {jaclang-0.0.5.dist-info → jaclang-0.0.8.dist-info}/entry_points.txt +0 -0
  94. {jaclang-0.0.5.dist-info → jaclang-0.0.8.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,1233 @@
1
+ # Copyright (c) Microsoft Corporation. All rights reserved.
2
+ # Licensed under the MIT License.
3
+ import sys
4
+ from typing import Any, List, Optional, Tuple, Union
5
+
6
+ import attrs
7
+ import cattrs
8
+
9
+ from . import types as lsp_types
10
+
11
+ LSPAny = lsp_types.LSPAny
12
+ OptionalPrimitive = Optional[Union[bool, int, str, float]]
13
+
14
+ # Flag to ensure we only resolve forward references once.
15
+ _resolved_forward_references = False
16
+
17
+
18
+ def _resolve_forward_references() -> None:
19
+ """Resolve forward references for faster processing with cattrs."""
20
+ global _resolved_forward_references
21
+ if not _resolved_forward_references:
22
+
23
+ def _filter(p: Tuple[str, object]) -> bool:
24
+ return isinstance(p[1], type) and attrs.has(p[1])
25
+
26
+ # Creating a concrete list here because `resolve_types` mutates the provided map.
27
+ items = list(filter(_filter, lsp_types.ALL_TYPES_MAP.items()))
28
+ for _, value in items:
29
+ if isinstance(value, type):
30
+ attrs.resolve_types(value, lsp_types.ALL_TYPES_MAP, {}) # type: ignore
31
+ _resolved_forward_references = True
32
+
33
+
34
+ def register_hooks(converter: cattrs.Converter) -> cattrs.Converter:
35
+ _resolve_forward_references()
36
+ converter = _register_capabilities_hooks(converter)
37
+ converter = _register_required_structure_hooks(converter)
38
+ return _register_custom_property_hooks(converter)
39
+
40
+
41
+ def _register_capabilities_hooks(converter: cattrs.Converter) -> cattrs.Converter:
42
+ def _text_document_sync_hook(
43
+ object_: Any, _: type
44
+ ) -> Union[OptionalPrimitive, lsp_types.TextDocumentSyncOptions]:
45
+ if object_ is None:
46
+ return None
47
+ if isinstance(object_, (bool, int, str, float)):
48
+ return object_
49
+ return converter.structure(object_, lsp_types.TextDocumentSyncOptions)
50
+
51
+ def _notebook_document_sync_hook(
52
+ object_: Any, _: type
53
+ ) -> Optional[
54
+ Union[
55
+ lsp_types.NotebookDocumentSyncRegistrationOptions,
56
+ lsp_types.NotebookDocumentSyncOptions,
57
+ ]
58
+ ]:
59
+ if object_ is None:
60
+ return None
61
+ if "id" in object_:
62
+ return converter.structure(
63
+ object_, lsp_types.NotebookDocumentSyncRegistrationOptions
64
+ )
65
+ else:
66
+ return converter.structure(object_, lsp_types.NotebookDocumentSyncOptions)
67
+
68
+ def _hover_provider_hook(
69
+ object_: Any, _: type
70
+ ) -> Union[OptionalPrimitive, lsp_types.HoverOptions]:
71
+ if object_ is None:
72
+ return None
73
+ if isinstance(object_, (bool, int, str, float)):
74
+ return object_
75
+ return converter.structure(object_, lsp_types.HoverOptions)
76
+
77
+ def _declaration_provider_hook(
78
+ object_: Any, _: type
79
+ ) -> Union[
80
+ OptionalPrimitive,
81
+ lsp_types.DeclarationRegistrationOptions,
82
+ lsp_types.DeclarationOptions,
83
+ ]:
84
+ if object_ is None:
85
+ return None
86
+ if isinstance(object_, (bool, int, str, float)):
87
+ return object_
88
+ if "id" in object_:
89
+ return converter.structure(
90
+ object_, lsp_types.DeclarationRegistrationOptions
91
+ )
92
+ else:
93
+ return converter.structure(object_, lsp_types.DeclarationOptions)
94
+
95
+ def _definition_provider_hook(
96
+ object_: Any, _: type
97
+ ) -> Union[OptionalPrimitive, lsp_types.DefinitionOptions]:
98
+ if object_ is None:
99
+ return None
100
+ if isinstance(object_, (bool, int, str, float)):
101
+ return object_
102
+ return converter.structure(object_, lsp_types.DefinitionOptions)
103
+
104
+ def _type_definition_provider_hook(
105
+ object_: Any, _: type
106
+ ) -> Union[
107
+ OptionalPrimitive,
108
+ lsp_types.TypeDefinitionRegistrationOptions,
109
+ lsp_types.TypeDefinitionOptions,
110
+ ]:
111
+ if object_ is None:
112
+ return None
113
+ if isinstance(object_, (bool, int, str, float)):
114
+ return object_
115
+ if "id" in object_:
116
+ return converter.structure(
117
+ object_, lsp_types.TypeDefinitionRegistrationOptions
118
+ )
119
+ else:
120
+ return converter.structure(object_, lsp_types.TypeDefinitionOptions)
121
+
122
+ def _implementation_provider_hook(
123
+ object_: Any, _: type
124
+ ) -> Union[
125
+ OptionalPrimitive,
126
+ lsp_types.ImplementationRegistrationOptions,
127
+ lsp_types.ImplementationOptions,
128
+ ]:
129
+ if object_ is None:
130
+ return None
131
+ if isinstance(object_, (bool, int, str, float)):
132
+ return object_
133
+ if "id" in object_:
134
+ return converter.structure(
135
+ object_, lsp_types.ImplementationRegistrationOptions
136
+ )
137
+ else:
138
+ return converter.structure(object_, lsp_types.ImplementationOptions)
139
+
140
+ def _references_provider_hook(
141
+ object_: Any, _: type
142
+ ) -> Union[OptionalPrimitive, lsp_types.ReferenceOptions]:
143
+ if object_ is None:
144
+ return None
145
+ if isinstance(object_, (bool, int, str, float)):
146
+ return object_
147
+ return converter.structure(object_, lsp_types.ReferenceOptions)
148
+
149
+ def _position_encoding_hook(
150
+ object_: Union[lsp_types.PositionEncodingKind, OptionalPrimitive], _: type
151
+ ) -> Union[lsp_types.PositionEncodingKind, OptionalPrimitive]:
152
+ return object_
153
+
154
+ def _document_highlight_provider_hook(
155
+ object_: Any, _: type
156
+ ) -> Union[OptionalPrimitive, lsp_types.DocumentHighlightOptions]:
157
+ if object_ is None:
158
+ return None
159
+ if isinstance(object_, (bool, int, str, float)):
160
+ return object_
161
+ return converter.structure(object_, lsp_types.DocumentHighlightOptions)
162
+
163
+ def _document_symbol_provider_hook(
164
+ object_: Any, _: type
165
+ ) -> Union[OptionalPrimitive, lsp_types.DocumentSymbolOptions]:
166
+ if object_ is None:
167
+ return None
168
+ if isinstance(object_, (bool, int, str, float)):
169
+ return object_
170
+ return converter.structure(object_, lsp_types.DocumentSymbolOptions)
171
+
172
+ def _code_action_provider_hook(
173
+ object_: Any, _: type
174
+ ) -> Union[OptionalPrimitive, lsp_types.CodeActionOptions]:
175
+ if object_ is None:
176
+ return None
177
+ if isinstance(object_, (bool, int, str, float)):
178
+ return object_
179
+ return converter.structure(object_, lsp_types.CodeActionOptions)
180
+
181
+ def _color_provider_hook(
182
+ object_: Any, _: type
183
+ ) -> Union[
184
+ OptionalPrimitive,
185
+ lsp_types.DocumentColorRegistrationOptions,
186
+ lsp_types.DocumentColorOptions,
187
+ ]:
188
+ if object_ is None:
189
+ return None
190
+ if isinstance(object_, (bool, int, str, float)):
191
+ return object_
192
+ if "id" in object_:
193
+ return converter.structure(
194
+ object_, lsp_types.DocumentColorRegistrationOptions
195
+ )
196
+ else:
197
+ return converter.structure(object_, lsp_types.DocumentColorOptions)
198
+
199
+ def _workspace_symbol_provider_hook(
200
+ object_: Any, _: type
201
+ ) -> Union[OptionalPrimitive, lsp_types.WorkspaceSymbolOptions]:
202
+ if object_ is None:
203
+ return None
204
+ if isinstance(object_, (bool, int, str, float)):
205
+ return object_
206
+ return converter.structure(object_, lsp_types.WorkspaceSymbolOptions)
207
+
208
+ def _document_formatting_provider_hook(
209
+ object_: Any, _: type
210
+ ) -> Union[OptionalPrimitive, lsp_types.DocumentFormattingOptions]:
211
+ if object_ is None:
212
+ return None
213
+ if isinstance(object_, (bool, int, str, float)):
214
+ return object_
215
+ return converter.structure(object_, lsp_types.DocumentFormattingOptions)
216
+
217
+ def _document_range_formatting_provider_hook(
218
+ object_: Any, _: type
219
+ ) -> Union[OptionalPrimitive, lsp_types.DocumentRangeFormattingOptions]:
220
+ if object_ is None:
221
+ return None
222
+ if isinstance(object_, (bool, int, str, float)):
223
+ return object_
224
+ return converter.structure(object_, lsp_types.DocumentRangeFormattingOptions)
225
+
226
+ def _rename_provider_hook(
227
+ object_: Any, _: type
228
+ ) -> Union[OptionalPrimitive, lsp_types.RenameOptions]:
229
+ if object_ is None:
230
+ return None
231
+ if isinstance(object_, (bool, int, str, float)):
232
+ return object_
233
+ return converter.structure(object_, lsp_types.RenameOptions)
234
+
235
+ def _folding_range_provider_hook(
236
+ object_: Any, _: type
237
+ ) -> Union[
238
+ OptionalPrimitive,
239
+ lsp_types.FoldingRangeRegistrationOptions,
240
+ lsp_types.FoldingRangeOptions,
241
+ ]:
242
+ if object_ is None:
243
+ return None
244
+ if isinstance(object_, (bool, int, str, float)):
245
+ return object_
246
+ if "id" in object_:
247
+ return converter.structure(
248
+ object_, lsp_types.FoldingRangeRegistrationOptions
249
+ )
250
+ else:
251
+ return converter.structure(object_, lsp_types.FoldingRangeOptions)
252
+
253
+ def _selection_range_provider_hook(
254
+ object_: Any, _: type
255
+ ) -> Union[
256
+ OptionalPrimitive,
257
+ lsp_types.SelectionRangeRegistrationOptions,
258
+ lsp_types.SelectionRangeOptions,
259
+ ]:
260
+ if object_ is None:
261
+ return None
262
+ if isinstance(object_, (bool, int, str, float)):
263
+ return object_
264
+ if "id" in object_:
265
+ return converter.structure(
266
+ object_, lsp_types.SelectionRangeRegistrationOptions
267
+ )
268
+ else:
269
+ return converter.structure(object_, lsp_types.SelectionRangeOptions)
270
+
271
+ def _call_hierarchy_provider_hook(
272
+ object_: Any, _: type
273
+ ) -> Union[
274
+ OptionalPrimitive,
275
+ lsp_types.CallHierarchyRegistrationOptions,
276
+ lsp_types.CallHierarchyOptions,
277
+ ]:
278
+ if object_ is None:
279
+ return None
280
+ if isinstance(object_, (bool, int, str, float)):
281
+ return object_
282
+ if "id" in object_:
283
+ return converter.structure(
284
+ object_, lsp_types.CallHierarchyRegistrationOptions
285
+ )
286
+ else:
287
+ return converter.structure(object_, lsp_types.CallHierarchyOptions)
288
+
289
+ def _linked_editing_range_provider_hook(
290
+ object_: Any, _: type
291
+ ) -> Union[
292
+ OptionalPrimitive,
293
+ lsp_types.LinkedEditingRangeRegistrationOptions,
294
+ lsp_types.LinkedEditingRangeOptions,
295
+ ]:
296
+ if object_ is None:
297
+ return None
298
+ if isinstance(object_, (bool, int, str, float)):
299
+ return object_
300
+ if "id" in object_:
301
+ return converter.structure(
302
+ object_, lsp_types.LinkedEditingRangeRegistrationOptions
303
+ )
304
+ else:
305
+ return converter.structure(object_, lsp_types.LinkedEditingRangeOptions)
306
+
307
+ def _semantic_tokens_provider_hook(
308
+ object_: Any, _: type
309
+ ) -> Union[
310
+ OptionalPrimitive,
311
+ lsp_types.SemanticTokensRegistrationOptions,
312
+ lsp_types.SemanticTokensOptions,
313
+ ]:
314
+ if object_ is None:
315
+ return None
316
+ if "id" in object_:
317
+ return converter.structure(
318
+ object_, lsp_types.SemanticTokensRegistrationOptions
319
+ )
320
+ else:
321
+ return converter.structure(object_, lsp_types.SemanticTokensOptions)
322
+
323
+ def _moniker_provider_hook(
324
+ object_: Any, _: type
325
+ ) -> Union[
326
+ OptionalPrimitive,
327
+ lsp_types.MonikerRegistrationOptions,
328
+ lsp_types.MonikerOptions,
329
+ ]:
330
+ if object_ is None:
331
+ return None
332
+ if isinstance(object_, (bool, int, str, float)):
333
+ return object_
334
+ if "id" in object_:
335
+ return converter.structure(object_, lsp_types.MonikerRegistrationOptions)
336
+ else:
337
+ return converter.structure(object_, lsp_types.MonikerOptions)
338
+
339
+ def _type_hierarchy_provider_hook(
340
+ object_: Any, _: type
341
+ ) -> Union[
342
+ OptionalPrimitive,
343
+ lsp_types.TypeHierarchyRegistrationOptions,
344
+ lsp_types.TypeHierarchyOptions,
345
+ ]:
346
+ if object_ is None:
347
+ return None
348
+ if isinstance(object_, (bool, int, str, float)):
349
+ return object_
350
+ if "id" in object_:
351
+ return converter.structure(
352
+ object_, lsp_types.TypeHierarchyRegistrationOptions
353
+ )
354
+ else:
355
+ return converter.structure(object_, lsp_types.TypeHierarchyOptions)
356
+
357
+ def _inline_value_provider_hook(
358
+ object_: Any, _: type
359
+ ) -> Union[
360
+ OptionalPrimitive,
361
+ lsp_types.InlineValueRegistrationOptions,
362
+ lsp_types.InlineValueOptions,
363
+ ]:
364
+ if object_ is None:
365
+ return None
366
+ if isinstance(object_, (bool, int, str, float)):
367
+ return object_
368
+ if "id" in object_:
369
+ return converter.structure(
370
+ object_, lsp_types.InlineValueRegistrationOptions
371
+ )
372
+ else:
373
+ return converter.structure(object_, lsp_types.InlineValueOptions)
374
+
375
+ def _inlay_hint_provider_hook(
376
+ object_: Any, _: type
377
+ ) -> Union[
378
+ OptionalPrimitive,
379
+ lsp_types.InlayHintRegistrationOptions,
380
+ lsp_types.InlayHintOptions,
381
+ ]:
382
+ if object_ is None:
383
+ return None
384
+ if isinstance(object_, (bool, int, str, float)):
385
+ return object_
386
+ if "id" in object_:
387
+ return converter.structure(object_, lsp_types.InlayHintRegistrationOptions)
388
+ else:
389
+ return converter.structure(object_, lsp_types.InlayHintOptions)
390
+
391
+ def _inlay_hint_label_part_hook(
392
+ object_: Any, _: type
393
+ ) -> Union[str, List[lsp_types.InlayHintLabelPart]]:
394
+ if isinstance(object_, str):
395
+ return object_
396
+
397
+ return [
398
+ converter.structure(item, lsp_types.InlayHintLabelPart) for item in object_
399
+ ]
400
+
401
+ def _diagnostic_provider_hook(
402
+ object_: Any, _: type
403
+ ) -> Union[
404
+ OptionalPrimitive,
405
+ lsp_types.DiagnosticRegistrationOptions,
406
+ lsp_types.DiagnosticOptions,
407
+ ]:
408
+ if object_ is None:
409
+ return None
410
+ if "id" in object_:
411
+ return converter.structure(object_, lsp_types.DiagnosticRegistrationOptions)
412
+ else:
413
+ return converter.structure(object_, lsp_types.DiagnosticOptions)
414
+
415
+ def _save_hook(
416
+ object_: Any, _: type
417
+ ) -> Union[OptionalPrimitive, lsp_types.SaveOptions]:
418
+ if object_ is None:
419
+ return None
420
+ if isinstance(object_, (bool, int, str, float)):
421
+ return object_
422
+ return converter.structure(object_, lsp_types.SaveOptions)
423
+
424
+ def _code_action_hook(
425
+ object_: Any, _: type
426
+ ) -> Union[lsp_types.Command, lsp_types.CodeAction]:
427
+ if "command" in object_:
428
+ return converter.structure(object_, lsp_types.Command)
429
+ else:
430
+ return converter.structure(object_, lsp_types.CodeAction)
431
+
432
+ def _completion_list_hook(
433
+ object_: Any, _: type
434
+ ) -> Optional[Union[lsp_types.CompletionList, List[lsp_types.CompletionItem]]]:
435
+ if object_ is None:
436
+ return None
437
+ if isinstance(object_, list):
438
+ return [
439
+ converter.structure(item, lsp_types.CompletionItem) for item in object_
440
+ ]
441
+ else:
442
+ return converter.structure(object_, lsp_types.CompletionList)
443
+
444
+ def _location_hook(
445
+ object_: Any, _: type
446
+ ) -> Optional[
447
+ Union[
448
+ lsp_types.Location,
449
+ List[lsp_types.Location],
450
+ List[lsp_types.LocationLink],
451
+ ]
452
+ ]:
453
+ if object_ is None:
454
+ return None
455
+ if isinstance(object_, list):
456
+ if len(object_) == 0:
457
+ return [] # type: ignore[return-value]
458
+ if "targetUri" in object_[0]:
459
+ return [
460
+ converter.structure(item, lsp_types.LocationLink)
461
+ for item in object_
462
+ ]
463
+ else:
464
+ return [
465
+ converter.structure(item, lsp_types.Location) for item in object_
466
+ ]
467
+ else:
468
+ return converter.structure(object_, lsp_types.Location)
469
+
470
+ def _symbol_hook(
471
+ object_: Any, _: type
472
+ ) -> Optional[
473
+ Union[List[lsp_types.DocumentSymbol], List[lsp_types.SymbolInformation]]
474
+ ]:
475
+ if object_ is None:
476
+ return None
477
+ if isinstance(object_, list):
478
+ if len(object_) == 0:
479
+ return [] # type: ignore[return-value]
480
+ if "location" in object_[0]:
481
+ return [
482
+ converter.structure(item, lsp_types.SymbolInformation)
483
+ for item in object_
484
+ ]
485
+ else:
486
+ return [
487
+ converter.structure(item, lsp_types.DocumentSymbol)
488
+ for item in object_
489
+ ]
490
+ else:
491
+ return None
492
+
493
+ def _markup_content_hook(
494
+ object_: Any, _: type
495
+ ) -> Optional[
496
+ Union[
497
+ OptionalPrimitive,
498
+ lsp_types.MarkupContent,
499
+ lsp_types.MarkedString_Type1,
500
+ List[Union[OptionalPrimitive, lsp_types.MarkedString_Type1]],
501
+ ]
502
+ ]:
503
+ if object_ is None:
504
+ return None
505
+ if isinstance(object_, (bool, int, str, float)):
506
+ return object_
507
+ if isinstance(object_, list):
508
+ return [
509
+ (
510
+ item
511
+ if isinstance(item, (bool, int, str, float))
512
+ else converter.structure(item, lsp_types.MarkedString_Type1)
513
+ )
514
+ for item in object_
515
+ ]
516
+ if "kind" in object_:
517
+ return converter.structure(object_, lsp_types.MarkupContent)
518
+ else:
519
+ return converter.structure(object_, lsp_types.MarkedString_Type1)
520
+
521
+ def _document_edit_hook(
522
+ object_: Any, _: type
523
+ ) -> Optional[
524
+ Union[
525
+ lsp_types.TextDocumentEdit,
526
+ lsp_types.CreateFile,
527
+ lsp_types.RenameFile,
528
+ lsp_types.DeleteFile,
529
+ ]
530
+ ]:
531
+ if object_ is None:
532
+ return None
533
+ if "kind" in object_:
534
+ if object_["kind"] == "create":
535
+ return converter.structure(object_, lsp_types.CreateFile)
536
+ elif object_["kind"] == "rename":
537
+ return converter.structure(object_, lsp_types.RenameFile)
538
+ elif object_["kind"] == "delete":
539
+ return converter.structure(object_, lsp_types.DeleteFile)
540
+ else:
541
+ raise ValueError("Unknown edit kind: ", object_)
542
+ else:
543
+ return converter.structure(object_, lsp_types.TextDocumentEdit)
544
+
545
+ def _semantic_tokens_hook(
546
+ object_: Any, _: type
547
+ ) -> Union[OptionalPrimitive, lsp_types.SemanticTokensOptionsFullType1]:
548
+ if object_ is None:
549
+ return None
550
+ if isinstance(object_, (bool, int, str, float)):
551
+ return object_
552
+ return converter.structure(object_, lsp_types.SemanticTokensOptionsFullType1)
553
+
554
+ def _semantic_tokens_capabilities_hook(
555
+ object_: Any, _: type
556
+ ) -> Union[
557
+ OptionalPrimitive,
558
+ lsp_types.SemanticTokensClientCapabilitiesRequestsTypeFullType1,
559
+ ]:
560
+ if object_ is None:
561
+ return None
562
+ if isinstance(object_, (bool, int, str, float)):
563
+ return object_
564
+ return converter.structure(
565
+ object_, lsp_types.SemanticTokensClientCapabilitiesRequestsTypeFullType1
566
+ )
567
+
568
+ def _code_action_kind_hook(
569
+ object_: Any, _: type
570
+ ) -> Union[OptionalPrimitive, lsp_types.CodeActionKind]:
571
+ if object_ is None:
572
+ return None
573
+ if isinstance(object_, (bool, int, str, float)):
574
+ return object_
575
+ return converter.structure(object_, lsp_types.CodeActionKind)
576
+
577
+ def _position_encoding_kind_hook(
578
+ object_: Any, _: type
579
+ ) -> Union[OptionalPrimitive, lsp_types.PositionEncodingKind]:
580
+ if object_ is None:
581
+ return None
582
+ if isinstance(object_, (bool, int, str, float)):
583
+ return object_
584
+ return converter.structure(object_, lsp_types.PositionEncodingKind)
585
+
586
+ def _folding_range_kind_hook(
587
+ object_: Any, _: type
588
+ ) -> Union[OptionalPrimitive, lsp_types.FoldingRangeKind]:
589
+ if object_ is None:
590
+ return None
591
+ if isinstance(object_, (bool, int, str, float)):
592
+ return object_
593
+ return converter.structure(object_, lsp_types.FoldingRangeKind)
594
+
595
+ def _semantic_token_types_hook(
596
+ object_: Any, _: type
597
+ ) -> Union[OptionalPrimitive, lsp_types.SemanticTokenTypes]:
598
+ if object_ is None:
599
+ return None
600
+ if isinstance(object_, (bool, int, str, float)):
601
+ return object_
602
+ return converter.structure(object_, lsp_types.SemanticTokenTypes)
603
+
604
+ def _semantic_token_modifiers_hook(
605
+ object_: Any, _: type
606
+ ) -> Union[OptionalPrimitive, lsp_types.SemanticTokenModifiers]:
607
+ if object_ is None:
608
+ return None
609
+ if isinstance(object_, (bool, int, str, float)):
610
+ return object_
611
+ return converter.structure(object_, lsp_types.SemanticTokenModifiers)
612
+
613
+ def _watch_kind_hook(
614
+ object_: Any, _: type
615
+ ) -> Union[OptionalPrimitive, lsp_types.WatchKind]:
616
+ if object_ is None:
617
+ return None
618
+ if isinstance(object_, (bool, int, str, float)):
619
+ return object_
620
+ return converter.structure(object_, lsp_types.WatchKind)
621
+
622
+ def _notebook_sync_option_selector_hook(
623
+ object_: Any, _: type
624
+ ) -> Union[
625
+ lsp_types.NotebookDocumentSyncOptionsNotebookSelectorType1,
626
+ lsp_types.NotebookDocumentSyncOptionsNotebookSelectorType2,
627
+ ]:
628
+ if "notebook" in object_:
629
+ return converter.structure(
630
+ object_, lsp_types.NotebookDocumentSyncOptionsNotebookSelectorType1
631
+ )
632
+ else:
633
+ return converter.structure(
634
+ object_, lsp_types.NotebookDocumentSyncOptionsNotebookSelectorType2
635
+ )
636
+
637
+ def _semantic_token_registration_options_hook(
638
+ object_: Any, _: type
639
+ ) -> Optional[
640
+ Union[OptionalPrimitive, lsp_types.SemanticTokensRegistrationOptionsFullType1]
641
+ ]:
642
+ if object_ is None:
643
+ return None
644
+ if isinstance(object_, (bool, int, str, float)):
645
+ return object_
646
+ return converter.structure(
647
+ object_, lsp_types.SemanticTokensRegistrationOptionsFullType1
648
+ )
649
+
650
+ def _inline_completion_provider_hook(
651
+ object_: Any, _: type
652
+ ) -> Optional[Union[OptionalPrimitive, lsp_types.InlineCompletionOptions]]:
653
+ if object_ is None:
654
+ return None
655
+ if isinstance(object_, (bool, int, str, float)):
656
+ return object_
657
+ return converter.structure(object_, lsp_types.InlineCompletionOptions)
658
+
659
+ def _inline_completion_list_hook(
660
+ object_: Any, _: type
661
+ ) -> Optional[
662
+ Union[lsp_types.InlineCompletionList, List[lsp_types.InlineCompletionItem]]
663
+ ]:
664
+ if object_ is None:
665
+ return None
666
+ if isinstance(object_, list):
667
+ return [
668
+ converter.structure(item, lsp_types.InlineCompletionItem)
669
+ for item in object_
670
+ ]
671
+ return converter.structure(object_, lsp_types.InlineCompletionList)
672
+
673
+ def _string_value_hook(
674
+ object_: Any, _: type
675
+ ) -> Union[OptionalPrimitive, lsp_types.StringValue]:
676
+ if object_ is None:
677
+ return None
678
+ if isinstance(object_, (bool, int, str, float)):
679
+ return object_
680
+ return converter.structure(object_, lsp_types.StringValue)
681
+
682
+ def _symbol_list_hook(
683
+ object_: Any, _: type
684
+ ) -> Optional[
685
+ Union[List[lsp_types.SymbolInformation], List[lsp_types.WorkspaceSymbol]]
686
+ ]:
687
+ if object_ is None:
688
+ return None
689
+ assert isinstance(object_, list)
690
+ if len(object_) == 0:
691
+ return [] # type: ignore[return-value]
692
+ if "location" in object_[0]:
693
+ return [
694
+ converter.structure(item, lsp_types.SymbolInformation)
695
+ for item in object_
696
+ ]
697
+ else:
698
+ return [
699
+ converter.structure(item, lsp_types.WorkspaceSymbol) for item in object_
700
+ ]
701
+
702
+ def _notebook_sync_registration_option_selector_hook(
703
+ object_: Any, _: type
704
+ ) -> Union[
705
+ lsp_types.NotebookDocumentSyncRegistrationOptionsNotebookSelectorType1,
706
+ lsp_types.NotebookDocumentSyncRegistrationOptionsNotebookSelectorType2,
707
+ ]:
708
+ if "notebook" in object_:
709
+ return converter.structure(
710
+ object_,
711
+ lsp_types.NotebookDocumentSyncRegistrationOptionsNotebookSelectorType1,
712
+ )
713
+ else:
714
+ return converter.structure(
715
+ object_,
716
+ lsp_types.NotebookDocumentSyncRegistrationOptionsNotebookSelectorType2,
717
+ )
718
+
719
+ structure_hooks = [
720
+ (
721
+ Optional[
722
+ Union[lsp_types.TextDocumentSyncOptions, lsp_types.TextDocumentSyncKind]
723
+ ],
724
+ _text_document_sync_hook,
725
+ ),
726
+ (
727
+ Optional[
728
+ Union[
729
+ lsp_types.NotebookDocumentSyncOptions,
730
+ lsp_types.NotebookDocumentSyncRegistrationOptions,
731
+ ]
732
+ ],
733
+ _notebook_document_sync_hook,
734
+ ),
735
+ (Optional[Union[bool, lsp_types.HoverOptions]], _hover_provider_hook),
736
+ (
737
+ Optional[
738
+ Union[
739
+ bool,
740
+ lsp_types.DeclarationOptions,
741
+ lsp_types.DeclarationRegistrationOptions,
742
+ ]
743
+ ],
744
+ _declaration_provider_hook,
745
+ ),
746
+ (Optional[Union[bool, lsp_types.DefinitionOptions]], _definition_provider_hook),
747
+ (
748
+ Optional[
749
+ Union[
750
+ bool,
751
+ lsp_types.TypeDefinitionOptions,
752
+ lsp_types.TypeDefinitionRegistrationOptions,
753
+ ]
754
+ ],
755
+ _type_definition_provider_hook,
756
+ ),
757
+ (
758
+ Optional[
759
+ Union[
760
+ bool,
761
+ lsp_types.ImplementationOptions,
762
+ lsp_types.ImplementationRegistrationOptions,
763
+ ]
764
+ ],
765
+ _implementation_provider_hook,
766
+ ),
767
+ (Optional[Union[bool, lsp_types.ReferenceOptions]], _references_provider_hook),
768
+ (
769
+ Optional[Union[bool, lsp_types.DocumentHighlightOptions]],
770
+ _document_highlight_provider_hook,
771
+ ),
772
+ (
773
+ Optional[Union[bool, lsp_types.DocumentSymbolOptions]],
774
+ _document_symbol_provider_hook,
775
+ ),
776
+ (
777
+ Optional[Union[bool, lsp_types.CodeActionOptions]],
778
+ _code_action_provider_hook,
779
+ ),
780
+ (
781
+ Optional[
782
+ Union[
783
+ bool,
784
+ lsp_types.DocumentColorOptions,
785
+ lsp_types.DocumentColorRegistrationOptions,
786
+ ]
787
+ ],
788
+ _color_provider_hook,
789
+ ),
790
+ (
791
+ Optional[Union[bool, lsp_types.WorkspaceSymbolOptions]],
792
+ _workspace_symbol_provider_hook,
793
+ ),
794
+ (
795
+ Optional[Union[bool, lsp_types.DocumentFormattingOptions]],
796
+ _document_formatting_provider_hook,
797
+ ),
798
+ (
799
+ Optional[Union[bool, lsp_types.DocumentRangeFormattingOptions]],
800
+ _document_range_formatting_provider_hook,
801
+ ),
802
+ (Optional[Union[bool, lsp_types.RenameOptions]], _rename_provider_hook),
803
+ (
804
+ Optional[
805
+ Union[
806
+ bool,
807
+ lsp_types.FoldingRangeOptions,
808
+ lsp_types.FoldingRangeRegistrationOptions,
809
+ ]
810
+ ],
811
+ _folding_range_provider_hook,
812
+ ),
813
+ (
814
+ Optional[
815
+ Union[
816
+ bool,
817
+ lsp_types.SelectionRangeOptions,
818
+ lsp_types.SelectionRangeRegistrationOptions,
819
+ ]
820
+ ],
821
+ _selection_range_provider_hook,
822
+ ),
823
+ (
824
+ Optional[
825
+ Union[
826
+ bool,
827
+ lsp_types.CallHierarchyOptions,
828
+ lsp_types.CallHierarchyRegistrationOptions,
829
+ ]
830
+ ],
831
+ _call_hierarchy_provider_hook,
832
+ ),
833
+ (
834
+ Optional[
835
+ Union[
836
+ bool,
837
+ lsp_types.LinkedEditingRangeOptions,
838
+ lsp_types.LinkedEditingRangeRegistrationOptions,
839
+ ]
840
+ ],
841
+ _linked_editing_range_provider_hook,
842
+ ),
843
+ (
844
+ Optional[
845
+ Union[
846
+ lsp_types.SemanticTokensOptions,
847
+ lsp_types.SemanticTokensRegistrationOptions,
848
+ ]
849
+ ],
850
+ _semantic_tokens_provider_hook,
851
+ ),
852
+ (
853
+ Optional[
854
+ Union[
855
+ bool, lsp_types.MonikerOptions, lsp_types.MonikerRegistrationOptions
856
+ ]
857
+ ],
858
+ _moniker_provider_hook,
859
+ ),
860
+ (
861
+ Optional[
862
+ Union[
863
+ bool,
864
+ lsp_types.TypeHierarchyOptions,
865
+ lsp_types.TypeHierarchyRegistrationOptions,
866
+ ]
867
+ ],
868
+ _type_hierarchy_provider_hook,
869
+ ),
870
+ (
871
+ Optional[
872
+ Union[
873
+ bool,
874
+ lsp_types.InlineValueOptions,
875
+ lsp_types.InlineValueRegistrationOptions,
876
+ ]
877
+ ],
878
+ _inline_value_provider_hook,
879
+ ),
880
+ (
881
+ Optional[
882
+ Union[
883
+ bool,
884
+ lsp_types.InlayHintOptions,
885
+ lsp_types.InlayHintRegistrationOptions,
886
+ ]
887
+ ],
888
+ _inlay_hint_provider_hook,
889
+ ),
890
+ (
891
+ Union[str, List[lsp_types.InlayHintLabelPart]],
892
+ _inlay_hint_label_part_hook,
893
+ ),
894
+ (
895
+ Optional[
896
+ Union[
897
+ lsp_types.DiagnosticOptions, lsp_types.DiagnosticRegistrationOptions
898
+ ]
899
+ ],
900
+ _diagnostic_provider_hook,
901
+ ),
902
+ (
903
+ Optional[Union[lsp_types.SaveOptions, bool]],
904
+ _save_hook,
905
+ ),
906
+ (
907
+ Union[lsp_types.Command, lsp_types.CodeAction],
908
+ _code_action_hook,
909
+ ),
910
+ (
911
+ Optional[Union[List[lsp_types.CompletionItem], lsp_types.CompletionList]],
912
+ _completion_list_hook,
913
+ ),
914
+ (
915
+ Optional[
916
+ Union[
917
+ lsp_types.Location,
918
+ List[lsp_types.Location],
919
+ List[lsp_types.LocationLink],
920
+ ]
921
+ ],
922
+ _location_hook,
923
+ ),
924
+ (
925
+ Optional[
926
+ Union[List[lsp_types.SymbolInformation], List[lsp_types.DocumentSymbol]]
927
+ ],
928
+ _symbol_hook,
929
+ ),
930
+ (
931
+ Union[
932
+ lsp_types.MarkupContent,
933
+ str,
934
+ lsp_types.MarkedString_Type1,
935
+ List[Union[str, lsp_types.MarkedString_Type1]],
936
+ ],
937
+ _markup_content_hook,
938
+ ),
939
+ (
940
+ Union[
941
+ lsp_types.TextDocumentEdit,
942
+ lsp_types.CreateFile,
943
+ lsp_types.RenameFile,
944
+ lsp_types.DeleteFile,
945
+ ],
946
+ _document_edit_hook,
947
+ ),
948
+ (
949
+ Optional[Union[bool, lsp_types.SemanticTokensOptionsFullType1]],
950
+ _semantic_tokens_hook,
951
+ ),
952
+ (
953
+ Optional[
954
+ Union[
955
+ bool,
956
+ lsp_types.SemanticTokensClientCapabilitiesRequestsTypeFullType1,
957
+ ]
958
+ ],
959
+ _semantic_tokens_capabilities_hook,
960
+ ),
961
+ (
962
+ Optional[Union[str, lsp_types.MarkupContent]],
963
+ _markup_content_hook,
964
+ ),
965
+ (
966
+ Optional[Union[lsp_types.CodeActionKind, str]],
967
+ _code_action_kind_hook,
968
+ ),
969
+ (
970
+ Union[lsp_types.CodeActionKind, str],
971
+ _code_action_kind_hook,
972
+ ),
973
+ (
974
+ Union[lsp_types.PositionEncodingKind, str],
975
+ _position_encoding_kind_hook,
976
+ ),
977
+ (
978
+ Optional[Union[lsp_types.FoldingRangeKind, str]],
979
+ _folding_range_kind_hook,
980
+ ),
981
+ (
982
+ Union[lsp_types.FoldingRangeKind, str],
983
+ _folding_range_kind_hook,
984
+ ),
985
+ (
986
+ Union[lsp_types.SemanticTokenTypes, str],
987
+ _semantic_token_types_hook,
988
+ ),
989
+ (
990
+ Optional[Union[lsp_types.SemanticTokenTypes, str]],
991
+ _semantic_token_types_hook,
992
+ ),
993
+ (
994
+ Union[lsp_types.SemanticTokenModifiers, str],
995
+ _semantic_token_modifiers_hook,
996
+ ),
997
+ (
998
+ Optional[Union[lsp_types.SemanticTokenModifiers, str]],
999
+ _semantic_token_modifiers_hook,
1000
+ ),
1001
+ (
1002
+ Union[lsp_types.WatchKind, int],
1003
+ _watch_kind_hook,
1004
+ ),
1005
+ (
1006
+ Optional[Union[lsp_types.WatchKind, int]],
1007
+ _watch_kind_hook,
1008
+ ),
1009
+ (
1010
+ Union[
1011
+ lsp_types.NotebookDocumentSyncOptionsNotebookSelectorType1,
1012
+ lsp_types.NotebookDocumentSyncOptionsNotebookSelectorType2,
1013
+ ],
1014
+ _notebook_sync_option_selector_hook,
1015
+ ),
1016
+ (
1017
+ Optional[
1018
+ Union[
1019
+ lsp_types.PositionEncodingKind,
1020
+ str,
1021
+ ]
1022
+ ],
1023
+ _position_encoding_hook,
1024
+ ),
1025
+ (
1026
+ Optional[Union[bool, lsp_types.SemanticTokensRegistrationOptionsFullType1]],
1027
+ _semantic_token_registration_options_hook,
1028
+ ),
1029
+ (
1030
+ Optional[Union[bool, lsp_types.InlineCompletionOptions]],
1031
+ _inline_completion_provider_hook,
1032
+ ),
1033
+ (
1034
+ Optional[
1035
+ Union[
1036
+ lsp_types.InlineCompletionList, List[lsp_types.InlineCompletionItem]
1037
+ ]
1038
+ ],
1039
+ _inline_completion_list_hook,
1040
+ ),
1041
+ (
1042
+ Union[str, lsp_types.StringValue],
1043
+ _string_value_hook,
1044
+ ),
1045
+ (
1046
+ Optional[
1047
+ Union[
1048
+ List[lsp_types.SymbolInformation], List[lsp_types.WorkspaceSymbol]
1049
+ ]
1050
+ ],
1051
+ _symbol_list_hook,
1052
+ ),
1053
+ (
1054
+ Union[
1055
+ lsp_types.NotebookDocumentSyncRegistrationOptionsNotebookSelectorType1,
1056
+ lsp_types.NotebookDocumentSyncRegistrationOptionsNotebookSelectorType2,
1057
+ ],
1058
+ _notebook_sync_registration_option_selector_hook,
1059
+ ),
1060
+ ]
1061
+ for type_, hook in structure_hooks:
1062
+ converter.register_structure_hook(type_, hook)
1063
+ return converter
1064
+
1065
+
1066
+ def _register_required_structure_hooks(
1067
+ converter: cattrs.Converter,
1068
+ ) -> cattrs.Converter:
1069
+ def _lsp_object_hook(object_: Any, type_: type) -> Any:
1070
+ return object_
1071
+
1072
+ def _parameter_information_label_hook(
1073
+ object_: Any, type: type
1074
+ ) -> Union[str, Tuple[int, int]]:
1075
+ if isinstance(object_, str):
1076
+ return object_
1077
+ else:
1078
+ return (int(object_[0]), int(object_[1]))
1079
+
1080
+ def _text_document_filter_hook(
1081
+ object_: Any, _: type
1082
+ ) -> Union[
1083
+ str,
1084
+ lsp_types.TextDocumentFilter_Type1,
1085
+ lsp_types.TextDocumentFilter_Type2,
1086
+ lsp_types.TextDocumentFilter_Type3,
1087
+ lsp_types.NotebookCellTextDocumentFilter,
1088
+ ]:
1089
+ if isinstance(object_, str):
1090
+ return str(object_)
1091
+ elif "notebook" in object_:
1092
+ return converter.structure(
1093
+ object_, lsp_types.NotebookCellTextDocumentFilter
1094
+ )
1095
+ elif "language" in object_:
1096
+ return converter.structure(object_, lsp_types.TextDocumentFilter_Type1)
1097
+ elif "scheme" in object_:
1098
+ return converter.structure(object_, lsp_types.TextDocumentFilter_Type2)
1099
+ else:
1100
+ return converter.structure(object_, lsp_types.TextDocumentFilter_Type3)
1101
+
1102
+ def _notebook_filter_hook(
1103
+ object_: Any, _: type
1104
+ ) -> Union[
1105
+ str,
1106
+ lsp_types.NotebookDocumentFilter_Type1,
1107
+ lsp_types.NotebookDocumentFilter_Type2,
1108
+ lsp_types.NotebookDocumentFilter_Type3,
1109
+ ]:
1110
+ if isinstance(object_, str):
1111
+ return str(object_)
1112
+ elif "notebookType" in object_:
1113
+ return converter.structure(object_, lsp_types.NotebookDocumentFilter_Type1)
1114
+ elif "scheme" in object_:
1115
+ return converter.structure(object_, lsp_types.NotebookDocumentFilter_Type2)
1116
+ else:
1117
+ return converter.structure(object_, lsp_types.NotebookDocumentFilter_Type3)
1118
+
1119
+ # TODO: Remove the ignore after this issue with attrs is addressed in either attrs or mypy
1120
+ NotebookSelectorItem = attrs.fields(
1121
+ lsp_types.NotebookCellTextDocumentFilter
1122
+ ).notebook.type
1123
+ STRUCTURE_HOOKS = [
1124
+ (type(None), lambda object_, _type: object_),
1125
+ (Optional[Union[int, str]], lambda object_, _type: object_),
1126
+ (Union[int, str], lambda object_, _type: object_),
1127
+ (lsp_types.LSPAny, _lsp_object_hook),
1128
+ (Optional[Union[str, bool]], lambda object_, _type: object_),
1129
+ (Optional[Union[bool, Any]], lambda object_, _type: object_),
1130
+ (
1131
+ Union[
1132
+ lsp_types.TextDocumentFilter_Type1,
1133
+ lsp_types.TextDocumentFilter_Type2,
1134
+ lsp_types.TextDocumentFilter_Type3,
1135
+ lsp_types.NotebookCellTextDocumentFilter,
1136
+ ],
1137
+ _text_document_filter_hook,
1138
+ ),
1139
+ (lsp_types.DocumentFilter, _text_document_filter_hook),
1140
+ (
1141
+ Union[
1142
+ str,
1143
+ lsp_types.NotebookDocumentFilter_Type1,
1144
+ lsp_types.NotebookDocumentFilter_Type2,
1145
+ lsp_types.NotebookDocumentFilter_Type3,
1146
+ ],
1147
+ _notebook_filter_hook,
1148
+ ),
1149
+ (NotebookSelectorItem, _notebook_filter_hook),
1150
+ (
1151
+ Union[lsp_types.LSPObject, List["LSPAny"], str, int, float, bool, None],
1152
+ _lsp_object_hook,
1153
+ ),
1154
+ (
1155
+ Union[
1156
+ lsp_types.LSPObject, List[lsp_types.LSPAny], str, int, float, bool, None
1157
+ ],
1158
+ _lsp_object_hook,
1159
+ ),
1160
+ (
1161
+ Union[str, Tuple[int, int]],
1162
+ _parameter_information_label_hook,
1163
+ ),
1164
+ (lsp_types.LSPObject, _lsp_object_hook),
1165
+ ]
1166
+
1167
+ if sys.version_info > (3, 8):
1168
+ STRUCTURE_HOOKS += [
1169
+ (
1170
+ Union[
1171
+ lsp_types.LSPObject,
1172
+ List[
1173
+ Union[
1174
+ lsp_types.LSPObject,
1175
+ List["LSPAny"],
1176
+ str,
1177
+ int,
1178
+ float,
1179
+ bool,
1180
+ None,
1181
+ ]
1182
+ ],
1183
+ str,
1184
+ int,
1185
+ float,
1186
+ bool,
1187
+ None,
1188
+ ],
1189
+ _lsp_object_hook,
1190
+ )
1191
+ ]
1192
+
1193
+ for type_, hook in STRUCTURE_HOOKS:
1194
+ converter.register_structure_hook(type_, hook)
1195
+
1196
+ return converter
1197
+
1198
+
1199
+ def _register_custom_property_hooks(converter: cattrs.Converter) -> cattrs.Converter:
1200
+ def _to_camel_case(name: str) -> str:
1201
+ # TODO: when min Python becomes >= 3.9, then update this to:
1202
+ # `return name.removesuffix("_")`.
1203
+ new_name = name[:-1] if name.endswith("_") else name
1204
+ parts = new_name.split("_")
1205
+ return parts[0] + "".join(p.title() for p in parts[1:])
1206
+
1207
+ def _omit(cls: type, prop: str) -> bool:
1208
+ special = lsp_types.is_special_property(cls, prop)
1209
+ return not special
1210
+
1211
+ def _with_custom_unstructure(cls: type) -> Any:
1212
+ attributes = {
1213
+ a.name: cattrs.gen.override(
1214
+ rename=_to_camel_case(a.name),
1215
+ omit_if_default=_omit(cls, a.name),
1216
+ )
1217
+ for a in attrs.fields(cls)
1218
+ }
1219
+ return cattrs.gen.make_dict_unstructure_fn(cls, converter, **attributes)
1220
+
1221
+ def _with_custom_structure(cls: type) -> Any:
1222
+ attributes = {
1223
+ a.name: cattrs.gen.override(
1224
+ rename=_to_camel_case(a.name),
1225
+ omit_if_default=_omit(cls, a.name),
1226
+ )
1227
+ for a in attrs.fields(cls)
1228
+ }
1229
+ return cattrs.gen.make_dict_structure_fn(cls, converter, **attributes)
1230
+
1231
+ converter.register_unstructure_hook_factory(attrs.has, _with_custom_unstructure)
1232
+ converter.register_structure_hook_factory(attrs.has, _with_custom_structure)
1233
+ return converter