jaclang 0.7.14__py3-none-any.whl → 0.7.17__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.
- jaclang/cli/cli.py +147 -77
- jaclang/cli/cmdreg.py +9 -12
- jaclang/compiler/__init__.py +19 -53
- jaclang/compiler/absyntree.py +94 -16
- jaclang/compiler/constant.py +8 -8
- jaclang/compiler/jac.lark +4 -3
- jaclang/compiler/parser.py +41 -25
- jaclang/compiler/passes/ir_pass.py +4 -13
- jaclang/compiler/passes/main/__init__.py +1 -1
- jaclang/compiler/passes/main/access_modifier_pass.py +96 -147
- jaclang/compiler/passes/main/fuse_typeinfo_pass.py +155 -54
- jaclang/compiler/passes/main/import_pass.py +99 -75
- jaclang/compiler/passes/main/py_collect_dep_pass.py +70 -0
- jaclang/compiler/passes/main/pyast_gen_pass.py +328 -565
- jaclang/compiler/passes/main/pyast_load_pass.py +33 -6
- jaclang/compiler/passes/main/pyjac_ast_link_pass.py +7 -0
- jaclang/compiler/passes/main/registry_pass.py +37 -3
- jaclang/compiler/passes/main/schedules.py +9 -2
- jaclang/compiler/passes/main/sym_tab_build_pass.py +10 -6
- jaclang/compiler/passes/main/tests/__init__.py +1 -1
- jaclang/compiler/passes/main/tests/fixtures/autoimpl.empty.impl.jac +0 -0
- jaclang/compiler/passes/main/tests/fixtures/autoimpl.jac +1 -1
- jaclang/compiler/passes/main/tests/fixtures/py_imp_test.jac +29 -0
- jaclang/compiler/passes/main/tests/fixtures/pygame_mock/__init__.py +3 -0
- jaclang/compiler/passes/main/tests/fixtures/pygame_mock/color.py +3 -0
- jaclang/compiler/passes/main/tests/fixtures/pygame_mock/constants.py +5 -0
- jaclang/compiler/passes/main/tests/fixtures/pygame_mock/display.py +2 -0
- jaclang/compiler/passes/main/tests/test_import_pass.py +72 -13
- jaclang/compiler/passes/main/type_check_pass.py +22 -5
- jaclang/compiler/passes/tool/jac_formatter_pass.py +135 -89
- jaclang/compiler/passes/tool/tests/fixtures/corelib.jac +37 -41
- jaclang/compiler/passes/tool/tests/fixtures/corelib_fmt.jac +37 -42
- jaclang/compiler/passes/tool/tests/fixtures/general_format_checks/access_mod_check.jac +27 -0
- jaclang/compiler/passes/tool/tests/fixtures/general_format_checks/architype_test.jac +13 -0
- jaclang/compiler/passes/tool/tests/fixtures/general_format_checks/comment_alignment.jac +11 -0
- jaclang/compiler/passes/tool/tests/fixtures/general_format_checks/comments.jac +13 -0
- jaclang/compiler/passes/tool/tests/fixtures/general_format_checks/decorator_stack.jac +37 -0
- jaclang/compiler/passes/tool/tests/fixtures/general_format_checks/esc_keywords.jac +5 -0
- jaclang/compiler/passes/tool/tests/fixtures/general_format_checks/long_names.jac +19 -0
- jaclang/compiler/passes/tool/tests/fixtures/general_format_checks/triple_quoted_string.jac +6 -0
- jaclang/compiler/passes/tool/tests/test_jac_format_pass.py +11 -0
- jaclang/compiler/passes/tool/tests/test_unparse_validate.py +33 -39
- jaclang/compiler/passes/transform.py +4 -0
- jaclang/compiler/passes/utils/mypy_ast_build.py +45 -0
- jaclang/compiler/semtable.py +31 -7
- jaclang/compiler/symtable.py +16 -11
- jaclang/compiler/tests/test_importer.py +25 -10
- jaclang/langserve/engine.py +104 -118
- jaclang/langserve/sem_manager.py +379 -0
- jaclang/langserve/server.py +24 -11
- jaclang/langserve/tests/fixtures/base_module_structure.jac +27 -6
- jaclang/langserve/tests/fixtures/circle.jac +3 -3
- jaclang/langserve/tests/fixtures/circle_err.jac +3 -3
- jaclang/langserve/tests/fixtures/circle_pure.test.jac +3 -3
- jaclang/langserve/tests/fixtures/import_include_statements.jac +1 -1
- jaclang/langserve/tests/fixtures/rename.jac +30 -0
- jaclang/langserve/tests/test_sem_tokens.py +277 -0
- jaclang/langserve/tests/test_server.py +287 -17
- jaclang/langserve/utils.py +184 -98
- jaclang/plugin/builtin.py +1 -1
- jaclang/plugin/default.py +288 -92
- jaclang/plugin/feature.py +65 -27
- jaclang/plugin/spec.py +62 -23
- jaclang/plugin/tests/fixtures/other_root_access.jac +82 -0
- jaclang/plugin/tests/test_jaseci.py +414 -42
- jaclang/runtimelib/architype.py +650 -0
- jaclang/{core → runtimelib}/constructs.py +5 -8
- jaclang/{core → runtimelib}/context.py +86 -59
- jaclang/runtimelib/importer.py +361 -0
- jaclang/runtimelib/machine.py +158 -0
- jaclang/runtimelib/memory.py +158 -0
- jaclang/{core → runtimelib}/utils.py +30 -15
- jaclang/settings.py +5 -4
- jaclang/tests/fixtures/abc.jac +3 -3
- jaclang/tests/fixtures/access_checker.jac +12 -17
- jaclang/tests/fixtures/access_modifier.jac +88 -33
- jaclang/tests/fixtures/baddy.jac +3 -0
- jaclang/tests/fixtures/baddy.test.jac +3 -0
- jaclang/tests/fixtures/bar.jac +34 -0
- jaclang/tests/fixtures/byllmissue.jac +1 -5
- jaclang/tests/fixtures/chandra_bugs2.jac +11 -10
- jaclang/tests/fixtures/cls_method.jac +41 -0
- jaclang/tests/fixtures/dblhello.jac +6 -0
- jaclang/tests/fixtures/deep/one_lev.jac +3 -3
- jaclang/tests/fixtures/deep/one_lev_dup.jac +2 -3
- jaclang/tests/fixtures/deep_import_mods.jac +13 -0
- jaclang/tests/fixtures/edge_node_walk.jac +1 -1
- jaclang/tests/fixtures/edge_ops.jac +1 -1
- jaclang/tests/fixtures/edges_walk.jac +1 -1
- jaclang/tests/fixtures/err.impl.jac +3 -0
- jaclang/tests/fixtures/err.jac +4 -2
- jaclang/tests/fixtures/err_runtime.jac +15 -0
- jaclang/tests/fixtures/foo.jac +43 -0
- jaclang/tests/fixtures/gendot_bubble_sort.jac +1 -1
- jaclang/tests/fixtures/hello.jac +4 -0
- jaclang/tests/fixtures/impl_grab.impl.jac +2 -1
- jaclang/tests/fixtures/impl_grab.jac +4 -1
- jaclang/tests/fixtures/import.jac +9 -0
- jaclang/tests/fixtures/index_slice.jac +30 -0
- jaclang/tests/fixtures/jp_importer_auto.jac +14 -0
- jaclang/tests/fixtures/maxfail_run_test.jac +4 -4
- jaclang/tests/fixtures/needs_import.jac +2 -2
- jaclang/tests/fixtures/pyfunc_1.py +1 -1
- jaclang/tests/fixtures/pyfunc_2.py +5 -2
- jaclang/tests/fixtures/pygame_mock/__init__.py +3 -0
- jaclang/tests/fixtures/pygame_mock/color.py +3 -0
- jaclang/tests/fixtures/pygame_mock/constants.py +5 -0
- jaclang/tests/fixtures/pygame_mock/display.py +2 -0
- jaclang/tests/fixtures/pygame_mock/inner/__init__.py +0 -0
- jaclang/tests/fixtures/pygame_mock/inner/iner_mod.py +2 -0
- jaclang/tests/fixtures/registry.jac +9 -0
- jaclang/tests/fixtures/run_test.jac +4 -4
- jaclang/tests/fixtures/semstr.jac +1 -4
- jaclang/tests/fixtures/simple_archs.jac +1 -1
- jaclang/tests/test_cli.py +109 -3
- jaclang/tests/test_language.py +170 -68
- jaclang/tests/test_reference.py +2 -3
- jaclang/utils/helpers.py +45 -21
- jaclang/utils/test.py +9 -0
- jaclang/utils/treeprinter.py +30 -7
- {jaclang-0.7.14.dist-info → jaclang-0.7.17.dist-info}/METADATA +3 -2
- {jaclang-0.7.14.dist-info → jaclang-0.7.17.dist-info}/RECORD +126 -90
- jaclang/core/architype.py +0 -502
- jaclang/core/importer.py +0 -344
- jaclang/core/memory.py +0 -99
- jaclang/tests/fixtures/aott_raise.jac +0 -25
- jaclang/tests/fixtures/package_import.jac +0 -6
- /jaclang/{core → runtimelib}/__init__.py +0 -0
- /jaclang/{core → runtimelib}/test.py +0 -0
- {jaclang-0.7.14.dist-info → jaclang-0.7.17.dist-info}/WHEEL +0 -0
- {jaclang-0.7.14.dist-info → jaclang-0.7.17.dist-info}/entry_points.txt +0 -0
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
"""Test Semantic Tokens Update."""
|
|
2
|
+
|
|
3
|
+
import copy
|
|
4
|
+
import lsprotocol.types as lspt
|
|
5
|
+
|
|
6
|
+
from jaclang.langserve.sem_manager import SemTokManager
|
|
7
|
+
from jaclang.utils.test import TestCase
|
|
8
|
+
|
|
9
|
+
from typing import Tuple
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class TestUpdateSemTokens(TestCase):
|
|
13
|
+
"""Test update semantic tokens"""
|
|
14
|
+
|
|
15
|
+
def setUp(self) -> None:
|
|
16
|
+
"""Set up test."""
|
|
17
|
+
# fmt: off
|
|
18
|
+
self.initial_sem_tokens = [
|
|
19
|
+
1, 10, 4, 0, 2, 3, 4, 14, 12, 1, 0, 15, 6, 7, 1, 0, 8, 5, 2, 1,
|
|
20
|
+
0, 10, 5, 2, 1, 1, 11, 4, 0, 2, 0, 10, 6, 7, 1, 0, 9, 6, 7, 1
|
|
21
|
+
]
|
|
22
|
+
# fmt: on
|
|
23
|
+
|
|
24
|
+
self.document_lines = [
|
|
25
|
+
"",
|
|
26
|
+
"import:py math;",
|
|
27
|
+
"",
|
|
28
|
+
'"""Function to calculate the area of a circle."""',
|
|
29
|
+
"can calculate_area(radius: float) -> float {",
|
|
30
|
+
" return math.pi * radius * radius;",
|
|
31
|
+
"}",
|
|
32
|
+
" ",
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
def check_semantic_token_update(self, case: Tuple, expected_output: str) -> None:
|
|
36
|
+
"""Check semantic token update."""
|
|
37
|
+
doc_lines = copy.deepcopy(self.document_lines)
|
|
38
|
+
|
|
39
|
+
updated_semtokens = SemTokManager.update_sem_tokens(
|
|
40
|
+
"circle_ir",
|
|
41
|
+
lspt.DidChangeTextDocumentParams(
|
|
42
|
+
text_document=lspt.VersionedTextDocumentIdentifier(
|
|
43
|
+
version=32,
|
|
44
|
+
uri="...jaclang/examples/manual_code/circle.jac",
|
|
45
|
+
),
|
|
46
|
+
content_changes=[
|
|
47
|
+
lspt.TextDocumentContentChangeEvent_Type1(
|
|
48
|
+
range=lspt.Range(start=case[0], end=case[1]),
|
|
49
|
+
text=case[2],
|
|
50
|
+
range_length=case[3],
|
|
51
|
+
)
|
|
52
|
+
],
|
|
53
|
+
),
|
|
54
|
+
sem_tokens=copy.deepcopy(self.initial_sem_tokens),
|
|
55
|
+
document_lines=doc_lines,
|
|
56
|
+
)
|
|
57
|
+
self.assertIn(
|
|
58
|
+
expected_output, str(updated_semtokens), f"\nFailed for case: {case[4]}"
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
def test_multiline_before_first_token(self) -> None:
|
|
62
|
+
"""Test multiline before first token."""
|
|
63
|
+
case = (
|
|
64
|
+
lspt.Position(line=0, character=0),
|
|
65
|
+
lspt.Position(line=0, character=0),
|
|
66
|
+
"\n",
|
|
67
|
+
0,
|
|
68
|
+
"Multiline before first token (Basic)",
|
|
69
|
+
)
|
|
70
|
+
self.document_lines.insert(1, "")
|
|
71
|
+
self.check_semantic_token_update(case, "2, 10, 4, 0, 2, 3, 4, 14,")
|
|
72
|
+
|
|
73
|
+
def test_multiline_between_tokens(self) -> None:
|
|
74
|
+
"""Test multiline between tokens."""
|
|
75
|
+
case = (
|
|
76
|
+
lspt.Position(line=5, character=19),
|
|
77
|
+
lspt.Position(line=5, character=19),
|
|
78
|
+
"\n ",
|
|
79
|
+
0,
|
|
80
|
+
"Multiline between tokens (Basic)",
|
|
81
|
+
)
|
|
82
|
+
self.document_lines[5] = " return math.pi "
|
|
83
|
+
self.document_lines.insert(6, " * radius * radius;")
|
|
84
|
+
self.check_semantic_token_update(case, "2, 1, 6, 6, 7, 1, ")
|
|
85
|
+
|
|
86
|
+
def test_multiline_at_end_of_line(self) -> None:
|
|
87
|
+
"""Test multiline at end of line."""
|
|
88
|
+
case = (
|
|
89
|
+
lspt.Position(line=4, character=37),
|
|
90
|
+
lspt.Position(line=4, character=37),
|
|
91
|
+
"\n",
|
|
92
|
+
0,
|
|
93
|
+
"Multiline at end of line",
|
|
94
|
+
)
|
|
95
|
+
self.document_lines[4] = "can calculate_area(radius: float) -> "
|
|
96
|
+
self.document_lines.insert(5, "float {")
|
|
97
|
+
self.check_semantic_token_update(case, " 2, 1, 1, 0, 5, 2, 1, ")
|
|
98
|
+
|
|
99
|
+
def test_sameline_space_between_tokens(self) -> None:
|
|
100
|
+
"""Test sameline space between tokens."""
|
|
101
|
+
case = (
|
|
102
|
+
lspt.Position(line=5, character=20),
|
|
103
|
+
lspt.Position(line=5, character=20),
|
|
104
|
+
" ",
|
|
105
|
+
0,
|
|
106
|
+
"Sameline space between tokens (Basic)",
|
|
107
|
+
)
|
|
108
|
+
self.check_semantic_token_update(case, "0, 11, 6, 7, 1,")
|
|
109
|
+
|
|
110
|
+
def test_sameline_tab_between_tokens(self) -> None:
|
|
111
|
+
"""Test sameline tab between tokens."""
|
|
112
|
+
case = (
|
|
113
|
+
lspt.Position(line=5, character=20),
|
|
114
|
+
lspt.Position(line=5, character=20),
|
|
115
|
+
" ",
|
|
116
|
+
0,
|
|
117
|
+
"Sameline tab between tokens (Basic)",
|
|
118
|
+
)
|
|
119
|
+
self.check_semantic_token_update(case, "0, 14, 6, 7, 1")
|
|
120
|
+
|
|
121
|
+
def test_tab_at_start_of_token(self) -> None:
|
|
122
|
+
"""Test tab at start of token."""
|
|
123
|
+
case = (
|
|
124
|
+
lspt.Position(line=5, character=21),
|
|
125
|
+
lspt.Position(line=5, character=21),
|
|
126
|
+
" ",
|
|
127
|
+
0,
|
|
128
|
+
"Tab at start of a token",
|
|
129
|
+
)
|
|
130
|
+
self.check_semantic_token_update(case, "0, 13, 6, 7, 1,")
|
|
131
|
+
|
|
132
|
+
def test_insert_inside_token(self) -> None:
|
|
133
|
+
"""Test insert inside token."""
|
|
134
|
+
case = (
|
|
135
|
+
lspt.Position(line=5, character=13),
|
|
136
|
+
lspt.Position(line=5, character=13),
|
|
137
|
+
"calculate",
|
|
138
|
+
0,
|
|
139
|
+
"insert inside a token",
|
|
140
|
+
)
|
|
141
|
+
self.check_semantic_token_update(case, "1, 11, 13, 0, 2, 0, 19, 6, 7, 1")
|
|
142
|
+
|
|
143
|
+
def test_insert_inside_token_selected_range(self) -> None:
|
|
144
|
+
"""Test insert inside token selected range."""
|
|
145
|
+
case = (
|
|
146
|
+
lspt.Position(line=5, character=12),
|
|
147
|
+
lspt.Position(line=5, character=14),
|
|
148
|
+
"calculate",
|
|
149
|
+
2,
|
|
150
|
+
"insert inside a token in a selected range",
|
|
151
|
+
)
|
|
152
|
+
self.check_semantic_token_update(case, "1, 11, 11, 0, 2, 0, 17, 6, 7, 1,")
|
|
153
|
+
|
|
154
|
+
def test_newline_at_start_of_token(self) -> None:
|
|
155
|
+
"""Test newline at start of token."""
|
|
156
|
+
case = (
|
|
157
|
+
lspt.Position(line=5, character=21),
|
|
158
|
+
lspt.Position(line=5, character=21),
|
|
159
|
+
"\n ",
|
|
160
|
+
0,
|
|
161
|
+
"Newline at start of a token",
|
|
162
|
+
)
|
|
163
|
+
self.document_lines[5] = " return math.pi * "
|
|
164
|
+
self.document_lines.insert(6, " radius * radius;")
|
|
165
|
+
self.check_semantic_token_update(case, "0, 2, 1, 4, 6, 7, 1, 0")
|
|
166
|
+
|
|
167
|
+
def test_newline_after_parenthesis(self) -> None:
|
|
168
|
+
"""Test newline after parenthesis."""
|
|
169
|
+
case = (
|
|
170
|
+
lspt.Position(line=4, character=19),
|
|
171
|
+
lspt.Position(line=4, character=19),
|
|
172
|
+
"\n ",
|
|
173
|
+
0,
|
|
174
|
+
"Newline after parenthesis",
|
|
175
|
+
)
|
|
176
|
+
self.document_lines[4] = "can calculate_area("
|
|
177
|
+
self.document_lines.insert(5, " radius: float) -> float {")
|
|
178
|
+
self.check_semantic_token_update(case, "12, 1, 1, 4, 6, 7, 1, 0, 8")
|
|
179
|
+
|
|
180
|
+
def test_insert_newline_at_end_of_token(self) -> None:
|
|
181
|
+
"""Test insert newline at end of token."""
|
|
182
|
+
case = (
|
|
183
|
+
lspt.Position(line=5, character=27),
|
|
184
|
+
lspt.Position(line=5, character=27),
|
|
185
|
+
"\n ",
|
|
186
|
+
0,
|
|
187
|
+
"Insert Newline at end of a token",
|
|
188
|
+
)
|
|
189
|
+
self.document_lines[5] = " return math.pi * radius"
|
|
190
|
+
self.document_lines.insert(6, " * radius;")
|
|
191
|
+
self.check_semantic_token_update(case, "7, 1, 1, 7, 6, 7")
|
|
192
|
+
|
|
193
|
+
def test_deletion_basic(self) -> None:
|
|
194
|
+
"""Test deletion basic."""
|
|
195
|
+
case = (
|
|
196
|
+
lspt.Position(line=5, character=4),
|
|
197
|
+
lspt.Position(line=5, character=4),
|
|
198
|
+
"",
|
|
199
|
+
4,
|
|
200
|
+
"Deletion Basic",
|
|
201
|
+
)
|
|
202
|
+
self.check_semantic_token_update(case, "0, 10, 5, 2, 1, 1, 7, 4, 0, 2, 0")
|
|
203
|
+
|
|
204
|
+
def test_multiline_deletion(self) -> None:
|
|
205
|
+
"""Test multiline deletion."""
|
|
206
|
+
case = (
|
|
207
|
+
lspt.Position(line=3, character=49),
|
|
208
|
+
lspt.Position(line=4, character=0),
|
|
209
|
+
"",
|
|
210
|
+
4,
|
|
211
|
+
"Multiline Deletion",
|
|
212
|
+
)
|
|
213
|
+
self.document_lines[3] = (
|
|
214
|
+
'"""Function to calculate the area of a circle."""can calculate_area(radius: float) -> float {'
|
|
215
|
+
)
|
|
216
|
+
del self.document_lines[4]
|
|
217
|
+
self.check_semantic_token_update(case, "2, 2, 53, 14, 12, 1, 0")
|
|
218
|
+
|
|
219
|
+
def test_single_deletion_inside_token(self) -> None:
|
|
220
|
+
"""Test single deletion inside token."""
|
|
221
|
+
case = (
|
|
222
|
+
lspt.Position(line=5, character=12),
|
|
223
|
+
lspt.Position(line=5, character=13),
|
|
224
|
+
"",
|
|
225
|
+
1,
|
|
226
|
+
"single Deletion inside token",
|
|
227
|
+
)
|
|
228
|
+
self.check_semantic_token_update(case, "1, 1, 11, 3, 0, 2, 0, 9, 6")
|
|
229
|
+
|
|
230
|
+
def test_deletion_inside_token_selected_range(self) -> None:
|
|
231
|
+
"""Test deletion inside token selected range."""
|
|
232
|
+
case = (
|
|
233
|
+
lspt.Position(line=4, character=10),
|
|
234
|
+
lspt.Position(line=4, character=15),
|
|
235
|
+
"",
|
|
236
|
+
5,
|
|
237
|
+
"Deletion inside token- selected range",
|
|
238
|
+
)
|
|
239
|
+
self.check_semantic_token_update(case, "4, 9, 12, 1, 0, 10, 6")
|
|
240
|
+
|
|
241
|
+
def test_selected_multiline_deletion(self) -> None:
|
|
242
|
+
"""Test selected multiline deletion."""
|
|
243
|
+
case = (
|
|
244
|
+
lspt.Position(line=4, character=44),
|
|
245
|
+
lspt.Position(line=5, character=4),
|
|
246
|
+
"",
|
|
247
|
+
5,
|
|
248
|
+
"selected Multi line Deletion",
|
|
249
|
+
)
|
|
250
|
+
self.document_lines[3] = (
|
|
251
|
+
"can calculate_area(radius: float) -> float {return math.pi * radius * radius;"
|
|
252
|
+
)
|
|
253
|
+
del self.document_lines[4]
|
|
254
|
+
self.check_semantic_token_update(case, "4, 0, 2, 3, 4, 14, 12, 1, 0, 15")
|
|
255
|
+
|
|
256
|
+
def test_multi_line_insert_on_selected_region(self) -> None:
|
|
257
|
+
"""Test multi line insert on selected region."""
|
|
258
|
+
case = (
|
|
259
|
+
lspt.Position(line=4, character=26),
|
|
260
|
+
lspt.Position(line=4, character=27),
|
|
261
|
+
':= a + a // 2) > 5 {\n print("b is grater than 5");\n }',
|
|
262
|
+
1,
|
|
263
|
+
"multi line insert on selected region ",
|
|
264
|
+
)
|
|
265
|
+
self.document_lines = [
|
|
266
|
+
"",
|
|
267
|
+
"import:py math;",
|
|
268
|
+
"",
|
|
269
|
+
'"""Function to calculate the area of a circle."""',
|
|
270
|
+
"can calculate_area(radius::= a + a // 2) > 5 {",
|
|
271
|
+
' print("b is grater than 5");',
|
|
272
|
+
" }float) -> float {",
|
|
273
|
+
" return math.pi * radius * radius;",
|
|
274
|
+
"}",
|
|
275
|
+
" ",
|
|
276
|
+
]
|
|
277
|
+
self.check_semantic_token_update(case, " 2, 1, 2, 14, 5, 2, 1, 1, ")
|
|
@@ -103,7 +103,7 @@ class TestJacLangServer(TestCase):
|
|
|
103
103
|
lsp.lsp._workspace = workspace
|
|
104
104
|
circle_file = uris.from_fs_path(self.fixture_abs_path("circle_pure.jac"))
|
|
105
105
|
lsp.deep_check(circle_file)
|
|
106
|
-
self.assertEqual(8, len(lsp.
|
|
106
|
+
self.assertEqual(8, len(lsp.get_outline(circle_file)))
|
|
107
107
|
|
|
108
108
|
def test_go_to_definition(self) -> None:
|
|
109
109
|
"""Test that the go to definition is correct."""
|
|
@@ -119,7 +119,7 @@ class TestJacLangServer(TestCase):
|
|
|
119
119
|
)
|
|
120
120
|
self.assertIn(
|
|
121
121
|
"fixtures/circle_pure.jac:13:11-13:16",
|
|
122
|
-
str(lsp.get_definition(circle_file, lspt.Position(20,
|
|
122
|
+
str(lsp.get_definition(circle_file, lspt.Position(20, 16))),
|
|
123
123
|
)
|
|
124
124
|
|
|
125
125
|
def test_go_to_definition_method(self) -> None:
|
|
@@ -170,7 +170,7 @@ class TestJacLangServer(TestCase):
|
|
|
170
170
|
lsp.lsp._workspace = workspace
|
|
171
171
|
circle_file = uris.from_fs_path(self.fixture_abs_path("circle_pure.test.jac"))
|
|
172
172
|
lsp.deep_check(circle_file)
|
|
173
|
-
pos = lspt.Position(13,
|
|
173
|
+
pos = lspt.Position(13, 21)
|
|
174
174
|
self.assertIn(
|
|
175
175
|
"shape_type: circle_pure.ShapeType",
|
|
176
176
|
lsp.get_hover_info(circle_file, pos).contents.value,
|
|
@@ -187,7 +187,7 @@ class TestJacLangServer(TestCase):
|
|
|
187
187
|
)
|
|
188
188
|
lsp.deep_check(import_file)
|
|
189
189
|
positions = [
|
|
190
|
-
(2,
|
|
190
|
+
(2, 24, "datetime.py:0:0-0:0"),
|
|
191
191
|
(3, 17, "base_module_structure.jac:0:0-0:0"),
|
|
192
192
|
(3, 87, "base_module_structure.jac:23:0-23:5"),
|
|
193
193
|
(5, 65, "py_import.py:12:0-20:5"),
|
|
@@ -201,6 +201,62 @@ class TestJacLangServer(TestCase):
|
|
|
201
201
|
str(lsp.get_definition(import_file, lspt.Position(line, char))),
|
|
202
202
|
)
|
|
203
203
|
|
|
204
|
+
def test_go_to_definition_foolme(self) -> None:
|
|
205
|
+
"""Test that the go to definition is correct."""
|
|
206
|
+
lsp = JacLangServer()
|
|
207
|
+
workspace_path = self.fixture_abs_path("")
|
|
208
|
+
workspace = Workspace(workspace_path, lsp)
|
|
209
|
+
lsp.lsp._workspace = workspace
|
|
210
|
+
import_file = uris.from_fs_path(
|
|
211
|
+
self.fixture_abs_path(
|
|
212
|
+
"../../../../jaclang/compiler/passes/main/tests/fixtures/py_imp_test.jac"
|
|
213
|
+
)
|
|
214
|
+
)
|
|
215
|
+
lsp.deep_check(import_file)
|
|
216
|
+
positions = [
|
|
217
|
+
(6, 39, "/pygame_mock/__init__.py:2:0-2:0"),
|
|
218
|
+
(6, 45, "/pygame_mock/constants.py:3:0-4:1"),
|
|
219
|
+
(7, 31, "/pygame_mock/__init__.py:2:0-2:0"),
|
|
220
|
+
(7, 35, "/pygame_mock/constants.py:3:0-4:1"),
|
|
221
|
+
(20, 51, "/py_imp_test.jac:6:4-6:11"),
|
|
222
|
+
(20, 64, "/pygame_mock/constants.py:4:3-4:15"),
|
|
223
|
+
(21, 48, "/py_imp_test.jac:10:4-10:6"),
|
|
224
|
+
(21, 58, "/py_imp_test.jac:11:8-11:15"),
|
|
225
|
+
(21, 68, "/pygame_mock/constants.py:4:3-4:15"),
|
|
226
|
+
(23, 58, "/pygame_mock/constants.py:4:3-4:15"),
|
|
227
|
+
]
|
|
228
|
+
|
|
229
|
+
for line, char, expected in positions:
|
|
230
|
+
with self.subTest(line=line, char=char):
|
|
231
|
+
self.assertIn(
|
|
232
|
+
expected,
|
|
233
|
+
str(lsp.get_definition(import_file, lspt.Position(line, char))),
|
|
234
|
+
)
|
|
235
|
+
|
|
236
|
+
def test_go_to_definition_index_expr(self) -> None:
|
|
237
|
+
"""Test that the go to definition is correct."""
|
|
238
|
+
lsp = JacLangServer()
|
|
239
|
+
workspace_path = self.fixture_abs_path("")
|
|
240
|
+
workspace = Workspace(workspace_path, lsp)
|
|
241
|
+
lsp.lsp._workspace = workspace
|
|
242
|
+
import_file = uris.from_fs_path(
|
|
243
|
+
self.fixture_abs_path("../../../../jaclang/tests/fixtures/index_slice.jac")
|
|
244
|
+
)
|
|
245
|
+
lsp.deep_check(import_file)
|
|
246
|
+
positions = [
|
|
247
|
+
(23, 20, "index_slice.jac:2:8-2:13"),
|
|
248
|
+
(24, 24, "index_slice.jac:2:8-2:13"),
|
|
249
|
+
(27, 33, "index_slice.jac:2:8-2:13"),
|
|
250
|
+
]
|
|
251
|
+
|
|
252
|
+
for line, char, expected in positions:
|
|
253
|
+
with self.subTest(line=line, char=char):
|
|
254
|
+
print(str(lsp.get_definition(import_file, lspt.Position(line, char))))
|
|
255
|
+
self.assertIn(
|
|
256
|
+
expected,
|
|
257
|
+
str(lsp.get_definition(import_file, lspt.Position(line, char))),
|
|
258
|
+
)
|
|
259
|
+
|
|
204
260
|
def test_sem_tokens(self) -> None:
|
|
205
261
|
"""Test that the Semantic Tokens are generated correctly."""
|
|
206
262
|
lsp = JacLangServer()
|
|
@@ -214,7 +270,7 @@ class TestJacLangServer(TestCase):
|
|
|
214
270
|
("<JacSemTokenType.VARIABLE: 8>, <JacSemTokenModifier.READONLY: 4>", 12),
|
|
215
271
|
(
|
|
216
272
|
"<JacSemTokenType.PROPERTY: 9>, <JacSemTokenModifier.DEFINITION: 2>,",
|
|
217
|
-
|
|
273
|
+
21,
|
|
218
274
|
),
|
|
219
275
|
(
|
|
220
276
|
"<JacSemTokenType.PARAMETER: 7>, <JacSemTokenModifier.DECLARATION: 1>,",
|
|
@@ -222,7 +278,7 @@ class TestJacLangServer(TestCase):
|
|
|
222
278
|
),
|
|
223
279
|
(
|
|
224
280
|
"<JacSemTokenType.FUNCTION: 12>, <JacSemTokenModifier.DECLARATION: 1>,",
|
|
225
|
-
|
|
281
|
+
6,
|
|
226
282
|
),
|
|
227
283
|
("<JacSemTokenType.METHOD: 13>, <JacSemTokenModifier.DECLARATION: 1>", 6),
|
|
228
284
|
("<JacSemTokenType.ENUM: 3>, <JacSemTokenModifier.DECLARATION: 1>,", 4),
|
|
@@ -246,32 +302,87 @@ class TestJacLangServer(TestCase):
|
|
|
246
302
|
)
|
|
247
303
|
lsp.deep_check(base_module_file)
|
|
248
304
|
test_cases = [
|
|
249
|
-
(lspt.Position(
|
|
305
|
+
(lspt.Position(38, 16), ["get_color1", "color1", "point1"], 3),
|
|
306
|
+
(lspt.Position(42, 22), ["RED", "GREEN", "BLUE"], 3),
|
|
307
|
+
(lspt.Position(42, 33), ["RED", "GREEN", "BLUE"], 3),
|
|
308
|
+
(lspt.Position(42, 45), ["RED", "GREEN", "BLUE"], 3),
|
|
309
|
+
(lspt.Position(46, 20), ["RED22", "GREEN22", "BLUE22"], 3),
|
|
310
|
+
(lspt.Position(46, 30), ["RED22", "GREEN22", "BLUE22"], 3),
|
|
311
|
+
(lspt.Position(46, 41), ["RED22", "GREEN22", "BLUE22"], 3),
|
|
250
312
|
(
|
|
251
|
-
lspt.Position(51,
|
|
313
|
+
lspt.Position(51, 32),
|
|
314
|
+
["RED22", "GREEN22", "BLUE22"],
|
|
315
|
+
3,
|
|
316
|
+
),
|
|
317
|
+
(
|
|
318
|
+
lspt.Position(65, 13),
|
|
252
319
|
[
|
|
253
320
|
"get_color1",
|
|
254
321
|
"color1",
|
|
255
322
|
"point1",
|
|
256
323
|
"base_colorred",
|
|
257
324
|
"pointred",
|
|
258
|
-
"
|
|
325
|
+
"inner_red",
|
|
326
|
+
"doubleinner",
|
|
327
|
+
"apply_red",
|
|
259
328
|
],
|
|
260
|
-
|
|
329
|
+
8,
|
|
330
|
+
),
|
|
331
|
+
(
|
|
332
|
+
lspt.Position(65, 23),
|
|
333
|
+
["color22", "doublepoint22", "point22", "apply_inner_red", "enum_red"],
|
|
334
|
+
5,
|
|
335
|
+
),
|
|
336
|
+
(
|
|
337
|
+
lspt.Position(65, 31),
|
|
338
|
+
["RED22", "GREEN22", "BLUE22"],
|
|
339
|
+
3,
|
|
340
|
+
),
|
|
341
|
+
(
|
|
342
|
+
lspt.Position(35, 28),
|
|
343
|
+
[],
|
|
344
|
+
0,
|
|
345
|
+
),
|
|
346
|
+
(
|
|
347
|
+
lspt.Position(72, 12),
|
|
348
|
+
[
|
|
349
|
+
"get_color1",
|
|
350
|
+
"color1",
|
|
351
|
+
"point1",
|
|
352
|
+
"base_colorred",
|
|
353
|
+
"pointred",
|
|
354
|
+
"inner_red",
|
|
355
|
+
"doubleinner",
|
|
356
|
+
"apply_red",
|
|
357
|
+
],
|
|
358
|
+
8,
|
|
359
|
+
),
|
|
360
|
+
(
|
|
361
|
+
lspt.Position(73, 22),
|
|
362
|
+
["color22", "doublepoint22", "apply_inner_red", "point22", "enum_red"],
|
|
363
|
+
5,
|
|
364
|
+
),
|
|
365
|
+
(
|
|
366
|
+
lspt.Position(37, 12),
|
|
367
|
+
["self", "add", "subtract", "x", "Colorenum", "Colour1", "red", "r"],
|
|
368
|
+
8,
|
|
369
|
+
None,
|
|
261
370
|
),
|
|
262
|
-
(lspt.Position(52, 19), ["color22", "point22"], 2),
|
|
263
371
|
]
|
|
264
|
-
|
|
372
|
+
default_trigger = "."
|
|
373
|
+
for case in test_cases:
|
|
374
|
+
position, expected_completions, expected_length = case[:3]
|
|
375
|
+
completion_trigger = case[3] if len(case) > 3 else default_trigger
|
|
265
376
|
completions = lsp.get_completion(
|
|
266
|
-
base_module_file, position, completion_trigger=
|
|
377
|
+
base_module_file, position, completion_trigger=completion_trigger
|
|
267
378
|
).items
|
|
268
379
|
for completion in expected_completions:
|
|
269
380
|
self.assertIn(completion, str(completions))
|
|
270
381
|
self.assertEqual(expected_length, len(completions))
|
|
271
382
|
|
|
272
|
-
if position == lspt.Position(
|
|
383
|
+
if position == lspt.Position(73, 12):
|
|
273
384
|
self.assertEqual(
|
|
274
|
-
|
|
385
|
+
2, str(completions).count("kind=<CompletionItemKind.Function: 3>")
|
|
275
386
|
)
|
|
276
387
|
self.assertEqual(
|
|
277
388
|
4, str(completions).count("kind=<CompletionItemKind.Field: 5>")
|
|
@@ -288,10 +399,169 @@ class TestJacLangServer(TestCase):
|
|
|
288
399
|
lsp.deep_check(circle_file)
|
|
289
400
|
test_cases = [
|
|
290
401
|
(47, 12, ["circle.jac:47:8-47:14", "69:8-69:14", "74:8-74:14"]),
|
|
291
|
-
(54, 66, ["54:62-54:76", "65:
|
|
292
|
-
(62, 14, ["65:
|
|
402
|
+
(54, 66, ["54:62-54:76", "65:22-65:36"]),
|
|
403
|
+
(62, 14, ["65:43-65:56", "70:32-70:45"]),
|
|
404
|
+
]
|
|
405
|
+
for line, char, expected_refs in test_cases:
|
|
406
|
+
references = str(lsp.get_references(circle_file, lspt.Position(line, char)))
|
|
407
|
+
for expected in expected_refs:
|
|
408
|
+
self.assertIn(expected, references)
|
|
409
|
+
|
|
410
|
+
def test_py_type__definition(self) -> None:
|
|
411
|
+
"""Test that the go to definition is correct for pythoon imports."""
|
|
412
|
+
lsp = JacLangServer()
|
|
413
|
+
workspace_path = self.fixture_abs_path("")
|
|
414
|
+
workspace = Workspace(workspace_path, lsp)
|
|
415
|
+
lsp.lsp._workspace = workspace
|
|
416
|
+
import_file = uris.from_fs_path(
|
|
417
|
+
self.fixture_abs_path(
|
|
418
|
+
"../../../../jaclang/compiler/passes/main/tests/fixtures/py_imp_test.jac"
|
|
419
|
+
)
|
|
420
|
+
)
|
|
421
|
+
lsp.deep_check(import_file)
|
|
422
|
+
positions = [
|
|
423
|
+
(19, 29, "pygame_mock/color.py:0:0-2:4"),
|
|
424
|
+
(3, 17, "/pygame_mock/__init__.py:0:0-0:0"),
|
|
425
|
+
(20, 45, "pygame_mock/color.py:0:0-2:4"),
|
|
426
|
+
(19, 77, "mock/constants.py:4:3-4:15"),
|
|
427
|
+
(26, 28, "mock/display.py:0:0-1:7"),
|
|
428
|
+
(24, 22, "/argparse.pyi:124:0-249:13"),
|
|
429
|
+
(19, 74, "pygame_mock/constants.py:4:3-4:15"),
|
|
430
|
+
(27, 17, "/stdlib/os/__init__.pyi:50:0-50:3"),
|
|
431
|
+
]
|
|
432
|
+
|
|
433
|
+
for line, char, expected in positions:
|
|
434
|
+
with self.subTest(line=line, char=char):
|
|
435
|
+
self.assertIn(
|
|
436
|
+
expected,
|
|
437
|
+
str(lsp.get_definition(import_file, lspt.Position(line, char))),
|
|
438
|
+
)
|
|
439
|
+
|
|
440
|
+
def test_py_type__references(self) -> None:
|
|
441
|
+
"""Test that the go to definition is correct for pythoon imports."""
|
|
442
|
+
lsp = JacLangServer()
|
|
443
|
+
workspace_path = self.fixture_abs_path("")
|
|
444
|
+
workspace = Workspace(workspace_path, lsp)
|
|
445
|
+
lsp.lsp._workspace = workspace
|
|
446
|
+
|
|
447
|
+
circle_file = uris.from_fs_path(
|
|
448
|
+
self.fixture_abs_path(
|
|
449
|
+
"../../../../jaclang/compiler/passes/main/tests/fixtures/py_imp_test.jac"
|
|
450
|
+
)
|
|
451
|
+
)
|
|
452
|
+
lsp.deep_check(circle_file)
|
|
453
|
+
test_cases = [
|
|
454
|
+
(
|
|
455
|
+
2,
|
|
456
|
+
21,
|
|
457
|
+
[
|
|
458
|
+
":6:21-6:32",
|
|
459
|
+
":7:11-7:22",
|
|
460
|
+
":11:25-11:36",
|
|
461
|
+
":12:15-12:26",
|
|
462
|
+
":18:33-18:44",
|
|
463
|
+
"19:46-19:57",
|
|
464
|
+
":19:8-19:19",
|
|
465
|
+
":19:46-19:57",
|
|
466
|
+
":20:8-20:19",
|
|
467
|
+
"21:8-21:19,",
|
|
468
|
+
"23:8-23:19",
|
|
469
|
+
":26:4-26:15",
|
|
470
|
+
],
|
|
471
|
+
),
|
|
472
|
+
(
|
|
473
|
+
19,
|
|
474
|
+
63,
|
|
475
|
+
[
|
|
476
|
+
"6:33-6:42",
|
|
477
|
+
"7:23-7:32",
|
|
478
|
+
"18:45-18:54",
|
|
479
|
+
"19:58-19:67",
|
|
480
|
+
"11:37-11:46",
|
|
481
|
+
"12:27-12:36",
|
|
482
|
+
],
|
|
483
|
+
),
|
|
484
|
+
(
|
|
485
|
+
24,
|
|
486
|
+
53,
|
|
487
|
+
[
|
|
488
|
+
"24:42-24:56",
|
|
489
|
+
"24:16-24:30",
|
|
490
|
+
"argparse.pyi:334:21-334:35",
|
|
491
|
+
"argparse.pyi:163:29-163:43",
|
|
492
|
+
"argparse.pyi:32:52-32:66",
|
|
493
|
+
],
|
|
494
|
+
),
|
|
293
495
|
]
|
|
294
496
|
for line, char, expected_refs in test_cases:
|
|
295
497
|
references = str(lsp.get_references(circle_file, lspt.Position(line, char)))
|
|
296
498
|
for expected in expected_refs:
|
|
297
499
|
self.assertIn(expected, references)
|
|
500
|
+
|
|
501
|
+
def test_rename_symbol(self) -> None:
|
|
502
|
+
"""Test that the rename is correct."""
|
|
503
|
+
lsp = JacLangServer()
|
|
504
|
+
workspace_path = self.fixture_abs_path("")
|
|
505
|
+
workspace = Workspace(workspace_path, lsp)
|
|
506
|
+
lsp.lsp._workspace = workspace
|
|
507
|
+
|
|
508
|
+
circle_file = uris.from_fs_path(self.fixture_abs_path("circle.jac"))
|
|
509
|
+
lsp.deep_check(circle_file)
|
|
510
|
+
test_cases = [
|
|
511
|
+
(
|
|
512
|
+
20,
|
|
513
|
+
14,
|
|
514
|
+
"ShapeKind",
|
|
515
|
+
"27:20-27:29,",
|
|
516
|
+
"36:19-36:28",
|
|
517
|
+
"75:26-75:35",
|
|
518
|
+
"20:5-20:14",
|
|
519
|
+
),
|
|
520
|
+
(12, 34, "circleRadius", "12:21-12:27", "12:30-12:36", "11:19-11:25"),
|
|
521
|
+
(62, 14, "target_area", "65:43-65:56", "70:32-70:45", "62:5-62:18"),
|
|
522
|
+
(57, 33, "type_of_shape", "75:12-75:22", "27:8-27:18,", "57:23-57:33"),
|
|
523
|
+
]
|
|
524
|
+
for tup in test_cases:
|
|
525
|
+
line, char, new_name, *expected_refs = tup
|
|
526
|
+
references = str(
|
|
527
|
+
lsp.rename_symbol(circle_file, lspt.Position(line, char), new_name)
|
|
528
|
+
)
|
|
529
|
+
for expected in expected_refs:
|
|
530
|
+
self.assertIn(expected, references)
|
|
531
|
+
|
|
532
|
+
def test_rename_uses(self) -> None:
|
|
533
|
+
"""Test that the rename is correct."""
|
|
534
|
+
lsp = JacLangServer()
|
|
535
|
+
workspace_path = self.fixture_abs_path("")
|
|
536
|
+
workspace = Workspace(workspace_path, lsp)
|
|
537
|
+
lsp.lsp._workspace = workspace
|
|
538
|
+
|
|
539
|
+
circle_file = uris.from_fs_path(self.fixture_abs_path("rename.jac"))
|
|
540
|
+
lsp.deep_check(circle_file)
|
|
541
|
+
# fmt: off
|
|
542
|
+
test_cases = [
|
|
543
|
+
(0, 7, "func", "25:4-25:7", "0:4-0:7", "4:5-4:8",),
|
|
544
|
+
(4, 6, "func", "25:4-25:7", "0:4-0:7", "4:5-4:8",),
|
|
545
|
+
(25, 7, "func", "25:4-25:7", "0:4-0:7", "4:5-4:8",),
|
|
546
|
+
(10, 10, "canBar", "27:8-27:11", "10:8-10:11"),
|
|
547
|
+
(27, 9, "canBar", "27:8-27:11", "10:8-10:11"),
|
|
548
|
+
(9, 6, "canBar", "26:10-26:13", "28:4-28:7", "16:5-16:8", "9:4-9:7"),
|
|
549
|
+
(26, 11, "canBar", "26:10-26:13", "28:4-28:7", "16:5-16:8", "9:4-9:7"),
|
|
550
|
+
(16, 7, "canBar", "26:10-26:13", "28:4-28:7", "16:5-16:8", "9:4-9:7"),
|
|
551
|
+
(28, 6, "canBar", "26:10-26:13", "28:4-28:7", "16:5-16:8", "9:4-9:7"),
|
|
552
|
+
(11, 10, "canBar", "11:8-11:11", "16:13-16:16", "28:11-28:14"),
|
|
553
|
+
(16, 14, "canBar", "11:8-11:11", "16:13-16:16", "28:11-28:14"),
|
|
554
|
+
(28, 13, "canBar", "11:8-11:11", "16:13-16:16", "28:11-28:14"),
|
|
555
|
+
(12, 10, "canBaz", "12:8-12:11", "20:13-20:16"),
|
|
556
|
+
(20, 14, "canBaz", "12:8-12:11", "20:13-20:16"),
|
|
557
|
+
(26, 6, "count", "27:4-27:7", "26:4-26:7"),
|
|
558
|
+
(27, 5, "count", "27:4-27:7", "26:4-26:7"),
|
|
559
|
+
]
|
|
560
|
+
# fmt: on
|
|
561
|
+
for tup in test_cases:
|
|
562
|
+
line, char, new_name, *expected_refs = tup
|
|
563
|
+
references = str(
|
|
564
|
+
lsp.rename_symbol(circle_file, lspt.Position(line, char), new_name)
|
|
565
|
+
)
|
|
566
|
+
for expected in expected_refs:
|
|
567
|
+
self.assertIn(expected, references)
|