mirror of
https://github.com/zed-industries/zed.git
synced 2025-02-06 10:42:08 +00:00
Fix delayed lsp request
This commit is contained in:
parent
722023e347
commit
93158bfcff
2 changed files with 20 additions and 7 deletions
|
@ -66,6 +66,7 @@ pub fn hide_hover(editor: &mut Editor, cx: &mut ViewContext<Editor>) -> bool {
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
editor.hover_state.task = None;
|
editor.hover_state.task = None;
|
||||||
|
editor.hover_state.triggered_from = None;
|
||||||
editor.hover_state.symbol_range = None;
|
editor.hover_state.symbol_range = None;
|
||||||
|
|
||||||
editor.clear_background_highlights::<HoverState>(cx);
|
editor.clear_background_highlights::<HoverState>(cx);
|
||||||
|
@ -115,11 +116,6 @@ fn show_hover(
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
// query the LSP for hover info
|
|
||||||
let hover_request = project.update(cx, |project, cx| {
|
|
||||||
project.hover(&buffer, buffer_position.clone(), cx)
|
|
||||||
});
|
|
||||||
|
|
||||||
// We should only delay if the hover popover isn't visible, it wasn't recently hidden, and
|
// We should only delay if the hover popover isn't visible, it wasn't recently hidden, and
|
||||||
// the hover wasn't triggered from the keyboard
|
// the hover wasn't triggered from the keyboard
|
||||||
let should_delay = editor.hover_state.popover.is_none() // Hover not visible currently
|
let should_delay = editor.hover_state.popover.is_none() // Hover not visible currently
|
||||||
|
@ -147,6 +143,16 @@ fn show_hover(
|
||||||
.buffer_snapshot
|
.buffer_snapshot
|
||||||
.anchor_at(multibuffer_offset, Bias::Left);
|
.anchor_at(multibuffer_offset, Bias::Left);
|
||||||
|
|
||||||
|
// Don't request again if the location is the same as the previous request
|
||||||
|
if let Some(triggered_from) = &editor.hover_state.triggered_from {
|
||||||
|
if triggered_from
|
||||||
|
.cmp(&anchor, &snapshot.buffer_snapshot)
|
||||||
|
.is_eq()
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let task = cx.spawn_weak(|this, mut cx| {
|
let task = cx.spawn_weak(|this, mut cx| {
|
||||||
async move {
|
async move {
|
||||||
// If we need to delay, delay a set amount initially before making the lsp request
|
// If we need to delay, delay a set amount initially before making the lsp request
|
||||||
|
@ -165,6 +171,13 @@ fn show_hover(
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// query the LSP for hover info
|
||||||
|
let hover_request = cx.update(|cx| {
|
||||||
|
project.update(cx, |project, cx| {
|
||||||
|
project.hover(&buffer, buffer_position.clone(), cx)
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
// Construct new hover popover from hover request
|
// Construct new hover popover from hover request
|
||||||
let hover_popover = hover_request.await.ok().flatten().and_then(|hover_result| {
|
let hover_popover = hover_request.await.ok().flatten().and_then(|hover_result| {
|
||||||
if hover_result.contents.is_empty() {
|
if hover_result.contents.is_empty() {
|
||||||
|
@ -239,6 +252,7 @@ fn show_hover(
|
||||||
pub struct HoverState {
|
pub struct HoverState {
|
||||||
pub popover: Option<HoverPopover>,
|
pub popover: Option<HoverPopover>,
|
||||||
pub hidden_at: Option<Instant>,
|
pub hidden_at: Option<Instant>,
|
||||||
|
pub triggered_from: Option<Anchor>,
|
||||||
pub symbol_range: Option<Range<Anchor>>,
|
pub symbol_range: Option<Range<Anchor>>,
|
||||||
pub task: Option<Task<Option<()>>>,
|
pub task: Option<Task<Option<()>>>,
|
||||||
}
|
}
|
||||||
|
|
|
@ -988,7 +988,6 @@ impl LspCommand for GetHover {
|
||||||
_: ModelHandle<Buffer>,
|
_: ModelHandle<Buffer>,
|
||||||
_: AsyncAppContext,
|
_: AsyncAppContext,
|
||||||
) -> Result<Self::Response> {
|
) -> Result<Self::Response> {
|
||||||
println!("Response from proto");
|
|
||||||
let range = if let (Some(start), Some(end)) = (message.start, message.end) {
|
let range = if let (Some(start), Some(end)) = (message.start, message.end) {
|
||||||
language::proto::deserialize_anchor(start)
|
language::proto::deserialize_anchor(start)
|
||||||
.and_then(|start| language::proto::deserialize_anchor(end).map(|end| start..end))
|
.and_then(|start| language::proto::deserialize_anchor(end).map(|end| start..end))
|
||||||
|
|
Loading…
Reference in a new issue