improve(ast-grep): better Python pattern hints

- Show exact pattern without colon when pattern ends with ':'
- More actionable hint message
This commit is contained in:
YeonGyu-Kim
2025-12-05 21:57:58 +09:00
parent 181194ae3c
commit f19cd8fc71

View File

@@ -15,10 +15,12 @@ function getEmptyResultHint(pattern: string, lang: CliLanguage): string | null {
if (lang === "python") { if (lang === "python") {
if (src.startsWith("class ") && src.endsWith(":")) { if (src.startsWith("class ") && src.endsWith(":")) {
return `💡 Hint: Python class patterns need body. Try "class $NAME" or include body with $$$BODY` const withoutColon = src.slice(0, -1)
return `💡 Hint: Remove trailing colon. Try: "${withoutColon}"`
} }
if ((src.startsWith("def ") || src.startsWith("async def ")) && src.endsWith(":")) { if ((src.startsWith("def ") || src.startsWith("async def ")) && src.endsWith(":")) {
return `💡 Hint: Python function patterns need body. Try "def $FUNC($$$):\\n $$$BODY"` const withoutColon = src.slice(0, -1)
return `💡 Hint: Remove trailing colon. Try: "${withoutColon}"`
} }
} }