Skip to content

Commit

Permalink
docs: add documentation to input public items
Browse files Browse the repository at this point in the history
  • Loading branch information
oyarsa committed Jan 20, 2025
1 parent 9854b8d commit 5e586c5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ static TS_QUERY_JAVASCRIPT: LazyLock<tree_sitter::Query> = LazyLock::new(|| {
});

impl FileType {
/// Get [Tree Sitter query](tree_sitter::Query) for file type.
pub fn tree_sitter_query(&self) -> &'static tree_sitter::Query {
match self {
FileType::Python => &TS_QUERY_PYTHON,
Expand All @@ -53,6 +54,7 @@ impl FileType {
}
}

/// Get [Tree Sitter language](tree_sitter::Language) object from file type.
pub fn tree_sitter_language(&self) -> tree_sitter::Language {
match self {
FileType::Python => tree_sitter_python::LANGUAGE.into(),
Expand All @@ -62,10 +64,18 @@ impl FileType {
}
}

/// Read content of file in `path` to a String.
///
/// # Errors
/// If there's a problem reading the file (e.g. if it doesn't exist).
pub fn read_file(path: &PathBuf) -> Result<String> {
fs::read_to_string(path).map_err(|e| anyhow::anyhow!("Failed to read file: {}", e))
}

/// Determine file type from `path` extension. See [FileType].
///
/// # Errors
/// If the file type is not supported.
pub fn determine_file_type(path: &PathBuf) -> Result<FileType> {
FileType::try_from(path)
}
Expand Down
1 change: 0 additions & 1 deletion src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ pub const TAG: &str = "@";
///
/// # Errors
/// If parsing the source code fails, or the tree-sitter query is invalid.
/// ```
pub fn extract_annotations(
source_code: &str,
file_type: &FileType,
Expand Down
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5e586c5

Please sign in to comment.