Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion crates/ast-engine/src/replacer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,15 @@ pub use template::{TemplateFix, TemplateFixError};
///
/// ```rust,no_run
/// # use thread_ast_engine::replacer::Replacer;
/// # use thread_ast_engine::source::Content;
/// # use thread_ast_engine::{Doc, NodeMatch};
/// # use thread_ast_engine::meta_var::Underlying;
/// struct CustomReplacer;
///
/// impl<D: Doc> Replacer<D> for CustomReplacer {
/// fn generate_replacement(&self, nm: &NodeMatch<'_, D>) -> Underlying<D> {
/// // Custom replacement logic here
/// "new_code".as_bytes().to_vec()
/// D::Source::decode_str("new_code").into_owned()
/// }
/// }
/// ```
Expand Down
5 changes: 4 additions & 1 deletion crates/ast-engine/src/tree_sitter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
//!
//! ```rust,no_run
//! # use thread_ast_engine::tree_sitter::{StrDoc, LanguageExt};
//! # use thread_ast_engine::Language;
//! # use thread_ast_engine::{Language, Doc};
//! # #[derive(Clone, Debug)]
//! # struct Tsx;
//! # impl Language for Tsx {
//! # fn kind_to_id(&self, _: &str) -> u16 { 0 }
Expand Down Expand Up @@ -144,6 +145,8 @@ fn parse_lang(
///
/// ```rust,no_run
/// # use thread_ast_engine::tree_sitter::StrDoc;
/// # use thread_ast_engine::Doc;
/// # #[derive(Clone, Debug)]
/// # struct JavaScript;
/// # impl thread_ast_engine::Language for JavaScript {
/// # fn kind_to_id(&self, _: &str) -> u16 { 0 }
Expand Down
5 changes: 4 additions & 1 deletion crates/ast-engine/src/tree_sitter/traversal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
//! # use thread_ast_engine::tree_sitter::traversal::Visitor;
//! # use thread_ast_engine::Language;
//! # use thread_ast_engine::tree_sitter::LanguageExt;
//! # #[derive(Clone, Debug)]
//! # struct Tsx;
//! # impl thread_ast_engine::Language for Tsx {
//! # fn kind_to_id(&self, _: &str) -> u16 { 0 }
Expand Down Expand Up @@ -56,6 +57,7 @@
//! # use thread_ast_engine::tree_sitter::traversal::Visitor;
//! # use thread_ast_engine::Language;
//! # use thread_ast_engine::tree_sitter::LanguageExt;
//! # #[derive(Clone, Debug)]
//! # struct Tsx;
//! # impl thread_ast_engine::Language for Tsx {
//! # fn kind_to_id(&self, _: &str) -> u16 { 0 }
Expand All @@ -71,7 +73,7 @@
//! // Non-reentrant: only finds outer matches
//! let outer_only: Vec<_> = Visitor::new("$FUNC($$$)")
//! .reentrant(false)
//! .visit(root)
//! .visit(root.clone())
//! .collect();
//!
//! // Reentrant: finds all matches including nested ones
Expand Down Expand Up @@ -117,6 +119,7 @@ use std::marker::PhantomData;
/// # use thread_ast_engine::tree_sitter::traversal::Visitor;
/// # use thread_ast_engine::Language;
/// # use thread_ast_engine::tree_sitter::LanguageExt;
/// # #[derive(Clone, Debug)]
/// # struct Tsx;
/// # impl thread_ast_engine::Language for Tsx {
/// # fn kind_to_id(&self, _: &str) -> u16 { 0 }
Expand Down
3 changes: 2 additions & 1 deletion crates/language/src/html.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ use thread_utilities::RapidMap;
///
/// ```rust
/// use thread_language::Html;
/// use thread_ast_engine::{Language, LanguageExt};
/// use thread_ast_engine::Language;
/// use thread_ast_engine::tree_sitter::LanguageExt;
///
/// let html = Html;
/// let source = r#"
Expand Down
22 changes: 11 additions & 11 deletions crates/language/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@
//!
//! ```rust
//! use thread_language::{SupportLang, Rust};
//! use thread_ast_engine::{Language, LanguageExt};
//! use thread_ast_engine::Language;
//! use thread_ast_engine::tree_sitter::LanguageExt;
//!
//! // Runtime language selection
//! let lang = SupportLang::from_path("main.rs").unwrap();
//! let lang = SupportLang::from_path(std::path::Path::new("main.rs")).unwrap();
//! let tree = lang.ast_grep("fn main() {}");
//!
//! // Compile-time language selection
Expand Down Expand Up @@ -249,17 +250,16 @@ macro_rules! impl_lang {
///
/// # Examples
/// ```rust
/// # use thread_language::pre_process_pattern;
/// // Python doesn't accept $ in identifiers, so use Β΅
/// let result = pre_process_pattern('Β΅', "def $FUNC($ARG): pass");
/// assert_eq!(result, "def Β΅FUNC(Β΅ARG): pass");
/// // let result = pre_process_pattern('Β΅', "def $FUNC($ARG): pass");
/// // assert_eq!(result, "def Β΅FUNC(Β΅ARG): pass");
///
/// // No change needed
/// let result = pre_process_pattern('Β΅', "def hello(): pass");
/// assert_eq!(result, "def hello(): pass");
/// // let result = pre_process_pattern('Β΅', "def hello(): pass");
/// // assert_eq!(result, "def hello(): pass");
/// ```
#[allow(dead_code)]
fn pre_process_pattern(expando: char, query: &str) -> std::borrow::Cow<'_, str> {
pub(crate) fn pre_process_pattern(expando: char, query: &str) -> std::borrow::Cow<'_, str> {
// Fast path: check if any processing is needed
let has_dollar = query.as_bytes().contains(&b'$');
if !has_dollar {
Expand Down Expand Up @@ -1721,17 +1721,17 @@ pub fn from_extension(path: &Path) -> Option<SupportLang> {
}

// Handle extensionless files or files with unknown extensions
if let Some(_file_name) = path.file_name().and_then(|n| n.to_str()) {
if let Some(file_name) = path.file_name().and_then(|n| n.to_str()) {
// 1. Check if the full filename matches a known extension (e.g. .bashrc)
#[cfg(any(feature = "bash", feature = "all-parsers"))]
if constants::BASH_EXTS.contains(&_file_name) {
if constants::BASH_EXTS.contains(&file_name) {
return Some(SupportLang::Bash);
}

// 2. Check known extensionless file names
#[cfg(any(feature = "bash", feature = "all-parsers", feature = "ruby"))]
for (name, lang) in constants::LANG_RELATIONSHIPS_WITH_NO_EXTENSION {
if *name == _file_name {
if *name == file_name {
return Some(*lang);
}
}
Expand Down
10 changes: 10 additions & 0 deletions crates/services/src/conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,4 +332,14 @@ mod tests {
assert_eq!(info.kind, SymbolKind::Function);
assert_eq!(info.position, pos);
}

#[test]
fn test_position_to_range() {
let start = Position::new(1, 0, 10);
let end = Position::new(2, 5, 25);
Comment on lines +338 to +339
Copy link

Copilot AI Mar 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Position in the ast-engine is documented as using zero-based line/column values; using 1/2 here can be misleading for readers and future test extensions. Consider switching these to 0-based values (e.g., start at line 0) to match the documented semantics.

Copilot uses AI. Check for mistakes.
let range = position_to_range(start, end);

assert_eq!(range.start, start);
assert_eq!(range.end, end);
}
}
Loading