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

Enhanced java parsing support #210

Merged
merged 6 commits into from
Dec 13, 2024
Merged

Enhanced java parsing support #210

merged 6 commits into from
Dec 13, 2024

Conversation

dhirenmathur
Copy link
Contributor

@dhirenmathur dhirenmathur commented Dec 13, 2024

Summary by CodeRabbit

  • New Features

    • Enhanced graph creation process with improved handling of node relationships and tags.
    • Added deduplication for user repositories fetched from the GitHub API.
  • Bug Fixes

    • Refined logic for handling demo projects during directory parsing.
  • Documentation

    • Improved clarity and organization in syntax tree definitions for Java constructs.
  • Style

    • Adjusted parameter formatting for improved readability in various methods.
  • Chores

    • Reordered import statements for consistency across multiple files.

Copy link
Contributor

coderabbitai bot commented Dec 13, 2024

Warning

Rate limit exceeded

@dhirenmathur has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 19 minutes and 2 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 0321d06 and f84508f.

📒 Files selected for processing (1)
  • app/modules/parsing/graph_construction/code_graph_service.py (4 hunks)

Walkthrough

The changes involve multiple files across the application, primarily focusing on enhancing the graph construction and parsing logic. Key modifications include the introduction of new helper methods for relationship creation in the RepoMap class, significant updates to the CodeGraphService class for graph creation, and refinements in the ParsingController for handling project parsing. Additionally, the syntax tree definitions for Java constructs have been restructured, and various formatting improvements have been made in the usage-related files, including parameter formatting and import statement reordering.

Changes

File Change Summary
app/modules/parsing/graph_construction/code_graph_service.py Added import for time. Modified create_and_store_graph to clear existing project data, update node processing logic, handle None values, and streamline batch insertion into Neo4j.
app/modules/parsing/graph_construction/parsing_controller.py Adjusted repo_name assignment in handle_new_project. Refined parse_directory to check for demo projects and handle project duplication.
app/modules/parsing/graph_construction/parsing_repomap.py Added create_relationship method to manage node relationships. Refactored create_graph to utilize this method and improve logging and handling of node definitions.
app/modules/parsing/graph_construction/queries/tree-sitter-java-tags.scm Added new sections for method invocations, class/interface definitions, and refined existing syntax tree definitions for better organization and clarity.
app/modules/code_provider/github/github_router.py Introduced deduplication in get_user_repos function to remove duplicate repositories while preserving order.
app/modules/usage/usage_controller.py Reformatted get_user_usage method signature for readability. Reordered import statements.
app/modules/usage/usage_router.py Reordered import statements and adjusted parameter formatting in get_usage method for consistency.
app/modules/usage/usage_schema.py Adjusted import statement for BaseModel for formatting consistency; added newline at the end of the file.
app/modules/usage/usage_service.py Added import for Message and MessageType. Minor formatting adjustments in get_usage_data method, including query construction.

Poem

In the code where rabbits play,
New paths and graphs light the way.
With nodes and edges, clear and bright,
We hop along, coding with delight!
Parsing projects, we leap and bound,
In this code garden, joy is found! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Experiment)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (9)
app/modules/parsing/graph_construction/code_graph_service.py (1)

65-93: Enhance error handling and code clarity in node processing.

  • Log or handle cases where node_type is UNKNOWN to assist in debugging.
  • Consolidate labels and node data preparation for better readability.
  • Ensure that all node types are accounted for or explicitly ignored.

Consider refactoring the code as follows:

for node_id, node_data in batch_nodes:
    node_type = node_data.get("type", "UNKNOWN")
    if node_type == "UNKNOWN":
        logging.warning(f"Unknown node type for node {node_id}")
        continue

    # Initialize labels
    labels = ["NODE", node_type] if node_type in ["FILE", "CLASS", "FUNCTION", "INTERFACE"] else ["NODE"]

    # Prepare node data
    processed_node = {
        "name": node_data.get("name", node_id),
        "file_path": node_data.get("file", ""),
        "start_line": node_data.get("line", -1),
        "end_line": node_data.get("end_line", -1),
        "repoId": project_id,
        "node_id": CodeGraphService.generate_node_id(node_id, user_id),
        "entityId": user_id,
        "type": node_type,
        "text": node_data.get("text", ""),
        "labels": labels,
    }

    # Remove None and empty string values
    processed_node = {k: v for k, v in processed_node.items() if v not in (None, "")}
    nodes_to_create.append(processed_node)
