@@ -30,11 +30,14 @@ uv add lsp-client
3030from pathlib import Path
3131import anyio
3232from lsp_client import Position
33- from lsp_client.clients.pyright import PyrightClient
33+ from lsp_client.clients.pyright import PyrightClient, PyrightLocalServer
3434
3535async def main ():
36- # Use current directory as workspace
37- async with PyrightClient(workspace = Path.cwd()) as client:
36+ workspace = Path.cwd()
37+ async with PyrightClient(
38+ workspace = workspace,
39+ server = PyrightLocalServer(),
40+ ) as client:
3841 # Find definition of something at line 11, character 28 in a file
3942 refs = await client.request_definition_locations(
4043 file_path = " src/main.py" ,
@@ -46,7 +49,7 @@ async def main():
4649 return
4750
4851 for ref in refs:
49- print (f " Found definition at: { ref.uri} " )
52+ print (f " Found definition at: { ref.uri} - Range: { ref.range } " )
5053
5154if __name__ == " __main__" :
5255 anyio.run(main)
@@ -57,15 +60,14 @@ if __name__ == "__main__":
5760``` python
5861from pathlib import Path
5962import anyio
60- from lsp_client.clients.pyright import PyrightClient, PyrightServer, PyrightDockerRuntime
63+ from lsp_client import Position
64+ from lsp_client.clients.pyright import PyrightClient, PyrightDockerServer
6165
6266async def main ():
6367 workspace = Path.cwd()
6468 async with PyrightClient(
6569 workspace = workspace,
66- server = PyrightServer(
67- runtime = PyrightDockerRuntime(mounts = [workspace]),
68- ),
70+ server = PyrightDockerServer(mounts = [workspace]),
6971 ) as client:
7072 # Find definition of something at line 11, character 28 in a file
7173 refs = await client.request_definition_locations(
@@ -78,7 +80,7 @@ async def main():
7880 return
7981
8082 for ref in refs:
81- print (f " Found definition at: { ref.uri} " )
83+ print (f " Found definition at: { ref.uri} - Range: { ref.range } " )
8284
8385if __name__ == " __main__" :
8486 anyio.run(main)
0 commit comments