From cfcd7d0c246fd1990d1aa6d0fbc21df09d666aaf Mon Sep 17 00:00:00 2001 From: Fabio Zadrozny Date: Sat, 28 Sep 2024 07:53:58 -0300 Subject: [PATCH] Fix in with_statement import on auto import --- .../AddTokenAndImportStatement.java | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/plugins/com.python.pydev.analysis/src/com/python/pydev/analysis/refactoring/quick_fixes/AddTokenAndImportStatement.java b/plugins/com.python.pydev.analysis/src/com/python/pydev/analysis/refactoring/quick_fixes/AddTokenAndImportStatement.java index 13d2b64bb5..525ab73f86 100644 --- a/plugins/com.python.pydev.analysis/src/com/python/pydev/analysis/refactoring/quick_fixes/AddTokenAndImportStatement.java +++ b/plugins/com.python.pydev.analysis/src/com/python/pydev/analysis/refactoring/quick_fixes/AddTokenAndImportStatement.java @@ -116,6 +116,17 @@ public LineStartingScope getPreviousLineThatStartsScope() { public void createTextEdit(ComputedInfo computedInfo) { try { + if (computedInfo.realImportRep.length() > 0) { + + //Workaround for: https://sourceforge.net/tracker/?func=detail&aid=2697165&group_id=85796&atid=577329 + //when importing from __future__ import with_statement, we actually want to add a 'with' token, not + //with_statement token. + boolean isWithStatement = computedInfo.realImportRep.equals("from __future__ import with_statement"); + if (isWithStatement) { + computedInfo.fReplacementString = "with"; + } + } + String delimiter = this.getDelimiter(); computedInfo.appliedWithTrigger = trigger == '.' || trigger == '('; @@ -151,15 +162,6 @@ public void createTextEdit(ComputedInfo computedInfo) { ImportHandleInfo realImportHandleInfo = null; if (computedInfo.realImportRep.length() > 0) { - - //Workaround for: https://sourceforge.net/tracker/?func=detail&aid=2697165&group_id=85796&atid=577329 - //when importing from __future__ import with_statement, we actually want to add a 'with' token, not - //with_statement token. - boolean isWithStatement = computedInfo.realImportRep.equals("from __future__ import with_statement"); - if (isWithStatement) { - computedInfo.fReplacementString = "with"; - } - if (groupImports) { try { realImportHandleInfo = new ImportHandleInfo(computedInfo.realImportRep);