1818)
1919
2020
21+ def split (
22+ result : Union [Location , LocationLink , List [Location ], List [LocationLink ], None ]
23+ ) -> Union [Location , LocationLink , List [Location ], List [LocationLink ], None ]:
24+ if result is None :
25+ return None
26+ if isinstance (result , Location ):
27+ return Location ((Uri (result .uri ).to_path ().name ), result .range )
28+ if isinstance (result , LocationLink ):
29+ return LocationLink (
30+ result .origin_selection_range ,
31+ (Uri (result .target_uri ).to_path ().name ),
32+ result .target_range ,
33+ result .target_selection_range ,
34+ )
35+ if isinstance (result , list ) and len (result ) > 0 and isinstance (result [0 ], LocationLink ):
36+ return cast ("List[LocationLink]" , [split (v ) for v in result ])
37+
38+ if isinstance (result , list ) and len (result ) > 0 and isinstance (result [0 ], Location ):
39+ return cast ("List[Location]" , [split (v ) for v in result ])
40+
41+ return result
42+
43+
2144@pytest .mark .parametrize (
2245 ("test_document" , "data" ),
2346 generate_tests_from_source_document (Path (Path (__file__ ).parent , "data/goto.robot" )),
2649)
2750@pytest .mark .usefixtures ("protocol" )
2851@pytest .mark .asyncio
29- async def test (
52+ async def test_definition (
3053 data_regression : DataRegressionFixture ,
3154 protocol : RobotLanguageServerProtocol ,
3255 test_document : TextDocument ,
@@ -39,26 +62,28 @@ async def test(
3962 Position (line = data .line , character = data .character ),
4063 )
4164
42- def split (
43- result : Union [Location , LocationLink , List [Location ], List [LocationLink ], None ]
44- ) -> Union [Location , LocationLink , List [Location ], List [LocationLink ], None ]:
45- if result is None :
46- return None
47- if isinstance (result , Location ):
48- return Location ((Uri (result .uri ).to_path ().name ), result .range )
49- if isinstance (result , LocationLink ):
50- return LocationLink (
51- result .origin_selection_range ,
52- (Uri (result .target_uri ).to_path ().name ),
53- result .target_range ,
54- result .target_selection_range ,
55- )
56- if isinstance (result , list ) and len (result ) > 0 and isinstance (result [0 ], LocationLink ):
57- return cast ("List[LocationLink]" , [split (v ) for v in result ])
65+ data_regression .check ({"data" : data , "result" : split (result )})
5866
59- if isinstance (result , list ) and len (result ) > 0 and isinstance (result [0 ], Location ):
60- return cast ("List[Location]" , [split (v ) for v in result ])
6167
62- return result
68+ @pytest .mark .parametrize (
69+ ("test_document" , "data" ),
70+ generate_tests_from_source_document (Path (Path (__file__ ).parent , "data/goto.robot" )),
71+ indirect = ["test_document" ],
72+ ids = generate_test_id ,
73+ )
74+ @pytest .mark .usefixtures ("protocol" )
75+ @pytest .mark .asyncio
76+ async def test_implementation (
77+ data_regression : DataRegressionFixture ,
78+ protocol : RobotLanguageServerProtocol ,
79+ test_document : TextDocument ,
80+ data : GeneratedTestData ,
81+ ) -> None :
82+
83+ result = await protocol .robot_goto .collect_implementation (
84+ protocol .robot_goto ,
85+ test_document ,
86+ Position (line = data .line , character = data .character ),
87+ )
6388
6489 data_regression .check ({"data" : data , "result" : split (result )})
0 commit comments