From 8755386a019179f425f558adf3f7d3edcf713f07 Mon Sep 17 00:00:00 2001 From: kugesan1105 Date: Mon, 26 Aug 2024 20:02:12 +0530 Subject: [PATCH 1/7] fix: missing uses for atom_trailer --- .../passes/main/fuse_typeinfo_pass.py | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/jaclang/compiler/passes/main/fuse_typeinfo_pass.py b/jaclang/compiler/passes/main/fuse_typeinfo_pass.py index 8e44c5313..fb59ba44f 100644 --- a/jaclang/compiler/passes/main/fuse_typeinfo_pass.py +++ b/jaclang/compiler/passes/main/fuse_typeinfo_pass.py @@ -6,7 +6,7 @@ from __future__ import annotations -from typing import Callable, TypeVar +from typing import Callable, Optional, TypeVar import jaclang.compiler.absyntree as ast from jaclang.compiler.passes import Pass @@ -489,3 +489,28 @@ def exit_atom_trailer(self, node: ast.AtomTrailer) -> None: right, ast.IndexSlice ): # TODO check why IndexSlice produce an issue right.name_spec.sym = left.type_sym_tab.lookup(right.sym_name) + + def find_tab(tab: ast.SymbolTable, name: str) -> Optional[ast.SymbolTable]: + """Recursively find symbol table from sym dotted name.""" + tab_list = name.split(".") + if len(tab_list) == 1: + return tab + else: + if tab_list[0] == tab.name: + return find_tab(tab, ".".join(tab_list[1:])) + else: + for child in tab.kid: + if child.name == tab_list[0]: + return find_tab(child, ".".join(tab_list[1:])) + return None + + for name_node in node.as_attr_list: + tab = ( + find_tab(self.ir.sym_tab, name_node.sym.sym_dotted_name) + if name_node.sym + else None + ) + if tab: + find_symbol = tab.lookup(name_node.sym_name) + if find_symbol and name_node not in find_symbol.uses: + find_symbol.add_use(name_node.name_spec) From 7342fbca198319a1a5080e7b451433aa18348325 Mon Sep 17 00:00:00 2001 From: kugesan1105 Date: Mon, 26 Aug 2024 20:15:32 +0530 Subject: [PATCH 2/7] Test updated to check the functionality of uses of atom trailer names --- jaclang/langserve/tests/test_server.py | 1 + 1 file changed, 1 insertion(+) diff --git a/jaclang/langserve/tests/test_server.py b/jaclang/langserve/tests/test_server.py index 9d8af2fc0..437c4a3ab 100644 --- a/jaclang/langserve/tests/test_server.py +++ b/jaclang/langserve/tests/test_server.py @@ -446,6 +446,7 @@ def test_rename_symbol(self) -> None: ), (12, 34, "circleRadius", "12:21-12:27", "12:30-12:36", "11:19-11:25"), (62, 14, "target_area", "65:43-65:56", "70:32-70:45", "62:5-62:18"), + (57, 33, "type_of_shape", "75:12-75:22", "27:8-27:18,", "57:23-57:33"), ] for tup in test_cases: line, char, new_name, *expected_refs = tup From 03fa63ccebc0883d80af8ea7b26410bc66a27026 Mon Sep 17 00:00:00 2001 From: kugesan1105 Date: Wed, 28 Aug 2024 16:19:24 +0530 Subject: [PATCH 3/7] Fix :Supporting renaming related to archrefchain --- jaclang/langserve/engine.py | 42 ++++++++++----------- jaclang/langserve/tests/fixtures/rename.jac | 23 +++++++++++ jaclang/langserve/utils.py | 28 ++++++++++++++ 3 files changed, 71 insertions(+), 22 deletions(-) create mode 100644 jaclang/langserve/tests/fixtures/rename.jac diff --git a/jaclang/langserve/engine.py b/jaclang/langserve/engine.py index 0c7a3e64a..ec03f8dd4 100644 --- a/jaclang/langserve/engine.py +++ b/jaclang/langserve/engine.py @@ -16,7 +16,9 @@ from jaclang.compiler.passes.tool import FuseCommentsPass, JacFormatPass from jaclang.langserve.sem_manager import SemTokManager from jaclang.langserve.utils import ( + add_unique_text_edit, collect_all_symbols_in_scope, + collect_linkage_symbol, create_range, find_deepest_symbol_node_at_pos, find_index, @@ -363,17 +365,7 @@ def get_definition( return None elif isinstance(node_selected, (ast.ElementStmt, ast.BuiltinType)): return None - decl_node = ( - node_selected.parent.body.target - if node_selected.parent - and isinstance(node_selected.parent, ast.AstImplNeedingNode) - and isinstance(node_selected.parent.body, ast.AstImplOnlyNode) - else ( - node_selected.sym.decl - if (node_selected.sym and node_selected.sym.decl) - else node_selected - ) - ) + decl_node = collect_linkage_symbol(node_selected) decl_uri = uris.from_fs_path(decl_node.loc.mod_path) try: decl_range = create_range(decl_node.loc) @@ -428,19 +420,25 @@ def rename_symbol( return None node_selected = self.modules[file_path].sem_manager.static_sem_tokens[index1][3] if node_selected and node_selected.sym: + xx = collect_linkage_symbol(node_selected) + decl_node = ( + xx.archs[0].arch_name + if isinstance(xx, ast.ArchRefChain) + else node_selected + ) changes: dict[str, list[lspt.TextEdit]] = {} - for node in [*node_selected.sym.uses, node_selected.sym.defn[0]]: + for node in [ + *node_selected.sym.uses, + node_selected.sym.defn[0], + decl_node, + node_selected, + ]: key = uris.from_fs_path(node.loc.mod_path) - value = [ - lspt.TextEdit( - range=create_range(node.loc), - new_text=new_name, - ) - ] - if key in changes: - changes[key].extend(value) - else: - changes[key] = value + new_edit = lspt.TextEdit( + range=create_range(node.loc), + new_text=new_name, + ) + add_unique_text_edit(changes, key, new_edit) return lspt.WorkspaceEdit(changes=changes) return None diff --git a/jaclang/langserve/tests/fixtures/rename.jac b/jaclang/langserve/tests/fixtures/rename.jac new file mode 100644 index 000000000..d469ed7be --- /dev/null +++ b/jaclang/langserve/tests/fixtures/rename.jac @@ -0,0 +1,23 @@ +can foo; + + + +:can:foo{ + print("foo"); +} + + +obj out{ + can bar; +} + + +:obj:out:can:bar{ + print("bar"); +} + + +with entry{ + foo(); + out().bar(); +} \ No newline at end of file diff --git a/jaclang/langserve/utils.py b/jaclang/langserve/utils.py index 92bace0cf..f90b260f9 100644 --- a/jaclang/langserve/utils.py +++ b/jaclang/langserve/utils.py @@ -625,3 +625,31 @@ def get_line_of_code(line_number: int, lines: list[str]) -> Optional[tuple[str, else first_non_space ) return None + + +def add_unique_text_edit( + changes: dict[str, list[lspt.TextEdit]], key: str, new_edit: lspt.TextEdit +) -> None: + """Add a new text edit to the changes dictionary if it is unique.""" + if key not in changes: + changes[key] = [new_edit] + else: + for existing_edit in changes[key]: + if ( + existing_edit.range.start == new_edit.range.start + and existing_edit.range.end == new_edit.range.end + and existing_edit.new_text == new_edit.new_text + ): + return + changes[key].append(new_edit) + + +def collect_linkage_symbol(node: ast.AstSymbolNode) -> ast.AstNode: + """Collect the symbol node that is linked to the symbol node.""" + return ( + node.parent.body.target + if node.parent + and isinstance(node.parent, ast.AstImplNeedingNode) + and isinstance(node.parent.body, ast.AstImplOnlyNode) + else (node.sym.decl if (node.sym and node.sym.decl) else node) + ) From b865be26d737cad1d289b87bab740672b395e9e7 Mon Sep 17 00:00:00 2001 From: kugesan1105 Date: Wed, 28 Aug 2024 22:43:39 +0530 Subject: [PATCH 4/7] Fix: rename symbol issues related to imple nodes and Test added --- jaclang/langserve/engine.py | 12 +++---- jaclang/langserve/tests/fixtures/rename.jac | 4 +++ jaclang/langserve/tests/test_server.py | 33 +++++++++++++++++++ jaclang/langserve/utils.py | 36 +++++++++++++++++++++ 4 files changed, 77 insertions(+), 8 deletions(-) diff --git a/jaclang/langserve/engine.py b/jaclang/langserve/engine.py index ec03f8dd4..e74b316f3 100644 --- a/jaclang/langserve/engine.py +++ b/jaclang/langserve/engine.py @@ -18,6 +18,7 @@ from jaclang.langserve.utils import ( add_unique_text_edit, collect_all_symbols_in_scope, + collect_impl_nodes, collect_linkage_symbol, create_range, find_deepest_symbol_node_at_pos, @@ -420,18 +421,13 @@ def rename_symbol( return None node_selected = self.modules[file_path].sem_manager.static_sem_tokens[index1][3] if node_selected and node_selected.sym: - xx = collect_linkage_symbol(node_selected) - decl_node = ( - xx.archs[0].arch_name - if isinstance(xx, ast.ArchRefChain) - else node_selected - ) + impl_node_uses, archi_name_uses = collect_impl_nodes(node_selected) changes: dict[str, list[lspt.TextEdit]] = {} for node in [ *node_selected.sym.uses, node_selected.sym.defn[0], - decl_node, - node_selected, + *impl_node_uses, + *archi_name_uses, ]: key = uris.from_fs_path(node.loc.mod_path) new_edit = lspt.TextEdit( diff --git a/jaclang/langserve/tests/fixtures/rename.jac b/jaclang/langserve/tests/fixtures/rename.jac index d469ed7be..72aaaa48d 100644 --- a/jaclang/langserve/tests/fixtures/rename.jac +++ b/jaclang/langserve/tests/fixtures/rename.jac @@ -9,6 +9,7 @@ can foo; obj out{ can bar; + can baz; } @@ -16,6 +17,9 @@ obj out{ print("bar"); } +:obj:out:can:baz{ + print("baz"); +} with entry{ foo(); diff --git a/jaclang/langserve/tests/test_server.py b/jaclang/langserve/tests/test_server.py index 437c4a3ab..7cad3966e 100644 --- a/jaclang/langserve/tests/test_server.py +++ b/jaclang/langserve/tests/test_server.py @@ -455,3 +455,36 @@ def test_rename_symbol(self) -> None: ) for expected in expected_refs: self.assertIn(expected, references) + + def test_rename_uses(self) -> None: + """Test that the rename is correct.""" + lsp = JacLangServer() + workspace_path = self.fixture_abs_path("") + workspace = Workspace(workspace_path, lsp) + lsp.lsp._workspace = workspace + + circle_file = uris.from_fs_path(self.fixture_abs_path("rename.jac")) + 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",), + ] + # fmt: on + for tup in test_cases: + line, char, new_name, *expected_refs = tup + references = str( + lsp.rename_symbol(circle_file, lspt.Position(line, char), new_name) + ) + for expected in expected_refs: + self.assertIn(expected, references) diff --git a/jaclang/langserve/utils.py b/jaclang/langserve/utils.py index f90b260f9..ca2b728bd 100644 --- a/jaclang/langserve/utils.py +++ b/jaclang/langserve/utils.py @@ -653,3 +653,39 @@ def collect_linkage_symbol(node: ast.AstSymbolNode) -> ast.AstNode: and isinstance(node.parent.body, ast.AstImplOnlyNode) else (node.sym.decl if (node.sym and node.sym.decl) else node) ) + + +def collect_impl_nodes( + node: ast.AstSymbolNode, +) -> tuple[list[ast.AstNode], list[ast.NameAtom]]: + """Collect nodes that are linked to impl node.""" + if not node.sym: + return [], [] + linkage_node = collect_linkage_symbol(node) + decl_linkage_node = collect_linkage_symbol(node.sym.decl) + symbol_type = node.sym.sym_type + referenced_nodes = [] + if symbol_type == SymbolType.OBJECT_ARCH and isinstance( + node.sym.decl.sym_tab.owner, ast.Architype + ): + archi_node: ast.Architype = node.sym.decl.sym_tab.owner + if archi_node.body and isinstance(archi_node.body, ast.SubNodeList): + for i in archi_node.body.items: + if ( + isinstance(i, ast.Ability) + and i.body + and isinstance(i.body, ast.AstImplOnlyNode) + ): + referenced_nodes.append(i.body.target.archs[0].arch_name) + + decls = [linkage_node, decl_linkage_node] + for i, decl in enumerate(decls): + if isinstance(decl, ast.ArchRefChain): + if len(decl.archs) > 1: + is_ability = symbol_type == SymbolType.ABILITY + decls[i] = ( + decl.archs[1].arch_name if is_ability else decl.archs[0].arch_name + ) + else: + decls[i] = decl.archs[0].arch_name + return decls, referenced_nodes From 89096c2b528cc31582e03e72fc9d39ee03c37d86 Mon Sep 17 00:00:00 2001 From: kugesan1105 Date: Sat, 31 Aug 2024 04:10:31 +0530 Subject: [PATCH 5/7] Uses of symbol are connected to NameAtom for most needed places elegently --- .../passes/main/fuse_typeinfo_pass.py | 29 ++---------- .../passes/main/pyjac_ast_link_pass.py | 9 ++++ jaclang/langserve/engine.py | 26 ++++++---- jaclang/langserve/tests/test_server.py | 2 +- jaclang/langserve/utils.py | 47 ------------------- 5 files changed, 31 insertions(+), 82 deletions(-) diff --git a/jaclang/compiler/passes/main/fuse_typeinfo_pass.py b/jaclang/compiler/passes/main/fuse_typeinfo_pass.py index 7fcf40fb1..8301c5c7d 100644 --- a/jaclang/compiler/passes/main/fuse_typeinfo_pass.py +++ b/jaclang/compiler/passes/main/fuse_typeinfo_pass.py @@ -510,31 +510,6 @@ def exit_atom_trailer(self, node: ast.AtomTrailer) -> None: ): # TODO check why IndexSlice produce an issue right.name_spec.sym = left.type_sym_tab.lookup(right.sym_name) - def find_tab(tab: ast.SymbolTable, name: str) -> Optional[ast.SymbolTable]: - """Recursively find symbol table from sym dotted name.""" - tab_list = name.split(".") - if len(tab_list) == 1: - return tab - else: - if tab_list[0] == tab.name: - return find_tab(tab, ".".join(tab_list[1:])) - else: - for child in tab.kid: - if child.name == tab_list[0]: - return find_tab(child, ".".join(tab_list[1:])) - return None - - for name_node in node.as_attr_list: - tab = ( - find_tab(self.ir.sym_tab, name_node.sym.sym_dotted_name) - if name_node.sym - else None - ) - if tab: - find_symbol = tab.lookup(name_node.sym_name) - if find_symbol and name_node not in find_symbol.uses: - find_symbol.add_use(name_node.name_spec) - # This function originally used `as_attr_list` in AtomTrailer # but an issue happened when doing stuff like fool_me().CONST_VALUE2 # The issue was due to the way `as_attr_list` implemented so the fix @@ -549,7 +524,7 @@ def find_tab(tab: ast.SymbolTable, name: str) -> Optional[ast.SymbolTable]: 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] @@ -597,3 +572,5 @@ def find_tab(tab: ast.SymbolTable, name: str) -> Optional[ast.SymbolTable]: else: if left.type_sym_tab: right.name_spec.sym = left.type_sym_tab.lookup(right.sym_name) + if right.name_spec.sym: + right.name_spec.sym.add_use(right.name_spec) diff --git a/jaclang/compiler/passes/main/pyjac_ast_link_pass.py b/jaclang/compiler/passes/main/pyjac_ast_link_pass.py index 78d6259c4..e2d3a48db 100644 --- a/jaclang/compiler/passes/main/pyjac_ast_link_pass.py +++ b/jaclang/compiler/passes/main/pyjac_ast_link_pass.py @@ -9,6 +9,7 @@ import jaclang.compiler.absyntree as ast from jaclang.compiler.passes import Pass +from jaclang.compiler.symtable import Symbol class PyJacAstLinkPass(Pass): @@ -161,6 +162,14 @@ 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 + ): + for arch in node.target.archs: + if arch.arch_name.sym and isinstance(arch.arch_name.sym, Symbol): + arch.arch_name.sym.add_use(arch.arch_name) def exit_param_var(self, node: ast.ParamVar) -> None: """Sub objects. diff --git a/jaclang/langserve/engine.py b/jaclang/langserve/engine.py index e74b316f3..88686d6f9 100644 --- a/jaclang/langserve/engine.py +++ b/jaclang/langserve/engine.py @@ -14,12 +14,11 @@ 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, collect_all_symbols_in_scope, - collect_impl_nodes, - collect_linkage_symbol, create_range, find_deepest_symbol_node_at_pos, find_index, @@ -366,7 +365,17 @@ def get_definition( return None elif isinstance(node_selected, (ast.ElementStmt, ast.BuiltinType)): return None - decl_node = collect_linkage_symbol(node_selected) + decl_node = ( + node_selected.parent.body.target + if node_selected.parent + and isinstance(node_selected.parent, ast.AstImplNeedingNode) + and isinstance(node_selected.parent.body, ast.AstImplOnlyNode) + else ( + node_selected.sym.decl + if (node_selected.sym and node_selected.sym.decl) + else node_selected + ) + ) decl_uri = uris.from_fs_path(decl_node.loc.mod_path) try: decl_range = create_range(decl_node.loc) @@ -420,14 +429,15 @@ 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: - impl_node_uses, archi_name_uses = collect_impl_nodes(node_selected) + if ( + node_selected + and node_selected.sym + and isinstance(node_selected.sym.decl.sym, Symbol) + ): changes: dict[str, list[lspt.TextEdit]] = {} for node in [ - *node_selected.sym.uses, + *node_selected.sym.decl.sym.uses, node_selected.sym.defn[0], - *impl_node_uses, - *archi_name_uses, ]: key = uris.from_fs_path(node.loc.mod_path) new_edit = lspt.TextEdit( diff --git a/jaclang/langserve/tests/test_server.py b/jaclang/langserve/tests/test_server.py index 8b03c92b4..57b3ea9a8 100644 --- a/jaclang/langserve/tests/test_server.py +++ b/jaclang/langserve/tests/test_server.py @@ -544,7 +544,7 @@ def test_rename_uses(self) -> None: (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 + (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",), diff --git a/jaclang/langserve/utils.py b/jaclang/langserve/utils.py index 49d6f2cf1..883d5c3b6 100644 --- a/jaclang/langserve/utils.py +++ b/jaclang/langserve/utils.py @@ -644,50 +644,3 @@ def add_unique_text_edit( ): return changes[key].append(new_edit) - - -def collect_linkage_symbol(node: ast.AstSymbolNode) -> ast.AstNode: - """Collect the symbol node that is linked to the symbol node.""" - return ( - node.parent.body.target - if node.parent - and isinstance(node.parent, ast.AstImplNeedingNode) - and isinstance(node.parent.body, ast.AstImplOnlyNode) - else (node.sym.decl if (node.sym and node.sym.decl) else node) - ) - - -def collect_impl_nodes( - node: ast.AstSymbolNode, -) -> tuple[list[ast.AstNode], list[ast.NameAtom]]: - """Collect nodes that are linked to impl node.""" - if not node.sym: - return [], [] - linkage_node = collect_linkage_symbol(node) - decl_linkage_node = collect_linkage_symbol(node.sym.decl) - symbol_type = node.sym.sym_type - referenced_nodes = [] - if symbol_type == SymbolType.OBJECT_ARCH and isinstance( - node.sym.decl.sym_tab.owner, ast.Architype - ): - archi_node: ast.Architype = node.sym.decl.sym_tab.owner - if archi_node.body and isinstance(archi_node.body, ast.SubNodeList): - for i in archi_node.body.items: - if ( - isinstance(i, ast.Ability) - and i.body - and isinstance(i.body, ast.AstImplOnlyNode) - ): - referenced_nodes.append(i.body.target.archs[0].arch_name) - - decls = [linkage_node, decl_linkage_node] - for i, decl in enumerate(decls): - if isinstance(decl, ast.ArchRefChain): - if len(decl.archs) > 1: - is_ability = symbol_type == SymbolType.ABILITY - decls[i] = ( - decl.archs[1].arch_name if is_ability else decl.archs[0].arch_name - ) - else: - decls[i] = decl.archs[0].arch_name - return decls, referenced_nodes From 0f4931247a6f1c1fd1e9841750afbf8360d20b62 Mon Sep 17 00:00:00 2001 From: kugesan1105 Date: Sat, 31 Aug 2024 04:49:21 +0530 Subject: [PATCH 6/7] 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: From 6ef0c71312ff4d6fcd3d58300db721f0dfaa8c58 Mon Sep 17 00:00:00 2001 From: kugesan1105 Date: Sat, 31 Aug 2024 04:51:48 +0530 Subject: [PATCH 7/7] tweak --- jaclang/compiler/passes/main/fuse_typeinfo_pass.py | 1 + jaclang/compiler/passes/main/pyjac_ast_link_pass.py | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/jaclang/compiler/passes/main/fuse_typeinfo_pass.py b/jaclang/compiler/passes/main/fuse_typeinfo_pass.py index db7de9a5c..efe0a8525 100644 --- a/jaclang/compiler/passes/main/fuse_typeinfo_pass.py +++ b/jaclang/compiler/passes/main/fuse_typeinfo_pass.py @@ -515,6 +515,7 @@ def exit_atom_trailer(self, node: ast.AtomTrailer) -> None: iteration_count += 1 if iteration_count > 50: break + 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 f25f4ac8e..00376fd79 100644 --- a/jaclang/compiler/passes/main/pyjac_ast_link_pass.py +++ b/jaclang/compiler/passes/main/pyjac_ast_link_pass.py @@ -9,7 +9,6 @@ import jaclang.compiler.absyntree as ast from jaclang.compiler.passes import Pass -from jaclang.compiler.symtable import Symbol class PyJacAstLinkPass(Pass): @@ -167,7 +166,7 @@ def exit_ability_def(self, node: ast.AbilityDef) -> None: node.target, ast.ArchRefChain ): for arch in node.target.archs: - if arch.arch_name.sym and isinstance(arch.arch_name.sym, Symbol): + if arch.arch_name.sym: arch.arch_name.sym.add_use(arch.arch_name) def exit_param_var(self, node: ast.ParamVar) -> None: