mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Merge branch 'python-fixes'
This commit is contained in:
+26
@@ -16,7 +16,15 @@
|
||||
package com.jetbrains.python.codeInsight.liveTemplates;
|
||||
|
||||
import com.intellij.codeInsight.template.FileTypeBasedContextType;
|
||||
import com.intellij.patterns.PsiElementPattern;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.util.ProcessingContext;
|
||||
import com.jetbrains.python.PyTokenTypes;
|
||||
import com.jetbrains.python.PythonFileType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static com.intellij.patterns.PlatformPatterns.psiElement;
|
||||
|
||||
/**
|
||||
* @author yole
|
||||
@@ -25,4 +33,22 @@ public class PythonTemplateContextType extends FileTypeBasedContextType {
|
||||
public PythonTemplateContextType() {
|
||||
super("Python", "Python", PythonFileType.INSTANCE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInContext(@NotNull PsiFile file, int offset) {
|
||||
if (super.isInContext(file, offset)) {
|
||||
final PsiElement element = file.findElementAt(offset);
|
||||
if (element != null) {
|
||||
return !isAfterDot(element);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean isAfterDot(@NotNull PsiElement element) {
|
||||
ProcessingContext context = new ProcessingContext();
|
||||
final PsiElementPattern.Capture<PsiElement> capture = psiElement().afterLeafSkipping(psiElement().whitespace(),
|
||||
psiElement().withElementType(PyTokenTypes.DOT));
|
||||
return capture.accepts(element, context);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user