Get docstring node from it parent node. Go's docstring is written line by line Args: node (tree_sitter.Node): parent node (usually function node) to get its docstring Return: List: list of docstring nodes Example:
(node)
| 25 | |
| 26 | @staticmethod |
| 27 | def get_docstring_node(node): |
| 28 | """ |
| 29 | Get docstring node from it parent node. |
| 30 | Go's docstring is written line by line |
| 31 | |
| 32 | Args: |
| 33 | node (tree_sitter.Node): parent node (usually function node) to get its docstring |
| 34 | Return: |
| 35 | List: list of docstring nodes |
| 36 | Example: |
| 37 | str = ''' |
| 38 | // The path package should only be used for paths separated by forward |
| 39 | // slashes, such as the paths in URLs. This package does not deal with |
| 40 | // Windows paths with drive letters or backslashes; to manipulate |
| 41 | // operating system paths, use the [path/filepath] package. |
| 42 | func (e TypeError) Error() string { |
| 43 | ... |
| 44 | } |
| 45 | ''' |
| 46 | ... |
| 47 | print(GoParser.get_docstring_node(function_node)) |
| 48 | |
| 49 | >>> [<Node type=comment, start_point=(x, y), end_point=(x, y)>, \ |
| 50 | <Node type=comment, start_point=(x, y), end_point=(x, y)>, \ |
| 51 | <Node type=comment, start_point=(x, y), end_point=(x, y)>, \ |
| 52 | <Node type=comment, start_point=(x, y), end_point=(x, y)>] |
| 53 | """ |
| 54 | docstring_node = [] |
| 55 | |
| 56 | prev_node = node.prev_sibling |
| 57 | if prev_node and prev_node.type == 'comment': |
| 58 | docstring_node.append(prev_node) |
| 59 | prev_node = prev_node.prev_sibling |
| 60 | |
| 61 | while prev_node and prev_node.type == 'comment': |
| 62 | # Assume the comment is dense |
| 63 | x_current = prev_node.start_point[0] |
| 64 | x_next = prev_node.next_sibling.start_point[0] |
| 65 | if x_next - x_current > 1: |
| 66 | break |
| 67 | |
| 68 | docstring_node.insert(0, prev_node) |
| 69 | prev_node = prev_node.prev_sibling |
| 70 | |
| 71 | return docstring_node |
| 72 | |
| 73 | @staticmethod |
| 74 | def get_docstring(node, blob:str=None): |