39 order to identify the connection |
39 order to identify the connection |
40 @type str |
40 @type str |
41 """ |
41 """ |
42 super().__init__(host, port, idString) |
42 super().__init__(host, port, idString) |
43 |
43 |
44 # TODO: add additional methods for these topics |
|
45 # - extract function |
|
46 # - extract variable |
|
47 # - inline variable |
|
48 self.__methodMapping = { |
44 self.__methodMapping = { |
49 "openProject": self.__openProject, |
45 "openProject": self.__openProject, |
50 "closeProject": self.__closeProject, |
46 "closeProject": self.__closeProject, |
51 |
47 |
52 "getCompletions": self.__getCompletions, |
48 "getCompletions": self.__getCompletions, |
57 "gotoReferences": self.__getReferences, |
53 "gotoReferences": self.__getReferences, |
58 |
54 |
59 "renameVariable": self.__renameVariable, |
55 "renameVariable": self.__renameVariable, |
60 "extractVariable": self.__extractVariable, |
56 "extractVariable": self.__extractVariable, |
61 "inlineVariable": self.__inlineVariable, |
57 "inlineVariable": self.__inlineVariable, |
|
58 "extractFunction": self.__extractFunction, |
62 "applyRefactoring": self.__applyRefactoring, |
59 "applyRefactoring": self.__applyRefactoring, |
63 "cancelRefactoring": self.__cancelRefactoring, |
60 "cancelRefactoring": self.__cancelRefactoring, |
64 } |
61 } |
65 |
62 |
66 self.__id = idString |
63 self.__id = idString |
517 } |
514 } |
518 result.update(errorDict) |
515 result.update(errorDict) |
519 |
516 |
520 self.sendJson("RefactoringDiff", result) |
517 self.sendJson("RefactoringDiff", result) |
521 |
518 |
|
519 def __extractFunction(self, params): |
|
520 """ |
|
521 Private method to extract an expression to a new function. |
|
522 |
|
523 @param params dictionary containing the method parameters |
|
524 @type dict |
|
525 """ |
|
526 filename = params["FileName"] |
|
527 source = params["Source"] |
|
528 line = params["Line"] |
|
529 index = params["Index"] |
|
530 endLine = params["EndLine"] |
|
531 endIndex = params["EndIndex"] |
|
532 uid = params["Uuid"] |
|
533 newName = params["NewName"] |
|
534 |
|
535 errorDict = {} |
|
536 diff = "" |
|
537 |
|
538 script = jedi.Script(source, path=filename, project=self.__project) |
|
539 |
|
540 try: |
|
541 refactoring = script.extract_function( |
|
542 line, index, new_name=newName, |
|
543 until_line=endLine, until_column=endIndex |
|
544 ) |
|
545 self.__refactorings[uid] = refactoring |
|
546 diff = refactoring.get_diff() |
|
547 except SuppressedException as err: |
|
548 errorDict = self.__handleError(err) |
|
549 |
|
550 result = { |
|
551 "Diff": diff, |
|
552 "Uuid": uid, |
|
553 } |
|
554 result.update(errorDict) |
|
555 |
|
556 self.sendJson("RefactoringDiff", result) |
|
557 |
522 def __applyRefactoring(self, params): |
558 def __applyRefactoring(self, params): |
523 """ |
559 """ |
524 Private method to apply a refactoring. |
560 Private method to apply a refactoring. |
525 |
561 |
526 @param params dictionary containing the method parameters |
562 @param params dictionary containing the method parameters |