Skip to content

Commit

Permalink
Fix in with_statement import on auto import
Browse files Browse the repository at this point in the history
  • Loading branch information
fabioz committed Sep 28, 2024
1 parent 382c67a commit cfcd7d0
Showing 1 changed file with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 == '(';
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit cfcd7d0

Please sign in to comment.