app/modules/parsing/graph_construction/parsing_repomap.py (5)

165-199: Replace print statements with proper logging.

Using print statements for debugging can clutter the console output. It's better to use the logging module to control the verbosity level.

Apply this diff to replace print with logging.debug:

- print(f"Processing file: {fname}")
- print(f"Language detected: {lang}")
...
- print(f"Captured node: {node_text} with tag: {tag}")
...
- print(f"Found method definition: {node_text}")
...
- print(f"Found method reference: {node_text}")
+ logging.debug(f"Processing file: {fname}")
+ logging.debug(f"Language detected: {lang}")
...
+ logging.debug(f"Captured node: {node_text} with tag: {tag}")
...
+ logging.debug(f"Found method definition: {node_text}")
...
+ logging.debug(f"Found method reference: {node_text}")

571-584: Simplify nested if statements by combining conditions.

The nested if statements can be combined using logical or operators to improve readability.

Apply this diff:

- if relationship_type == "REFERENCES":
-     if (source_data.get('type') == 'FUNCTION' and 
-         target_data.get('type') == 'FUNCTION' and
-         'Impl' in source): # Implementation class
-         valid_direction = True
-     elif source_data.get('type') == 'FUNCTION':
-         valid_direction = True
-     elif target_data.get('type') == 'CLASS':
-         valid_direction = True
+ if relationship_type == "REFERENCES" and (
+     (source_data.get('type') == 'FUNCTION' and target_data.get('type') == 'FUNCTION' and 'Impl' in source) or
+     source_data.get('type') == 'FUNCTION' or
+     target_data.get('type') == 'CLASS'
+ ):
+     valid_direction = True
🧰 Tools
🪛 Ruff (0.8.2)

572-579: Combine if branches using logical or operator

Combine if branches

(SIM114)


578-583: Combine if branches using logical or operator

Combine if branches

(SIM114)


602-602: Rename unused loop variable dirs to _ to indicate it's unused.

In the loop at line 602, the dirs variable isn't used within the loop body.

Apply this diff:

- for root, dirs, files in os.walk(repo_dir):
+ for root, _, files in os.walk(repo_dir):
🧰 Tools
🪛 Ruff (0.8.2)

602-602: Loop control variable dirs not used within loop body

Rename unused dirs to _dirs

(B007)


704-704: Rename unused loop variables src_class and src_method to _ to indicate they are unused.

In the loop at line 704, src_class and src_method are not used.

Apply this diff:

- for source, line, end_line, src_class, src_method in refs:
+ for source, line, end_line, _, _ in refs:
🧰 Tools
🪛 Ruff (0.8.2)

704-704: Loop control variable src_class not used within loop body

Rename unused src_class to _src_class

(B007)


704-704: Loop control variable src_method not used within loop body

Rename unused src_method to _src_method

(B007)


751-754: Simplify if statements in find_node_by_range method.

Combine the nested if conditions using logical or for clarity.

Apply this diff:

- if node_type == "FUNCTION" and node.type in ["function_definition", "method","method_declaration",  "function"]:
-     return node
- elif node_type in ["CLASS", "INTERFACE"] and node.type in ["class_definition", "interface", "class", "class_declaration",  "interface_declaration"]:
-     return node
+ if (
+     (node_type == "FUNCTION" and node.type in ["function_definition", "method", "method_declaration", "function"]) or
+     (node_type in ["CLASS", "INTERFACE"] and node.type in ["class_definition", "interface", "class", "class_declaration", "interface_declaration"])
+ ):
+     return node
🧰 Tools
🪛 Ruff (0.8.2)

751-754: Combine if branches using logical or operator

Combine if branches

(SIM114)

app/modules/auth/auth_service.py (1)

Line range hint 52-61: Ensure mock authentication is securely managed and disabled in production.

The introduction of a development mode mock authentication is useful for testing. However, to prevent security risks:

  • Make sure the isDevelopmentMode flag cannot be enabled accidentally in production environments.
  • Consider using environment variables that are securely managed and distinct between development and production.
  • Add checks or safeguards to prevent misuse.
🧰 Tools
🪛 Ruff (0.8.2)

