Skip to content

OSA Tree Sitter

osa_tool.operations.codebase.docstring_generation.osa_treesitter

OSA_TreeSitter

Bases: object

Class for the extraction of the source code's structure to be processed later by LLM.

Attributes:

Name Type Description
cwd

A current working directory with source code files.

__init__(scripts_path, ignore_list=None)

Initialization of the instance based on the provided path to the scripts.

Parameters:

Name Type Description Default
scripts_path str

provided by user path to the scripts.

required

analyze_directory(path)

Method analyzes provided directory.

Parameters:

Name Type Description Default
path str

provided by user path to the scripts.

required

Returns:

Type Description
dict

Dictionary containing a filename and its source code's structure.

build_function_index(results) staticmethod

Build an index of all functions and methods for quick lookup by name.

This allows retrieving source code of called functions without storing it in every reference.

Parameters:

Name Type Description Default
results dict

Dictionary returned from analyze_directory() containing the parsed structure.

required

Returns:

Type Description
dict

A dictionary mapping function names to their full details:

dict

{ 'function_name': { 'source_code': '...', 'arguments': [...], 'docstring': '...', 'return_type': '...', 'file': 'path/to/file.py', 'start_line': 123, ... }

dict

}

extract_structure(filename)

Method extracts the structure of the occured file in the provided directory.

Parameters:

Name Type Description Default
filename str

name of the file occured in the provided directory.

required

Returns:

Type Description
list

List containing occurring in file functions, classes, their start lines and methods

files_list(path)

Method provides a list of files occurring in the provided path.

If user provided a path to a file with a particular extension the method returns a corresponding status which will trigger inner "_if_file_handler" method to cut the path's tail.

Parameters:

Name Type Description Default
path str

provided by user path to the scripts.

required

Returns:

Type Description
tuple[list, 0] | tuple[list[str], 1]

A tuple containing a list of files in the provided directory

tuple[list, 0] | tuple[list[str], 1]

and status for a specific file usecase. Statuses:

tuple[list, 0] | tuple[list[str], 1]

0 - a directory was provided

tuple[list, 0] | tuple[list[str], 1]

1 - a path to the specific file was provided.

log_results(results)

Method logs the results of the directory analyze into "examples/report.txt".

Parameters:

Name Type Description Default
results dict

dictionary containing a filename and its source code's structure.

required

open_file(file) staticmethod

Method reads the content of the occured file.

Parameters:

Name Type Description Default
file str

file occured in the provided directory.

required

Returns:

Type Description
str

Read content.

show_results(results)

Method logs out the results of the directory analyze.

Parameters:

Name Type Description Default
results dict

dictionary containing a filename and its source code's structure.

required