Skip to content

land: import-and-ast-grep-fixes - #842

Merged
ualtinok merged 7 commits into
mainfrom
land/import-and-ast-grep-fixes
Oct 24, 2026
Merged

ualtinok merged 7 commits into
mainfrom
land/import-and-ast-grep-fixes

Conversation

@aft-alfonso

@aft-alfonso aft-alfonso Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Accepted agent delivery; branch-keyed search descriptor included.


Summary by cubic

Improves import comment handling so comments travel with imports, fixes comment parsing edge cases, and fixes two ast-grep display and preview inconsistencies.

Import handling

  • Organizing imports keeps same-line and directly-above comments with their statements; only comments separated from the next import by a blank line still split sorting.
  • Imports containing comments are kept verbatim instead of being regenerated, which previously dropped the comment.
  • Python groups follow isort's default order: import x lines by module, then from x import ... lines by module.
  • Removing an import now deletes its end-of-line comment along with it.
  • Line comments end at \r or \n instead of only \n, so removal and organize stop at the line break in CR-only files instead of erasing following code.
  • Lua long comments with level markers (--[=[, --[==[, ...) are recognized; code after a leveled comment on an import line is no longer deleted.

ast-grep

  • Dry-run rewrites that fail syntax validation now refuse with the affected file names, matching what apply does.
  • ast_search returns meta_variable_text; variadic $$$ captures render as their source text (e.g. $A: 1, 2) instead of the joined node list (. $A: 1,,,2).

Written for commit 4d72c89. Summary will update on new commits.

View guided diff Turn on auto-fix

RetriggerView in GreptileConfidence Score: 5/5

The changes appear safe to merge; no blocking issue remains.

Summary

The PR keeps comments with imports, improves Python import sorting, rejects invalid rewrite previews, and displays variadic captures as source text.

  • Organizing imports keeps comments with the statements they describe.
  • Removing an import also removes its same-line comment.
  • Ast-grep dry runs refuse rewrites that fail syntax checks.
  • Ast-grep search shows variadic captures as they appear in source.

Reviews (3) · Last reviewed commit: "Use the canonical path argument in the #..." · Reviewed by Greptile

ualtinok and others added 4 commits October 24, 2026 04:24
…st_grep dry-run/variadic display (#827, #828)

Co-authored-by: alfonso-aft <289616620+alfonso-aft@users.noreply.github.com>
…se invalid ast_replace previews (#827, #828)

aft_import organize:
- A same-line comment belongs to the statement before it, and comment
  lines directly above a statement (no blank line between) belong to that
  statement; both move with it when organize reorders, deduplicates or
  merges it. Only comments still left between imports (for example a
  section comment followed by a blank line) split the sort into segments,
  as before. Comments above the first import stay where they are.
- A statement with a comment inside it (for example inside a multi-line
  named-import list) is kept verbatim instead of being regenerated, which
  used to drop the comment silently.
- Python groups follow isort's default order: `import x` lines, then
  `from x import ...` lines, each by module name.

aft_import remove deletes the removed statement's same-line comment.

ast_replace dry runs refuse rewrites that fail the same syntax validation
apply uses, naming the files, instead of previewing them as success.

ast_search adds `meta_variable_text` (source text of each `$$$` capture)
and the reply shows it, so `foo(1, 2)` with `foo($$$A)` reads `$A: 1, 2`
instead of `$A: 1,,,2`. The `meta_variables` array is unchanged.
ast-grep's re-indentation of multi-line captures in rewrites is kept.

The six regression tests from the previous commit are no longer ignored;
the Python sort test now also pins isort's default order (`import json`
before `from collections ...`), and the dry-run test pins the exact reply.

Co-authored-by: alfonso-aft <289616620+alfonso-aft@users.noreply.github.com>
The Pi renderer builds its own match view from the raw ast_search payload,
so it still joined a variadic capture's node list (`1, ,, 2`). It now
prefers meta_variable_text when present, as the native reply does, and
falls back to the node list for an engine that does not send it. The
OpenCode plugin returns the native reply text, so it needs no change.

Co-authored-by: alfonso-aft <289616620+alfonso-aft@users.noreply.github.com>
…ixes

Co-authored-by: alfonso-aft <289616620+alfonso-aft@users.noreply.github.com>
Comment thread crates/aft/src/commands/remove_import.rs
Comment thread crates/aft/src/commands/organize_imports.rs Outdated
ualtinok and others added 3 commits October 24, 2026 04:54
…the line break (#828)

A line comment ran to the next \n only. In a file with CR-only line
endings that is the end of the file, so remove's same-line-tail expansion
deleted every line after the removed import (the result still parsed, so
nothing caught it), and organize carried the code after the last import
into the import block as that import's comment. Line comments now end at
\r or \n, and a same-line comment may not contain either.

Tests: CR-only remove and organize fail without the fix; the CRLF remove
case (TypeScript and Python) is a guard that already passed.

Co-authored-by: alfonso-aft <289616620+alfonso-aft@users.noreply.github.com>
Only `--[[ ... ]]` was recognized as a Lua long comment, so `--[=[`,
`--[==[` and deeper openers were read as line comments. remove's
same-line-tail expansion then deleted code that followed a one-line
leveled comment on the import's line (the result still parsed), and
organize refused a file whose leveled comment spans lines between imports
as "multiple code regions". A long comment now ends only at the closer
with the same number of `=` as its opener.

Tests: the remove-keeps-code and organize-multi-line cases fail without
the fix; the one-line `--[=[ ... ]=]` same-line removal is a guard that
already passed.

Co-authored-by: alfonso-aft <289616620+alfonso-aft@users.noreply.github.com>
The landing policy's vocabulary audit refuses the retired filePath spelling.

Co-authored-by: alfonso-aft <289616620+alfonso-aft@users.noreply.github.com>
@ualtinok
ualtinok added this pull request to the merge queue Oct 24, 2026
Merged via the queue into main with commit e40e776 Oct 24, 2026
88 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant