From 7b5dfcfd61faa3f9012cefdc25c4131ccd122480 Mon Sep 17 00:00:00 2001 From: Andrey Vlasovskikh Date: Thu, 25 Dec 2014 15:37:55 +0300 Subject: [PATCH] Don't suggest live template inside string literals (PY-12349) The previous fix was unsuccessful since we ignored only string literal elements but not their subparts. --- .../liveTemplates/PythonTemplateContextType.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/python/src/com/jetbrains/python/codeInsight/liveTemplates/PythonTemplateContextType.java b/python/src/com/jetbrains/python/codeInsight/liveTemplates/PythonTemplateContextType.java index 359ad9cf3ba0..a3146634ad4e 100644 --- a/python/src/com/jetbrains/python/codeInsight/liveTemplates/PythonTemplateContextType.java +++ b/python/src/com/jetbrains/python/codeInsight/liveTemplates/PythonTemplateContextType.java @@ -43,13 +43,16 @@ public class PythonTemplateContextType extends FileTypeBasedContextType { if (super.isInContext(file, offset)) { final PsiElement element = file.findElementAt(offset); if (element != null) { - return !(isAfterDot(element) || element instanceof PsiComment || element instanceof PyStringLiteralExpression || - isInsideParameterList(element)); + return !(isAfterDot(element) || element instanceof PsiComment || isInsideStringLiteral(element) || isInsideParameterList(element)); } } return false; } + private static boolean isInsideStringLiteral(@NotNull PsiElement element) { + return PsiTreeUtil.getParentOfType(element, PyStringLiteralExpression.class, false) != null; + } + private static boolean isInsideParameterList(@NotNull PsiElement element) { return PsiTreeUtil.getParentOfType(element, PyParameterList.class) != null; }