jaclang 0.8.0__py3-none-any.whl → 0.8.2__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 (124) hide show
  1. jaclang/__init__.py +6 -0
  2. jaclang/cli/cli.py +23 -50
  3. jaclang/compiler/codeinfo.py +0 -1
  4. jaclang/compiler/jac.lark +14 -22
  5. jaclang/compiler/larkparse/jac_parser.py +2 -2
  6. jaclang/compiler/parser.py +378 -531
  7. jaclang/compiler/passes/main/__init__.py +0 -14
  8. jaclang/compiler/passes/main/annex_pass.py +2 -8
  9. jaclang/compiler/passes/main/cfg_build_pass.py +39 -13
  10. jaclang/compiler/passes/main/def_impl_match_pass.py +14 -13
  11. jaclang/compiler/passes/main/def_use_pass.py +4 -7
  12. jaclang/compiler/passes/main/import_pass.py +6 -14
  13. jaclang/compiler/passes/main/inheritance_pass.py +2 -2
  14. jaclang/compiler/passes/main/pyast_gen_pass.py +428 -799
  15. jaclang/compiler/passes/main/pyast_load_pass.py +115 -311
  16. jaclang/compiler/passes/main/pyjac_ast_link_pass.py +8 -7
  17. jaclang/compiler/passes/main/sym_tab_build_pass.py +3 -3
  18. jaclang/compiler/passes/main/sym_tab_link_pass.py +6 -9
  19. jaclang/compiler/passes/main/tests/fixtures/symtab_link_tests/action/actions.jac +1 -5
  20. jaclang/compiler/passes/main/tests/fixtures/symtab_link_tests/main.jac +1 -8
  21. jaclang/compiler/passes/main/tests/test_cfg_build_pass.py +5 -9
  22. jaclang/compiler/passes/main/tests/test_decl_impl_match_pass.py +7 -8
  23. jaclang/compiler/passes/main/tests/test_import_pass.py +5 -18
  24. jaclang/compiler/passes/main/tests/test_pyast_gen_pass.py +2 -6
  25. jaclang/compiler/passes/main/tests/test_sub_node_pass.py +1 -3
  26. jaclang/compiler/passes/main/tests/test_sym_tab_link_pass.py +20 -17
  27. jaclang/compiler/passes/tool/doc_ir_gen_pass.py +425 -216
  28. jaclang/compiler/passes/tool/jac_formatter_pass.py +2 -0
  29. jaclang/compiler/passes/tool/tests/fixtures/archetype_frmt.jac +14 -0
  30. jaclang/compiler/passes/tool/tests/fixtures/general_format_checks/triple_quoted_string.jac +5 -4
  31. jaclang/compiler/passes/tool/tests/fixtures/import_fmt.jac +6 -0
  32. jaclang/compiler/passes/tool/tests/fixtures/simple_walk_fmt.jac +3 -3
  33. jaclang/compiler/passes/tool/tests/fixtures/tagbreak.jac +9 -0
  34. jaclang/compiler/passes/tool/tests/test_jac_format_pass.py +18 -3
  35. jaclang/compiler/passes/tool/tests/test_unparse_validate.py +2 -2
  36. jaclang/compiler/program.py +22 -66
  37. jaclang/compiler/tests/fixtures/fam.jac +2 -2
  38. jaclang/compiler/tests/fixtures/pkg_import_lib/__init__.jac +1 -0
  39. jaclang/compiler/tests/fixtures/pkg_import_lib/sub/__init__.jac +1 -0
  40. jaclang/compiler/tests/fixtures/pkg_import_lib/sub/helper.jac +3 -0
  41. jaclang/compiler/tests/fixtures/pkg_import_lib/tools.jac +3 -0
  42. jaclang/compiler/tests/fixtures/pkg_import_lib_py/__init__.py +5 -0
  43. jaclang/compiler/tests/fixtures/pkg_import_lib_py/sub/__init__.py +3 -0
  44. jaclang/compiler/tests/fixtures/pkg_import_lib_py/sub/helper.jac +3 -0
  45. jaclang/compiler/tests/fixtures/pkg_import_lib_py/tools.jac +3 -0
  46. jaclang/compiler/tests/fixtures/pkg_import_main.jac +10 -0
  47. jaclang/compiler/tests/fixtures/pkg_import_main_py.jac +11 -0
  48. jaclang/compiler/tests/test_importer.py +30 -13
  49. jaclang/compiler/tests/test_parser.py +1 -0
  50. jaclang/compiler/unitree.py +488 -320
  51. jaclang/langserve/__init__.jac +1 -0
  52. jaclang/langserve/engine.jac +503 -0
  53. jaclang/langserve/sem_manager.jac +309 -0
  54. jaclang/langserve/server.jac +201 -0
  55. jaclang/langserve/tests/server_test/test_lang_serve.py +139 -48
  56. jaclang/langserve/tests/server_test/utils.py +35 -6
  57. jaclang/langserve/tests/session.jac +294 -0
  58. jaclang/langserve/tests/test_sem_tokens.py +2 -2
  59. jaclang/langserve/tests/test_server.py +8 -7
  60. jaclang/langserve/utils.jac +51 -30
  61. jaclang/runtimelib/archetype.py +128 -6
  62. jaclang/runtimelib/builtin.py +17 -14
  63. jaclang/runtimelib/importer.py +51 -76
  64. jaclang/runtimelib/machine.py +469 -305
  65. jaclang/runtimelib/meta_importer.py +86 -0
  66. jaclang/runtimelib/tests/fixtures/graph_purger.jac +24 -26
  67. jaclang/runtimelib/tests/fixtures/other_root_access.jac +25 -16
  68. jaclang/runtimelib/tests/fixtures/traversing_save.jac +7 -5
  69. jaclang/runtimelib/tests/test_jaseci.py +3 -1
  70. jaclang/runtimelib/utils.py +3 -3
  71. jaclang/tests/fixtures/arch_rel_import_creation.jac +23 -23
  72. jaclang/tests/fixtures/async_ability.jac +43 -10
  73. jaclang/tests/fixtures/async_function.jac +18 -0
  74. jaclang/tests/fixtures/async_walker.jac +17 -12
  75. jaclang/tests/fixtures/backward_edge_visit.jac +31 -0
  76. jaclang/tests/fixtures/builtin_printgraph.jac +85 -0
  77. jaclang/tests/fixtures/builtin_printgraph_json.jac +21 -0
  78. jaclang/tests/fixtures/builtin_printgraph_mermaid.jac +16 -0
  79. jaclang/tests/fixtures/chandra_bugs2.jac +20 -13
  80. jaclang/tests/fixtures/concurrency.jac +1 -1
  81. jaclang/tests/fixtures/create_dynamic_archetype.jac +25 -28
  82. jaclang/tests/fixtures/deep/deeper/deep_outer_import.jac +7 -4
  83. jaclang/tests/fixtures/deep/deeper/snd_lev.jac +2 -2
  84. jaclang/tests/fixtures/deep/deeper/snd_lev_dup.jac +6 -0
  85. jaclang/tests/fixtures/deep/one_lev.jac +2 -2
  86. jaclang/tests/fixtures/deep/one_lev_dup.jac +4 -3
  87. jaclang/tests/fixtures/dynamic_archetype.jac +19 -12
  88. jaclang/tests/fixtures/edge_ability.jac +49 -0
  89. jaclang/tests/fixtures/foo.jac +14 -22
  90. jaclang/tests/fixtures/guess_game.jac +1 -1
  91. jaclang/tests/fixtures/here_usage_error.jac +21 -0
  92. jaclang/tests/fixtures/here_visitor_usage.jac +21 -0
  93. jaclang/tests/fixtures/jac_from_py.py +1 -1
  94. jaclang/tests/fixtures/jp_importer.jac +6 -6
  95. jaclang/tests/fixtures/jp_importer_auto.jac +5 -3
  96. jaclang/tests/fixtures/node_del.jac +30 -36
  97. jaclang/tests/fixtures/unicode_strings.jac +24 -0
  98. jaclang/tests/fixtures/visit_traversal.jac +47 -0
  99. jaclang/tests/fixtures/walker_update.jac +5 -7
  100. jaclang/tests/test_cli.py +12 -7
  101. jaclang/tests/test_language.py +218 -145
  102. jaclang/tests/test_reference.py +9 -4
  103. jaclang/tests/test_typecheck.py +13 -26
  104. jaclang/utils/helpers.py +14 -6
  105. jaclang/utils/lang_tools.py +9 -8
  106. jaclang/utils/module_resolver.py +23 -0
  107. jaclang/utils/tests/test_lang_tools.py +2 -1
  108. jaclang/utils/treeprinter.py +3 -4
  109. {jaclang-0.8.0.dist-info → jaclang-0.8.2.dist-info}/METADATA +4 -3
  110. {jaclang-0.8.0.dist-info → jaclang-0.8.2.dist-info}/RECORD +112 -94
  111. {jaclang-0.8.0.dist-info → jaclang-0.8.2.dist-info}/WHEEL +1 -1
  112. jaclang/compiler/passes/main/tests/fixtures/main_err.jac +0 -6
  113. jaclang/compiler/passes/main/tests/fixtures/second_err.jac +0 -4
  114. jaclang/compiler/passes/tool/tests/fixtures/corelib.jac +0 -644
  115. jaclang/compiler/passes/tool/tests/test_doc_ir_gen_pass.py +0 -29
  116. jaclang/langserve/__init__.py +0 -1
  117. jaclang/langserve/engine.py +0 -553
  118. jaclang/langserve/sem_manager.py +0 -383
  119. jaclang/langserve/server.py +0 -167
  120. jaclang/langserve/tests/session.py +0 -255
  121. jaclang/tests/fixtures/builtin_dotgen.jac +0 -42
  122. jaclang/tests/fixtures/builtin_dotgen_json.jac +0 -21
  123. jaclang/tests/fixtures/deep/deeper/__init__.jac +0 -1
  124. {jaclang-0.8.0.dist-info → jaclang-0.8.2.dist-info}/entry_points.txt +0 -0
