Repository navigation
land: import-and-ast-grep-fixes - #842
Merged
Merged
Conversation
…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>
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
import xlines by module, thenfrom x import ...lines by module.\ror\ninstead of only\n, so removal and organize stop at the line break in CR-only files instead of erasing following code.--[=[,--[==[, ...) are recognized; code after a leveled comment on an import line is no longer deleted.ast-grep
ast_searchreturnsmeta_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.


Confidence 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.
Reviews (3) · Last reviewed commit: "Use the canonical path argument in the #..." · Reviewed by Greptile