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

adjust selectionRange API #474

Closed
wants to merge 1 commit into from

Conversation

matklad
Copy link
Contributor

@matklad matklad commented Mar 27, 2019

Tested manally with insiders code and this commit in rust-analyzer. Seems to work :)

if (selectionRange.parent) {
parent = this.asSelectionRange(selectionRange.parent);
if (!parent || !(parent.range.contains(range) && !parent.range.isEqual(range))) {
return undefined
Copy link
Contributor Author

Choose a reason for hiding this comment

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

What is the proper way to report invalid data? eg, when parent is smaller than a child?

Copy link
Member

Choose a reason for hiding this comment

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

@jrieken any recommendation?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, child must be contained by parents

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, and this code checks this conditions. The question is, what to do if the server implementation returns wrong data?

The behavior should be such that:

  • server implementer ideally should see a loud error and fix the problem, instead of spending time with debugger to figure out where exactly the info is dropped
  • editor user should ideally get some message (such that they can open an issue for the corresponding extension), but it should not be distracting, and it should not be repeating.

Is there some function like show_error_dialog_if_in_dev_mode_otherwise_log_a_warning?

}
return new VSelectionRange(range, parent);
}
}

declare module 'vscode' {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

note that the API is not proposed in insiders, so we should remove this once we update vscode dependency

@dbaeumer
Copy link
Member

dbaeumer commented Apr 5, 2019

I created a branch with the updated API

https://github.com/Microsoft/vscode-languageserver-node/tree/dbaeumer/selectionRange

Regarding error checking:

  • since the VS Code API already checks this there is IMO no need to check it in the LSP client again.
  • checking this in the server is up to the server implementation / library. If in dev mode you could use the showMessage request to show a message to the user.

Let me know if the changes look OK?

@dbaeumer
Copy link
Member

dbaeumer commented Apr 5, 2019

Sorry for the overlap but this PR was closed / merged for me :-)

@matklad
Copy link
Contributor Author

matklad commented Apr 5, 2019

Changes in https://github.com/Microsoft/vscode-languageserver-node/tree/dbaeumer/selectionRange look good to me! I would prefer if client did more validation/error reporting, to make it easier to debug a buggy server, and to make protocol more strict, but this would be only a small quality of life improvement, nothing too important.

@dbaeumer
Copy link
Member

dbaeumer commented Apr 5, 2019

I see the point. Could we do the following. I merge the update into master and then we take it from there?

@matklad
Copy link
Contributor Author

matklad commented Apr 5, 2019

I wasn't clear enough: I would be more more than happy to have any version of this in master, I don't think validation should block anything (or, for that matter, I am only 80% sure that it is worth having validation at all).

@dbaeumer
Copy link
Member

dbaeumer commented Apr 5, 2019

OK. Great.

@matklad
Copy link
Contributor Author

matklad commented Apr 21, 2019

I guess this can be closed? The impl is already im master!

@matklad matklad closed this Apr 21, 2019
@dbaeumer
Copy link
Member

Yes. Thanks for closing.

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.

3 participants