Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

Osse
Copy link

@Osse Osse commented Sep 11, 2025

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:

  • As far as I can tell the RPC stuff needs to be async functions while
    get_semantic_zones() from the Pane trait is not. I worked around this by
    using smol::block_on(). I see that is used many places in the code base but I'm
    not sure it's acceptable here. An alternative is to make the function async
    in the trait, but that seemed messy for other reasons.
  • I couldn't find any places to add a test for this.
  • There is no new documentation. Imo. that's justified as I am making an
    existing feature work in more contexts which the existing documentation did
    not clarify that it didn't work.

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.
@Osse Osse force-pushed the remote-semantic-zones branch from cf9ecef to 7a8ec45 Compare September 11, 2025 20:29
Copy link
Member

@wez wez left a 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,
Copy link
Member

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.

Copy link
Author

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 {
Copy link
Member

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

Copy link
Author

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.

Copy link
Author

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.
@Osse Osse force-pushed the remote-semantic-zones branch from 0cdf12a to 2452d27 Compare September 13, 2025 17:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Jump to semantic regions not working through non-local domains
2 participants