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
11 changes: 11 additions & 0 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ _Coming soon._
| YAML (incl. Kubernetes) | ✓ | ✓ | | ✓ | | |
| JSON | ✓ | ✓ | ✓ | | | |
| TOML | ✓ | ✓ | | ✓ | | |
| Nix | ✓ | ✓ | ✓ | ✓ | | |
| Solidity | ✓ | ✓ | ✓ | ✓ | ✓ | |
| Pascal | ✓ | ✓ | ✓ | ✓ | | |
| R | ✓ | ✓ | ✓ | ✓ | | |
Expand All @@ -187,7 +188,7 @@ Every listed language works with `aft_outline`, `aft_zoom`, and `read`/`edit`/`w

Objective-C `.h` headers continue to use the C grammar in v1, so Objective-C interfaces declared only in headers may outline imperfectly compared with `.m`/`.mm` implementation files.

Metal uses the C++ grammar because there is no maintained tree-sitter-metal grammar; covered shader qualifiers still produce ordinary function symbols. CUDA uses the dedicated tree-sitter-cuda grammar so kernel launches remain call expressions, and `__global__` definitions render as `kernel` symbols. TOML is structural for outline, zoom, and semantic chunking, but is intentionally absent from AST pattern tools because its key grammar does not accept ast-grep's identifier metavariable sentinels.
Metal uses the C++ grammar because there is no maintained tree-sitter-metal grammar; covered shader qualifiers still produce ordinary function symbols. CUDA uses the dedicated tree-sitter-cuda grammar so kernel launches remain call expressions, and `__global__` definitions render as `kernel` symbols. TOML is structural for outline, zoom, and semantic chunking, but is intentionally absent from AST pattern tools because its key grammar does not accept ast-grep's identifier metavariable sentinels. Nix supports outline, zoom, AST search/replace, and semantic chunking, but its Imports and Refactor columns are intentionally blank and it contributes no call-graph edges: bindings are not declarations; standalone bindings and `inherit` clauses use contextual patterns, while complete Nix expressions use the normal AST pattern path. `$NAME` metavariables are rewritten to `_NAME`, so an identifier of `_` followed by an all-uppercase name (`_FOO`) is read as a metavariable, while `_module.args`, `_Foo`, and `__functor` stay literal.

Indexes honor `.gitignore` and an optional `.aftignore` (same syntax) for paths git can't exclude, such as submodules. Naming a file explicitly in `grep` searches it even when ignored, matching ripgrep.

Expand Down
2 changes: 2 additions & 0 deletions assets/aft.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
"rustfmt",
"goimports",
"gofmt",
"nixfmt",
"none"
]
}
Expand Down Expand Up @@ -1004,6 +1005,7 @@
"rustfmt",
"goimports",
"gofmt",
"nixfmt",
"none"
]
}
Expand Down
6 changes: 4 additions & 2 deletions crates/aft-base/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -992,8 +992,10 @@ pub struct Config {
/// Optional automatic validation mode after edits (default: None, disabled).
/// When "syntax", only tree-sitter parse check. When "full", runs type checker.
pub validate_on_edit: Option<String>,
/// Per-language formatter overrides. Keys: "typescript", "python", "rust", "go".
/// Values: "biome", "oxfmt", "prettier", "deno", "ruff", "black", "rustfmt", "goimports", "gofmt", "none".
/// Per-language formatter overrides. Keys: "typescript", "python", "rust",
/// "go", "nix". Values: "biome", "oxfmt", "prettier", "deno", "ruff",
/// "black", "rustfmt", "goimports", "gofmt", "nixfmt", "none". Nix has no
/// auto-detection and formats only when "nix" is set explicitly.
pub formatter: HashMap<String, String>,
/// Per-language type checker overrides. Keys: "typescript", "python", "rust", "go".
/// Values: "tsc", "tsgo", "biome", "pyright", "ruff", "cargo", "go", "staticcheck", "none".
Expand Down
26 changes: 26 additions & 0 deletions crates/aft-base/src/config_resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ pub enum RawFormatter {
Rustfmt,
Goimports,
Gofmt,
Nixfmt,
Comment thread
kido5217 marked this conversation as resolved.
Resolved
None,
}

Expand All @@ -335,6 +336,7 @@ impl RawFormatter {
Self::Rustfmt => "rustfmt",
Self::Goimports => "goimports",
Self::Gofmt => "gofmt",
Self::Nixfmt => "nixfmt",
Self::None => "none",
}
}
Expand Down Expand Up @@ -4069,6 +4071,30 @@ where

#[cfg(test)]
mod tests {
#[test]
fn nixfmt_is_a_recognized_formatter_and_reaches_the_resolved_map() {
let raw = serde_json::from_str::<super::RawAftConfig>(r#"{"formatter":{"nix":"nixfmt"}}"#);
assert!(raw.is_ok(), "formatter.nix must accept nixfmt: {raw:?}");

let result = super::resolve_config_for_harness(
&[tier("user", r#"{"formatter":{"nix":"nixfmt"}}"#)],
Some(&Harness::Opencode),
);
assert!(result.errors.is_empty(), "{:?}", result.errors);
assert_eq!(
result.config.formatter.get("nix").map(String::as_str),
Some("nixfmt")
);
assert!(
!result
.dropped
.iter()
.any(|dropped| dropped.key.starts_with("formatter")),
"formatter.nix must not be dropped: {:?}",
result.dropped
);
}

#[test]
fn storage_cache_dir_is_a_recognized_user_setting() {
let raw = serde_json::from_str::<super::RawAftConfig>(
Expand Down
4 changes: 3 additions & 1 deletion crates/aft-base/src/lang_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ pub enum LangId {
ObjC,
Toml,
Luau,
Nix,
}

#[cfg(any(test, feature = "test-support"))]
Expand All @@ -50,7 +51,7 @@ pub const TEST_EXTENSIONS: &[&str] = &[
"htm", "md", "markdown", "mdx", "qmd", "Qmd", "rmd", "Rmd", "sol", "scss", "vue", "json",
"jsonc", "scala", "sc", "java", "rb", "kt", "kts", "swift", "inc", "php", "lua", "pl", "pm",
"t", "yaml", "yml", "pas", "pp", "dpr", "dpk", "lpr", "R", "r", "groovy", "gvy", "gy", "gsh",
"gradle", "m", "mm", "toml", "luau", "H", "unknown", "",
"gradle", "m", "mm", "toml", "luau", "nix", "H", "unknown", "",
];

/// Classify by name without reading the file. A `.h` result is provisional C;
Expand Down Expand Up @@ -98,6 +99,7 @@ pub fn native_language_by_extension(ext: &str) -> Option<LangId> {
"groovy" | "gvy" | "gy" | "gsh" | "gradle" => Some(LangId::Groovy),
"m" | "mm" => Some(LangId::ObjC),
"toml" => Some(LangId::Toml),
"nix" => Some(LangId::Nix),
_ => None,
}
}
1 change: 1 addition & 0 deletions crates/aft-parse/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ tree-sitter-solidity = "1.2"
tree-sitter-vue = { package = "tree-sitter-vue-next", version = "0.1" }
tree-sitter-json = "0.24"
tree-sitter-toml = { package = "tree-sitter-toml-ng", version = "0.7.0" }
tree-sitter-nix = "0.3.0"
tree-sitter-scala = "0.26"
tree-sitter-java = "0.23"
tree-sitter-ruby = "0.23"
Expand Down
110 changes: 110 additions & 0 deletions crates/aft-parse/src/ast_grep_hints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,21 @@ pub fn detect_language_specific_mistake(pattern: &str, lang: &AstGrepLang) -> Op
);
}
}
AstGrepLang::Nix => {
// An attrset body (`a = 1; b = 2;` / `a = 1; inherit b;`) is several
// sibling expressions with no single AST node to bind, so the
// contextual fallback refuses it. Scope the pattern to one member.
if nix_pattern_has_multiple_bindings(src) {
return Some(
"Hint: A nix pattern must contain one binding or one inherit clause \
(e.g. \"$NAME = $VALUE;\" or \"inherit $NAME;\"). An attrset body is \
several expressions with no single AST node to match, so it will not \
parse — search for one binding at a time, or match the enclosing \
attrset expression."
.to_string(),
);
}
}
_ => {}
}

Expand Down Expand Up @@ -166,6 +181,101 @@ fn has_regex_escape(src: &str) -> bool {
false
}

/// A Nix attrset body carries several sibling members (`a = 1; b = 2;` or
/// `a = 1; inherit b;`), so the contextual fallback has no single node to bind
/// and refuses the pattern. The shape reads as a top-level `;` with a further
/// binding-shaped member after it. String contents are skipped so a `;` inside
/// `"x;y"` is not mistaken for a binding terminator.
fn nix_pattern_has_multiple_bindings(src: &str) -> bool {
let bytes = src.as_bytes();
let mut depth: i32 = 0;
let mut in_string = false;
let mut in_indented_string = false;
let mut escaped = false;
let mut i = 0;
while i < bytes.len() {
let b = bytes[i];
if in_indented_string {
// `''` closes an indented string only when not immediately
// followed by `'` (the `'''` literal apostrophe) or `$` (the
// `''${` literal interpolation marker; interpolation itself is
// `${`, which never closes).
if b == b'\'' && bytes.get(i + 1) == Some(&b'\'') {
match bytes.get(i + 2) {
Some(&b'\'') | Some(&b'$') => i += 3,
_ => {
in_indented_string = false;
i += 2;
}
}
continue;
}
i += 1;
continue;
}
if in_string {
if escaped {
escaped = false;
} else if b == b'\\' {
escaped = true;
} else if b == b'"' {
in_string = false;
}
i += 1;
continue;
}
match b {
// Consume both opening quotes so escape detection stays anchored
// at delimiter boundaries (`''''` is an empty indented string,
// not an opening followed by an escape).
b'\'' if bytes.get(i + 1) == Some(&b'\'') => {
in_indented_string = true;
i += 2;
continue;
}
b'"' => in_string = true,
b'{' | b'[' | b'(' => depth += 1,
b'}' | b']' | b')' => depth = (depth - 1).max(0),
b';' if depth == 0 => {
// The next member can hide behind whitespace and `#` line
// comments, or open as a quoted attribute name (`"a" = 1;`).
let mut j = i + 1;
while j < bytes.len() {
let c = bytes[j];
if c.is_ascii_whitespace() {
j += 1;
} else if c == b'#' {
while j < bytes.len() && bytes[j] != b'\n' {
j += 1;
}
} else {
break;
}
}
if let Some(&c) = bytes.get(j) {
// A top-level `let …; in …` expression is one member: the
// `in` that terminates the let is not a sibling binding.
if c == b'i'
&& bytes.get(j + 1) == Some(&b'n')
&& !matches!(bytes.get(j + 2),
Some(w) if w.is_ascii_alphanumeric() || *w == b'_')
{
i = j + 2;
continue;
}
if c.is_ascii_alphabetic() || c == b'_' || c == b'$' || c == b'"' || c == b'\''
{
return true;
Comment on lines +255 to +268

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Valid searches get wrong advice

A valid pattern such as let a = 1; in a triggers this hint because the scanner treats in after the semicolon as another binding. When the search finds no matches, ast_search incorrectly says the expression cannot parse and should be split apart. Users or agents following that advice may abandon the intended search.

Check that the pattern is an attrset-body fragment before giving this advice.

}
}
}
_ => {}
}
i += 1;
}
false
}

/// Recognize compact regex ranges, not subtraction inside an AST subscript.
/// A receiver followed by a terminal index is valid code even when the index
/// resembles a range; only unmistakable character-class shapes warrant advice.
Expand Down
Loading
Loading