src/eric7/Plugins/CheckerPlugins/SyntaxChecker/SyntaxCheckService.py

branch
eric7
changeset 10341
3fdffd9cc21d
parent 9972
68ac01294544
child 10373
093dcebe5ecb
equal deleted inserted replaced
10340:548b4c7f410e 10341:3fdffd9cc21d
46 46
47 def __determineLanguage(self, filename, source): 47 def __determineLanguage(self, filename, source):
48 """ 48 """
49 Private method to determine the language of the file. 49 Private method to determine the language of the file.
50 50
51 @param filename of the sourcefile (str) 51 @param filename of the sourcefile
52 @param source code of the file (str) 52 @type str
53 @return language of the file or None if not found (str or None) 53 @param source code of the file
54 @type str
55 @return language of the file or None if not found
56 @rtype str or None
54 """ 57 """
55 pyVer = PythonUtilities.determinePythonVersion(filename, source) 58 pyVer = PythonUtilities.determinePythonVersion(filename, source)
56 if pyVer: 59 if pyVer:
57 return "Python{0}".format(pyVer) 60 return "Python{0}".format(pyVer)
58 61
64 67
65 def addLanguage(self, lang, env, path, module, getArgs, getExt, callback, onError): 68 def addLanguage(self, lang, env, path, module, getArgs, getExt, callback, onError):
66 """ 69 """
67 Public method to register a new language to the supported languages. 70 Public method to register a new language to the supported languages.
68 71
69 @param lang new language to check syntax (str) 72 @param lang new language to check syntax
70 @param env the environment in which the checker is implemented (str) 73 @type str
71 @param path full path to the module (str) 74 @param env the environment in which the checker is implemented
72 @param module name to import (str) 75 @type str
76 @param path full path to the module
77 @type str
78 @param module name to import
79 @type str
73 @param getArgs function to collect the required arguments to call the 80 @param getArgs function to collect the required arguments to call the
74 syntax checker on client side (function) 81 syntax checker on client side
82 @type function
75 @param getExt function that returns the supported file extensions of 83 @param getExt function that returns the supported file extensions of
76 the syntax checker (function) 84 the syntax checker
77 @param callback function on service response (function) 85 @type function
86 @param callback function on service response
87 @type function
78 @param onError callback function if client or service isn't available 88 @param onError callback function if client or service isn't available
79 (function) 89 @type function
80 """ 90 """
81 self.__supportedLanguages[lang] = env, getArgs, getExt 91 self.__supportedLanguages[lang] = env, getArgs, getExt
82 # Connect to the background service 92 # Connect to the background service
83 self.backgroundService.serviceConnect( 93 self.backgroundService.serviceConnect(
84 "{0}Syntax".format(lang), 94 "{0}Syntax".format(lang),
92 102
93 def getLanguages(self): 103 def getLanguages(self):
94 """ 104 """
95 Public method to return the supported language names. 105 Public method to return the supported language names.
96 106
97 @return list of languanges supported (list of str) 107 @return list of languanges supported
108 @rtype list of str
98 """ 109 """
99 return list(self.__supportedLanguages.keys()) + ["MicroPython"] 110 return list(self.__supportedLanguages.keys()) + ["MicroPython"]
100 111
101 def removeLanguage(self, lang): 112 def removeLanguage(self, lang):
102 """ 113 """
103 Public method to remove the language from syntax check. 114 Public method to remove the language from syntax check.
104 115
105 @param lang language to remove (str) 116 @param lang language to remove
117 @type str
106 """ 118 """
107 self.__supportedLanguages.pop(lang, None) 119 self.__supportedLanguages.pop(lang, None)
108 self.backgroundService.serviceDisconnect("{0}Syntax".format(lang), lang) 120 self.backgroundService.serviceDisconnect("{0}Syntax".format(lang), lang)
109 121
110 def getExtensions(self): 122 def getExtensions(self):
111 """ 123 """
112 Public method to return all supported file extensions for the 124 Public method to return all supported file extensions for the
113 syntax checker dialog. 125 syntax checker dialog.
114 126
115 @return set of all supported file extensions (set of str) 127 @return set of all supported file extensions
128 @rtype set of str
116 """ 129 """
117 extensions = set() 130 extensions = set()
118 for _env, _getArgs, getExt in self.__supportedLanguages.values(): 131 for _env, _getArgs, getExt in self.__supportedLanguages.values():
119 for ext in getExt(): 132 for ext in getExt():
120 extensions.add(ext) 133 extensions.add(ext)
152 165
153 def syntaxBatchCheck(self, argumentsList): 166 def syntaxBatchCheck(self, argumentsList):
154 """ 167 """
155 Public method to prepare a syntax check on multiple source files. 168 Public method to prepare a syntax check on multiple source files.
156 169
157 @param argumentsList list of arguments tuples with each tuple 170 @param argumentsList list of argument tuples with each tuple
158 containing filename and source (string, string) 171 containing filename and source
172 @type list of tuples of (str, str)
159 """ 173 """
160 data = {} 174 data = {}
161 for lang in self.getLanguages(): 175 for lang in self.getLanguages():
162 data[lang] = [] 176 data[lang] = []
163 177
201 215
202 def __serviceError(self, fn, msg): 216 def __serviceError(self, fn, msg):
203 """ 217 """
204 Private slot handling service errors. 218 Private slot handling service errors.
205 219
206 @param fn file name (string) 220 @param fn file name
207 @param msg message text (string) 221 @type str
222 @param msg message text
223 @type str
208 """ 224 """
209 self.error.emit(fn, msg) 225 self.error.emit(fn, msg)
210 226
211 def serviceErrorPy3(self, fx, lang, fn, msg): 227 def serviceErrorPy3(self, fx, lang, fn, msg):
212 """ 228 """
213 Public method handling service errors for Python 3. 229 Public method handling service errors for Python 3.
214 230
215 @param fx service name (string) 231 @param fx service name
216 @param lang language (string) 232 @type str
217 @param fn file name (string) 233 @param lang language
218 @param msg message text (string) 234 @type str
235 @param fn file name
236 @type str
237 @param msg message text
238 @type str
219 """ 239 """
220 if fx in ["Python3Syntax", "batch_Python3Syntax"]: 240 if fx in ["Python3Syntax", "batch_Python3Syntax"]:
221 if fx == "Python3Syntax": 241 if fx == "Python3Syntax":
222 self.__serviceError(fn, msg) 242 self.__serviceError(fn, msg)
223 else: 243 else:
226 246
227 def serviceErrorJavaScript(self, fx, lang, fn, msg): 247 def serviceErrorJavaScript(self, fx, lang, fn, msg):
228 """ 248 """
229 Public method handling service errors for JavaScript. 249 Public method handling service errors for JavaScript.
230 250
231 @param fx service name (string) 251 @param fx service name
232 @param lang language (string) 252 @type str
233 @param fn file name (string) 253 @param lang language
234 @param msg message text (string) 254 @type str
255 @param fn file name
256 @type str
257 @param msg message text
258 @type str
235 """ 259 """
236 if fx in ["JavaScriptSyntax", "batch_JavaScriptSyntax"]: 260 if fx in ["JavaScriptSyntax", "batch_JavaScriptSyntax"]:
237 if fx == "JavaScriptSyntax": 261 if fx == "JavaScriptSyntax":
238 self.__serviceError(fn, msg) 262 self.__serviceError(fn, msg)
239 else: 263 else:
242 266
243 def serviceErrorYAML(self, fx, lang, fn, msg): 267 def serviceErrorYAML(self, fx, lang, fn, msg):
244 """ 268 """
245 Public method handling service errors for YAML. 269 Public method handling service errors for YAML.
246 270
247 @param fx service name (string) 271 @param fx service name
248 @param lang language (string) 272 @type str
249 @param fn file name (string) 273 @param lang language
250 @param msg message text (string) 274 @type str
275 @param fn file name
276 @type str
277 @param msg message text
278 @type str
251 """ 279 """
252 if fx in ["YAMLSyntax", "batch_YAMLSyntax"]: 280 if fx in ["YAMLSyntax", "batch_YAMLSyntax"]:
253 if fx == "YAMLSyntax": 281 if fx == "YAMLSyntax":
254 self.__serviceError(fn, msg) 282 self.__serviceError(fn, msg)
255 else: 283 else:
258 286
259 def serviceErrorJSON(self, fx, lang, fn, msg): 287 def serviceErrorJSON(self, fx, lang, fn, msg):
260 """ 288 """
261 Public method handling service errors for JSON. 289 Public method handling service errors for JSON.
262 290
263 @param fx service name (string) 291 @param fx service name
264 @param lang language (string) 292 @type str
265 @param fn file name (string) 293 @param lang language
266 @param msg message text (string) 294 @type str
295 @param fn file name
296 @type str
297 @param msg message text
298 @type str
267 """ 299 """
268 if fx in ["JSONSyntax", "batch_JSONSyntax"]: 300 if fx in ["JSONSyntax", "batch_JSONSyntax"]:
269 if fx == "JSONSyntax": 301 if fx == "JSONSyntax":
270 self.__serviceError(fn, msg) 302 self.__serviceError(fn, msg)
271 else: 303 else:
274 306
275 def serviceErrorTOML(self, fx, lang, fn, msg): 307 def serviceErrorTOML(self, fx, lang, fn, msg):
276 """ 308 """
277 Public method handling service errors for TOML. 309 Public method handling service errors for TOML.
278 310
279 @param fx service name (string) 311 @param fx service name
280 @param lang language (string) 312 @type str
281 @param fn file name (string) 313 @param lang language
282 @param msg message text (string) 314 @type str
315 @param fn file name
316 @type str
317 @param msg message text
318 @type str
283 """ 319 """
284 if fx in ["TOMLSyntax", "batch_TOMLSyntax"]: 320 if fx in ["TOMLSyntax", "batch_TOMLSyntax"]:
285 if fx == "TOMLSyntax": 321 if fx == "TOMLSyntax":
286 self.__serviceError(fn, msg) 322 self.__serviceError(fn, msg)
287 else: 323 else:
290 326
291 def batchJobDone(self, fx, lang): 327 def batchJobDone(self, fx, lang):
292 """ 328 """
293 Public slot handling the completion of a batch job. 329 Public slot handling the completion of a batch job.
294 330
295 @param fx service name (string) 331 @param fx service name
296 @param lang language (string) 332 @type str
333 @param lang language
334 @type str
297 """ 335 """
298 if fx in [ 336 if fx in [
299 "Python3Syntax", 337 "Python3Syntax",
300 "batch_Python3Syntax", 338 "batch_Python3Syntax",
301 "JavaScriptSyntax", 339 "JavaScriptSyntax",

eric ide

mercurial