1717
1818async def main ():
1919 # Initialize Pyrefly client with local server
20+ # if `workspace` not specified, defaults to current working directory
2021 async with PyreflyClient (server = PyreflyLocalServer ()) as client :
21- # Request references to PyreflyClient at line 21 , column 19
22+ # Request references to PyreflyClient at line 22 , column 20
2223 refs = await client .request_references (
2324 file_path = "src/lsp_client/clients/pyrefly.py" ,
2425 position = Position (21 , 19 ),
25- include_declaration = False , # Don't include the declaration itself
26+ # some requests may support additional options,
27+ # e.g. this one excludes the declaration itself from results
28+ include_declaration = False ,
2629 )
2730
28- if not refs :
29- print ("No references found." )
30- return
31+ assert refs , "No references found."
3132
32- # Print all found references
3333 for ref in refs :
34- print (f"Reference found at { ref .uri } - Range: { ref .range } " )
34+ # LSP Server always returns URI instead of file paths
35+ # So we need to convert it back to file path using `from_uri`
36+ file_path = client .from_uri (ref .uri )
37+ print (f"Reference found at { file_path } - Range: { ref .range } " )
3538
3639 # Verify that this example file contains a reference to PyreflyClient
3740 # This demonstrates the reference finding functionality works correctly
@@ -44,8 +47,7 @@ async def main():
4447 )
4548 for ref in refs
4649 )
47- print ("Reference assertion passed." )
4850
4951
5052if __name__ == "__main__" :
51- anyio .run (main ) # Run the async example
53+ anyio .run (main )
0 commit comments