@@ -0,0 +1 @@
1
+ """Jaclang langserve package."""
@@ -0,0 +1,503 @@
1
+ """Living Workspace of Jac project."""
2
+
3
+ import asyncio;
4
+ import logging;
5
+ import time;
6
+ import from concurrent.futures { ThreadPoolExecutor }
7
+ import from typing { Callable , Optional }
8
+
9
+ import jaclang.compiler.unitree as uni;
10
+ import from jaclang { JacMachineInterface as Jac }
11
+ import from jaclang.compiler.program { JacProgram }
12
+ import from jaclang.compiler.unitree { UniScopeNode }
13
+ import from sem_manager { SemTokManager }
14
+ import from jaclang.vendor.pygls { uris }
15
+ import from jaclang.vendor.pygls.server { LanguageServer }
16
+
17
+ import lsprotocol.types as lspt;
18
+ import utils;
19
+
20
+
21
+ """Handles Jac module, semantic manager, and alert management."""
22
+ class ModuleManager {
23
+ """Initialize ModuleManager."""
24
+ def init(self: ModuleManager, program: JacProgram, sem_managers: <>dict) -> None {
25
+ self.program = program;
26
+ self.sem_managers = sem_managers;
27
+ }
28
+
29
+ """Update modules in JacProgram's hub and semantic managers."""
30
+ def update(
31
+ self: ModuleManager, file_path: str, build: uni.Module, update_annexed: bool = True
32
+ ) -> None {
33
+ file_path = file_path.removeprefix('file://');
34
+ self.program.mod.hub[file_path] = build;
35
+ if update_annexed {
36
+ self.sem_managers[file_path] = SemTokManager(ir=build);
37
+ for (p, mod) in self.program.mod.hub.items() { if p != file_path {
38
+ self.sem_managers[p] = SemTokManager(ir=mod);
39
+ } }
40
+ }
41
+ }
42
+
43
+ """Remove errors and warnings for a specific file from the lists."""
44
+ def clear_alerts_for_file(self: ModuleManager, file_path_fs: str) -> None {
45
+ self.program.errors_had =
46
+ [ e for e in self.program.errors_had if e.loc.mod_path != file_path_fs ];
47
+ self.program.warnings_had =
48
+ [ w for w in self.program.warnings_had if w.loc.mod_path != file_path_fs ];
49
+ }
50
+ }
51
+
52
+
53
+ """Jac Language Server, manages JacProgram and LSP."""
54
+ class JacLangServer ( JacProgram , LanguageServer ) {
55
+ """Initialize JacLangServer."""
56
+ def init(self: JacLangServer) -> None {
57
+ LanguageServer.init(self, 'jac-lsp', 'v0.1');
58
+ JacProgram.init(self);
59
+ self.executor = ThreadPoolExecutor();
60
+ self.tasks: <>dict[(str, asyncio.Task)] = {} ;
61
+ self.sem_managers: <>dict[(str, SemTokManager)] = {} ;
62
+ self.module_manager = ModuleManager(self, self.sem_managers);
63
+ }
64
+
65
+ """Return diagnostics for all files as a dict {uri: diagnostics}."""
66
+ @ property
67
+ def diagnostics(self: JacLangServer, ) -> <>dict[str, <>list] {
68
+ result = {} ;
69
+ for file_path in self.mod.hub { uri = uris.from_fs_path(file_path); result[uri] =
70
+ utils.gen_diagnostics(uri, self.errors_had, self.warnings_had); }
71
+ return result;
72
+ }
73
+
74
+ """Remove errors and warnings for a specific file from the lists."""
75
+ def _clear_alerts_for_file(self: JacLangServer, file_path_fs: str) -> None {
76
+ self.module_manager.clear_alerts_for_file(file_path_fs);
77
+ }
78
+
79
+ """Get IR for a file path."""
80
+ def get_ir(self: JacLangServer, file_path: str) -> Optional[uni.Module] {
81
+ file_path = file_path.removeprefix('file://');
82
+ return self.mod.hub.get(file_path);
83
+ }
84
+
85
+ """Update modules in JacProgram's hub and semantic managers."""
86
+ def update_modules(
87
+ self: JacLangServer, file_path: str, build: uni.Module, need: bool = True
88
+ ) -> None {
89
+ self.log_py(f"'Updating modules for '{file_path}");
90
+ self.module_manager.update(file_path, build, update_annexed=need);
91
+ }
92
+
93
+ """Rebuild a file (syntax only)."""
94
+ def quick_check(self: JacLangServer, file_path: str) -> bool {
95
+ try { file_path_fs = file_path.removeprefix('file://'); document =
96
+ self.workspace.get_text_document(file_path); self._clear_alerts_for_file(file_path_fs); build =
97
+ self.compile(use_str=document.source, file_path=document.path); self.update_modules(file_path_fs, build, need=False); self.publish_diagnostics(
98
+ file_path, utils.gen_diagnostics(
99
+ file_path, self.errors_had, self.warnings_had
100
+ )
101
+ ); build_errors =
102
+ [ e for e in self.errors_had if e.loc.mod_path == file_path_fs ]; return len(build_errors) == 0; } except Exception as e { self.log_error(f"'Error during syntax check: '{e}"); return False; }
103
+ }
104
+
105
+ """Rebuild a file and its dependencies (typecheck)."""
106
+ def deep_check(
107
+ self: JacLangServer, file_path: str, annex_view: Optional[str] = None
108
+ ) -> bool {
109
+ try { start_time = time.time(); file_path_fs =
110
+ file_path.removeprefix('file://'); document =
111
+ self.workspace.get_text_document(file_path); self._clear_alerts_for_file(file_path_fs); build =
112
+ self.build(use_str=document.source, file_path=document.path); self.update_modules(file_path_fs, build); if build.annexable_by {
113
+ return self.deep_check(
114
+ uris.from_fs_path(build.annexable_by), annex_view=file_path
115
+ );
116
+ } self.publish_diagnostics(
117
+ annex_view if annex_view else file_path, utils.gen_diagnostics(
118
+ annex_view if annex_view else file_path, self.errors_had, self.warnings_had
119
+ )
120
+ ); if annex_view {
121
+ self.publish_diagnostics(
122
+ file_path, utils.gen_diagnostics(
123
+ file_path, self.errors_had, self.warnings_had
124
+ )
125
+ );
126
+ } self.log_py(
127
+ f"'PROFILE: Deep check took '{(time.time() - start_time)}' seconds.'"
128
+ ); return len(self.errors_had) == 0; } except Exception as e { self.log_py(f"'Error during deep check: '{e}"); return False; }
129
+ }
130
+
131
+ """Analyze and publish diagnostics."""
132
+ async def launch_quick_check(self: JacLangServer, uri: str) -> bool {
133
+ return await asyncio.get_event_loop().run_in_executor(
134
+ self.executor, self.quick_check, uri
135
+ );
136
+ }
137
+
138
+ """Analyze and publish diagnostics."""
139
+ async def launch_deep_check(self: JacLangServer, uri: str) -> None {
140
+ async def run_in_executor(
141
+ func: Callable[([str, Optional[str]], bool)], file_path: str, annex_view: Optional[str] = None
142
+ ) -> None {
143
+ loop = asyncio.get_event_loop();
144
+ await loop.run_in_executor(self.executor, func, file_path, annex_view);
145
+ }
146
+ if uri in self.tasks and not self.tasks[uri].done() {
147
+ self.log_py(f"'Canceling '{uri}' deep check...'");
148
+ self.tasks[uri].cancel();
149
+ del (self.tasks[uri], ) ;
150
+ }
151
+ self.log_py(f"'Analyzing '{uri}'...'");
152
+ task = asyncio.create_task(run_in_executor(self.deep_check, uri));
153
+ self.tasks[uri] = task;
154
+ await task;
155
+ }
156
+
157
+ """Return completion for a file."""
158
+ def get_completion(
159
+ self: JacLangServer, file_path: str, position: lspt.Position, completion_trigger: Optional[str]
160
+ ) -> lspt.CompletionList {
161
+ try { document = self.workspace.get_text_document(file_path); mod_ir =
162
+ self.get_ir(file_path); if not mod_ir {
163
+ return lspt.CompletionList(is_incomplete=False, items=[]);
164
+ } current_line = document.lines[position.line]; current_pos =
165
+ position.character; current_symbol_path =
166
+ utils.parse_symbol_path(current_line, current_pos); builtin_mod =
167
+ next(( mod for (name, mod) in self.mod.hub.items() if 'builtins' in name )); builtin_tab =
168
+ builtin_mod.sym_tab; assert isinstance(builtin_tab, UniScopeNode) ; completion_items =
169
+ []; node_selected =
170
+ utils.find_deepest_symbol_node_at_pos(
171
+ mod_ir, position.line, (position.character - 2)
172
+ ); mod_tab = mod_ir.sym_tab if not node_selected else node_selected.sym_tab; current_symbol_table =
173
+ mod_tab; if completion_trigger == '.' {
174
+ if current_symbol_path {
175
+ temp_tab = mod_tab;
176
+ for symbol in current_symbol_path { if symbol == 'self' {
177
+ is_ability_def =
178
+ temp_tab
179
+ if isinstance(temp_tab, uni.ImplDef)
180
+ else temp_tab.find_parent_of_type(uni.ImplDef);
181
+ if not is_ability_def {
182
+ archi_owner = mod_tab.find_parent_of_type(uni.Archetype);
183
+ temp_tab =
184
+ archi_owner.sym_tab
185
+ if archi_owner and archi_owner.sym_tab
186
+ else mod_tab;
187
+ continue;
188
+ } else {
189
+ archi_owner =
190
+ is_ability_def.decl_link.find_parent_of_type(uni.Archetype)
191
+ if is_ability_def.decl_link
192
+ else None;
193
+ temp_tab =
194
+ archi_owner.sym_tab
195
+ if archi_owner and archi_owner.sym_tab
196
+ else temp_tab;
197
+ continue;
198
+ }
199
+ } symb = temp_tab.lookup(symbol); if symb {
200
+ fetc_tab = symb.fetch_sym_tab;
201
+ if fetc_tab {
202
+ temp_tab = fetc_tab;
203
+ } else {
204
+ temp_tab =
205
+ symb.defn[0].type_sym_tab
206
+ if symb.defn[0].type_sym_tab
207
+ else temp_tab;
208
+ }
209
+ } else {
210
+ break;
211
+ } }
212
+ completion_items += utils.collect_all_symbols_in_scope(
213
+ temp_tab, up_tree=False
214
+ );
215
+ if isinstance(temp_tab, uni.Archetype) and temp_tab.base_classes {
216
+ base = [];
217
+ for base_name in temp_tab.base_classes { if isinstance(base_name, uni.Name) and base_name.sym {
218
+ base.append(base_name.sym);
219
+ } }
220
+ for base_class_symbol in base { if base_class_symbol.fetch_sym_tab {
221
+ completion_items += utils.collect_all_symbols_in_scope(
222
+ base_class_symbol.fetch_sym_tab, up_tree=False
223
+ );
224
+ } }
225
+ }
226
+ }
227
+ } elif node_selected and node_selected.find_parent_of_type(uni.Archetype)
228
+ or node_selected.find_parent_of_type(uni.ImplDef)
229
+ {
230
+ self_symbol =
231
+
232
+ [lspt.CompletionItem(
233
+ label='self', kind=lspt.CompletionItemKind.Variable
234
+ )];
235
+ } else {
236
+ self_symbol = [];
237
+ } return lspt.CompletionList(is_incomplete=False, items=completion_items); } except Exception as e { self.log_py(f"'Error during completion: '{e}"); return lspt.CompletionList(is_incomplete=False, items=[]); }
238
+ }
239
+
240
+ """Rename module."""
241
+ def rename_module(self: JacLangServer, old_path: str, new_path: str) -> None {
242
+ if old_path in self.mod.hub and new_path != old_path {
243
+ self.mod.hub[new_path] = self.mod.hub[old_path];
244
+ self.sem_managers[new_path] = self.sem_managers[old_path];
245
+ del (self.mod.hub[old_path], ) ;
246
+ del (self.sem_managers[old_path], ) ;
247
+ }
248
+ }
249
+
250
+ """Delete module."""
251
+ def delete_module(self: JacLangServer, uri: str) -> None {
252
+ if uri in self.mod.hub {
253
+ del (self.mod.hub[uri], ) ;
254
+ }
255
+ if uri in self.sem_managers {
256
+ del (self.sem_managers[uri], ) ;
257
+ }
258
+ }
259
+
260
+ """Return formatted jac."""
261
+ def formatted_jac(self: JacLangServer, file_path: str) -> <>list[lspt.TextEdit] {
262
+ try { document = self.workspace.get_text_document(file_path); formatted_text =
263
+ JacProgram.jac_str_formatter(
264
+ source_str=document.source, file_path=document.path
265
+ ); } except Exception as e { self.log_error(f"'Error during formatting: '{e}"); formatted_text =
266
+ document.source; }
267
+ return
268
+ [lspt.TextEdit(
269
+ range=lspt.Range(
270
+ start=lspt.Position(line=0, character=0), end=lspt.Position(
271
+ line=(len(document.source.splitlines()) + 1), character=0
272
+ )
273
+ ), new_text=formatted_text
274
+ )];
275
+ }
276
+
277
+ """Return hover information for a file."""
278
+ def get_hover_info(
279
+ self: JacLangServer, file_path: str, position: lspt.Position
280
+ ) -> Optional[lspt.Hover] {
281
+ file_path_fs = file_path.removeprefix('file://');
282
+ if file_path_fs not in self.mod.hub {
283
+ return None;
284
+ }
285
+ sem_mgr = self.sem_managers.get(file_path_fs);
286
+ if not sem_mgr {
287
+ return None;
288
+ }
289
+ token_index =
290
+ utils.find_index(sem_mgr.sem_tokens, position.line, position.character);
291
+ if token_index is None {
292
+ return None;
293
+ }
294
+ node_selected = sem_mgr.static_sem_tokens[token_index][3];
295
+ value = self.get_node_info(node_selected) if node_selected else None;
296
+ if value {
297
+ return lspt.Hover(
298
+ contents=lspt.MarkupContent(
299
+ kind=lspt.MarkupKind.PlainText, value=f"{value}"
300
+ )
301
+ );
302
+ }
303
+ return None;
304
+ }
305
+
306
+ """Extract meaningful information from the AST node."""
307
+ def get_node_info(self: JacLangServer, <>node: uni.AstSymbolNode) -> Optional[str] {
308
+ try { if isinstance(<>node, uni.NameAtom) {
309
+ <>node = <>node.name_of;
310
+ } access = (<>node.sym.access.value + ' ') if <>node.sym else None; node_info =
311
+ f"'('{access if access else ''}{<>node.sym_category.value}') '{<>node.sym_name}"; if <>node.name_spec.clean_type {
312
+ node_info += f"': '{<>node.name_spec.clean_type}";
313
+ } if isinstance(<>node, uni.AstDocNode) and <>node.doc {
314
+ node_info += f"'\n'{<>node.doc.value}";
315
+ } if isinstance(<>node, uni.Ability) and <>node.signature {
316
+ node_info += f"'\n'{<>node.signature.unparse()}";
317
+ } } except AttributeError as e { self.log_warning(f"'Attribute error when accessing node attributes: '{e}"); }
318
+ return node_info.strip();
319
+ }
320
+
321
+ """Return document symbols for a file."""
322
+ def get_outline(self: JacLangServer, file_path: str) -> <>list[lspt.DocumentSymbol] {
323
+ file_path_fs = file_path.removeprefix('file://');
324
+ if file_path_fs in self.mod.hub
325
+ and (root_node := self.mod.hub[file_path_fs].sym_tab)
326
+ {
327
+ return utils.get_symbols_for_outline(root_node);
328
+ }
329
+ return [];
330
+ }
331
+
332
+ """Return definition location for a file."""
333
+ def get_definition(
334
+ self: JacLangServer, file_path: str, position: lspt.Position
335
+ ) -> Optional[lspt.Location] {
336
+ file_path_fs = file_path.removeprefix('file://');
337
+ if file_path_fs not in self.mod.hub {
338
+ return None;
339
+ }
340
+ sem_mgr = self.sem_managers.get(file_path_fs);
341
+ if not sem_mgr {
342
+ return None;
343
+ }
344
+ token_index =
345
+ utils.find_index(sem_mgr.sem_tokens, position.line, position.character);
346
+ if token_index is None {
347
+ return None;
348
+ }
349
+ node_selected = sem_mgr.static_sem_tokens[token_index][3];
350
+ if node_selected {
351
+ if isinstance(node_selected, uni.Name)
352
+ and node_selected.parent
353
+ and isinstance(node_selected.parent, uni.ModulePath)
354
+ {
355
+ spec = node_selected.parent.parent.abs_path;
356
+ if spec {
357
+ spec = spec[ 5 : ] if spec.startswith('File:') else spec;
358
+ return lspt.Location(
359
+ uri=uris.from_fs_path(spec), range=lspt.Range(
360
+ start=lspt.Position(line=0, character=0), end=lspt.Position(line=0, character=0)
361
+ )
362
+ );
363
+ } else {
364
+ return None;
365
+ }
366
+ } elif node_selected.parent
367
+ and isinstance(node_selected.parent, uni.ModuleItem)
368
+ {
369
+ path =
370
+ node_selected.parent.abs_path
371
+ or node_selected.parent.from_mod_path.abs_path
372
+ ;
373
+ loc_range = (0, 0, 0, 0);
374
+ if path and loc_range {
375
+ path = path[ 5 : ] if path.startswith('File:') else path;
376
+ return lspt.Location(
377
+ uri=uris.from_fs_path(path), range=lspt.Range(
378
+ start=lspt.Position(
379
+ line=loc_range[0], character=loc_range[1]
380
+ ), end=lspt.Position(line=loc_range[2], character=loc_range[3])
381
+ )
382
+ );
383
+ }
384
+ } elif isinstance(node_selected, uni.ElementStmt) {
385
+ return None;
386
+ }
387
+ decl_node =
388
+ node_selected.parent.body.target
389
+ if node_selected.parent
390
+ and isinstance(node_selected.parent, uni.AstImplNeedingNode)
391
+ and isinstance(node_selected.parent.body, uni.ImplDef)
392
+
393
+ else node_selected.sym.decl
394
+ if node_selected.sym and node_selected.sym.decl
395
+ else node_selected;
396
+ if isinstance(decl_node, list) {
397
+ valid_path = decl_node[0].loc.mod_path;
398
+ } else {
399
+ valid_path = decl_node.loc.mod_path;
400
+ }
401
+ decl_uri = uris.from_fs_path(valid_path);
402
+ if isinstance(decl_node, list) {
403
+ valid_range = decl_node[0].loc;
404
+ } else {
405
+ valid_range = decl_node.loc;
406
+ }
407
+ try { decl_range = utils.create_range(valid_range); } except ValueError { return None; }
408
+ decl_location = lspt.Location(uri=decl_uri, range=decl_range);
409
+ return decl_location;
410
+ } else {
411
+ return None;
412
+ }
413
+ }
414
+
415
+ """Return references for a file."""
416
+ def get_references(
417
+ self: JacLangServer, file_path: str, position: lspt.Position
418
+ ) -> <>list[lspt.Location] {
419
+ file_path_fs = file_path.removeprefix('file://');
420
+ if file_path_fs not in self.mod.hub {
421
+ return [];
422
+ }
423
+ sem_mgr = self.sem_managers.get(file_path_fs);
424
+ if not sem_mgr {
425
+ return [];
426
+ }
427
+ index1 =
428
+ utils.find_index(sem_mgr.sem_tokens, position.line, position.character);
429
+ if index1 is None {
430
+ return [];
431
+ }
432
+ node_selected = sem_mgr.static_sem_tokens[index1][3];
433
+ if node_selected and node_selected.sym {
434
+ list_of_references: <>list[lspt.Location] =
435
+ [ lspt.Location(
436
+ uri=uris.from_fs_path(<>node.loc.mod_path), range=utils.create_range(<>node.loc)
437
+ ) for <>node in node_selected.sym.uses ];
438
+ return list_of_references;
439
+ }
440
+ return [];
441
+ }
442
+
443
+ """Rename a symbol in a file."""
444
+ def rename_symbol(
445
+ self: JacLangServer, file_path: str, position: lspt.Position, new_name: str
446
+ ) -> Optional[lspt.WorkspaceEdit] {
447
+ file_path_fs = file_path.removeprefix('file://');
448
+ if file_path_fs not in self.mod.hub {
449
+ return None;
450
+ }
451
+ sem_mgr = self.sem_managers.get(file_path_fs);
452
+ if not sem_mgr {
453
+ return None;
454
+ }
455
+ index1 =
456
+ utils.find_index(sem_mgr.sem_tokens, position.line, position.character);
457
+ if index1 is None {
458
+ return None;
459
+ }
460
+ node_selected = sem_mgr.static_sem_tokens[index1][3];
461
+ if node_selected and node_selected.sym {
462
+ changes: <>dict[(str, <>list[lspt.TextEdit])] = {} ;
463
+ for <>node in [*node_selected.sym.uses, node_selected.sym.defn[0]] { key =
464
+ uris.from_fs_path(<>node.loc.mod_path); new_edit =
465
+ lspt.TextEdit(range=utils.create_range(<>node.loc), new_text=new_name); utils.add_unique_text_edit(changes, key, new_edit); }
466
+ return lspt.WorkspaceEdit(changes=changes);
467
+ }
468
+ return None;
469
+ }
470
+
471
+ """Return semantic tokens for a file."""
472
+ def get_semantic_tokens(self: JacLangServer, file_path: str) -> lspt.SemanticTokens {
473
+ file_path_fs = file_path.removeprefix('file://');
474
+ sem_mgr = self.sem_managers.get(file_path_fs);
475
+ if not sem_mgr {
476
+ return lspt.SemanticTokens(data=[]);
477
+ }
478
+ return lspt.SemanticTokens(data=sem_mgr.sem_tokens);
479
+ }
480
+
481
+ """Log an error message."""
482
+ def log_error(self: JacLangServer, message: str) -> None {
483
+ self.show_message_log(message, lspt.MessageType.Error);
484
+ self.show_message(message, lspt.MessageType.Error);
485
+ }
486
+
487
+ """Log a warning message."""
488
+ def log_warning(self: JacLangServer, message: str) -> None {
489
+ self.show_message_log(message, lspt.MessageType.Warning);
490
+ self.show_message(message, lspt.MessageType.Warning);
491
+ }
492
+
493
+ """Log an info message."""
494
+ def log_info(self: JacLangServer, message: str) -> None {
495
+ self.show_message_log(message, lspt.MessageType.Info);
496
+ self.show_message(message, lspt.MessageType.Info);
497
+ }
498
+
499
+ """Log a message."""
500
+ def log_py(self: JacLangServer, message: str) -> None {
501
+ logging.info(message);
502
+ }
503
+ }