Pass 3 of 3 · Deep dive of PHAROSPass 1 · OverviewPass 2 · How it works
Code Observatory / function
_leading_comment
codeintel.parsers.treesitter_parser._leading_comment
PINNED SOURCE Source and edges from the index at this commit. An execution appears only where one was recorded.
PHAROS at 975a38dMIT license
Around this symbol
Search all symbolsLoading
| Symbol | File | Resolved by |
|---|---|---|
| clip | base.py | through an import |
| _clean_comment | treesitter_parser.py | same file |
| _text | treesitter_parser.py | same file |
| Symbol | File | Resolved by |
|---|---|---|
| parse_treesitter | treesitter_parser.py | same file |
| Symbol | File | Resolved by |
|---|---|---|
| treesitter_parser | treesitter_parser.py | same file |
codeintel.parsers.treesitter_parser._leading_commentbackend/app/codeintel/parsers/treesitter_parser.py, lines 350–371Open source
def _leading_comment(node, src: bytes) -> str: """Contiguous comment block directly above ``node`` (doc comments).""" target = node # Wrapper nodes (`export function f`, `const f = () => …`, Go # `type X struct`, C++ templates): the comment precedes the wrapper. parent = node.parent while parent is not None and parent.type in _DOC_WRAPPERS and parent.start_point[0] >= target.start_point[0] - 1: target = parent parent = parent.parent comments = [] expected_end_row = target.start_point[0] sibling = target.prev_sibling while sibling is not None and sibling.type in _COMMENT_TYPES | _ATTRIBUTE_TYPES: if sibling.end_point[0] < expected_end_row - 1: break # a blank line separates the comment from the definition if sibling.type in _COMMENT_TYPES: comments.append(_text(sibling, src)) expected_end_row = sibling.start_point[0] sibling = sibling.prev_sibling if not comments: return "" return clip(_clean_comment("\n".join(reversed(comments))), MAX_DOCSTRING_CHARS)What the index recorded
- Signature
def _leading_comment(node, src: bytes) -> str:- File
backend/app/codeintel/parsers/treesitter_parser.py- Lines
- 350–371
- Parser
- python-ast
- Git blob
bf0c9a8044cadd3452ebf5ffa82b866ae00395a9- Call sites
- 6 named, 3 resolved, 3 left unlinked
