Skip to content
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

Add support for measure_width #26

Merged
merged 5 commits into from
Jun 6, 2019

Conversation

little-dude
Copy link
Collaborator

@little-dude little-dude commented May 28, 2019

This is based on #24 so that @Cogitri can try it out if they want. Also note that I haven't tested it out yet because I'm not sure how to make xi-core to send me that specific request.

This is the first time we support requests (as opposed to notifications) from the core.

I could not reuse XiEvent because unlike all the events we've been handling until now, we need to return something to the core. As a result, we cannot use handle_event(). As a result, I added a method to Frontend, and renamed XiEvent and handle_event() to XiNotification and handle_notification() respectively.

One thing that annoys me is that with requests, we'll be reproducing the issue described in #21, because we'll add one method to the Frontend trait for each request with a distinct return type. For instance, here I added:

fn handle_measure_width(&mut self, request: MeasureWidthRequest) -> Box<Future<Item = MeasureWidthResponse, Error = ServerError>>;

One solution would be to only have one method called handle_request, and an enum XiRequest similar to the current XiEvent:

fn handle_measure_width(&mut self, request: XiRequest) -> Box<Future<Item = Value, Error = ServerError>>;

The problem is that we lose the strong typing on the return value, and implementors would have to convert their result into a Value which does not seem very nice.

What do you think @ByteBuddha @Cogitri ?

unimplemented!();
match method {
"measure_width" => match from_value::<MeasureWidthRequest>(params) {
Ok(req) => Box::new(
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's kind of a shame that we have to re-box something that was already boxed... If I understand correctly, impl Trait would help here, but it's not supported in trait methods, yet. Not sure if there's something else to try.

@Cogitri
Copy link
Collaborator

Cogitri commented May 28, 2019

Also note that I haven't tested it out yet because I'm not sure how to make xi-core to send me that specific request.

Enabling word_wrap should cause Xi to send you this upon inserting characters.

@little-dude
Copy link
Collaborator Author

Ah nice, I'll try this out with xi-term then. I see you already added modify_user_config, so it should be easy enough.

@Cogitri
Copy link
Collaborator

Cogitri commented May 28, 2019

Feel free to ping me if you need help with that. I guess I won't be able to test it in gxi before #27 is resolved :/

@little-dude little-dude force-pushed the issue-25 branch 4 times, most recently from b2c69e7 to b37f6d2 Compare June 4, 2019 14:55
@little-dude
Copy link
Collaborator Author

xi-term builds and runs correctly with this. See: xi-frontend/xi-term#101

@Cogitri
Copy link
Collaborator

Cogitri commented Jun 4, 2019

Alright, I'll try to add this to gxi later

@Cogitri
Copy link
Collaborator

Cogitri commented Jun 4, 2019

The problem is that we lose the strong typing on the return value, and implementors would have to convert their result into a Value which does not seem very nice.

I've thought about this for a bit, but I can't come up with a prettier solution than using one function per Request either, since using dynamic typing for this doesn't sound good, as you've mentioned.

@little-dude little-dude force-pushed the issue-25 branch 2 times, most recently from e0adaaf to 9c70346 Compare June 4, 2019 20:19
@little-dude
Copy link
Collaborator Author

The measure_width thing is not working currently, don't waste your time. I'll let you know when I get it working.

@Cogitri
Copy link
Collaborator

Cogitri commented Jun 5, 2019

Oh, okay, thanks :)

@little-dude
Copy link
Collaborator Author

So I got things kind of working: it does not crash, but line wrapping is a bit weird, as shown in the screenshot below

screenshot_line_wrapping

@Cogitri
Copy link
Collaborator

Cogitri commented Jun 5, 2019

Does xi-term send resize to Xi?

@little-dude
Copy link
Collaborator Author

No it doesn't

@little-dude
Copy link
Collaborator Author

I'll try with resize thanks @Cogitri

@Cogitri
Copy link
Collaborator

Cogitri commented Jun 5, 2019

Then that explains why it "bugs" out like that. You have to send Xi resize so it knows how big the view is in size so it knows when to break a line :)

match JsonRpcResult::<Value, Value>::deserialize(deserializer)? {

JsonRpcResult::Result(value) => {
println!("{:?}", value);
Copy link
Collaborator Author

@little-dude little-dude Jun 5, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note to self: remove that

src/client.rs Outdated
"changes": changes,
}),
)
pub fn modify_user_config(&self, domain: ConfigDomain, changes: ConfigChanges) -> ClientResult<()> {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Cogitri I think you use modify_user_config quite a lot already in gxi so this will impact you. If having to deal with this bothers you, I'll move this change to a separate PR that can be merged later, just let me know.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yes, thanks for the heads up! I do use this a lot in gxi - I don't use the file based config of xi anymore but allow configuration via the UI and GSettings (the GLib integrated way to deal with settings). It's a bit of a bother that I'll have to pass in all of my settings into the function now via ConfigChanges instead of just passing what has actually changed to it, but I guess this works for me.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'll remove that change from this PR, we'll see later.

This changes the `Frontend` trait, renaming the too generic
`handle_event()` into `handle_notification()`, and `XiEvent` into
`XiNotification`.
we just ran `cargo fix --edition-idioms`
responses were not deserialized correctly, so this commit fixes it.
it also simplifies (de)serialization with the `flatten` attribute.
- derive Default
- skip serializing fields that are None
- add `word_wrap`
@little-dude
Copy link
Collaborator Author

I dropped the changes to modify_user_config and got line wrapping kind of working in xi-term, so I think this PR is good to go:

xi-term-line-wrapping

@Cogitri
Copy link
Collaborator

Cogitri commented Jun 6, 2019

Nice, will add to gxi. Thanks for your work! :)

Will look at #29 in a few minutes I suppose.

@little-dude little-dude merged commit ca3549d into xi-frontend:master Jun 6, 2019
@little-dude
Copy link
Collaborator Author

Yeah I'll look this afternoon (in ~2h probably).

@little-dude little-dude deleted the issue-25 branch June 6, 2019 12:24
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.

2 participants