@@ -35,7 +35,7 @@ class GetAllTestsParams(Model):
35
35
@dataclass (repr = False )
36
36
class GetTestsParams (Model ):
37
37
text_document : TextDocumentIdentifier
38
- id : Optional [str ]
38
+ base_name : Optional [str ]
39
39
40
40
41
41
@dataclass (repr = False )
@@ -48,6 +48,7 @@ class TestItem(Model):
48
48
type : str
49
49
id : str
50
50
label : str
51
+ longname : str
51
52
uri : Optional [DocumentUri ] = None
52
53
children : Optional [List [TestItem ]] = None
53
54
description : Optional [str ] = None
@@ -57,10 +58,10 @@ class TestItem(Model):
57
58
58
59
59
60
class FindTestCasesVisitor (AsyncVisitor ):
60
- async def get (self , source : DocumentUri , model : ast .AST , id : Optional [str ]) -> List [TestItem ]:
61
+ async def get (self , source : DocumentUri , model : ast .AST , base_name : Optional [str ]) -> List [TestItem ]:
61
62
self ._results : List [TestItem ] = []
62
63
self .source = source
63
- self .id = id
64
+ self .base_name = base_name
64
65
await self .visit (model )
65
66
return self ._results
66
67
@@ -75,10 +76,12 @@ async def visit_TestCase(self, node: ast.AST) -> None: # noqa: N802
75
76
from robot .parsing .model .statements import Tags
76
77
77
78
test_case = cast (TestCase , node )
79
+ longname = f"{ self .base_name } .{ test_case .name } " if self .base_name else test_case .name
78
80
self ._results .append (
79
81
TestItem (
80
82
type = "test" ,
81
- id = f"{ self .id } .{ test_case .name } " if self .id else test_case .name ,
83
+ id = f"{ self .source } ;{ longname } ;{ test_case .lineno } " ,
84
+ longname = longname ,
82
85
label = test_case .name ,
83
86
uri = self .source ,
84
87
range = Range (
@@ -203,12 +206,14 @@ def generate(suite: TestSuite) -> TestItem:
203
206
204
207
test : TestCase
205
208
for test in suite .tests :
209
+ uri = str (Uri .from_path (test .source )) if test .source else None
206
210
children .append (
207
211
TestItem (
208
212
type = "test" ,
209
- id = test .longname ,
213
+ id = f" { uri } ; { test .longname } ; { test . lineno } " ,
210
214
label = test .name ,
211
- uri = str (Uri .from_path (test .source )) if test .source else None ,
215
+ longname = test .longname ,
216
+ uri = uri ,
212
217
range = Range (
213
218
start = Position (line = test .lineno - 1 , character = 0 ),
214
219
end = Position (line = test .lineno - 1 , character = 0 ),
@@ -220,11 +225,13 @@ def generate(suite: TestSuite) -> TestItem:
220
225
for s in suite .suites :
221
226
children .append (generate (s ))
222
227
228
+ uri = str (Uri .from_path (suite .source )) if suite .source else None
223
229
return TestItem (
224
230
type = "suite" ,
225
- id = suite .longname ,
231
+ id = f" { uri } ; { suite .longname } " ,
226
232
label = suite .name ,
227
- uri = str (Uri .from_path (suite .source )) if suite .source else None ,
233
+ longname = suite .longname ,
234
+ uri = uri ,
228
235
children = children ,
229
236
range = Range (
230
237
start = Position (line = 0 , character = 0 ),
@@ -270,17 +277,21 @@ def nonexisting_paths(paths: List[str]) -> Iterator[str]:
270
277
)
271
278
suite_item = [generate (suite )] if suite else []
272
279
280
+ uri = str (Uri .from_path (Path .cwd ()))
273
281
return [
274
282
TestItem (
275
283
type = "workspace" ,
276
- id = Path . cwd (). name ,
284
+ id = uri ,
277
285
label = Path .cwd ().name ,
286
+ longname = Path .cwd ().name ,
287
+ uri = uri ,
278
288
children = [
279
289
* suite_item ,
280
290
* [
281
291
TestItem (
282
292
type = "error" ,
283
- id = i ,
293
+ id = f"{ Uri .from_path (i )} ;ERROR" ,
294
+ longname = "error" ,
284
295
label = i ,
285
296
error = f"Parsing '{ i } ' failed: File or directory to does not exist." ,
286
297
)
@@ -298,7 +309,15 @@ def nonexisting_paths(paths: List[str]) -> Iterator[str]:
298
309
except (SystemExit , KeyboardInterrupt ):
299
310
raise
300
311
except BaseException as e :
301
- return [TestItem (type = "error" , id = Path .cwd ().name , label = Path .cwd ().name , error = str (e ))]
312
+ return [
313
+ TestItem (
314
+ type = "error" ,
315
+ id = str (Uri .from_path (Path .cwd ())),
316
+ longname = "error" ,
317
+ label = Path .cwd ().name ,
318
+ error = str (e ),
319
+ )
320
+ ]
302
321
303
322
@rpc_method (name = "robot/discovering/getTestsFromWorkspace" , param_type = GetAllTestsParams )
304
323
@_logger .call
@@ -317,7 +336,7 @@ async def get_tests_from_workspace(
317
336
@rpc_method (name = "robot/discovering/getTestsFromDocument" , param_type = GetTestsParams )
318
337
@_logger .call
319
338
async def get_tests_from_document (
320
- self , text_document : TextDocumentIdentifier , id : Optional [str ], * args : Any , ** kwargs : Any
339
+ self , text_document : TextDocumentIdentifier , base_name : Optional [str ], * args : Any , ** kwargs : Any
321
340
) -> List [TestItem ]:
322
341
async def run () -> List [TestItem ]:
323
342
try :
@@ -328,7 +347,7 @@ async def run() -> List[TestItem]:
328
347
Uri (text_document .uri ).to_path (), language_id = "robotframework"
329
348
)
330
349
),
331
- id ,
350
+ base_name ,
332
351
)
333
352
except (asyncio .CancelledError , SystemExit , KeyboardInterrupt ):
334
353
raise
0 commit comments