79 "Config": self.__setConfig, |
80 "Config": self.__setConfig, |
80 "CompletionsResult": self.__processCompletionsResult, |
81 "CompletionsResult": self.__processCompletionsResult, |
81 "CallTipsResult": self.__processCallTipsResult, |
82 "CallTipsResult": self.__processCallTipsResult, |
82 "DocumentationResult": self.__processDocumentationResult, |
83 "DocumentationResult": self.__processDocumentationResult, |
83 "GotoDefinitionResult": self.__gotoDefinitionResult, |
84 "GotoDefinitionResult": self.__gotoDefinitionResult, |
|
85 "GotoReferencesResult": self.__processGotoReferencesResult, |
84 |
86 |
85 "ClientException": self.__processClientException, |
87 "ClientException": self.__processClientException, |
86 } |
88 } |
87 |
89 |
88 self.__typeMapping = { |
90 self.__typeMapping = { |
94 "module": self.tr("module"), |
96 "module": self.tr("module"), |
95 "package": self.tr("package"), |
97 "package": self.tr("package"), |
96 "object": self.tr("object"), |
98 "object": self.tr("object"), |
97 "<unknown>": self.tr("not known"), |
99 "<unknown>": self.tr("not known"), |
98 } |
100 } |
|
101 |
|
102 # temporary store for editor references indexed by Uuid |
|
103 self.__editors = {} |
99 |
104 |
100 # Python 3 |
105 # Python 3 |
101 self.__ensureActive("Python3") |
106 self.__ensureActive("Python3") |
102 |
107 |
103 def __updateEditorLanguageMapping(self): |
108 def __updateEditorLanguageMapping(self): |
458 source = editor.text() |
463 source = editor.text() |
459 line, index = editor.getCursorPosition() |
464 line, index = editor.getCursorPosition() |
460 offset = len("".join(source.splitlines(True)[:line])) + index |
465 offset = len("".join(source.splitlines(True)[:line])) + index |
461 |
466 |
462 self.__ensureActive(idString) |
467 self.__ensureActive(idString) |
|
468 |
|
469 euuid = str(uuid.uuid4()) |
|
470 self.__editors[euuid] = editor |
|
471 |
463 self.sendJson("gotoDefinition", { |
472 self.sendJson("gotoDefinition", { |
464 "FileName": filename, |
473 "FileName": filename, |
465 "Offset": offset, |
474 "Offset": offset, |
466 "Source": editor.text(), |
475 "Source": source, |
467 "SysPath": sys.path, |
476 "SysPath": sys.path, |
|
477 "Uuid": euuid, |
468 }, idString=idString) |
478 }, idString=idString) |
469 |
479 |
470 def __gotoDefinitionResult(self, result): |
480 def __gotoDefinitionResult(self, result): |
471 """ |
481 """ |
472 Private method to handle the "Goto Definition" result sent by |
482 Private method to handle the "Goto Definition" result sent by |
475 @param result dictionary containing the result data |
485 @param result dictionary containing the result data |
476 @type dict |
486 @type dict |
477 """ |
487 """ |
478 if "Error" not in result: |
488 if "Error" not in result: |
479 # ignore errors silently |
489 # ignore errors silently |
480 if "Location" in result: |
490 location = result["Location"] |
481 location = result["Location"] |
491 euuid = result["Uuid"] |
|
492 if location: |
|
493 try: |
|
494 editor = self.__editors[euuid] |
|
495 except KeyError: |
|
496 editor = None |
|
497 |
|
498 if ( |
|
499 editor is not None and |
|
500 editor.getFileName() == location["ModulePath"] and |
|
501 editor.getCursorPosition()[0] + 1 == location["Line"] |
|
502 ): |
|
503 # this was a click onto the definition line |
|
504 # -> get references |
|
505 idString = self.__idString(editor) |
|
506 filename = editor.getFileName() |
|
507 source = editor.text() |
|
508 line, index = editor.getCursorPosition() |
|
509 offset = ( |
|
510 len("".join(source.splitlines(True)[:line])) + |
|
511 index |
|
512 ) |
|
513 self.sendJson("gotoReferences", { |
|
514 "FileName": filename, |
|
515 "Offset": offset, |
|
516 "Line": line + 1, |
|
517 "SysPath": sys.path, |
|
518 "Uuid": euuid, |
|
519 }, idString=idString) |
|
520 return |
|
521 |
482 self.__vm.openSourceFile(location["ModulePath"], |
522 self.__vm.openSourceFile(location["ModulePath"], |
483 location["Line"], |
523 location["Line"], |
484 addNext=True) |
524 addNext=True) |
485 else: |
525 else: |
486 ericApp().getObject("UserInterface").statusBar().showMessage( |
526 ericApp().getObject("UserInterface").statusBar().showMessage( |
487 self.tr('Code Assist: No definition found'), 5000) |
527 self.tr('Code Assist: No definition found'), 5000) |
|
528 |
|
529 with contextlib.suppress(KeyError): |
|
530 del self.__editors[euuid] |
|
531 |
|
532 def __processGotoReferencesResult(self, result): |
|
533 """ |
|
534 Private method callback for the goto references result. |
|
535 |
|
536 @param result dictionary containing the result data |
|
537 @type dict |
|
538 """ |
|
539 with contextlib.suppress(ImportError): |
|
540 from QScintilla.Editor import ReferenceItem |
|
541 |
|
542 if "Error" not in result: |
|
543 # ignore errors silently |
|
544 references = result["GotoReferencesList"] |
|
545 euuid = result["Uuid"] |
|
546 if references: |
|
547 try: |
|
548 editor = self.__editors[euuid] |
|
549 except KeyError: |
|
550 editor = None |
|
551 if editor is not None: |
|
552 referenceItemsList = [ |
|
553 ReferenceItem( |
|
554 modulePath=ref["ModulePath"], |
|
555 codeLine=ref["Code"], |
|
556 line=ref["Line"], |
|
557 column=0, |
|
558 ) for ref in references |
|
559 ] |
|
560 editor.gotoReferenceHandler(referenceItemsList) |
|
561 |
|
562 with contextlib.suppress(KeyError): |
|
563 del self.__editors[euuid] |
488 |
564 |
489 ####################################################################### |
565 ####################################################################### |
490 ## Methods below handle the network connection |
566 ## Methods below handle the network connection |
491 ####################################################################### |
567 ####################################################################### |
492 |
568 |