RefactoringRope/CodeAssistClient.py

branch
eric7
changeset 413
a4cba20ad7ab
parent 412
6fa5892b9097
child 426
7592a1c052e8
equal deleted inserted replaced
412:6fa5892b9097 413:a4cba20ad7ab
15 15
16 try: 16 try:
17 import rope.base.libutils 17 import rope.base.libutils
18 import rope.base.project 18 import rope.base.project
19 import rope.contrib.codeassist 19 import rope.contrib.codeassist
20 20 import rope.contrib.findit
21
22 from rope.base import pynames, pyobjects, pyobjectsdef
21 from rope.base.exceptions import BadIdentifierError, ModuleSyntaxError 23 from rope.base.exceptions import BadIdentifierError, ModuleSyntaxError
24 from rope.contrib import fixsyntax
22 except ImportError: 25 except ImportError:
23 sys.exit(42) 26 sys.exit(42)
24 27
25 from eric7.EricNetwork.EricJsonClient import EricJsonClient 28 from eric7.EricNetwork.EricJsonClient import EricJsonClient
26 29
44 order to identify the connection 47 order to identify the connection
45 @type str 48 @type str
46 @param projectPath path to the project 49 @param projectPath path to the project
47 @type str 50 @type str
48 """ 51 """
52 from FileSystemCommands import RefactoringClientFileSystemCommands # noqa: I102
53
49 super().__init__(host, port, idString) 54 super().__init__(host, port, idString)
50 55
51 self.__methodMapping = { 56 self.__methodMapping = {
52 "getConfig": self.__getConfig, 57 "getConfig": self.__getConfig,
53 "configChanged": self.__configChanged, 58 "configChanged": self.__configChanged,
58 "gotoDefinition": self.__gotoDefinition, 63 "gotoDefinition": self.__gotoDefinition,
59 "gotoReferences": self.__getReferences, 64 "gotoReferences": self.__getReferences,
60 "reportChanged": self.__reportChanged, 65 "reportChanged": self.__reportChanged,
61 } 66 }
62 67
63 from FileSystemCommands import RefactoringClientFileSystemCommands
64
65 self.__fsCommands = RefactoringClientFileSystemCommands(self) 68 self.__fsCommands = RefactoringClientFileSystemCommands(self)
66 69
67 self.__projectpath = projectPath 70 self.__projectpath = projectPath
68 self.__project = rope.base.project.Project( 71 self.__project = rope.base.project.Project(
69 self.__projectpath, fscommands=self.__fsCommands 72 self.__projectpath, fscommands=self.__fsCommands
102 errorDict["ErrorFile"] = err.filename 105 errorDict["ErrorFile"] = err.filename
103 errorDict["ErrorLine"] = err.lineno 106 errorDict["ErrorLine"] = err.lineno
104 107
105 return errorDict 108 return errorDict
106 109
107 def __getConfig(self, params): 110 def __getConfig(self, params): # noqa: U100
108 """ 111 """
109 Private method to send some configuration data to the server. 112 Private method to send some configuration data to the server.
110 113
111 @param params dictionary containing the method parameters sent by 114 @param params dictionary containing the method parameters sent by
112 the server 115 the server
117 "Id": self.__id, 120 "Id": self.__id,
118 } 121 }
119 122
120 self.sendJson("Config", result) 123 self.sendJson("Config", result)
121 124
122 def __configChanged(self, params): 125 def __configChanged(self, params): # noqa: U100
123 """ 126 """
124 Private method to handle a change of the configuration file. 127 Private method to handle a change of the configuration file.
125 128
126 @param params dictionary containing the method parameters sent by 129 @param params dictionary containing the method parameters sent by
127 the server 130 the server
131 self.__project = rope.base.project.Project( 134 self.__project = rope.base.project.Project(
132 self.__projectpath, fscommands=self.__fsCommands 135 self.__projectpath, fscommands=self.__fsCommands
133 ) 136 )
134 self.__project.validate(self.__project.root) 137 self.__project.validate(self.__project.root)
135 138
136 def __closeProject(self, params): 139 def __closeProject(self, params): # noqa: U100
137 """ 140 """
138 Private slot to validate the project. 141 Private slot to validate the project.
139 142
140 @param params dictionary containing the method parameters sent by 143 @param params dictionary containing the method parameters sent by
141 the server 144 the server
362 @param maxfixes number of fixes to be done 365 @param maxfixes number of fixes to be done
363 @type int 366 @type int
364 @return tuple containing the object type and name 367 @return tuple containing the object type and name
365 @rtype tuple of (str, str) 368 @rtype tuple of (str, str)
366 """ 369 """
367 from rope.base import pynames, pyobjects, pyobjectsdef
368 from rope.contrib import fixsyntax
369
370 try: 370 try:
371 fixer = fixsyntax.FixSyntax(project, sourceCode, resource, maxfixes) 371 fixer = fixsyntax.FixSyntax(project, sourceCode, resource, maxfixes)
372 pyname = fixer.pyname_at(offset) 372 pyname = fixer.pyname_at(offset)
373 except BadIdentifierError: 373 except BadIdentifierError:
374 pyname = None 374 pyname = None
410 410
411 @param params dictionary containing the method parameters sent by 411 @param params dictionary containing the method parameters sent by
412 the server 412 the server
413 @type dict 413 @type dict
414 """ 414 """
415 import rope.base.libutils
416
417 filename = params["FileName"] 415 filename = params["FileName"]
418 offset = params["Offset"] 416 offset = params["Offset"]
419 source = params["Source"] 417 source = params["Source"]
420 uid = params["Uuid"] 418 uid = params["Uuid"]
421 419
426 else None 424 else None
427 ) 425 )
428 426
429 errorDict = {} 427 errorDict = {}
430 result = {} 428 result = {}
431
432 import rope.contrib.findit
433 429
434 try: 430 try:
435 location = rope.contrib.findit.find_definition( 431 location = rope.contrib.findit.find_definition(
436 self.__project, source, offset, resource 432 self.__project, source, offset, resource
437 ) 433 )
455 451
456 @param params dictionary containing the method parameters sent by 452 @param params dictionary containing the method parameters sent by
457 the server 453 the server
458 @type dict 454 @type dict
459 """ 455 """
460 import rope.base.libutils
461
462 filename = params["FileName"] 456 filename = params["FileName"]
463 offset = params["Offset"] 457 offset = params["Offset"]
464 line = params["Line"] 458 line = params["Line"]
465 uid = params["Uuid"] 459 uid = params["Uuid"]
466 460
471 else None 465 else None
472 ) 466 )
473 467
474 errorDict = {} 468 errorDict = {}
475 gotoReferences = [] 469 gotoReferences = []
476
477 import rope.contrib.findit
478 470
479 try: 471 try:
480 occurrences = rope.contrib.findit.find_occurrences( 472 occurrences = rope.contrib.findit.find_occurrences(
481 self.__project, resource, offset, in_hierarchy=True 473 self.__project, resource, offset, in_hierarchy=True
482 ) 474 )

eric ide

mercurial