Skip to content

Commit

Permalink
json-extension: support cancellation in progress example
Browse files Browse the repository at this point in the history
  • Loading branch information
perrinjerome committed Jul 10, 2022
1 parent 8adc050 commit db66295
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion examples/json-extension/server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,14 @@ async def progress(ls: JsonLanguageServer, *args):
# Create
await ls.progress.create_async(token)
# Begin
ls.progress.begin(token, WorkDoneProgressBegin(title='Indexing', percentage=0))
ls.progress.begin(token, WorkDoneProgressBegin(title='Indexing', percentage=0, cancellable=True))
# Report
for i in range(1, 10):
# Check for cancellation from client
if ls.progress.is_cancelled(token):
# ... and stop the computation if client cancelled
ls.progress.end(token, WorkDoneProgressEnd(message='Cancelled'))
return
ls.progress.report(
token,
WorkDoneProgressReport(message=f'{i * 10}%', percentage= i * 10),
Expand Down

0 comments on commit db66295

Please sign in to comment.