inject SQL in arguments of sqlite3 module (PY-4260 work in progress)

This commit is contained in:
Dmitry Jemerov
2013-07-19 16:29:23 +02:00
parent 58d28e44dc
commit 36f033f667
3 changed files with 18 additions and 1 deletions

View File

@@ -3,6 +3,7 @@
<idea-plugin version="2">
<extensions defaultExtensionNs="org.intellij.intelliLang">
<languageSupport implementation="com.jetbrains.python.intelliLang.PyLanguageInjectionSupport"/>
<injectionConfig config="pyInjections.xml"/>
</extensions>
<extensions defaultExtensionNs="com.intellij">
<patterns.patternClass className="com.jetbrains.python.patterns.PythonPatterns" alias="py"/>

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<component name="LanguageInjectionConfiguration">
<injection language="SQLite" injector-id="python">
<display-name>sqlite3</display-name>
<place><![CDATA[pyLiteralExpression().and(pyMethodArgument("execute", 0, "_sqlite3.Connection"))]]></place>
<place><![CDATA[pyLiteralExpression().and(pyMethodArgument("executemany", 0, "_sqlite3.Connection"))]]></place>
<place><![CDATA[pyLiteralExpression().and(pyMethodArgument("execute", 0, "_sqlite3.Cursor"))]]></place>
<place><![CDATA[pyLiteralExpression().and(pyMethodArgument("executemany", 0, "_sqlite3.Cursor"))]]></place>
</injection>
</component>

View File

@@ -9,6 +9,7 @@ import com.intellij.util.ProcessingContext;
import com.jetbrains.python.codeInsight.controlflow.ScopeOwner;
import com.jetbrains.python.psi.*;
import com.jetbrains.python.psi.resolve.PyResolveContext;
import com.jetbrains.python.psi.types.TypeEvalContext;
import org.jetbrains.annotations.Nullable;
/**
@@ -69,7 +70,12 @@ public class PythonPatterns extends PlatformPatterns {
}
PyExpression expression = (PyExpression) o;
PyCallExpression call = (PyCallExpression) expression.getParent().getParent();
PyCallExpression.PyMarkedCallee callee = call.resolveCallee(PyResolveContext.noImplicits());
// TODO is it better or worse to allow implicits here?
PyResolveContext context = PyResolveContext.noImplicits()
.withTypeEvalContext(TypeEvalContext.codeAnalysis(expression.getContainingFile()));
PyCallExpression.PyMarkedCallee callee = call.resolveCallee(context);
return callee != null ? callee.getCallable() : null;
}