From 0f4931247a6f1c1fd1e9841750afbf8360d20b62 Mon Sep 17 00:00:00 2001 From: kugesan1105 Date: Sat, 31 Aug 2024 04:49:21 +0530 Subject: [PATCH] test updated for renaming symbols and PR cleanup --- .../passes/main/fuse_typeinfo_pass.py | 10 ------- .../passes/main/pyjac_ast_link_pass.py | 1 - jaclang/langserve/engine.py | 9 ++---- jaclang/langserve/tests/fixtures/rename.jac | 5 +++- jaclang/langserve/tests/test_server.py | 28 +++++++++++-------- 5 files changed, 22 insertions(+), 31 deletions(-) diff --git a/jaclang/compiler/passes/main/fuse_typeinfo_pass.py b/jaclang/compiler/passes/main/fuse_typeinfo_pass.py index 8301c5c7d..db7de9a5c 100644 --- a/jaclang/compiler/passes/main/fuse_typeinfo_pass.py +++ b/jaclang/compiler/passes/main/fuse_typeinfo_pass.py @@ -500,15 +500,6 @@ def exit_atom_trailer(self, node: ast.AtomTrailer) -> None: """Adding symbol links to AtomTrailer right nodes.""" # This will fix adding the symbol links to nodes in atom trailer # self.x.z = 5 # will add symbol links to both x and z - for i in range(1, len(node.as_attr_list)): - left = node.as_attr_list[i - 1] - right = node.as_attr_list[i] - # assert isinstance(left, ast.NameAtom) - # assert isinstance(right, ast.NameAtom) - if left.type_sym_tab and not isinstance( - right, ast.IndexSlice - ): # TODO check why IndexSlice produce an issue - right.name_spec.sym = left.type_sym_tab.lookup(right.sym_name) # This function originally used `as_attr_list` in AtomTrailer # but an issue happened when doing stuff like fool_me().CONST_VALUE2 @@ -524,7 +515,6 @@ def exit_atom_trailer(self, node: ast.AtomTrailer) -> None: iteration_count += 1 if iteration_count > 50: break - # print(1234,'atom_trailer_unwind',atom_trailer_unwind) for i in range(1, len(atom_trailer_unwind)): left = atom_trailer_unwind[i - 1] right = atom_trailer_unwind[i] diff --git a/jaclang/compiler/passes/main/pyjac_ast_link_pass.py b/jaclang/compiler/passes/main/pyjac_ast_link_pass.py index e2d3a48db..f25f4ac8e 100644 --- a/jaclang/compiler/passes/main/pyjac_ast_link_pass.py +++ b/jaclang/compiler/passes/main/pyjac_ast_link_pass.py @@ -162,7 +162,6 @@ def exit_ability_def(self, node: ast.AbilityDef) -> None: jac_node=node.signature.return_type, py_nodes=node.parent.signature.return_type.gen.py_ast, ) - """Enter ability definition.""" if isinstance(node.decl_link, ast.Ability) and isinstance( node.target, ast.ArchRefChain diff --git a/jaclang/langserve/engine.py b/jaclang/langserve/engine.py index 88686d6f9..bffea3ef5 100644 --- a/jaclang/langserve/engine.py +++ b/jaclang/langserve/engine.py @@ -14,7 +14,6 @@ from jaclang.compiler.passes import Pass from jaclang.compiler.passes.main.schedules import py_code_gen_typed from jaclang.compiler.passes.tool import FuseCommentsPass, JacFormatPass -from jaclang.compiler.symtable import Symbol from jaclang.langserve.sem_manager import SemTokManager from jaclang.langserve.utils import ( add_unique_text_edit, @@ -429,14 +428,10 @@ def rename_symbol( if index1 is None: return None node_selected = self.modules[file_path].sem_manager.static_sem_tokens[index1][3] - if ( - node_selected - and node_selected.sym - and isinstance(node_selected.sym.decl.sym, Symbol) - ): + if node_selected and node_selected.sym: changes: dict[str, list[lspt.TextEdit]] = {} for node in [ - *node_selected.sym.decl.sym.uses, + *node_selected.sym.uses, node_selected.sym.defn[0], ]: key = uris.from_fs_path(node.loc.mod_path) diff --git a/jaclang/langserve/tests/fixtures/rename.jac b/jaclang/langserve/tests/fixtures/rename.jac index 72aaaa48d..ab1266410 100644 --- a/jaclang/langserve/tests/fixtures/rename.jac +++ b/jaclang/langserve/tests/fixtures/rename.jac @@ -8,6 +8,7 @@ can foo; obj out{ + has cnt :int; can bar; can baz; } @@ -23,5 +24,7 @@ obj out{ with entry{ foo(); - out().bar(); + new = out(); + new.cnt; + out(1).bar(); } \ No newline at end of file diff --git a/jaclang/langserve/tests/test_server.py b/jaclang/langserve/tests/test_server.py index 57b3ea9a8..79f7a90e4 100644 --- a/jaclang/langserve/tests/test_server.py +++ b/jaclang/langserve/tests/test_server.py @@ -540,18 +540,22 @@ def test_rename_uses(self) -> None: lsp.deep_check(circle_file) # fmt: off test_cases = [ - (0, 7, "func", "24:4-24:7", "0:4-0:7", "4:5-4:8",), - (4, 6, "func", "24:4-24:7", "0:4-0:7", "4:5-4:8",), - (24, 7, "func", "24:4-24:7", "0:4-0:7", "4:5-4:8",), - (10, 10, "canBar", "10:8-10:11", "15:13-15:16", ), # until merge fool me - (15, 15, "ubar", "15:13-15:16", "10:8-10:11" ), # until merge fool me - # (10, 10, "canBar", "10:8-10:11", "14:13-14:16", "21....",), # True - # (14, 15, "ubar", "14:13-14:16", "10:8-10:11", "21......" ), # True - (9, 7, "result", "9:4-9:7", "25:4-25:7", "15:5-15:8", "15:5-15:8",), - (15, 7, "result", "9:4-9:7", "25:4-25:7", "15:5-15:8",), - (25, 7, "result", "9:4-9:7", "25:4-25:7", "15:5-15:8",), - (25, 7, "result", "9:4-9:7", "25:4-25:7", "15:5-15:8",), - (25, 7, "result", "9:4-9:7", "25:4-25:7", "15:5-15:8",), + (0, 7, "func", "25:4-25:7", "0:4-0:7", "4:5-4:8",), + (4, 6, "func", "25:4-25:7", "0:4-0:7", "4:5-4:8",), + (25, 7, "func", "25:4-25:7", "0:4-0:7", "4:5-4:8",), + (10, 10, "canBar", "27:8-27:11", "10:8-10:11"), + (27, 9, "canBar", "27:8-27:11", "10:8-10:11"), + (9, 6, "canBar", "26:10-26:13", "28:4-28:7", "16:5-16:8", "9:4-9:7"), + (26, 11, "canBar", "26:10-26:13", "28:4-28:7", "16:5-16:8", "9:4-9:7"), + (16, 7, "canBar", "26:10-26:13", "28:4-28:7", "16:5-16:8", "9:4-9:7"), + (28, 6, "canBar", "26:10-26:13", "28:4-28:7", "16:5-16:8", "9:4-9:7"), + (11, 10, "canBar", "11:8-11:11", "16:13-16:16", "28:11-28:14"), + (16, 14, "canBar", "11:8-11:11", "16:13-16:16", "28:11-28:14"), + (28, 13, "canBar", "11:8-11:11", "16:13-16:16", "28:11-28:14"), + (12, 10, "canBaz", "12:8-12:11", "20:13-20:16"), + (20, 14, "canBaz", "12:8-12:11", "20:13-20:16"), + (26, 6, "count", "27:4-27:7", "26:4-26:7"), + (27, 5, "count", "27:4-27:7", "26:4-26:7"), ] # fmt: on for tup in test_cases: