Skip to content

Commit 5572560

Browse files
committed
doc: update examples
1 parent ee1f195 commit 5572560

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

examples/pyrefly.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,24 @@
1717

1818
async 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

5052
if __name__ == "__main__":
51-
anyio.run(main) # Run the async example
53+
anyio.run(main)

examples/pyright_docker.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ async def main():
1818
# Set up workspace directory and mount it in Docker
1919
workspace = Path.cwd()
2020
async with PyrightClient(
21+
# here we use `PyrightDockerServer`
2122
server=PyrightDockerServer(
22-
mounts=[workspace]
23-
), # Mount workspace into container
23+
mounts=[workspace] # Mount workspace into container
24+
),
2425
workspace=workspace,
2526
) as client:
2627
# Find definition of PyrightDockerServer at line 12, column 28

0 commit comments

Comments
 (0)