Plugins/CheckerPlugins/Pep8/Pep8Dialog.py

changeset 2891
6843b7d23279
parent 2890
86b03a0c94bc
child 2894
8e4264045fc9
--- a/Plugins/CheckerPlugins/Pep8/Pep8Dialog.py	Thu Sep 05 20:02:02 2013 +0200
+++ b/Plugins/CheckerPlugins/Pep8/Pep8Dialog.py	Sat Sep 07 14:18:32 2013 +0200
@@ -126,6 +126,7 @@
         @param fixed flag indicating a fixed issue (boolean)
         @param autofixing flag indicating, that we are fixing issues
             automatically (boolean)
+        @return reference to the created item (QTreeWidgetItem)
         """
         from .Pep8Fixer import Pep8FixableIssues
         
@@ -163,6 +164,8 @@
         itm.setData(0, self.messageRole, message)
         itm.setData(0, self.fixableRole, fixable)
         itm.setData(0, self.codeRole, code)
+        
+        return itm
     
     def __modifyFixedResultItem(self, itm, text, fixed):
         """
@@ -413,6 +416,7 @@
                         )
                         report = styleGuide.check_files([file])
                         report.errors.sort(key=lambda a: a[1])
+                    deferredFixes = {}
                     for error in report.errors:
                         fname, lineno, position, text = error
                         if lineno > len(source):
@@ -420,15 +424,35 @@
                         if "__IGNORE_WARNING__" not in Utilities.extractLineFlags(
                                 source[lineno - 1].strip()):
                             self.noResults = False
-                            fixed = False
                             if fixer:
-                                fixed, msg = fixer.fixIssue(lineno, position, text)
-                                if fixed:
+                                res, msg, id_ = fixer.fixIssue(lineno, position, text)
+                                if res == 1:
                                     text += "\n" + \
                                             self.trUtf8("Fix: {0}").format(msg)
-                            self.__createResultItem(
-                                fname, lineno, position, text, fixed, fixIssues)
-                    fixer and fixer.saveFile(encoding)
+                                    self.__createResultItem(
+                                        fname, lineno, position, text, True, True)
+                                elif res == 0:
+                                    self.__createResultItem(
+                                        fname, lineno, position, text, False, True)
+                                else:
+                                    itm = self.__createResultItem(
+                                        fname, lineno, position,
+                                        text, False, False)
+                                    deferredFixes[id_] = itm
+                            else:
+                                self.__createResultItem(
+                                    fname, lineno, position, text, False, False)
+                    if fixer:
+                        deferredResults = fixer.finalize()
+                        for id_ in deferredResults:
+                            fixed, msg = deferredResults[id_]
+                            itm = deferredFixes[id_]
+                            if fixed == 1:
+                                text = "\n" + self.trUtf8("Fix: {0}").format(msg)
+                                self.__modifyFixedResultItem(itm, text, True)
+                            else:
+                                self.__modifyFixedResultItem(itm, "", False)
+                        fixer.saveFile(encoding)
                     self.__updateStatistics(report.counters, fixer)
                     progress += 1
             finally:
@@ -753,6 +777,7 @@
                     progress += 1
                     continue
                 
+                deferredFixes = {}
                 fixer = Pep8Fixer(self.__project, file, source,
                                   fixCodes, noFixCodes, maxLineLength,
                                   True)  # always fix in place
@@ -762,12 +787,24 @@
                     (lineno, position, text), itm = error
                     if lineno > len(source):
                         lineno = len(source)
-                    fixed, msg = fixer.fixIssue(lineno, position, text)
-                    if fixed:
+                    fixed, msg, id_ = fixer.fixIssue(lineno, position, text)
+                    if fixed == 1:
                         text = "\n" + self.trUtf8("Fix: {0}").format(msg)
+                        self.__modifyFixedResultItem(itm, text, True)
+                    elif fixed == 0:
+                        self.__modifyFixedResultItem(itm, "", False)
                     else:
-                        text = ""
-                    self.__modifyFixedResultItem(itm, text, fixed)
+                        # remember item for the deferred fix
+                        deferredFixes[id_] = itm
+                deferredResults = fixer.finalize()
+                for id_ in deferredResults:
+                    fixed, msg = deferredResults[id_]
+                    itm = deferredFixes[id_]
+                    if fixed == 1:
+                        text = "\n" + self.trUtf8("Fix: {0}").format(msg)
+                        self.__modifyFixedResultItem(itm, text, True)
+                    else:
+                        self.__modifyFixedResultItem(itm, "", False)
                 fixer.saveFile(encoding)
                 
                 self.__updateFixerStatistics(fixer)

eric ide

mercurial