Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug - class methods appear in top level index #54

Merged
merged 1 commit into from
Jul 18, 2024

Conversation

ryanhoangt
Copy link
Contributor

@ryanhoangt ryanhoangt commented Jul 4, 2024

Hi, thanks for the awesome project!

PR description

When trying to test the context search API implementation, I observed that the methods defined in classes are also added into the top-level function index. Not sure if it is actually an issue.

('Found 2 methods with name `search_class` in file manager.py:\n'
 '\n'
 '- Search result 1:\n'
 '```\n'
 '<file>./search/manager.py</file>\n'
 ' <func>search_class</func>\n'
 '<code>\n'
 '    def search_class(self, class_name):\n'
 '        # initialize them to error case\n'
 "        summary = f'Class {class_name} did not appear in the codebase.'\n"
 "        tool_result = f'Could not find class {class_name} in the codebase.'\n"
 '\n'
 '        if class_name not in self.class_index:\n'
 '            return tool_result, summary, None\n'
 '\n'
 '        search_res: list[SearchResult] = []\n'
 '        for fname, _ in self.class_index[class_name]:\n'
 '            # there are some classes; we return their signatures\n'
 '            code = get_class_signature(fname, class_name)\n'
 '            res = SearchResult(fname, class_name, None, code)\n'
 '            search_res.append(res)\n'
 '\n'
 '        if not search_res:\n'
 '            # this should not happen, but just in case\n'
 '            return tool_result, summary, False\n'
 '\n'
 '        # the good path\n'
 '        # for all the searched result, append them and form the final '
 'result\n'
 "        tool_result = f'Found {len(search_res)} classes with name "
 "{class_name} in the codebase:\\n\\n'\n"
 '        if len(search_res) > RESULT_SHOW_LIMIT:\n'
 "            tool_result += 'They appeared in the following files:\\n'\n"
 '            tool_result += SearchResult.collapse_to_file_level(\n'
 '                search_res, self.project_path\n'
 '            )\n'
 '        else:\n'
 '            for idx, res in enumerate(search_res):\n'
 '                res_str = res.to_tagged_str(self.project_path)\n'
 "                tool_result += f'- Search result {idx + "
 "1}:\\n```\\n{res_str}\\n```\\n'\n"
 "        summary = f'The tool returned information about class "
 "`{class_name}`.'\n"
 '        return tool_result, summary, True\n'
 '\n'
 '</code>\n'
 '```\n'
 '- Search result 2:\n'
 '```\n'
 '<file>./search/manager.py</file>\n'
 '<class>SearchManager</class> <func>search_class</func>\n'
 '<code>\n'
 '    def search_class(self, class_name):\n'
 '        # initialize them to error case\n'
 "        summary = f'Class {class_name} did not appear in the codebase.'\n"
 "        tool_result = f'Could not find class {class_name} in the codebase.'\n"
 '\n'
 '        if class_name not in self.class_index:\n'
 '            return tool_result, summary, None\n'
 '\n'
 '        search_res: list[SearchResult] = []\n'
 '        for fname, _ in self.class_index[class_name]:\n'
 '            # there are some classes; we return their signatures\n'
 '            code = get_class_signature(fname, class_name)\n'
 '            res = SearchResult(fname, class_name, None, code)\n'
 '            search_res.append(res)\n'
 '\n'
 '        if not search_res:\n'
 '            # this should not happen, but just in case\n'
 '            return tool_result, summary, False\n'
 '\n'
 '        # the good path\n'
 '        # for all the searched result, append them and form the final '
 'result\n'
 "        tool_result = f'Found {len(search_res)} classes with name "
 "{class_name} in the codebase:\\n\\n'\n"
 '        if len(search_res) > RESULT_SHOW_LIMIT:\n'
 "            tool_result += 'They appeared in the following files:\\n'\n"
 '            tool_result += SearchResult.collapse_to_file_level(\n'
 '                search_res, self.project_path\n'
 '            )\n'
 '        else:\n'
 '            for idx, res in enumerate(search_res):\n'
 '                res_str = res.to_tagged_str(self.project_path)\n'
 "                tool_result += f'- Search result {idx + "
 "1}:\\n```\\n{res_str}\\n```\\n'\n"
 "        summary = f'The tool returned information about class "
 "`{class_name}`.'\n"
 '        return tool_result, summary, True\n'
 '\n'
 '</code>\n'
 '```\n',
 'Found 2 methods with name `search_class` in file manager.py:\n\n',
 True)

This PR attempts to fix it.

@Marti2203
Copy link
Collaborator

Hi!
I'm sorry for the delay - we looked over it and talked about the change, and it looks good!
Thanks for the contribution!

@Marti2203 Marti2203 merged commit 759a732 into nus-apr:main Jul 18, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants