Skip to content

Commit

Permalink
feat: Add comments of future todos
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelarie committed Oct 17, 2024
1 parent 242799b commit 7a60e93
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/config/alias_ignore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub struct AliasIgnoreResult {

pub fn get_ignore_set() -> Option<AliasIgnoreResult> {
let ignore_file = std::fs::read_to_string(".aliasignore");
let should_debug = *DEBUG_MODE_GLOBAL.get().unwrap_or(&false);

match ignore_file {
Ok(file_content) => {
Expand All @@ -20,15 +21,15 @@ pub fn get_ignore_set() -> Option<AliasIgnoreResult> {
let alias_name = line.trim_start_matches('!').to_string();

if first_char == Some('!') {
if *DEBUG_MODE_GLOBAL.get().unwrap_or(&false) {
if should_debug {
println!(
"IGNORE_CMD({}): Command ignored from alias list",
alias_name
);
}
command_ignores.push(alias_name);
} else {
if *DEBUG_MODE_GLOBAL.get().unwrap_or(&false) {
if should_debug {
println!(
"IGNORE({}): Alias ignored from alias list",
alias_name
Expand Down
28 changes: 26 additions & 2 deletions src/syntax_tree/alias.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use rayon::prelude::*;
// use crate::command::arguments::DEBUG_MODE_GLOBAL;

use super::nushell::validate_alias_with_nu_parser;
use rayon::prelude::*;

/// Unquote a string by removing the surrounding quotes.
/// Bash standard:
Expand Down Expand Up @@ -126,11 +128,13 @@ pub struct Alias {
}

/// Find aliases in the given syntax tree.
/// Uses rayon for parallel processing.
pub fn find_aliases(
cursor: &mut tree_sitter::TreeCursor,
source: &[u8],
) -> Vec<Alias> {
let mut aliases = Vec::new();
// let should_debug = *DEBUG_MODE_GLOBAL.get().unwrap_or(&false);

if !cursor.goto_first_child() {
return aliases;
Expand All @@ -150,7 +154,13 @@ pub fn find_aliases(
error_messages: Vec::new(),
});
}
}
} // TODO: Implement alias detection inside functions
// else if node.kind() == "function_definition" {
// if cursor.goto_first_child() {
// aliases.extend(find_aliases(cursor, source));
// cursor.goto_parent();
// }
// }

if !cursor.goto_next_sibling() {
break;
Expand All @@ -161,6 +171,20 @@ pub fn find_aliases(
aliases.par_iter_mut().for_each(|alias| {
let validate_result =
validate_alias_with_nu_parser(&alias.name, &alias.content);

// This might not be useful for the end user
// if should_debug {
// println!(
// "PARSED({}): Alias is {}",
// alias.name,
// if validate_result.is_valid {
// "valid"
// } else {
// "invalid"
// }
// );
// }

alias.is_valid_nushell = validate_result.is_valid;
alias.error_messages = validate_result.error_messages;
});
Expand Down

0 comments on commit 7a60e93

Please sign in to comment.