Skip to content

Commit f19cd8f

Browse files
committed
improve(ast-grep): better Python pattern hints
- Show exact pattern without colon when pattern ends with ':' - More actionable hint message
1 parent 181194a commit f19cd8f

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/tools/ast-grep/tools.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ function getEmptyResultHint(pattern: string, lang: CliLanguage): string | null {
1515

1616
if (lang === "python") {
1717
if (src.startsWith("class ") && src.endsWith(":")) {
18-
return `💡 Hint: Python class patterns need body. Try "class $NAME" or include body with $$$BODY`
18+
const withoutColon = src.slice(0, -1)
19+
return `💡 Hint: Remove trailing colon. Try: "${withoutColon}"`
1920
}
2021
if ((src.startsWith("def ") || src.startsWith("async def ")) && src.endsWith(":")) {
21-
return `💡 Hint: Python function patterns need body. Try "def $FUNC($$$):\\n $$$BODY"`
22+
const withoutColon = src.slice(0, -1)
23+
return `💡 Hint: Remove trailing colon. Try: "${withoutColon}"`
2224
}
2325
}
2426

0 commit comments

Comments
 (0)