RefactoringRope/CodeAssistServer.py

changeset 291
da88cb84ae30
parent 287
09afe26b734c
child 293
dd1c7ed6d880
equal deleted inserted replaced
290:6b3530ce34d0 291:da88cb84ae30
14 14
15 from PyQt5.QtCore import pyqtSlot, QCoreApplication, QTimer 15 from PyQt5.QtCore import pyqtSlot, QCoreApplication, QTimer
16 16
17 from E5Gui.E5Application import e5App 17 from E5Gui.E5Application import e5App
18 from E5Gui import E5MessageBox 18 from E5Gui import E5MessageBox
19
20 from QScintilla.Editor import Editor
19 21
20 from .JsonServer import JsonServer 22 from .JsonServer import JsonServer
21 23
22 import Globals 24 import Globals
23 import Preferences 25 import Preferences
27 class CodeAssistServer(JsonServer): 29 class CodeAssistServer(JsonServer):
28 """ 30 """
29 Class implementing the autocompletion interface to rope. 31 Class implementing the autocompletion interface to rope.
30 """ 32 """
31 IdProject = "Project" 33 IdProject = "Project"
34
35 PictureIDs = {
36 "class": "?{0}".format(Editor.ClassID),
37 "_class": "?{0}".format(Editor.ClassProtectedID),
38 "__class": "?{0}".format(Editor.ClassPrivateID),
39 "instance": "?{0}".format(Editor.ClassID),
40 "_instance": "?{0}".format(Editor.ClassProtectedID),
41 "__instance": "?{0}".format(Editor.ClassPrivateID),
42 "function": "?{0}".format(Editor.MethodID),
43 "_function": "?{0}".format(Editor.MethodProtectedID),
44 "__function": "?{0}".format(Editor.MethodPrivateID),
45 "module": "?{0}".format(Editor.ModuleID),
46 "_module": "?{0}".format(Editor.ModuleID),
47 "__module": "?{0}".format(Editor.ModuleID),
48 "None": "",
49 }
32 50
33 def __init__(self, plugin, parent=None): 51 def __init__(self, plugin, parent=None):
34 """ 52 """
35 Constructor 53 Constructor
36 54
277 Private method to process the completions sent by the client. 295 Private method to process the completions sent by the client.
278 296
279 @param result dictionary containing the result sent by the client 297 @param result dictionary containing the result sent by the client
280 @type dict 298 @type dict
281 """ 299 """
300 names = []
301 for completion in result["Completions"]:
302 name = completion['Name']
303
304 name += CodeAssistServer.PictureIDs.get(
305 completion['CompletionType'], '')
306 names.append(name)
307
282 if self.__asyncCompletions: 308 if self.__asyncCompletions:
283 # asynchronous variant for eric6 17.11 and later 309 # asynchronous variant for eric6 17.11 and later
284 if "Error" not in result: 310 if "Error" not in result:
285 editor = self.__vm.getOpenEditor(result["FileName"]) 311 editor = self.__vm.getOpenEditor(result["FileName"])
286 if editor is not None: 312 if editor is not None:
287 editor.completionsListReady(result["Completions"], 313 editor.completionsListReady(names,
288 result["CompletionText"]) 314 result["CompletionText"])
289 else: 315 else:
290 # synchronous variant for eric6 before 17.11 316 # synchronous variant for eric6 before 17.11
291 if "Error" in result: 317 if "Error" in result:
292 self.__completions = [] 318 self.__completions = []
378 @type QScintilla.Editor.Editor 404 @type QScintilla.Editor.Editor
379 """ 405 """
380 if self.__documentationViewer is None: 406 if self.__documentationViewer is None:
381 return 407 return
382 408
383 language = editor.getLanguage() 409 idString = self.__idString(editor)
384 if not self.isSupportedLanguage(language): 410
411 if not idString:
412 language = editor.getLanguage()
385 if Preferences.getDocuViewer("ShowInfoAsRichText"): 413 if Preferences.getDocuViewer("ShowInfoAsRichText"):
386 warning = self.tr("Language <b>{0}</b> is not supported.")\ 414 warning = self.tr("Language <b>{0}</b> is not supported.")\
387 .format(language) 415 .format(language)
388 else: 416 else:
389 warning = self.tr("Language '{0}' is not supported.")\ 417 warning = self.tr("Language '{0}' is not supported.")\
390 .format(language) 418 .format(language)
391 self.__documentationViewer.documentationReady( 419 self.__documentationViewer.documentationReady(
392 warning, isWarning=True) 420 warning, isWarning=True)
393 return
394
395 idString = self.__idString(editor)
396 if not idString:
397 return 421 return
398 422
399 filename = editor.getFileName() 423 filename = editor.getFileName()
400 source = editor.text() 424 source = editor.text()
401 line, index = editor.getCursorPosition() 425 line, index = editor.getCursorPosition()
483 @param params dictionary containing the exception data 507 @param params dictionary containing the exception data
484 @type dict 508 @type dict
485 """ 509 """
486 if params["ExceptionType"] == "ProtocolError": 510 if params["ExceptionType"] == "ProtocolError":
487 self.__ui.appendToStderr( 511 self.__ui.appendToStderr(
488 self.tr("""The data received from the code assist""" 512 self.tr("The data received from the code assist"
489 """ server could not be decoded. Please report""" 513 " server could not be decoded. Please report"
490 """ this issue with the received data to the""" 514 " this issue with the received data to the"
491 """ eric bugs email address.\n""" 515 " eric bugs email address.\n"
492 """Error: {0}\n""" 516 "Error: {0}\n"
493 """Data: {1}\n""").format( 517 "Data:\n{1}\n").format(
494 params["ExceptionValue"], 518 params["ExceptionValue"],
495 params["ProtocolData"])) 519 params["ProtocolData"]))
496 else: 520 else:
497 self.__ui.appendToStderr( 521 self.__ui.appendToStderr(
498 self.tr("An exception happened in the code assist" 522 self.tr("An exception happened in the code assist"
778 Public method to connect an editor. 802 Public method to connect an editor.
779 803
780 @param editor reference to the editor 804 @param editor reference to the editor
781 @type QScintilla.Editor.Editor 805 @type QScintilla.Editor.Editor
782 """ 806 """
807 # TODO: special treatment for project files
783 if self.isSupportedLanguage(editor.getLanguage()): 808 if self.isSupportedLanguage(editor.getLanguage()):
784 if self.__plugin.getPreferences("CodeAssistEnabled") and \ 809 if self.__plugin.getPreferences("CodeAssistEnabled") and \
785 editor.getCompletionListHook("rope") is None: 810 editor.getCompletionListHook("rope") is None:
786 self.__setAutoCompletionHook(editor) 811 self.__setAutoCompletionHook(editor)
787 if self.__plugin.getPreferences("CodeAssistCalltipsEnabled") and \ 812 if self.__plugin.getPreferences("CodeAssistCalltipsEnabled") and \

eric ide

mercurial