59 |
59 |
60 ericPath = getConfig('ericDir') |
60 ericPath = getConfig('ericDir') |
61 path = os.path.join(ericPath, 'Plugins', 'CheckerPlugins', |
61 path = os.path.join(ericPath, 'Plugins', 'CheckerPlugins', |
62 'SyntaxChecker') |
62 'SyntaxChecker') |
63 |
63 |
64 self.syntaxCheckService.addLanguage('Python2', path, 'SyntaxCheck', |
64 self.syntaxCheckService.addLanguage( |
65 self.__getPythonOptions, |
65 'Python2', path, 'SyntaxCheck', |
66 lambda: Preferences.getPython("PythonExtensions"), |
66 self.__getPythonOptions, |
67 self.__translateSyntaxCheck, |
67 lambda: Preferences.getPython("PythonExtensions"), |
68 lambda fx, lng, fn, msg: \ |
68 self.__translateSyntaxCheck, |
69 self.syntaxCheckService.syntaxChecked.emit( |
69 lambda fx, lng, fn, msg: |
70 fn, True, fn, 0, 0, '', msg, [])) |
70 self.syntaxCheckService.syntaxChecked.emit( |
71 |
71 fn, {'error': (fn, 0, 0, '', msg)})) |
72 self.syntaxCheckService.addLanguage('Python3', path, 'SyntaxCheck', |
72 |
73 self.__getPythonOptions, |
73 self.syntaxCheckService.addLanguage( |
74 lambda: Preferences.getPython("Python3Extensions"), |
74 'Python3', path, 'SyntaxCheck', |
75 self.__translateSyntaxCheck, |
75 self.__getPythonOptions, |
76 lambda fx, lng, fn, msg: \ |
76 lambda: Preferences.getPython("Python3Extensions"), |
77 self.syntaxCheckService.syntaxChecked.emit( |
77 self.__translateSyntaxCheck, |
78 fn, True, fn, 0, 0, '', msg, [])) |
78 lambda fx, lng, fn, msg: |
|
79 self.syntaxCheckService.syntaxChecked.emit( |
|
80 fn, {'error': (fn, 0, 0, '', msg)})) |
79 |
81 |
80 def __initialize(self): |
82 def __initialize(self): |
81 """ |
83 """ |
82 Private slot to (re)initialize the plugin. |
84 Private slot to (re)initialize the plugin. |
83 """ |
85 """ |
101 checkFlakes = Preferences.getFlakes("IncludeInSyntaxCheck") |
103 checkFlakes = Preferences.getFlakes("IncludeInSyntaxCheck") |
102 ignoreStarImportWarnings = Preferences.getFlakes( |
104 ignoreStarImportWarnings = Preferences.getFlakes( |
103 "IgnoreStarImportWarnings") |
105 "IgnoreStarImportWarnings") |
104 return checkFlakes, ignoreStarImportWarnings |
106 return checkFlakes, ignoreStarImportWarnings |
105 |
107 |
106 def __translateSyntaxCheck( |
108 def __translateSyntaxCheck(self, fn, problems): |
107 self, fn, nok, fname, line, index, code, error, warnings): |
|
108 """ |
109 """ |
109 Slot to translate the resulting messages. |
110 Slot to translate the resulting messages. |
110 |
111 |
111 If checkFlakes is True, warnings contains a list of strings containing |
112 If checkFlakes is True, warnings contains a list of strings containing |
112 the warnings (marker, file name, line number, message) |
113 the warnings (marker, file name, line number, message) |
113 The values are only valid, if nok is False. |
114 The values are only valid, if nok is False. |
114 |
115 |
115 @param fn filename of the checked file (str) |
116 @param fn filename of the checked file (str) |
116 @param nok flag if an error in the source was found (boolean) |
117 @param problems dictionary with the keys 'error' and 'warnings' which |
117 @param fname filename of the checked file (str) # TODO: remove dubl. |
118 hold a list containing details about the error/ warnings |
118 @param line number where the error occured (int) |
119 (file name, line number, column, codestring (only at syntax |
119 @param index the column where the error occured (int) |
120 errors), the message, a list with arguments for the message) |
120 @param code the part of the code where the error occured (str) |
121 """ |
121 @param error the name of the error (str) |
122 warnings = problems.get('warnings', []) |
122 @param warnings a list of strings containing the warnings |
|
123 (marker, file name, line number, col, message, list(msg_args)) |
|
124 """ |
|
125 for warning in warnings: |
123 for warning in warnings: |
126 # Translate messages |
124 # Translate messages |
127 msg_args = warning.pop() |
125 msg_args = warning.pop() |
128 translated = QApplication.translate( |
126 translated = QApplication.translate( |
129 'py3Flakes', warning[4]).format(*msg_args) |
127 'py3Flakes', warning[4]).format(*msg_args) |
130 # Avoid leading "u" at Python2 unicode strings |
128 # Avoid leading "u" at Python2 unicode strings |
131 if translated.startswith("u'"): |
129 if translated.startswith("u'"): |
132 translated = translated[1:] |
130 translated = translated[1:] |
133 warning[4] = translated.replace(" u'", " '") |
131 warning[4] = translated.replace(" u'", " '") |
134 |
132 |
135 self.syntaxCheckService.syntaxChecked.emit( |
133 problems['warnings'] = warnings |
136 fn, nok, line, index, code, error, warnings) |
134 self.syntaxCheckService.syntaxChecked.emit(fn, problems) |
137 |
135 |
138 def activate(self): |
136 def activate(self): |
139 """ |
137 """ |
140 Public method to activate this plugin. |
138 Public method to activate this plugin. |
141 |
139 |