49-49: Do not perform function call HTTPBearer in argument defaults; instead, perform the call within the function, or read the default from a module-level singleton variable

(B008)


54-54: Use capitalized environment variable ISDEVELOPMENTMODE instead of isDevelopmentMode

(SIM112)


55-55: Use capitalized environment variable DEFAULTUSERNAME instead of defaultUsername

(SIM112)

app/modules/parsing/graph_construction/parsing_controller.py (2)

Line range hint 1-250: Consider the following architectural improvements:

  1. Extract duplicate repo_name derivation logic into a helper method
  2. Move demo repository handling logic into a separate method
  3. Add error handling for async tasks

Here's a suggested refactor for the repo_name derivation:

@staticmethod
def _derive_repo_name(repo_details: ParsingRequest) -> str:
    return repo_details.repo_name or repo_details.repo_path.split("/")[-1]

This would help maintain consistency and make the code more DRY. Would you like me to provide more detailed refactoring suggestions for the other improvements?


Line range hint 206-208: Improve async task error handling.

The async task creation for get_project_structure_async lacks error handling. Consider wrapping it in a try-catch block and implementing a proper error handling strategy.

Here's a suggested improvement:

-asyncio.create_task(
-    CodeProviderService(db).get_project_structure_async(new_project_id)
-)
+async def handle_project_structure():
+    try:
+        await CodeProviderService(db).get_project_structure_async(new_project_id)
+    except Exception as e:
+        logger.error(f"Failed to get project structure: {e}")
+        await project_manager.update_project_status(
+            new_project_id, 
+            ProjectStatusEnum.ERROR
+        )
+
+asyncio.create_task(handle_project_structure())
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ad79761 and 8509d68.

📒 Files selected for processing (5)
  • app/modules/auth/auth_service.py (1 hunks)
  • app/modules/parsing/graph_construction/code_graph_service.py (4 hunks)
  • app/modules/parsing/graph_construction/parsing_controller.py (1 hunks)
  • app/modules/parsing/graph_construction/parsing_repomap.py (3 hunks)
  • app/modules/parsing/graph_construction/queries/tree-sitter-java-tags.scm (1 hunks)
🧰 Additional context used
🪛 Ruff (0.8.2)
app/modules/parsing/graph_construction/parsing_repomap.py

572-579: Combine if branches using logical or operator

Combine if branches

(SIM114)


578-583: Combine if branches using logical or operator

Combine if branches

(SIM114)


602-602: Loop control variable dirs not used within loop body

Rename unused dirs to _dirs

(B007)


704-704: Loop control variable src_class not used within loop body

Rename unused src_class to _src_class

(B007)


704-704: Loop control variable src_method not used within loop body

Rename unused src_method to _src_method

(B007)


751-754: Combine if branches using logical or operator

Combine if branches

(SIM114)

🔇 Additional comments (4)
app/modules/parsing/graph_construction/code_graph_service.py (2)

4-4: Importing the 'time' module for performance logging is appropriate.


134-135: Logging the elapsed time is helpful for performance monitoring.

app/modules/parsing/graph_construction/queries/tree-sitter-java-tags.scm (1)

1-35: Tree-sitter query additions are correctly structured.

The added queries for methods, classes, interfaces, and variable declarations enhance the parsing capabilities for Java code and are well-defined.

app/modules/parsing/graph_construction/parsing_controller.py (1)

Line range hint 198-204: LGTM! Moving repo_name assignment improves code clarity.

The change to move the repo_name assignment before its usage in register_project is a good improvement. It ensures the variable is defined before use and makes the code flow more logical.

Let's verify that this pattern is consistent across the codebase:

✅ Verification successful

The repo_name assignment pattern is consistent and correctly implemented

The search results confirm that:

  1. The pattern repo_name = repo_details.repo_name or repo_details.repo_path.split("/")[-1] is unique to the parsing controller and appropriately handles the fallback case.
  2. Other repo_name assignments in the codebase handle different scenarios (e.g., direct assignments from project details or database records).
  3. The register_project calls consistently use the repo_name as the first parameter.

The moved assignment improves code clarity without breaking any patterns in the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for other instances where repo_name is derived from repo_path
# to ensure consistent pattern usage

ast-grep --pattern 'repo_name = $x.repo_name or $x.repo_path.split("/")[-1]'

Length of output: 78


Script:

