Skip to content

Conversation

@fsouza
Copy link
Contributor

@fsouza fsouza commented Mar 5, 2019

I probably did a lot of things wrong, feedback is appreciated :)

I was able to test this with Scala Metals and everything seems to work fine (see fsouza/dotfiles@914bb5d).

let mut v = Value::Null;
let result: Option<i64> = self.vim()?.rpcclient.call("s:inputlist", options)?;
if let Some(answer) = result {
if answer > 0 && answer < (n_actions - 1) as i64 {
Copy link
Owner

Choose a reason for hiding this comment

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

The second portion should be something like <= n_actions, right?

Say there are 2 actions, 2 should be a legitimate answer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The mapping between actions and parameters to inputlist isn't 1 to 1, they're actually shifted to accommodate the prompt. params.message is actually the index 0, so when the user types 1, they're actually selecting 0.

See screenshot:

image

We're instructing the user to type from 1 to 3, but the user could actually type 0 and get an invalid option. Vim also supports mouse click, so that's why we can't simply say that the second option is index 0.

Copy link
Owner

Choose a reason for hiding this comment

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

Yes, I get that part.

What I meant is, say in this screenshot, if I select or click 3, it should still be an acceptable answer, right? But in your code, 3 < (3 - 1), which is returning false.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh shoot you're right I got this wrong, my bad.

let result: Option<i64> = self.vim()?.rpcclient.call("s:inputlist", options)?;
if let Some(answer) = result {
if answer > 0 && answer < (n_actions - 1) as i64 {
let raw_actions: Vec<Value> = try_get("actions", &params)?.unwrap_or_default();
Copy link
Owner

Choose a reason for hiding this comment

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

Parse action is not necessary since there is already deserialized instance before hand. Around L1833, you can use iter() instead of into_iter() so you can continue use the instance here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I thought the struct in lsp-type wouldn't contain everything that's required, but I just checked the spec and it does. Will fix the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Question: what's the easiest way to convert MessageActionItem into Value? 🤔

Copy link
Owner

Choose a reason for hiding this comment

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

serde_json::to_value

if let Some(answer) = result {
if answer > 0 && answer < (n_actions - 1) as i64 {
let raw_actions: Vec<Value> = try_get("actions", &params)?.unwrap_or_default();
v = raw_actions[(answer - 1) as usize].clone();
Copy link
Owner

Choose a reason for hiding this comment

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

Please try not indexing from an array. If the index is out of range, it crashes the whole program. use get() instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We're doing a bounds check two lines before 😬 I'll update the code though.

@autozimu
Copy link
Owner

autozimu commented Mar 7, 2019

Thanks for contributing. Please see my comments inline.

@autozimu autozimu merged commit f64b9fa into autozimu:next Mar 8, 2019
@autozimu
Copy link
Owner

autozimu commented Mar 8, 2019

Thanks!

@fsouza
Copy link
Contributor Author

fsouza commented Mar 8, 2019

@autozimu hey I didn't get a chance to address all the feedback, sorry about that. I can look into them later today or tomorrow.

Thanks for all the feedback!

@autozimu
Copy link
Owner

autozimu commented Mar 8, 2019

I will create a commit to clean it up.

@fsouza
Copy link
Contributor Author

fsouza commented Mar 8, 2019

Oh cool, thank you and sorry about that: :)

@fsouza fsouza deleted the window/showMessageRequest branch March 8, 2019 00:47
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