mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-05 01:50:56 +07:00
inject SQL in arguments of sqlite3 module (PY-4260 work in progress)
This commit is contained in:
@@ -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"/>
|
||||
|
||||
10
python/IntelliLang-python/src/pyInjections.xml
Normal file
10
python/IntelliLang-python/src/pyInjections.xml
Normal 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>
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user