Skip to content

Added hover support#753

Merged
cmyr merged 2 commits into
xi-editor:masterfrom
betterclever:hover-new
Jul 26, 2018
Merged

Added hover support#753
cmyr merged 2 commits into
xi-editor:masterfrom
betterclever:hover-new

Conversation

@betterclever
Copy link
Copy Markdown
Member

@betterclever betterclever commented Jul 18, 2018

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:

document.sendRpcAsync("request_hover", params: ["request_id": hoverRequestID, "position": ["line": hoverPosition.line, "column": hoverPosition.column]])

PS: I am yet to test out the Range conversion successfully yet since RLS sends it as null and we are not using it on the client either.

}
}

/// Counts the number of utf-16 code units in the given string.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

can we delete all this now?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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.

@cmyr
Copy link
Copy Markdown
Member

cmyr commented Jul 19, 2018

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)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

these two functions probably don't belong here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Removing this bit.

Copy link
Copy Markdown
Member

@cmyr cmyr left a comment

Choose a reason for hiding this comment

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

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;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

{...}

Comment thread rust/core-lib/src/rpc.rs Outdated

use config::{Table, ConfigDomainExternal};
use plugins::PlaceholderRpc;
use plugins::{PlaceholderRpc};
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

braces not needed

Comment thread rust/core-lib/src/plugins/rpc.rs Outdated
UpdateStatusItem { key: String, value: String },
RemoveStatusItem { key: String }
RemoveStatusItem { key: String },
ShowHover { request_id: usize, result: Result<Hover, LanguageResponseError>, rev: u64 }
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: we can add a trailing , here

Comment thread rust/core-lib/src/rpc.rs
}

#[derive(Serialize, Deserialize, PartialEq, Eq, Debug)]
pub struct Position {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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?)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Okay, good point.

Comment thread rust/lsp-lib/src/lsp_plugin.rs Outdated
eprintln!("close view {}", view.get_id());

if let Some(view_info) = self.view_info.get(&view.get_id()) {
let ls_client = self
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm noticing you have to write these ~4 lines a lot..

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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.

Comment thread rust/core-lib/src/plugins/rpc.rs Outdated

#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "snake_case")]
pub struct Position {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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?

Comment thread rust/core-lib/src/client.rs Outdated
}

#[derive(Serialize, Deserialize)]
pub struct Range {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What is this used for, again? As in, if this is present what is the client supposed to do with that information?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@cmyr Views on this?

Comment thread rust/core-lib/src/event_context.rs Outdated
.map(|offset| self.get_position(offset))
}

fn get_position(&mut self, utf8_offset: usize) -> Position {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would call this something like offset_to_plugin_position.

Comment thread rust/core-lib/src/event_context.rs Outdated
}
}

fn get_utf8_offset_from_position_enum(&mut self, position: PositionEnum) -> usize {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

@betterclever betterclever force-pushed the hover-new branch 2 times, most recently from 3712683 to 0a8da37 Compare July 20, 2018 17:01
@betterclever
Copy link
Copy Markdown
Member Author

@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.

@betterclever
Copy link
Copy Markdown
Member Author

@cmyr this failed due to a storage full error, I think it is unrelated to this work. Maybe restart the build?

Copy link
Copy Markdown
Member

@cmyr cmyr left a comment

Choose a reason for hiding this comment

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

Okay that's my last batch of nits I think!

Comment thread rust/core-lib/src/client.rs Outdated
}

#[derive(Debug, Serialize, Deserialize)]
pub struct Range {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

let's not send the range to the client.

Comment thread rust/core-lib/src/event_context.rs Outdated
f(&mut view, editor.get_buffer())
}

fn with_rope<R, F>(&mut self, f: F) -> R
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd either just use with_view or rename this to with_text.

Comment thread rust/core-lib/src/event_context.rs Outdated
f(editor.get_buffer())
}

fn with_rope_rev<R, F>(&mut self, rev: u64, f: F) -> Option<R>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

"with_rev"?

Comment thread rust/core-lib/src/event_context.rs Outdated
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 } => {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would put all the login in something like do_show_hover.

Comment thread rust/core-lib/src/event_context.rs Outdated
}
}

// Gives the requested position in UTF-8 offset format to be sent to plugin
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

three /// ?

Comment thread rust/core-lib/src/plugins/rpc.rs Outdated

#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "snake_case")]
pub enum LanguageResponseError {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

let's use xi_rpc::RemoteError

Comment thread rust/core-lib/src/plugins/rpc.rs Outdated
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "snake_case")]
pub struct CorePosition {
pub utf8_offset: usize,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

maybe just offset? utf8 offsets are our default representation. You could mention that it's utf8 in a doc comment.

@betterclever betterclever force-pushed the hover-new branch 4 times, most recently from dd60d30 to a2b5ea6 Compare July 25, 2018 19:24
Copy link
Copy Markdown
Member

@cmyr cmyr left a comment

Choose a reason for hiding this comment

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

okay just took a look through and I think this is solid. I'll build and play around tonight, but looks good code-wise.

Copy link
Copy Markdown
Member

@cmyr cmyr left a comment

Choose a reason for hiding this comment

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

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.

@cmyr cmyr merged commit 10f4c28 into xi-editor:master Jul 26, 2018
@cmyr cmyr mentioned this pull request Oct 17, 2018
12 tasks
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