-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[ty] Support cancellation and retry in the server #18273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
1aacb8c
to
038c831
Compare
038c831
to
5bc3aee
Compare
397f1bc
to
8bd8ab7
Compare
f5ece05
to
775a29a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you very much. This all looks very reasonable, but I can not review this as deeply as it might be necessary. I'm not (yet) familiar with the LSP server code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great! It simplifies a bunch of stuff.
A few questions / notes going through the diff:
- The spec mentions that cancellation would make it possible to return partial results. I don't think that's supported right now and I don't even think it's required or necessary now or in the near future until we've completed most of the capabilities. I don't know if partial results is going to be useful and if so how much.
- Does the current implementation only "records" that this request has been cancelled and not actually cancel the running thread?
That's correct. The current implementation always omits the entire result. Partial results would complicate things a bit because The server can't send the cancelled response immediately if the request is already in progress. We also need to pass the
This is correct. However, I don't think it should matter in most cases because the main reason for a client to send a cancellation is when some content changed, which results in mutating the database. Salsa implements mutation by unwinding all other db clones when they are accessed the next time. What this means in practice is that salsa cancels in-flight requests. However, we could pass the |
775a29a
to
de5ab7f
Compare
ec656fa
to
cc0f233
Compare
* main: [ty] Support ephemeral uv virtual environments (#18335) Add a `ViolationMetadata::rule` method (#18234) Return `DiagnosticGuard` from `Checker::report_diagnostic` (#18232) [flake8_use_pathlib]: Replace os.symlink with Path.symlink_to (PTH211) (#18337) [ty] Support cancellation and retry in the server (#18273) [ty] Synthetic function-like callables (#18242) [ty] Support publishing diagnostics in the server (#18309) Add Autofix for ISC003 (#18256) [`pyupgrade`]: new rule UP050 (`useless-class-metaclass-type`) (#18334) [pycodestyle] Make `E712` suggestion not assume a context (#18328)
* main: (246 commits) [ty] Simplify signature types, use them in `CallableType` (astral-sh#18344) [ty] Support ephemeral uv virtual environments (astral-sh#18335) Add a `ViolationMetadata::rule` method (astral-sh#18234) Return `DiagnosticGuard` from `Checker::report_diagnostic` (astral-sh#18232) [flake8_use_pathlib]: Replace os.symlink with Path.symlink_to (PTH211) (astral-sh#18337) [ty] Support cancellation and retry in the server (astral-sh#18273) [ty] Synthetic function-like callables (astral-sh#18242) [ty] Support publishing diagnostics in the server (astral-sh#18309) Add Autofix for ISC003 (astral-sh#18256) [`pyupgrade`]: new rule UP050 (`useless-class-metaclass-type`) (astral-sh#18334) [pycodestyle] Make `E712` suggestion not assume a context (astral-sh#18328) put similar dunder-call tests next to each other (astral-sh#18343) [ty] Derive `PartialOrd, Ord` for `KnownInstanceType` (astral-sh#18340) [ty] Simplify `Type::try_bool()` (astral-sh#18342) [ty] Simplify `Type::normalized` slightly (astral-sh#18339) [ty] Move arviz off the list of selected primer projects (astral-sh#18336) [ty] Add --config-file CLI arg (astral-sh#18083) [ty] Tell the user why we inferred a certain Python version when reporting version-specific syntax errors (astral-sh#18295) [ty] Implement implicit inheritance from `Generic[]` for PEP-695 generic classes (astral-sh#18283) [ty] Add hint if async context manager is used in non-async with statement (astral-sh#18299) ...
Summary
This PR implements the following releated features:
This required significant refactoring of the server's request/notification/respond model because tracking the pending requests requires access to
Session
, which we don't have in background tasks.This PR:
Requester
,Responder
andNotifier
and unifies them under a singleClient
API. I found them more confusing than helpful, and I don't see any reason why we should restrict background tasks from sending requests.ClientSender
: This is mostly a fallout of the above.IOThreads
out ofConnection
: This removes the entire complexity around weak references because scoping rules now ensure thatConnection
(and its senders) are dropped before we join the thread.MESSENGER
and instead require callers to explicitly pass aClient
. This helped findshow_message
call sites whereMESSENGER
wasn't initialized. It also removes global state, which is always goodSession
that background tasks don't have. This approach is the same as r-a's.Closes astral-sh/ty#75
Test Plan