ast-comments icon indicating copy to clipboard operation
ast-comments copied to clipboard

inlined comments

Open t3rn0 opened this issue 3 years ago • 4 comments

Currently we don't identify inlined comments in code, all comments are just regular (not inlined) (https://github.com/t3rn0/ast-comments#notes). Difference between them is lost after the code is parsed into the tree. We should try distinguish inlined and regular comments when unparsing the tree back to the code.

It'd be great to cover following cases:

  • simple expression:
    a = 1  # c1
    
  • if-elif-else
    if a:  # c2
        ...
    elif b:  # c3
        ...
    else:  # c4
        ...
    
  • try-except-else-finally
  • for-else
  • match

t3rn0 avatar Mar 05 '23 18:03 t3rn0

anyway i can support with this ticket? i stumbled upon your lib today and it does exactly what i need but this bug is causing me small issues :/

example:

def __init__(self, **kwargs: Any):
    """Initialize a MarkdownTextSplitter."""
    separators = [
        # First, try to split along class definitions
        "\nclass ",
        "\ndef ",
        "\n\tdef ",
        # Now split by the normal type of lines
        "\n\n",
        "\n",
        " ",
        "",
    ]
    super().__init__(separators=separators, **kwargs)
    

becomes this:

def __init__(self, **kwargs: Any):
    """Initialize a MarkdownTextSplitter."""
    # First, try to split along class definitions
    # Now split by the normal type of lines
    separators = ['\nclass ', '\ndef ', '\n\tdef ', '\n\n', '\n', ' ', '']
    super().__init__(separators=separators, **kwargs)

Roni1993 avatar Apr 12 '23 23:04 Roni1993

Thanks for noticing that. The example you gave is not relevant to the issue, so I opened another one https://github.com/t3rn0/ast-comments/issues/13 I don't have enough time to look at it right now but I'll try to fix it next month

t3rn0 avatar Apr 17 '23 17:04 t3rn0

Any progress here? Not urgent for me as this lib already does everything I need but I just wanted to add a gentle nudge to continue developing it as it's an amazing tool for anyone who delved a bit too deep into AST.

Big thanks for making this effort and I hope this library gets a lot more popular!

zmievsa avatar Dec 21 '23 00:12 zmievsa

Hello. Thank you for your interest in the library. The original problem here was resolved a few commits ago. Almost... There is one element left: comments for match blocks. Now this issue serves as a kind reminder to me that there is still work to be done. 😁

t3rn0 avatar Dec 25 '23 19:12 t3rn0