Writes the current context window to logs/current_context_window (uses a symlink to a session ID). This PR was unfortunately generated by a different LLM and did a ton of superficial reformating, it's actually a fairly small and benign change, but I don't want to roll back everything. Hope that's ok.
45 lines
1.2 KiB
Rust
45 lines
1.2 KiB
Rust
//! Test Python async query
|
|
|
|
use streaming_iterator::StreamingIterator;
|
|
use tree_sitter::{Language, Parser, Query, QueryCursor};
|
|
|
|
fn main() -> anyhow::Result<()> {
|
|
let source_code = r#"
|
|
def regular_function():
|
|
pass
|
|
|
|
async def async_function():
|
|
pass
|
|
"#;
|
|
|
|
let mut parser = Parser::new();
|
|
let language: Language = tree_sitter_python::LANGUAGE.into();
|
|
parser.set_language(&language)?;
|
|
|
|
let tree = parser.parse(source_code, None).unwrap();
|
|
|
|
// Try different queries
|
|
let queries = vec![
|
|
"(function_definition (async) name: (identifier) @name)",
|
|
"(function_definition (async))",
|
|
"(async)",
|
|
];
|
|
|
|
for query_str in queries {
|
|
println!("\nTrying query: {}", query_str);
|
|
match Query::new(&language, query_str) {
|
|
Ok(query) => {
|
|
let mut cursor = QueryCursor::new();
|
|
let matches = cursor.matches(&query, tree.root_node(), source_code.as_bytes());
|
|
let count = matches.count();
|
|
println!(" ✓ Valid query, found {} matches", count);
|
|
}
|
|
Err(e) => {
|
|
println!(" ✗ Invalid query: {}", e);
|
|
}
|
|
}
|
|
}
|
|
|
|
Ok(())
|
|
}
|