-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Implement get_semantic_zones() for ClientPane #7216
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
base: main
Are you sure you want to change the base?
Conversation
By adding a new request and response we can query the remote terminal for its semantic zones. Thus handy features like the ScrollToPrompt and CopyMode actions work as expected in other domains than the local domain.
cf9ecef
to
7a8ec45
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.
Thanks for diving in!
I think the approach looks fine, but we have to implement this without using block_on
.
I think you can probably get quite far (maybe even 100%) with making this async just by changing the signature of the trait method and seeing what the compiler complains about; likely just then adding some .awaits
.
Could you give that a try and update the PR?
Thanks!
GetPaneDirection: 60, | ||
GetPaneDirectionResponse: 61, | ||
AdjustPaneSize: 62, | ||
SemanticZonesRequest: 63, |
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.
Please increment CODEC_VERSION
(on line 444 above this) when adding new PDUs; that will enable the client to realize when the server doesn't support the PDU and error out and inform the user.
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.
Done!
} | ||
|
||
fn get_semantic_zones(&self) -> anyhow::Result<Vec<SemanticZone>> { | ||
match smol::block_on(async { |
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.
we must not use block_on here, as it will block the GUI thread that may be calling into this code, and can lead to deadlock in various scenarios
The proper fix would be to change the signature of get_semantic_zones
in the trait definition in mux/src/pane.rs
to be async, then to address the fan-out from that to add appropriate awaits in the all the places that the compiler will identify
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.
I suspected this was the case. I pushed 0cdf12a to make it async, but I ended up adding even more smol::block_on()
because of it. It's WIP. Hopefully I can spend some more time on it today.
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.
Made some progress and have pushed 2452d27, replacing the previous one. I assume this will all be squashed in the end (either by you or me). This just shows the changes needed from my first proposal to making it async.
There are three smol::block_on()
calls left that I don't know what to do with. Looking at the nearby code promise::spawn::spawn(...).detach()
is used a lot. It seems to be used in cases where you just "fire and forget" something, which doesn't work in this case I believe.
Getting the semantic zones from a remote terminal is inherently an async process, so change the signature of get_semantic_zones() in the `Pane` trait to be async and adapt the affected code appropriately.
0cdf12a
to
2452d27
Compare
By adding a new request and response we can query the remote terminal
for its semantic zones. Thus handy features like the ScrollToPrompt and
CopyMode actions work as expected in other domains than the local
domain.
Fixes #5141
I implemented this fairly quickly buy just basing it on the patterns in
surrouding code, and it seems to work exactly as I had hoped. Some
concerns/points:
async
functions whileget_semantic_zones()
from thePane
trait is not. I worked around this byusing
smol::block_on()
. I see that is used many places in the code base but I'mnot sure it's acceptable here. An alternative is to make the function
async
in the trait, but that seemed messy for other reasons.
existing feature work in more contexts which the existing documentation did
not clarify that it didn't work.