Be more lenient with hint resolution, always return some hint

This commit is contained in:
Kirill Bulatov 2023-08-24 16:37:53 +03:00
parent 852427e87b
commit 3c55c933d4
2 changed files with 27 additions and 32 deletions

View File

@ -449,30 +449,26 @@ impl InlayHintCache {
})
})?;
if let Some(resolved_hint_task) = resolved_hint_task {
if let Some(mut resolved_hint) =
resolved_hint_task.await.context("hint resolve task")?
{
editor.update(&mut cx, |editor, _| {
if let Some(excerpt_hints) =
editor.inlay_hint_cache.hints.get(&excerpt_id)
let mut resolved_hint =
resolved_hint_task.await.context("hint resolve task")?;
editor.update(&mut cx, |editor, _| {
if let Some(excerpt_hints) =
editor.inlay_hint_cache.hints.get(&excerpt_id)
{
let mut guard = excerpt_hints.write();
if let Some(cached_hint) = guard
.hints
.iter_mut()
.find(|(hint_id, _)| hint_id == &id)
.map(|(_, hint)| hint)
{
let mut guard = excerpt_hints.write();
if let Some(cached_hint) = guard
.hints
.iter_mut()
.find(|(hint_id, _)| hint_id == &id)
.map(|(_, hint)| hint)
{
if cached_hint.resolve_state == ResolveState::Resolving
{
resolved_hint.resolve_state =
ResolveState::Resolved;
*cached_hint = resolved_hint;
}
if cached_hint.resolve_state == ResolveState::Resolving {
resolved_hint.resolve_state = ResolveState::Resolved;
*cached_hint = resolved_hint;
}
}
})?;
}
}
})?;
}
anyhow::Ok(())

View File

@ -5033,7 +5033,7 @@ impl Project {
buffer_handle: ModelHandle<Buffer>,
server_id: LanguageServerId,
cx: &mut ModelContext<Self>,
) -> Task<anyhow::Result<Option<InlayHint>>> {
) -> Task<anyhow::Result<InlayHint>> {
if self.is_local() {
let buffer = buffer_handle.read(cx);
let (_, lang_server) = if let Some((adapter, server)) =
@ -5041,7 +5041,7 @@ impl Project {
{
(adapter.clone(), server.clone())
} else {
return Task::ready(Ok(None));
return Task::ready(Ok(hint));
};
let can_resolve = lang_server
.capabilities()
@ -5050,7 +5050,7 @@ impl Project {
.and_then(|options| options.resolve_provider)
.unwrap_or(false);
if !can_resolve {
return Task::ready(Ok(None));
return Task::ready(Ok(hint));
}
let buffer_snapshot = buffer.snapshot();
@ -5071,7 +5071,7 @@ impl Project {
&mut cx,
)
.await?;
Ok(Some(resolved_hint))
Ok(resolved_hint)
})
} else if let Some(project_id) = self.remote_id() {
let client = self.client.clone();
@ -5079,7 +5079,7 @@ impl Project {
project_id,
buffer_id: buffer_handle.read(cx).remote_id(),
language_server_id: server_id.0 as u64,
hint: Some(InlayHints::project_to_proto_hint(hint, cx)),
hint: Some(InlayHints::project_to_proto_hint(hint.clone(), cx)),
};
cx.spawn(|project, mut cx| async move {
let response = client
@ -5090,10 +5090,9 @@ impl Project {
Some(resolved_hint) => {
InlayHints::proto_to_project_hint(resolved_hint, &project, &mut cx)
.await
.map(Some)
.context("inlay hints proto resolve response conversion")
}
None => Ok(None),
None => Ok(hint),
}
})
} else {
@ -6917,7 +6916,7 @@ impl Project {
.and_then(|buffer| buffer.upgrade(cx))
.ok_or_else(|| anyhow!("unknown buffer id {}", envelope.payload.buffer_id))
})?;
let resolved_hint = this
let response_hint = this
.update(&mut cx, |project, cx| {
project.resolve_inlay_hint(
hint,
@ -6927,11 +6926,11 @@ impl Project {
)
})
.await
.context("inlay hints fetch")?
.map(|hint| cx.read(|cx| InlayHints::project_to_proto_hint(hint, cx)));
.context("inlay hints fetch")?;
let resolved_hint = cx.read(|cx| InlayHints::project_to_proto_hint(response_hint, cx));
Ok(proto::ResolveInlayHintResponse {
hint: resolved_hint,
hint: Some(resolved_hint),
})
}