@@ -165,16 +165,16 @@ async def references_KeywordName( # noqa: N802
165
165
if not name_token :
166
166
return None
167
167
168
- result = await namespace .find_keyword (name_token .value )
168
+ keyword = await namespace .find_keyword (name_token .value )
169
169
170
- if result is not None and result .source and not result .is_error_handler :
170
+ if keyword is not None and keyword .source and not keyword .is_error_handler :
171
171
return [
172
172
* (
173
- [Location (uri = str (Uri .from_path (result .source )), range = range_from_token_or_node (node , name_token ))]
173
+ [Location (uri = str (Uri .from_path (keyword .source )), range = range_from_token_or_node (node , name_token ))]
174
174
if context .include_declaration
175
175
else []
176
176
),
177
- * await self ._find_keyword_references (document , result ),
177
+ * await self ._find_keyword_references (document , keyword ),
178
178
]
179
179
180
180
return None
@@ -190,24 +190,24 @@ async def references_KeywordCall( # noqa: N802
190
190
return None
191
191
192
192
kw_node = cast (KeywordCall , node )
193
- result = await self .get_keyworddoc_and_token_from_position (
193
+ keyword = await self .get_keyworddoc_and_token_from_position (
194
194
kw_node .keyword ,
195
195
cast (Token , kw_node .get_token (RobotToken .KEYWORD )),
196
196
[cast (Token , t ) for t in kw_node .get_tokens (RobotToken .ARGUMENT )],
197
197
namespace ,
198
198
position ,
199
199
)
200
200
201
- if result is not None and result [0 ] is not None :
202
- source = result [0 ].source
201
+ if keyword is not None and keyword [0 ] is not None :
202
+ source = keyword [0 ].source
203
203
if source is not None :
204
204
return [
205
205
* (
206
- [Location (uri = str (Uri .from_path (source )), range = result [0 ].range )]
206
+ [Location (uri = str (Uri .from_path (source )), range = keyword [0 ].range )]
207
207
if context .include_declaration
208
208
else []
209
209
),
210
- * await self ._find_keyword_references (document , result [0 ]),
210
+ * await self ._find_keyword_references (document , keyword [0 ]),
211
211
]
212
212
213
213
return None
@@ -223,24 +223,24 @@ async def references_Fixture( # noqa: N802
223
223
return None
224
224
225
225
fixture_node = cast (Fixture , node )
226
- result = await self .get_keyworddoc_and_token_from_position (
226
+ keyword = await self .get_keyworddoc_and_token_from_position (
227
227
fixture_node .name ,
228
228
cast (Token , fixture_node .get_token (RobotToken .NAME )),
229
229
[cast (Token , t ) for t in fixture_node .get_tokens (RobotToken .ARGUMENT )],
230
230
namespace ,
231
231
position ,
232
232
)
233
233
234
- if result is not None and result [0 ] is not None :
235
- source = result [0 ].source
234
+ if keyword is not None and keyword [0 ] is not None :
235
+ source = keyword [0 ].source
236
236
if source is not None :
237
237
return [
238
238
* (
239
- [Location (uri = str (Uri .from_path (source )), range = result [0 ].range )]
239
+ [Location (uri = str (Uri .from_path (source )), range = keyword [0 ].range )]
240
240
if context .include_declaration
241
241
else []
242
242
),
243
- * await self ._find_keyword_references (document , result [0 ]),
243
+ * await self ._find_keyword_references (document , keyword [0 ]),
244
244
]
245
245
246
246
return None
@@ -254,7 +254,7 @@ async def _references_Template_or_TestTemplate( # noqa: N802
254
254
node = cast (Union [Template , TestTemplate ], node )
255
255
if node .value :
256
256
257
- name_token = cast (RobotToken , node .get_token (RobotToken .NAME ))
257
+ name_token = cast (RobotToken , node .get_token (RobotToken .NAME , RobotToken . ARGUMENT ))
258
258
if name_token is None :
259
259
return None
260
260
@@ -263,20 +263,20 @@ async def _references_Template_or_TestTemplate( # noqa: N802
263
263
if namespace is None :
264
264
return None
265
265
266
- result = await namespace .find_keyword (node .value )
267
- if result is not None and result .source is not None :
266
+ keyword = await namespace .find_keyword (node .value )
267
+ if keyword is not None and keyword .source is not None :
268
268
return [
269
269
* (
270
270
[
271
271
Location (
272
- uri = str (Uri .from_path (result .source )),
273
- range = range_from_token_or_node ( node , name_token ) ,
272
+ uri = str (Uri .from_path (keyword .source )),
273
+ range = keyword . range ,
274
274
)
275
275
]
276
276
if context .include_declaration
277
277
else []
278
278
),
279
- * await self ._find_keyword_references (document , result ),
279
+ * await self ._find_keyword_references (document , keyword ),
280
280
]
281
281
282
282
return None
@@ -318,7 +318,12 @@ async def _find_keyword_references_in_namespace(
318
318
self , namespace : Namespace , kw_doc : KeywordDoc , cancel_token : CancelationToken
319
319
) -> List [Location ]:
320
320
from robot .parsing .lexer .tokens import Token as RobotToken
321
- from robot .parsing .model .statements import Fixture , KeywordCall
321
+ from robot .parsing .model .statements import (
322
+ Fixture ,
323
+ KeywordCall ,
324
+ Template ,
325
+ TestTemplate ,
326
+ )
322
327
323
328
result : List [Location ] = []
324
329
@@ -344,6 +349,11 @@ async def _find_keyword_references_in_namespace(
344
349
namespace , kw_doc , node , kw_token , arguments
345
350
):
346
351
result .append (location )
352
+ elif isinstance (node , (Template , TestTemplate )):
353
+ kw_token = node .get_token (RobotToken .NAME , RobotToken .ARGUMENT )
354
+
355
+ async for location in self .get_keyword_references_from_tokens (namespace , kw_doc , node , kw_token , []):
356
+ result .append (location )
347
357
348
358
return result
349
359
0 commit comments