mix lazy_doc (LazyDoc v0.4.1)

## Main functionality

The module Mix.Tasks.LazyDoc provides a Mix task for processing source files to extract and format documentation for Elixir modules and functions.

## Description

It enables the extraction of documentation using AI to enhance the documentation generation process, verifying and formatting documentation as per specified requirements. It handles reading the source code, interacting with a provider for documentation prompts, and writing the results back in a structured format.

Summary

Functions

Parameters

Parameters

  • docs - the documentation string to be converted to an abstract syntax tree (AST).
  • acc_ast - the accumulator AST to which the new documentation will be added.
  • module_ast - the AST of the module where the documentation will be inserted.

Description

Converts a documentation string into an Elixir AST and inserts it into the specified module's AST.

This should work for most of the modules, it will not work if the module contains only one function because Elixir does not create a __block__ node in this case.

Parameters

  • ast - the Abstract Syntax Tree (AST) representing the module structure.
  • module_ast - the AST representation of the specific module to be modified.
  • ast_doc - a documentation string or AST node to be inserted into the module.

Description

Inserts documentation into a specified module in the AST by traversing and modifying the module's structure.

write to given file the given Elixir AST This function does not write it in the proper format and it will remove comments as well

Parameters

  • file - the name of the file where the formatted content will be written.
  • ast - the abstract syntax tree representation of the code to be written.
  • comments - optional comments to include with the formatted output.

Description

Formats the given abstract syntax tree (AST) and writes it to the specified file, including any provided comments.

Functions

docs_are_ok?(docs)

Parameters

docs - a string representing the documentation to be validated. Description Checks if the provided documentation format is correct.

Returns true if the documentation is formatted correctly, false otherwise.

docs_to_module_doc_node(docs, acc_ast, module_ast)

Parameters

  • docs - the documentation string to be converted to an abstract syntax tree (AST).
  • acc_ast - the accumulator AST to which the new documentation will be added.
  • module_ast - the AST of the module where the documentation will be inserted.

Description

Converts a documentation string into an Elixir AST and inserts it into the specified module's AST.

Returns

the updated accumulator AST after inserting the new documentation.

insert_doc_for_function(ast, name_func, ast_doc, module_ast)

This should work for most of the modules, it will not work if the module contains only one function because Elixir does not create a __block__ node in this case.

insert_module_doc(ast, module_ast, ast_doc)

Parameters

  • ast - the Abstract Syntax Tree (AST) representing the module structure.
  • module_ast - the AST representation of the specific module to be modified.
  • ast_doc - a documentation string or AST node to be inserted into the module.

Description

Inserts documentation into a specified module in the AST by traversing and modifying the module's structure.

Returns

The modified AST with the new documentation inserted.

insert_nodes_in_module(arg, final_prompt, provider_mod, model_text, token, params, acc)

Parameters

_module - the module to which the nodes will be inserted. module_ast - the abstract syntax tree of the module. functions - a list of functions to be processed. final_prompt - a string prompt to be appended to each function's prompt. provider_mod - the module responsible for making requests to the provider. model_text - the text representation of the model used in the request. token - the authentication token for the provider. acc - the accumulator for building the updated abstract syntax tree.

Description Inserts nodes into a module based on provided functions and prompts.

Returns the updated abstract syntax tree after processing the functions.

proccess_files(entries)

Parameters

entries - a list of entry structures containing functions and associated ASTs. Description A list of entries to process, transforming functions based on model responses.

Returns None

run(command_line_args)

Parameters

_command_line_args - command line arguments provided to the function. Description Runs the main application logic for the LazyDoc utility, processing source files to extract documentation.

Returns None

write_to_file(file, ast)

write to given file the given Elixir AST This function does not write it in the proper format and it will remove comments as well

write_to_file_formatted(file, ast, comments)

Parameters

  • file - the name of the file where the formatted content will be written.
  • ast - the abstract syntax tree representation of the code to be written.
  • comments - optional comments to include with the formatted output.

Description

Formats the given abstract syntax tree (AST) and writes it to the specified file, including any provided comments.

Returns

:ok if the write operation is successful, or {:error, reason} if it fails.