Skip to content

Commit fa429a5

Browse files
committed
refactor(langserver): remove some unused code
1 parent 3836362 commit fa429a5

File tree

1 file changed

+15
-87
lines changed
  • packages/language_server/src/robotcode/language_server/robotframework/parts

1 file changed

+15
-87
lines changed

packages/language_server/src/robotcode/language_server/robotframework/parts/rename.py

Lines changed: 15 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
List,
77
Optional,
88
Tuple,
9-
Type,
109
TypeVar,
1110
Union,
1211
cast,
@@ -36,9 +35,6 @@
3635
)
3736
from robotcode.robot.diagnostics.library_doc import KeywordDoc
3837
from robotcode.robot.diagnostics.model_helper import ModelHelper
39-
from robotcode.robot.utils.ast import (
40-
get_nodes_at_position,
41-
)
4238

4339
from ...common.parts.rename import CantRenameError
4440
from .protocol_part import RobotLanguageServerProtocolPart
@@ -62,90 +58,36 @@ def __init__(self, parent: "RobotLanguageServerProtocol") -> None:
6258
parent.rename.collect.add(self.collect)
6359
parent.rename.collect_prepare.add(self.collect_prepare)
6460

65-
def _find_method(self, cls: Type[Any], prefix: str) -> Optional[_T]:
66-
if cls is ast.AST:
67-
return None
68-
method_name = prefix + "_" + cls.__name__
69-
if hasattr(self, method_name):
70-
method = getattr(self, method_name)
71-
if callable(method):
72-
return cast(_T, method)
73-
for base in cls.__bases__:
74-
method = self._find_method(base, prefix)
75-
if method:
76-
return cast(_T, method)
77-
return None
78-
7961
@language_id("robotframework")
8062
@_logger.call
8163
def collect(
82-
self,
83-
sender: Any,
84-
document: TextDocument,
85-
position: Position,
86-
new_name: str,
64+
self, sender: Any, document: TextDocument, position: Position, new_name: str
8765
) -> Optional[WorkspaceEdit]:
88-
result_nodes = get_nodes_at_position(
89-
self.parent.documents_cache.get_model(document),
90-
position,
91-
include_end=True,
92-
)
93-
94-
if not result_nodes:
95-
return None
96-
97-
result_node = result_nodes[-1]
98-
99-
result = self._rename_variable(result_nodes, document, position, new_name)
66+
result = self._rename_variable(document, position, new_name)
10067
if result:
10168
return result
10269

103-
result = self._rename_keyword(result_nodes, document, position, new_name)
70+
result = self._rename_keyword(document, position, new_name)
10471
if result:
10572
return result
10673

107-
method: Optional[_RenameMethod] = self._find_method(type(result_node), "rename")
108-
if method is not None:
109-
result = method(result_node, document, position, new_name)
110-
if result is not None:
111-
return result
112-
11374
return None
11475

11576
@language_id("robotframework")
11677
@_logger.call
11778
def collect_prepare(self, sender: Any, document: TextDocument, position: Position) -> Optional[PrepareRenameResult]:
118-
result_nodes = get_nodes_at_position(
119-
self.parent.documents_cache.get_model(document),
120-
position,
121-
include_end=True,
122-
)
123-
124-
if not result_nodes:
125-
return None
126-
127-
result_node = result_nodes[-1]
128-
129-
result = self._prepare_rename_variable(result_nodes, document, position)
79+
result = self._prepare_rename_variable(document, position)
13080
if result:
13181
return result
13282

133-
result = self._prepare_rename_keyword(result_nodes, document, position)
83+
result = self._prepare_rename_keyword(document, position)
13484
if result:
13585
return result
13686

137-
method: Optional[_PrepareRenameMethod] = self._find_method(type(result_node), "prepare_rename")
138-
if method is not None:
139-
result = method(result_node, document, position)
140-
if result is not None:
141-
return result
142-
14387
return None
14488

145-
def _prepare_rename_variable(
146-
self, nodes: List[ast.AST], document: TextDocument, position: Position
147-
) -> Optional[PrepareRenameResult]:
148-
result = self._find_variable_definition_on_pos(nodes, document, position)
89+
def _prepare_rename_variable(self, document: TextDocument, position: Position) -> Optional[PrepareRenameResult]:
90+
result = self._find_variable_definition_on_pos(document, position)
14991
if result is not None:
15092
var, found_range = result
15193

@@ -172,20 +114,14 @@ def _prepare_rename_variable(
172114

173115
return None
174116

175-
def _rename_variable(
176-
self,
177-
nodes: List[ast.AST],
178-
document: TextDocument,
179-
position: Position,
180-
new_name: str,
181-
) -> Optional[WorkspaceEdit]:
117+
def _rename_variable(self, document: TextDocument, position: Position, new_name: str) -> Optional[WorkspaceEdit]:
182118
if " " in new_name or "\t" in new_name:
183119
raise CantRenameError(
184120
"Variable names cannot contain more then one spaces or tabs. "
185121
"Please use only one space or underscores instead.",
186122
)
187123

188-
result = self._find_variable_definition_on_pos(nodes, document, position)
124+
result = self._find_variable_definition_on_pos(document, position)
189125

190126
if result is not None:
191127
var, _ = result
@@ -218,7 +154,7 @@ def _rename_variable(
218154
return None
219155

220156
def _find_variable_definition_on_pos(
221-
self, nodes: List[ast.AST], document: TextDocument, position: Position
157+
self, document: TextDocument, position: Position
222158
) -> Optional[Tuple[VariableDefinition, Range]]:
223159
namespace = self.parent.documents_cache.get_namespace(document)
224160

@@ -243,10 +179,8 @@ def _find_variable_definition_on_pos(
243179
return variable, found_range
244180
return None
245181

246-
def _prepare_rename_keyword(
247-
self, nodes: List[ast.AST], document: TextDocument, position: Position
248-
) -> Optional[PrepareRenameResult]:
249-
result = self._find_keyword_definition_on_pos(nodes, document, position)
182+
def _prepare_rename_keyword(self, document: TextDocument, position: Position) -> Optional[PrepareRenameResult]:
183+
result = self._find_keyword_definition_on_pos(document, position)
250184
if result is not None:
251185
kw_doc, found_range = result
252186

@@ -263,20 +197,14 @@ def _prepare_rename_keyword(
263197

264198
return None
265199

266-
def _rename_keyword(
267-
self,
268-
nodes: List[ast.AST],
269-
document: TextDocument,
270-
position: Position,
271-
new_name: str,
272-
) -> Optional[WorkspaceEdit]:
200+
def _rename_keyword(self, document: TextDocument, position: Position, new_name: str) -> Optional[WorkspaceEdit]:
273201
if " " in new_name or "\t" in new_name:
274202
raise CantRenameError(
275203
"Keyword names cannot contain more then one spaces or tabs. "
276204
"Please use only one space or underscores instead.",
277205
)
278206

279-
result = self._find_keyword_definition_on_pos(nodes, document, position)
207+
result = self._find_keyword_definition_on_pos(document, position)
280208
if result is not None:
281209
kw_doc, _ = result
282210

@@ -303,7 +231,7 @@ def _rename_keyword(
303231
return None
304232

305233
def _find_keyword_definition_on_pos(
306-
self, nodes: List[ast.AST], document: TextDocument, position: Position
234+
self, document: TextDocument, position: Position
307235
) -> Optional[Tuple[KeywordDoc, Range]]:
308236
namespace = self.parent.documents_cache.get_namespace(document)
309237

0 commit comments

Comments
 (0)