RefactoringRope/RefactoringClient.py

branch
server_client_variant
changeset 173
2cdb7c48b719
parent 172
c8890f852917
child 174
04583cac110f
equal deleted inserted replaced
172:c8890f852917 173:2cdb7c48b719
450 450
451 from ProgressHandle import ProgressHandle 451 from ProgressHandle import ProgressHandle
452 self.__progressHandle = ProgressHandle(self, params["Title"], False) 452 self.__progressHandle = ProgressHandle(self, params["Title"], False)
453 try: 453 try:
454 changes = self.__changes[params["ChangeGroup"]] 454 changes = self.__changes[params["ChangeGroup"]]
455 self.___project.do(changes, self.__progressHandle) 455 self.__project.do(changes, self.__progressHandle)
456 except Exception as err: 456 except Exception as err:
457 errorDict = self.__handleRopeError(err) 457 errorDict = self.__handleRopeError(err)
458 self.__progressHandle.reset() 458 self.__progressHandle.reset()
459 self.__progressHandle = None 459 self.__progressHandle = None
460 460
461 result = { 461 result = {
462 "Subcommand": "ChangesApplied", 462 "Subcommand": "ChangesApplied",
463 "ChangeGroup": params["ChangeGroup"], 463 "ChangeGroup": params["ChangeGroup"],
464 "Title": params["Title"],
464 "ChangedFiles": [ 465 "ChangedFiles": [
465 res.real_path for res in changes.get_changed_resources() 466 res.real_path for res in changes.get_changed_resources()
466 ], 467 ],
467 } 468 }
468 result.update(errorDict) 469 result.update(errorDict)
475 476
476 @param params dictionary containing the method parameters sent by 477 @param params dictionary containing the method parameters sent by
477 the server 478 the server
478 @type dict 479 @type dict
479 """ 480 """
480 changes = self.__changes[params["ChangeGroup"]] 481 try:
482 changes = self.__changes[params["ChangeGroup"]]
483 description = changes.description
484 except KeyError:
485 changes = None
486 description = ""
481 487
482 changesData = [] 488 changesData = []
483 for change in changes: 489 if changes is not None:
484 changeTitle = str(change) 490 for change in changes.changes:
485 try: 491 changeTitle = str(change)
486 changeText = change.get_description() 492 try:
487 except AttributeError: 493 changeText = change.get_description()
488 changeText = None 494 except AttributeError:
489 changesData.append([changeTitle, changeText]) 495 changeText = None
496 changesData.append([changeTitle, changeText])
490 497
491 result = { 498 result = {
492 "Subcommand": "PreviewChanges", 499 "Subcommand": "PreviewChanges",
493 "ChangeGroup": params["ChangeGroup"], 500 "ChangeGroup": params["ChangeGroup"],
494 "Description": changes.description, 501 "Description": description,
495 "Changes": changesData, 502 "Changes": changesData,
496 } 503 }
497 504
498 self.sendJson("Changes", result) 505 self.sendJson("Changes", result)
499 506
504 511
505 @param params dictionary containing the method parameters sent by 512 @param params dictionary containing the method parameters sent by
506 the server 513 the server
507 @type dict 514 @type dict
508 """ 515 """
516 changeGroup = params["ChangeGroup"]
509 title = params["Title"] 517 title = params["Title"]
510 filename = params["FileName"] 518 filename = params["FileName"]
511 offset = params["Offset"] 519 offset = params["Offset"]
512 isLocal = params["LocalRename"] 520 isLocal = params["LocalRename"]
513 newName = params["NewName"] 521 newName = params["NewName"]
515 renameInStrings = params["RenameInStrings"] 523 renameInStrings = params["RenameInStrings"]
516 524
517 errorDict = {} 525 errorDict = {}
518 changes = [] 526 changes = []
519 result = { 527 result = {
520 "ChangeGroup": params["ChangeGroup"], 528 "ChangeGroup": changeGroup,
529 "Title": title,
521 } 530 }
522 531
523 import rope.refactor.rename 532 import rope.refactor.rename
524 resource = rope.base.libutils.path_to_resource( 533 resource = rope.base.libutils.path_to_resource(
525 self.__project, filename) 534 self.__project, filename)
543 try: 552 try:
544 changes = renamer.get_changes( 553 changes = renamer.get_changes(
545 newName, 554 newName,
546 resources=resources, 555 resources=resources,
547 in_hierarchy=renameHierarchy, 556 in_hierarchy=renameHierarchy,
548 unsure=self.__confirmUnsure, 557 unsure=lambda o: self.__confirmUnsure(o, changeGroup),
549 docs=renameInStrings, 558 docs=renameInStrings,
550 task_handle=self.__progressHandle) 559 task_handle=self.__progressHandle)
551 except Exception as err: 560 except Exception as err:
552 errorDict = self.__handleRopeError(err) 561 errorDict = self.__handleRopeError(err)
553 self.__progressHandle.reset() 562 self.__progressHandle.reset()
554 self.__progressHandle = None 563 self.__progressHandle = None
555 564
556 if changes: 565 self.__changes[changeGroup] = changes
557 self.__changes[params["ChangeGroup"]] = changes
558 566
559 result["Subcommand"] = "ChangesCalculated" 567 result["Subcommand"] = "ChangesCalculated"
560 result.update(errorDict) 568 result.update(errorDict)
561 569
562 self.sendJson("Changes", result) 570 self.sendJson("Changes", result)
563 571
564 def __confirmUnsure(self, occurrence): 572 def __confirmUnsure(self, occurrence, changeGroup):
565 """ 573 """
566 Private method to confirm unsure occurrences. 574 Private method to confirm unsure occurrences.
567 575
568 @parameter occurrence reference to the occurrence object 576 @parameter occurrence reference to the occurrence object
569 @type rope.refactor.occurrences.Occurrence 577 @type rope.refactor.occurrences.Occurrence
578 @param changeGroup name of the change group
579 @type str
570 @return flag indicating an occurrence 580 @return flag indicating an occurrence
571 @rtype bool 581 @rtype bool
572 """ 582 """
573 # TODO: implement this method; synchronous poll 583 filename = occurrence.resource.real_path
584 start, end = occurrence.get_primary_range()
585
586 self.sendJson("Changes", {
587 "Subcommand": "ConfirmUnsure",
588 "ChangeGroup": changeGroup,
589 "FileName": filename,
590 "StartOffset": start,
591 "EndOffset": end,
592 })
593
594 answer = self.poll(waitMethod="ConfirmUnsure")
595
596 return answer["Answer"]
574 597
575 if __name__ == '__main__': 598 if __name__ == '__main__':
576 if len(sys.argv) != 4: 599 if len(sys.argv) != 4:
577 print('Host, port and project path parameters are missing. Abort.') 600 print('Host, port and project path parameters are missing. Abort.')
578 sys.exit(1) 601 sys.exit(1)

eric ide

mercurial