[pycharm] restrict analysis in order to improve completion performance

GitOrigin-RevId: 1c2427d1dbb07d88672347311ec5d6f362881847
This commit is contained in:
Vladimir Koshelev
2024-07-16 11:54:05 +02:00
committed by intellij-monorepo-bot
parent 2eff1b56c4
commit 1aaaf77781

View File

@@ -87,9 +87,9 @@ public final class PyDefUseUtil {
return ControlFlowUtil.Operation.CONTINUE;
}
// not a back edge
if (instruction.num() < startNum && context.getOrigin() != null) {
// switch back to code analysis, since all other analyses are too aggressive
var newContext = TypeEvalContext.codeAnalysis(context.getOrigin().getProject(), context.getOrigin());
if (instruction.num() < startNum && context.getOrigin() == callInstruction.getElement().getContainingFile()) {
var newContext = TypeEvalContext.codeAnalysis(context.getOrigin().getProject(),
context.getOrigin());
if (callInstruction.isNoReturnCall(newContext)) return ControlFlowUtil.Operation.CONTINUE;
}
}
@@ -98,9 +98,9 @@ public final class PyDefUseUtil {
if (acceptTypeAssertions
&& instruction instanceof ConditionalInstruction conditionalInstruction
&& instruction.num() < startNum) {
if (conditionalInstruction.getCondition() instanceof PyTypedElement typedElement && context.getOrigin() != null) {
// switch back to code analysis, since all other analyses are too aggressive
TypeEvalContext newContext = TypeEvalContext.codeAnalysis(context.getOrigin().getProject(), context.getOrigin());
if (conditionalInstruction.getCondition() instanceof PyTypedElement typedElement && context.getOrigin() == typedElement.getContainingFile()) {
var newContext = TypeEvalContext.codeAnalysis(context.getOrigin().getProject(),
context.getOrigin());
if (newContext.getType(typedElement) instanceof PyNarrowedType narrowedType) {
if (narrowedType.getQname().equals(varName)) {
pendingTypeGuard.put(narrowedType.getOriginal(), conditionalInstruction);