#!/bin/bash
# Let's try a broader search for repo_name assignments and repo_path usage patterns
# First, let's look for repo_name assignments
rg "repo_name\s*=" -A 2

# Then, let's look for repo_path splits
rg "repo_path.*split.*\[-1\]" -A 2

# Finally, let's look for register_project calls to verify parameter usage
rg "register_project" -A 5

Length of output: 4830

Comment on lines 46 to 53
# First, clear any existing data for this project
session.run(
"""
MATCH (n {repoId: $project_id})
DETACH DELETE n
""",
project_id=project_id,
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Neo4j deletion operation needs additional safeguards

The code review reveals several concerns about the deletion operation:

  • The deletion operation is not wrapped in an explicit transaction
  • There's no error handling around the Neo4j operations
  • The deletion query correctly uses repoId parameter to scope the deletion
  • The same deletion pattern is used in both create_and_store_graph and cleanup_graph methods

Recommended changes:

  • Wrap the deletion operation in a try-catch block to handle potential Neo4j errors
  • Use an explicit transaction with session.begin_transaction() to ensure atomicity
  • Add logging to track successful deletions and failures
  • Consider adding a validation step to confirm the deletion affected only intended nodes

Example implementation:

with self.driver.session() as session:
    try:
        with session.begin_transaction() as tx:
            result = tx.run(
                """
                MATCH (n {repoId: $project_id})
                DETACH DELETE n
                RETURN count(n) as deleted_count
                """,
                project_id=project_id,
            )
            deleted_count = result.single()["deleted_count"]
            tx.commit()
            logging.info(f"Successfully deleted {deleted_count} nodes for project {project_id}")
    except Exception as e:
        logging.error(f"Error deleting nodes for project {project_id}: {str(e)}")
        raise
🔗 Analysis chain

Ensure safe deletion of existing project data in Neo4j.

The code deletes all nodes associated with project_id from the Neo4j database. Verify that this operation does not unintentionally affect other data. Consider wrapping this operation in a transaction and adding error handling.

Run the following script to check if nodes outside of the specified project_id are unaffected:

This script uses rg to list all unique repoId values before and after the deletion to ensure no unintended data is removed.


Let me gather more information about the transaction and error handling aspects by examining the code context around this deletion operation.


Let me try one more search to understand the complete context of the code_graph_service class and its error handling patterns.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that only nodes related to the specific project_id are deleted.

# Find all unique repoIds before deletion
echo "Repo IDs before deletion:"
rg -o --no-filename 'repoId: [^\n]+' | sort | uniq

# After deletion, check again
echo "Repo IDs after deletion:"
rg -o --no-filename 'repoId: [^\n]+' | sort | uniq

Length of output: 959


Script:

#!/bin/bash
# Check the context of the deletion operation and any transaction/error handling
ast-grep --pattern 'def create_graph($$$)' app/modules/parsing/graph_construction/code_graph_service.py -A 60

Length of output: 111


Script:

#!/bin/bash
# Look for transaction handling patterns in Neo4j operations
rg -B 2 -A 2 "session\.(begin_transaction|run)" app/modules/parsing/graph_construction/code_graph_service.py

Length of output: 1238


Script:

#!/bin/bash
# Check for error handling patterns around Neo4j operations
rg -B 2 -A 2 "try:.*(session|transaction)" app/modules/parsing/graph_construction/code_graph_service.py

Length of output: 105


Script:

#!/bin/bash
# Get the complete content of the code_graph_service.py file
cat app/modules/parsing/graph_construction/code_graph_service.py

Length of output: 7247

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (8)
app/modules/code_provider/github/github_router.py (2)

Line range hint 582-704: Consider optimizing the graph creation process.

While the implementation is functionally correct, there are opportunities for improvement:

  1. The unused variables in the loop can be renamed with underscore prefix
  2. The relationship creation calls could be simplified

Apply these changes:

- for root, dirs, files in os.walk(repo_dir):
+ for root, _dirs, files in os.walk(repo_dir):
- for source, line, end_line, src_class, src_method in refs:
+ for source, line, end_line, _src_class, _src_method in refs:

Line range hint 739-752: Simplify the node type conditions using logical operators.

The nested if conditions for node type checking can be simplified.

Apply this change:

- if node_type == "FUNCTION" and node.type in [
-     "function_definition",
-     "method",
-     "method_declaration",
-     "function",
- ]:
-     return node
- elif node_type in ["CLASS", "INTERFACE"] and node.type in [
-     "class_definition",
-     "interface",
-     "class",
-     "class_declaration",
-     "interface_declaration",
- ]:
+ function_types = ["function_definition", "method", "method_declaration", "function"]
+ class_types = ["class_definition", "interface", "class", "class_declaration", "interface_declaration"]
+ if (node_type == "FUNCTION" and node.type in function_types) or \
+    (node_type in ["CLASS", "INTERFACE"] and node.type in class_types):
     return node
app/modules/usage/usage_service.py (1)

Line range hint 18-28: Consider indexing strategy for query performance

The query involves multiple joins, filters, and aggregations. Ensure proper indexing exists for:

  • Conversation.user_id
  • Message.created_at
  • Message.conversation_id
  • Message.type

This will help maintain good performance as the data grows.

app/modules/parsing/graph_construction/parsing_repomap.py (5)

181-189: LGTM! Consider adding null check for decoded text

The Java method call handling enhancement is well-implemented. However, consider adding a null check when decoding the object reference text to handle potential encoding issues gracefully.

 if object_node:
-    node_text = f"{object_node.text.decode('utf-8')}.{node_text}"
+    try:
+        object_text = object_node.text.decode('utf-8')
+        node_text = f"{object_text}.{node_text}"
+    except UnicodeDecodeError:
+        logging.warning(f"Failed to decode object reference in {rel_fname}")

534-580: LGTM! Consider adding type enums for better type safety

The relationship creation helper is well-implemented with clear validation rules. To enhance type safety and maintainability, consider using enums for relationship and node types.

+from enum import Enum
+
+class NodeType(Enum):
+    FUNCTION = "FUNCTION"
+    CLASS = "CLASS"
+    INTERFACE = "INTERFACE"
+
+class RelationType(Enum):
+    REFERENCES = "REFERENCES"
+    CONTAINS = "CONTAINS"

 def create_relationship(
     G, source, target, relationship_type, seen_relationships, extra_data=None
 ):
     # ...
-    if relationship_type == "REFERENCES":
+    if relationship_type == RelationType.REFERENCES:
         # Implementation -> Interface
         if (
-            source_data.get("type") == "FUNCTION"
-            and target_data.get("type") == "FUNCTION"
+            source_data.get("type") == NodeType.FUNCTION.value
+            and target_data.get("type") == NodeType.FUNCTION.value
🧰 Tools
🪛 Ruff (0.8.2)

568-573: Combine if branches using logical or operator

Combine if branches

(SIM114)


588-588: Fix unused loop variable

Rename unused loop variable dirs to _dirs as per static analysis suggestion.

-for root, dirs, files in os.walk(repo_dir):
+for root, _dirs, files in os.walk(repo_dir):
🧰 Tools
🪛 Ruff (0.8.2)

588-588: Loop control variable dirs not used within loop body

Rename unused dirs to _dirs

(B007)


582-704: Consider refactoring for better modularity

The graph creation logic is well-implemented but could benefit from better modularity. Consider extracting the file processing logic into a separate method and creating a helper for node creation to reduce code duplication.

 def create_graph(self, repo_dir):
     G = nx.MultiDiGraph()
     defines = defaultdict(set)
     references = defaultdict(set)
     seen_relationships = set()
+    
+    def process_file(file_path, rel_path):
+        if not self.parse_helper.is_text_file(file_path):
+            return
+        
+        logging.info(f"\nProcessing file: {rel_path}")
+        add_file_node(G, rel_path, self.io.read_text(file_path))
+        process_tags(file_path, rel_path)
+    
+    def add_file_node(G, rel_path, content):
+        if not G.has_node(rel_path):
+            G.add_node(
+                rel_path,
+                file=rel_path,
+                type="FILE",
+                text=content or "",
+                line=0,
+                end_line=0,
+                name=rel_path.split("/")[-1],
+            )

     for root, _dirs, files in os.walk(repo_dir):
         if any(part.startswith(".") for part in root.split(os.sep)):
             continue
         
         for file in files:
             file_path = os.path.join(root, file)
             rel_path = os.path.relpath(file_path, repo_dir)
-            # ... rest of the file processing logic
+            process_file(file_path, rel_path)
🧰 Tools
🪛 Ruff (0.8.2)

588-588: Loop control variable dirs not used within loop body

Rename unused dirs to _dirs

(B007)


688-688: Loop control variable src_class not used within loop body

Rename unused src_class to _src_class

(B007)


688-688: Loop control variable src_method not used within loop body

Rename unused src_method to _src_method

(B007)


739-752: Consider using constants for node types

While the node type checking is correct, consider defining constants for the node types to improve maintainability and prevent typos.

+# At the top of the file
+FUNCTION_NODE_TYPES = frozenset([
+    "function_definition",
+    "method",
+    "method_declaration",
+    "function",
+])
+
+CLASS_NODE_TYPES = frozenset([
+    "class_definition",
+    "interface",
+    "class",
+    "class_declaration",
+    "interface_declaration",
+])

 def find_node_by_range(root_node, start_line, node_type):
     def traverse(node):
         if node.start_point[0] <= start_line and node.end_point[0] >= start_line:
-            if node_type == "FUNCTION" and node.type in [
-                "function_definition",
-                "method",
-                "method_declaration",
-                "function",
-            ]:
+            if node_type == "FUNCTION" and node.type in FUNCTION_NODE_TYPES:
                 return node
-            elif node_type in ["CLASS", "INTERFACE"] and node.type in [
-                "class_definition",
-                "interface",
-                "class",
-                "class_declaration",
-                "interface_declaration",
-            ]:
+            elif node_type in ["CLASS", "INTERFACE"] and node.type in CLASS_NODE_TYPES:
                 return node
🧰 Tools
🪛 Ruff (0.8.2)

739-753: Combine if branches using logical or operator

Combine if branches

(SIM114)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8509d68 and 0321d06.

📒 Files selected for processing (8)
  • app/modules/code_provider/github/github_router.py (1 hunks)
  • app/modules/parsing/graph_construction/code_graph_service.py (4 hunks)
  • app/modules/parsing/graph_construction/parsing_controller.py (4 hunks)
  • app/modules/parsing/graph_construction/parsing_repomap.py (4 hunks)
  • app/modules/usage/usage_controller.py (1 hunks)
  • app/modules/usage/usage_router.py (1 hunks)
  • app/modules/usage/usage_schema.py (1 hunks)
  • app/modules/usage/usage_service.py (3 hunks)
✅ Files skipped from review due to trivial changes (2)
  • app/modules/usage/usage_schema.py
  • app/modules/usage/usage_router.py
🚧 Files skipped from review as they are similar to previous changes (2)
  • app/modules/parsing/graph_construction/code_graph_service.py
  • app/modules/parsing/graph_construction/parsing_controller.py
🧰 Additional context used
🪛 Ruff (0.8.2)
app/modules/parsing/graph_construction/parsing_repomap.py

568-573: Combine if branches using logical or operator

Combine if branches

(SIM114)


588-588: Loop control variable dirs not used within loop body

Rename unused dirs to _dirs

(B007)


688-688: Loop control variable src_class not used within loop body

Rename unused src_class to _src_class

(B007)


688-688: Loop control variable src_method not used within loop body

Rename unused src_method to _src_method

(B007)


739-753: Combine if branches using logical or operator

Combine if branches

(SIM114)

🔇 Additional comments (5)
app/modules/code_provider/github/github_router.py (2)

19-31: LGTM! Clean implementation of repository deduplication.

The implementation efficiently removes duplicate repositories while preserving order, using the repository's full name as a unique identifier.


Line range hint 534-580: Well-structured relationship creation logic with proper validation.

The create_relationship helper method effectively:

  • Prevents self-referential relationships
  • Avoids duplicate bidirectional relationships
  • Enforces valid relationship directions based on node types
app/modules/usage/usage_controller.py (1)

9-11: LGTM: Improved method signature formatting

The parameter formatting change improves readability by placing each parameter on a separate line.

app/modules/usage/usage_service.py (2)

32-41: LGTM: Clean data transformation

The conversion of query results to a dictionary and the calculation of total messages is clean and efficient.


Line range hint 43-46: LGTM: Proper error handling

The error handling appropriately catches SQLAlchemy errors, logs them, and raises a generic exception to avoid exposing internal details.

@dhirenmathur dhirenmathur merged commit e889a4f into main Dec 13, 2024
3 of 4 checks 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.

1 participant