Added hover support#753
Conversation
| } | ||
| } | ||
|
|
||
| /// Counts the number of utf-16 code units in the given string. |
There was a problem hiding this comment.
Actually, I currently handled the conversion for Hover only. This is still being used for the update methods. I plan to address them in a separate PR to keep it clean.
|
Is this ready for review? |
| self.send_request("textDocument/hover", params, Box::new(on_result)) | ||
| } | ||
|
|
||
| pub fn request_definition<CB>(&mut self, view_id: ViewId, position: Position, on_result: CB) |
There was a problem hiding this comment.
these two functions probably don't belong here?
cmyr
left a comment
There was a problem hiding this comment.
Only some nits. Haven't run this version too much yet, will do that shortly.
| use tabs::ViewId; | ||
| use config::Table; | ||
| use styles::ThemeSettings; | ||
| use plugins::rpc::ClientPluginInfo; |
|
|
||
| use config::{Table, ConfigDomainExternal}; | ||
| use plugins::PlaceholderRpc; | ||
| use plugins::{PlaceholderRpc}; |
| UpdateStatusItem { key: String, value: String }, | ||
| RemoveStatusItem { key: String } | ||
| RemoveStatusItem { key: String }, | ||
| ShowHover { request_id: usize, result: Result<Hover, LanguageResponseError>, rev: u64 } |
| } | ||
|
|
||
| #[derive(Serialize, Deserialize, PartialEq, Eq, Debug)] | ||
| pub struct Position { |
There was a problem hiding this comment.
I'd remove this, and just include line and col params like we do with the gesture RPC, if only to keep the protocol somewhat consistent.
(in fact, it might make sense for us to be just adding a hover GestureType?)
There was a problem hiding this comment.
I added this Position struct since the whole parameter i.e. line/col is optional, it uses caret position as a fallback (this makes more sense for terminal clients). However, adding this as a gesture type is a good possibility but how do terminal client invoke this then?
| eprintln!("close view {}", view.get_id()); | ||
|
|
||
| if let Some(view_info) = self.view_info.get(&view.get_id()) { | ||
| let ls_client = self |
There was a problem hiding this comment.
I'm noticing you have to write these ~4 lines a lot..
There was a problem hiding this comment.
I added a helper function that do take rest of the code in a closure to clean this up (see below). Will use that here as well.
|
|
||
| #[derive(Serialize, Deserialize, Debug, Clone)] | ||
| #[serde(rename_all = "snake_case")] | ||
| pub struct Position { |
There was a problem hiding this comment.
These two types will be confusing for people. I've been trying to come up with better names without a lot of luck. maybe CorePosition and ClientPosition?
| } | ||
|
|
||
| #[derive(Serialize, Deserialize)] | ||
| pub struct Range { |
There was a problem hiding this comment.
What is this used for, again? As in, if this is present what is the client supposed to do with that information?
There was a problem hiding this comment.
The client is supposed to highlight this area while hover is active. Thinking again, it makes sense to convert this to Line/Col according to View which client can use to have a tint over that area. What do you think?
| .map(|offset| self.get_position(offset)) | ||
| } | ||
|
|
||
| fn get_position(&mut self, utf8_offset: usize) -> Position { |
There was a problem hiding this comment.
I would call this something like offset_to_plugin_position.
| } | ||
| } | ||
|
|
||
| fn get_utf8_offset_from_position_enum(&mut self, position: PositionEnum) -> usize { |
There was a problem hiding this comment.
maybe offset_from_plugin_position? I appreciate that this is a different type than above, but at least this fn name communicates what we're doing.
3712683 to
0a8da37
Compare
|
@cmyr I fixed most of the things. @nangtrongvuon PR does not have the above change in RPC request yet so be sure to make a change if running now. |
|
@cmyr this failed due to a storage full error, I think it is unrelated to this work. Maybe restart the build? |
cmyr
left a comment
There was a problem hiding this comment.
Okay that's my last batch of nits I think!
| } | ||
|
|
||
| #[derive(Debug, Serialize, Deserialize)] | ||
| pub struct Range { |
There was a problem hiding this comment.
let's not send the range to the client.
| f(&mut view, editor.get_buffer()) | ||
| } | ||
|
|
||
| fn with_rope<R, F>(&mut self, f: F) -> R |
There was a problem hiding this comment.
I'd either just use with_view or rename this to with_text.
| f(editor.get_buffer()) | ||
| } | ||
|
|
||
| fn with_rope_rev<R, F>(&mut self, rev: u64, f: F) -> Option<R> |
| self.view_id, &key, &value), | ||
| RemoveStatusItem { key } => self.client.remove_status_item(self.view_id, &key) | ||
| RemoveStatusItem { key } => self.client.remove_status_item(self.view_id, &key), | ||
| ShowHover { request_id, result, rev } => { |
There was a problem hiding this comment.
I would put all the login in something like do_show_hover.
| } | ||
| } | ||
|
|
||
| // Gives the requested position in UTF-8 offset format to be sent to plugin |
|
|
||
| #[derive(Serialize, Deserialize, Debug, Clone)] | ||
| #[serde(rename_all = "snake_case")] | ||
| pub enum LanguageResponseError { |
| #[derive(Serialize, Deserialize, Debug, Clone)] | ||
| #[serde(rename_all = "snake_case")] | ||
| pub struct CorePosition { | ||
| pub utf8_offset: usize, |
There was a problem hiding this comment.
maybe just offset? utf8 offsets are our default representation. You could mention that it's utf8 in a doc comment.
dd60d30 to
a2b5ea6
Compare
cmyr
left a comment
There was a problem hiding this comment.
okay just took a look through and I think this is solid. I'll build and play around tonight, but looks good code-wise.
cmyr
left a comment
There was a problem hiding this comment.
Okay I think this is a good checkpoint. There are still some open questions, but let's get this in and we can iterate from there.
I'm not going to have time to update my autocomplete stuff tonight, but first thing tomorrow I'll merge this and rebase my stuff and we can start working from there.
Tracking issues/ PRs: #717 #693 #746
This PR adds support for Hover via Language Server only. It is currently based on work from #750 but will be rebased to master once that is resolved and merged.
Meanwhile this is working with the Client work done by @nangtrongvuon with these changes. The RPC for client has been updated. See the relevant files in this PR.
The changes required in Xi-mac client PR is:
PS: I am yet to test out the Range conversion successfully yet since RLS sends it as
nulland we are not using it on the client either.