Skip to content

Conversation

@Brianleach11
Copy link

Added a Python Parser solution and modified the EnclosingContext to return as a Node | SyntaxNode | null to adjust. Updated the review file to ensure the line bounds are being read from each type of context.
Includes console logs to ensure the capture of an enclosing context.

Parsing Algorithm:

  • get the file 'Tree'
  • traverse tree starting at root node
  • use base cases to determine if the node is multi-line and contains the diff context
  • find meaningful node types and add them to their respective list (definitions, blocks)
  • find the best node:
    • default to the smallest enclosing definition node
    • fall back to the largest enclosing block node
  • recursively call traverse on all nodes

Definitions: function, class
Blocks: if, while, with, block, for, try

Dynamic solution:

  • The python parser utilizes the web-tree-sitter library that is a base for any programming language. Simply loading in a wasm file containing the grammar for Python allows for parsing of .py files.
  • In future languages, a solution could be to make the python-parser a general 'parser' file and in a 'parser-loader' file, determine which parser to use, and initialize the web-tree-sitter parser and load the wasm grammar; similarly to the getParserForExtension funciton

Example logging:

Extension detected: py
Parser found: PythonParser
Parser for streamlit_app.py: Found
Using functionContextPatchStrategy
💡 functionContextPatchStrategy for streamlit_app.py
📊 Processing hunks for streamlit_app.py
🔍 Searching for context with expanded range: 223-232
🔍 Searching for context for range: 223 - 232
🔍 Getting Python parser...
Found block context if_statement at lines 183-238
Found block context block at lines 185-238
Selected block context: if_statement at lines 183-238
✅ Found enclosing context: if_statement at lines 183-238

@Brianleach11
Copy link
Author

I noticed that when the extra context is being read properly, the inline comments function fails to post the comment to github due to github's api protection that inline comments can only be allowed on diff lines. The alternative to this would be to leave a regular comment on a PR like this one.
Could use some insight on this :)

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