Do not convert lsp::Location of hint labels before resolve
This commit is contained in:
parent
d6ffb68305
commit
ddd7ab116f
4 changed files with 163 additions and 209 deletions
|
@ -4,13 +4,15 @@ use crate::{
|
||||||
hover_popover::{self, InlayHover},
|
hover_popover::{self, InlayHover},
|
||||||
Anchor, DisplayPoint, Editor, EditorSnapshot, SelectPhase,
|
Anchor, DisplayPoint, Editor, EditorSnapshot, SelectPhase,
|
||||||
};
|
};
|
||||||
|
use anyhow::Context;
|
||||||
use gpui::{Task, ViewContext};
|
use gpui::{Task, ViewContext};
|
||||||
use language::{Bias, ToOffset};
|
use language::{point_from_lsp, Bias, LanguageServerName, ToOffset};
|
||||||
|
use lsp::LanguageServerId;
|
||||||
use project::{
|
use project::{
|
||||||
HoverBlock, HoverBlockKind, InlayHintLabelPartTooltip, InlayHintTooltip, Location,
|
HoverBlock, HoverBlockKind, InlayHintLabelPartTooltip, InlayHintTooltip, Location,
|
||||||
LocationLink, ResolveState,
|
LocationLink, ResolveState,
|
||||||
};
|
};
|
||||||
use std::ops::Range;
|
use std::{ops::Range, sync::Arc};
|
||||||
use util::TryFutureExt;
|
use util::TryFutureExt;
|
||||||
|
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
|
@ -24,7 +26,7 @@ pub struct LinkGoToDefinitionState {
|
||||||
|
|
||||||
pub enum GoToDefinitionTrigger {
|
pub enum GoToDefinitionTrigger {
|
||||||
Text(DisplayPoint),
|
Text(DisplayPoint),
|
||||||
InlayHint(InlayRange, LocationLink),
|
InlayHint(InlayRange, lsp::Location, LanguageServerId),
|
||||||
None,
|
None,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,7 +40,7 @@ pub struct InlayRange {
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum TriggerPoint {
|
pub enum TriggerPoint {
|
||||||
Text(Anchor),
|
Text(Anchor),
|
||||||
InlayHint(InlayRange, LocationLink),
|
InlayHint(InlayRange, lsp::Location, LanguageServerId),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
|
@ -61,12 +63,12 @@ impl DocumentRange {
|
||||||
let point_after_start = range.start.cmp(point, &snapshot.buffer_snapshot).is_le();
|
let point_after_start = range.start.cmp(point, &snapshot.buffer_snapshot).is_le();
|
||||||
point_after_start && range.end.cmp(point, &snapshot.buffer_snapshot).is_ge()
|
point_after_start && range.end.cmp(point, &snapshot.buffer_snapshot).is_ge()
|
||||||
}
|
}
|
||||||
(DocumentRange::Inlay(range), TriggerPoint::InlayHint(point, _)) => {
|
(DocumentRange::Inlay(range), TriggerPoint::InlayHint(point, _, _)) => {
|
||||||
range.highlight_start.cmp(&point.highlight_end).is_le()
|
range.highlight_start.cmp(&point.highlight_end).is_le()
|
||||||
&& range.highlight_end.cmp(&point.highlight_end).is_ge()
|
&& range.highlight_end.cmp(&point.highlight_end).is_ge()
|
||||||
}
|
}
|
||||||
(DocumentRange::Inlay(_), TriggerPoint::Text(_))
|
(DocumentRange::Inlay(_), TriggerPoint::Text(_))
|
||||||
| (DocumentRange::Text(_), TriggerPoint::InlayHint(_, _)) => false,
|
| (DocumentRange::Text(_), TriggerPoint::InlayHint(_, _, _)) => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -75,7 +77,7 @@ impl TriggerPoint {
|
||||||
fn anchor(&self) -> &Anchor {
|
fn anchor(&self) -> &Anchor {
|
||||||
match self {
|
match self {
|
||||||
TriggerPoint::Text(anchor) => anchor,
|
TriggerPoint::Text(anchor) => anchor,
|
||||||
TriggerPoint::InlayHint(coordinates, _) => &coordinates.inlay_position,
|
TriggerPoint::InlayHint(coordinates, _, _) => &coordinates.inlay_position,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,7 +90,7 @@ impl TriggerPoint {
|
||||||
LinkDefinitionKind::Symbol
|
LinkDefinitionKind::Symbol
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
TriggerPoint::InlayHint(_, _) => LinkDefinitionKind::Type,
|
TriggerPoint::InlayHint(_, _, _) => LinkDefinitionKind::Type,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -110,7 +112,9 @@ pub fn update_go_to_definition_link(
|
||||||
p.to_offset(&snapshot.display_snapshot, Bias::Left),
|
p.to_offset(&snapshot.display_snapshot, Bias::Left),
|
||||||
)))
|
)))
|
||||||
}
|
}
|
||||||
GoToDefinitionTrigger::InlayHint(p, target) => Some(TriggerPoint::InlayHint(p, target)),
|
GoToDefinitionTrigger::InlayHint(p, lsp_location, language_server_id) => {
|
||||||
|
Some(TriggerPoint::InlayHint(p, lsp_location, language_server_id))
|
||||||
|
}
|
||||||
GoToDefinitionTrigger::None => None,
|
GoToDefinitionTrigger::None => None,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -277,35 +281,25 @@ pub fn update_inlay_link_and_hover_points(
|
||||||
);
|
);
|
||||||
hover_updated = true;
|
hover_updated = true;
|
||||||
}
|
}
|
||||||
if let Some(location) = hovered_hint_part.location {
|
if let Some((language_server_id, location)) =
|
||||||
if let Some(buffer) =
|
hovered_hint_part.location
|
||||||
cached_hint.position.buffer_id.and_then(|buffer_id| {
|
{
|
||||||
editor.buffer().read(cx).buffer(buffer_id)
|
go_to_definition_updated = true;
|
||||||
})
|
update_go_to_definition_link(
|
||||||
{
|
editor,
|
||||||
go_to_definition_updated = true;
|
GoToDefinitionTrigger::InlayHint(
|
||||||
update_go_to_definition_link(
|
InlayRange {
|
||||||
editor,
|
inlay_position: hovered_hint.position,
|
||||||
GoToDefinitionTrigger::InlayHint(
|
highlight_start: part_range.start,
|
||||||
InlayRange {
|
highlight_end: part_range.end,
|
||||||
inlay_position: hovered_hint.position,
|
},
|
||||||
highlight_start: part_range.start,
|
location,
|
||||||
highlight_end: part_range.end,
|
language_server_id,
|
||||||
},
|
),
|
||||||
LocationLink {
|
cmd_held,
|
||||||
origin: Some(Location {
|
shift_held,
|
||||||
buffer,
|
cx,
|
||||||
range: cached_hint.position
|
);
|
||||||
..cached_hint.position,
|
|
||||||
}),
|
|
||||||
target: location,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
cmd_held,
|
|
||||||
shift_held,
|
|
||||||
cx,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -415,7 +409,6 @@ pub fn show_link_definition(
|
||||||
let end = snapshot
|
let end = snapshot
|
||||||
.buffer_snapshot
|
.buffer_snapshot
|
||||||
.anchor_in_excerpt(excerpt_id.clone(), origin.range.end);
|
.anchor_in_excerpt(excerpt_id.clone(), origin.range.end);
|
||||||
|
|
||||||
DocumentRange::Text(start..end)
|
DocumentRange::Text(start..end)
|
||||||
})
|
})
|
||||||
}),
|
}),
|
||||||
|
@ -423,10 +416,59 @@ pub fn show_link_definition(
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
TriggerPoint::InlayHint(trigger_source, trigger_target) => Some((
|
TriggerPoint::InlayHint(trigger_source, lsp_location, server_id) => {
|
||||||
Some(DocumentRange::Inlay(trigger_source.clone())),
|
let target = match project.update(&mut cx, |project, cx| {
|
||||||
vec![trigger_target.clone()],
|
let language_server_name = project
|
||||||
)),
|
.language_server_for_buffer(buffer.read(cx), *server_id, cx)
|
||||||
|
.map(|(_, lsp_adapter)| {
|
||||||
|
LanguageServerName(Arc::from(lsp_adapter.name()))
|
||||||
|
});
|
||||||
|
language_server_name.map(|language_server_name| {
|
||||||
|
project.open_local_buffer_via_lsp(
|
||||||
|
lsp_location.uri.clone(),
|
||||||
|
*server_id,
|
||||||
|
language_server_name,
|
||||||
|
cx,
|
||||||
|
)
|
||||||
|
})
|
||||||
|
}) {
|
||||||
|
Some(task) => Some({
|
||||||
|
let target_buffer_handle = task.await.context("open local buffer")?;
|
||||||
|
let range = cx.read(|cx| {
|
||||||
|
let target_buffer = target_buffer_handle.read(cx);
|
||||||
|
let target_start = target_buffer.clip_point_utf16(
|
||||||
|
point_from_lsp(lsp_location.range.start),
|
||||||
|
Bias::Left,
|
||||||
|
);
|
||||||
|
let target_end = target_buffer.clip_point_utf16(
|
||||||
|
point_from_lsp(lsp_location.range.end),
|
||||||
|
Bias::Left,
|
||||||
|
);
|
||||||
|
target_buffer.anchor_after(target_start)
|
||||||
|
..target_buffer.anchor_before(target_end)
|
||||||
|
});
|
||||||
|
Location {
|
||||||
|
buffer: target_buffer_handle,
|
||||||
|
range,
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
None => None,
|
||||||
|
};
|
||||||
|
|
||||||
|
target.map(|target| {
|
||||||
|
(
|
||||||
|
Some(DocumentRange::Inlay(trigger_source.clone())),
|
||||||
|
vec![LocationLink {
|
||||||
|
origin: Some(Location {
|
||||||
|
buffer: buffer.clone(),
|
||||||
|
range: trigger_source.inlay_position.text_anchor
|
||||||
|
..trigger_source.inlay_position.text_anchor,
|
||||||
|
}),
|
||||||
|
target,
|
||||||
|
}],
|
||||||
|
)
|
||||||
|
})
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.update(&mut cx, |this, cx| {
|
this.update(&mut cx, |this, cx| {
|
||||||
|
@ -479,7 +521,7 @@ pub fn show_link_definition(
|
||||||
..snapshot.anchor_after(offset_range.end),
|
..snapshot.anchor_after(offset_range.end),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
TriggerPoint::InlayHint(inlay_coordinates, _) => {
|
TriggerPoint::InlayHint(inlay_coordinates, _, _) => {
|
||||||
DocumentRange::Inlay(inlay_coordinates)
|
DocumentRange::Inlay(inlay_coordinates)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
DocumentHighlight, Hover, HoverBlock, HoverBlockKind, InlayHint, InlayHintLabel,
|
DocumentHighlight, Hover, HoverBlock, HoverBlockKind, InlayHint, InlayHintLabel,
|
||||||
InlayHintLabelPart, InlayHintLabelPartTooltip, InlayHintTooltip, Item, Location, LocationLink,
|
InlayHintLabelPart, InlayHintLabelPartTooltip, InlayHintTooltip, Location, LocationLink,
|
||||||
MarkupContent, Project, ProjectTransaction, ResolveState,
|
MarkupContent, Project, ProjectTransaction, ResolveState,
|
||||||
};
|
};
|
||||||
use anyhow::{anyhow, Context, Result};
|
use anyhow::{anyhow, Context, Result};
|
||||||
|
@ -14,8 +14,8 @@ use language::{
|
||||||
point_from_lsp, point_to_lsp,
|
point_from_lsp, point_to_lsp,
|
||||||
proto::{deserialize_anchor, deserialize_version, serialize_anchor, serialize_version},
|
proto::{deserialize_anchor, deserialize_version, serialize_anchor, serialize_version},
|
||||||
range_from_lsp, range_to_lsp, Anchor, Bias, Buffer, BufferSnapshot, CachedLspAdapter, CharKind,
|
range_from_lsp, range_to_lsp, Anchor, Bias, Buffer, BufferSnapshot, CachedLspAdapter, CharKind,
|
||||||
CodeAction, Completion, LanguageServerName, OffsetRangeExt, PointUtf16, ToOffset, ToPointUtf16,
|
CodeAction, Completion, OffsetRangeExt, PointUtf16, ToOffset, ToPointUtf16, Transaction,
|
||||||
Transaction, Unclipped,
|
Unclipped,
|
||||||
};
|
};
|
||||||
use lsp::{DocumentHighlightKind, LanguageServer, LanguageServerId, OneOf, ServerCapabilities};
|
use lsp::{DocumentHighlightKind, LanguageServer, LanguageServerId, OneOf, ServerCapabilities};
|
||||||
use std::{cmp::Reverse, ops::Range, path::Path, sync::Arc};
|
use std::{cmp::Reverse, ops::Range, path::Path, sync::Arc};
|
||||||
|
@ -1787,7 +1787,6 @@ impl LspCommand for OnTypeFormatting {
|
||||||
impl InlayHints {
|
impl InlayHints {
|
||||||
pub async fn lsp_to_project_hint(
|
pub async fn lsp_to_project_hint(
|
||||||
lsp_hint: lsp::InlayHint,
|
lsp_hint: lsp::InlayHint,
|
||||||
project: &ModelHandle<Project>,
|
|
||||||
buffer_handle: &ModelHandle<Buffer>,
|
buffer_handle: &ModelHandle<Buffer>,
|
||||||
server_id: LanguageServerId,
|
server_id: LanguageServerId,
|
||||||
resolve_state: ResolveState,
|
resolve_state: ResolveState,
|
||||||
|
@ -1809,15 +1808,9 @@ impl InlayHints {
|
||||||
buffer.anchor_after(position)
|
buffer.anchor_after(position)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
let label = Self::lsp_inlay_label_to_project(
|
let label = Self::lsp_inlay_label_to_project(lsp_hint.label, server_id)
|
||||||
&buffer_handle,
|
.await
|
||||||
project,
|
.context("lsp to project inlay hint conversion")?;
|
||||||
server_id,
|
|
||||||
lsp_hint.label,
|
|
||||||
cx,
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
.context("lsp to project inlay hint conversion")?;
|
|
||||||
let padding_left = if force_no_type_left_padding && kind == Some(InlayHintKind::Type) {
|
let padding_left = if force_no_type_left_padding && kind == Some(InlayHintKind::Type) {
|
||||||
false
|
false
|
||||||
} else {
|
} else {
|
||||||
|
@ -1847,72 +1840,14 @@ impl InlayHints {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn lsp_inlay_label_to_project(
|
async fn lsp_inlay_label_to_project(
|
||||||
buffer: &ModelHandle<Buffer>,
|
|
||||||
project: &ModelHandle<Project>,
|
|
||||||
server_id: LanguageServerId,
|
|
||||||
lsp_label: lsp::InlayHintLabel,
|
lsp_label: lsp::InlayHintLabel,
|
||||||
cx: &mut AsyncAppContext,
|
server_id: LanguageServerId,
|
||||||
) -> anyhow::Result<InlayHintLabel> {
|
) -> anyhow::Result<InlayHintLabel> {
|
||||||
let label = match lsp_label {
|
let label = match lsp_label {
|
||||||
lsp::InlayHintLabel::String(s) => InlayHintLabel::String(s),
|
lsp::InlayHintLabel::String(s) => InlayHintLabel::String(s),
|
||||||
lsp::InlayHintLabel::LabelParts(lsp_parts) => {
|
lsp::InlayHintLabel::LabelParts(lsp_parts) => {
|
||||||
let mut parts_data = Vec::with_capacity(lsp_parts.len());
|
let mut parts = Vec::with_capacity(lsp_parts.len());
|
||||||
buffer.update(cx, |buffer, cx| {
|
for lsp_part in lsp_parts {
|
||||||
for lsp_part in lsp_parts {
|
|
||||||
let location_buffer_task = match &lsp_part.location {
|
|
||||||
Some(lsp_location) => {
|
|
||||||
let location_buffer_task = project.update(cx, |project, cx| {
|
|
||||||
let language_server_name = project
|
|
||||||
.language_server_for_buffer(buffer, server_id, cx)
|
|
||||||
.map(|(_, lsp_adapter)| {
|
|
||||||
LanguageServerName(Arc::from(lsp_adapter.name()))
|
|
||||||
});
|
|
||||||
language_server_name.map(|language_server_name| {
|
|
||||||
project.open_local_buffer_via_lsp(
|
|
||||||
lsp_location.uri.clone(),
|
|
||||||
server_id,
|
|
||||||
language_server_name,
|
|
||||||
cx,
|
|
||||||
)
|
|
||||||
})
|
|
||||||
});
|
|
||||||
Some(lsp_location.clone()).zip(location_buffer_task)
|
|
||||||
}
|
|
||||||
None => None,
|
|
||||||
};
|
|
||||||
|
|
||||||
parts_data.push((lsp_part, location_buffer_task));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
let mut parts = Vec::with_capacity(parts_data.len());
|
|
||||||
for (lsp_part, location_buffer_task) in parts_data {
|
|
||||||
let location = match location_buffer_task {
|
|
||||||
Some((lsp_location, target_buffer_handle_task)) => {
|
|
||||||
let target_buffer_handle = target_buffer_handle_task
|
|
||||||
.await
|
|
||||||
.context("resolving location for label part buffer")?;
|
|
||||||
let range = cx.read(|cx| {
|
|
||||||
let target_buffer = target_buffer_handle.read(cx);
|
|
||||||
let target_start = target_buffer.clip_point_utf16(
|
|
||||||
point_from_lsp(lsp_location.range.start),
|
|
||||||
Bias::Left,
|
|
||||||
);
|
|
||||||
let target_end = target_buffer.clip_point_utf16(
|
|
||||||
point_from_lsp(lsp_location.range.end),
|
|
||||||
Bias::Left,
|
|
||||||
);
|
|
||||||
target_buffer.anchor_after(target_start)
|
|
||||||
..target_buffer.anchor_before(target_end)
|
|
||||||
});
|
|
||||||
Some(Location {
|
|
||||||
buffer: target_buffer_handle,
|
|
||||||
range,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
None => None,
|
|
||||||
};
|
|
||||||
|
|
||||||
parts.push(InlayHintLabelPart {
|
parts.push(InlayHintLabelPart {
|
||||||
value: lsp_part.value,
|
value: lsp_part.value,
|
||||||
tooltip: lsp_part.tooltip.map(|tooltip| match tooltip {
|
tooltip: lsp_part.tooltip.map(|tooltip| match tooltip {
|
||||||
|
@ -1929,7 +1864,7 @@ impl InlayHints {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
location,
|
location: Some(server_id).zip(lsp_part.location),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
InlayHintLabel::LabelParts(parts)
|
InlayHintLabel::LabelParts(parts)
|
||||||
|
@ -1939,7 +1874,7 @@ impl InlayHints {
|
||||||
Ok(label)
|
Ok(label)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn project_to_proto_hint(response_hint: InlayHint, cx: &AppContext) -> proto::InlayHint {
|
pub fn project_to_proto_hint(response_hint: InlayHint) -> proto::InlayHint {
|
||||||
let (state, lsp_resolve_state) = match response_hint.resolve_state {
|
let (state, lsp_resolve_state) = match response_hint.resolve_state {
|
||||||
ResolveState::Resolved => (0, None),
|
ResolveState::Resolved => (0, None),
|
||||||
ResolveState::CanResolve(server_id, resolve_data) => (
|
ResolveState::CanResolve(server_id, resolve_data) => (
|
||||||
|
@ -1969,7 +1904,11 @@ impl InlayHints {
|
||||||
InlayHintLabel::String(s) => proto::inlay_hint_label::Label::Value(s),
|
InlayHintLabel::String(s) => proto::inlay_hint_label::Label::Value(s),
|
||||||
InlayHintLabel::LabelParts(label_parts) => {
|
InlayHintLabel::LabelParts(label_parts) => {
|
||||||
proto::inlay_hint_label::Label::LabelParts(proto::InlayHintLabelParts {
|
proto::inlay_hint_label::Label::LabelParts(proto::InlayHintLabelParts {
|
||||||
parts: label_parts.into_iter().map(|label_part| proto::InlayHintLabelPart {
|
parts: label_parts.into_iter().map(|label_part| {
|
||||||
|
let location_url = label_part.location.as_ref().map(|(_, location)| location.uri.to_string());
|
||||||
|
let location_range_start = label_part.location.as_ref().map(|(_, location)| point_from_lsp(location.range.start).0).map(|point| proto::PointUtf16 { row: point.row, column: point.column });
|
||||||
|
let location_range_end = label_part.location.as_ref().map(|(_, location)| point_from_lsp(location.range.end).0).map(|point| proto::PointUtf16 { row: point.row, column: point.column });
|
||||||
|
proto::InlayHintLabelPart {
|
||||||
value: label_part.value,
|
value: label_part.value,
|
||||||
tooltip: label_part.tooltip.map(|tooltip| {
|
tooltip: label_part.tooltip.map(|tooltip| {
|
||||||
let proto_tooltip = match tooltip {
|
let proto_tooltip = match tooltip {
|
||||||
|
@ -1981,12 +1920,11 @@ impl InlayHints {
|
||||||
};
|
};
|
||||||
proto::InlayHintLabelPartTooltip {content: Some(proto_tooltip)}
|
proto::InlayHintLabelPartTooltip {content: Some(proto_tooltip)}
|
||||||
}),
|
}),
|
||||||
location: label_part.location.map(|location| proto::Location {
|
location_url,
|
||||||
start: Some(serialize_anchor(&location.range.start)),
|
location_range_start,
|
||||||
end: Some(serialize_anchor(&location.range.end)),
|
location_range_end,
|
||||||
buffer_id: location.buffer.read(cx).remote_id(),
|
language_server_id: label_part.location.as_ref().map(|(server_id, _)| server_id.0 as u64),
|
||||||
}),
|
}}).collect()
|
||||||
}).collect()
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
|
@ -1994,16 +1932,12 @@ impl InlayHints {
|
||||||
kind: response_hint.kind.map(|kind| kind.name().to_string()),
|
kind: response_hint.kind.map(|kind| kind.name().to_string()),
|
||||||
tooltip: response_hint.tooltip.map(|response_tooltip| {
|
tooltip: response_hint.tooltip.map(|response_tooltip| {
|
||||||
let proto_tooltip = match response_tooltip {
|
let proto_tooltip = match response_tooltip {
|
||||||
InlayHintTooltip::String(s) => {
|
InlayHintTooltip::String(s) => proto::inlay_hint_tooltip::Content::Value(s),
|
||||||
proto::inlay_hint_tooltip::Content::Value(s)
|
|
||||||
}
|
|
||||||
InlayHintTooltip::MarkupContent(markup_content) => {
|
InlayHintTooltip::MarkupContent(markup_content) => {
|
||||||
proto::inlay_hint_tooltip::Content::MarkupContent(
|
proto::inlay_hint_tooltip::Content::MarkupContent(proto::MarkupContent {
|
||||||
proto::MarkupContent {
|
is_markdown: markup_content.kind == HoverBlockKind::Markdown,
|
||||||
is_markdown: markup_content.kind == HoverBlockKind::Markdown,
|
value: markup_content.value,
|
||||||
value: markup_content.value,
|
})
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
proto::InlayHintTooltip {
|
proto::InlayHintTooltip {
|
||||||
|
@ -2014,16 +1948,7 @@ impl InlayHints {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn proto_to_project_hint(
|
pub fn proto_to_project_hint(message_hint: proto::InlayHint) -> anyhow::Result<InlayHint> {
|
||||||
message_hint: proto::InlayHint,
|
|
||||||
project: &ModelHandle<Project>,
|
|
||||||
cx: &mut AsyncAppContext,
|
|
||||||
) -> anyhow::Result<InlayHint> {
|
|
||||||
let buffer_id = message_hint
|
|
||||||
.position
|
|
||||||
.as_ref()
|
|
||||||
.and_then(|location| location.buffer_id)
|
|
||||||
.context("missing buffer id")?;
|
|
||||||
let resolve_state = message_hint.resolve_state.as_ref().unwrap_or_else(|| {
|
let resolve_state = message_hint.resolve_state.as_ref().unwrap_or_else(|| {
|
||||||
panic!("incorrect proto inlay hint message: no resolve state in hint {message_hint:?}",)
|
panic!("incorrect proto inlay hint message: no resolve state in hint {message_hint:?}",)
|
||||||
});
|
});
|
||||||
|
@ -2064,9 +1989,6 @@ impl InlayHints {
|
||||||
proto::inlay_hint_label::Label::LabelParts(parts) => {
|
proto::inlay_hint_label::Label::LabelParts(parts) => {
|
||||||
let mut label_parts = Vec::new();
|
let mut label_parts = Vec::new();
|
||||||
for part in parts.parts {
|
for part in parts.parts {
|
||||||
let buffer = project
|
|
||||||
.update(cx, |this, cx| this.wait_for_remote_buffer(buffer_id, cx))
|
|
||||||
.await?;
|
|
||||||
label_parts.push(InlayHintLabelPart {
|
label_parts.push(InlayHintLabelPart {
|
||||||
value: part.value,
|
value: part.value,
|
||||||
tooltip: part.tooltip.map(|tooltip| match tooltip.content {
|
tooltip: part.tooltip.map(|tooltip| match tooltip.content {
|
||||||
|
@ -2087,19 +2009,35 @@ impl InlayHints {
|
||||||
}),
|
}),
|
||||||
None => InlayHintLabelPartTooltip::String(String::new()),
|
None => InlayHintLabelPartTooltip::String(String::new()),
|
||||||
}),
|
}),
|
||||||
location: match part.location {
|
location: {
|
||||||
Some(location) => Some(Location {
|
match part
|
||||||
range: location
|
.location_url
|
||||||
.start
|
.zip(
|
||||||
.and_then(language::proto::deserialize_anchor)
|
part.location_range_start.and_then(|start| {
|
||||||
.context("invalid start")?
|
Some(start..part.location_range_end?)
|
||||||
..location
|
}),
|
||||||
.end
|
)
|
||||||
.and_then(language::proto::deserialize_anchor)
|
.zip(part.language_server_id)
|
||||||
.context("invalid end")?,
|
{
|
||||||
buffer,
|
Some(((uri, range), server_id)) => Some((
|
||||||
}),
|
LanguageServerId(server_id as usize),
|
||||||
None => None,
|
lsp::Location {
|
||||||
|
uri: lsp::Url::parse(&uri)
|
||||||
|
.context("invalid uri in hint part {part:?}")?,
|
||||||
|
range: lsp::Range::new(
|
||||||
|
point_to_lsp(PointUtf16::new(
|
||||||
|
range.start.row,
|
||||||
|
range.start.column,
|
||||||
|
)),
|
||||||
|
point_to_lsp(PointUtf16::new(
|
||||||
|
range.end.row,
|
||||||
|
range.end.column,
|
||||||
|
)),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
)),
|
||||||
|
None => None,
|
||||||
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -2132,12 +2070,7 @@ impl InlayHints {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn project_to_lsp_hint(
|
pub fn project_to_lsp_hint(hint: InlayHint, snapshot: &BufferSnapshot) -> lsp::InlayHint {
|
||||||
hint: InlayHint,
|
|
||||||
project: &ModelHandle<Project>,
|
|
||||||
snapshot: &BufferSnapshot,
|
|
||||||
cx: &AsyncAppContext,
|
|
||||||
) -> lsp::InlayHint {
|
|
||||||
lsp::InlayHint {
|
lsp::InlayHint {
|
||||||
position: point_to_lsp(hint.position.to_point_utf16(snapshot)),
|
position: point_to_lsp(hint.position.to_point_utf16(snapshot)),
|
||||||
kind: hint.kind.map(|kind| match kind {
|
kind: hint.kind.map(|kind| match kind {
|
||||||
|
@ -2190,22 +2123,7 @@ impl InlayHints {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}),
|
}),
|
||||||
location: part.location.and_then(|location| {
|
location: part.location.map(|(_, location)| location),
|
||||||
let (path, location_snapshot) = cx.read(|cx| {
|
|
||||||
let buffer = location.buffer.read(cx);
|
|
||||||
let project_path = buffer.project_path(cx)?;
|
|
||||||
let location_snapshot = buffer.snapshot();
|
|
||||||
let path = project.read(cx).absolute_path(&project_path, cx);
|
|
||||||
path.zip(Some(location_snapshot))
|
|
||||||
})?;
|
|
||||||
Some(lsp::Location::new(
|
|
||||||
lsp::Url::from_file_path(path).unwrap(),
|
|
||||||
range_to_lsp(
|
|
||||||
location.range.start.to_point_utf16(&location_snapshot)
|
|
||||||
..location.range.end.to_point_utf16(&location_snapshot),
|
|
||||||
),
|
|
||||||
))
|
|
||||||
}),
|
|
||||||
command: None,
|
command: None,
|
||||||
})
|
})
|
||||||
.collect(),
|
.collect(),
|
||||||
|
@ -2299,12 +2217,10 @@ impl LspCommand for InlayHints {
|
||||||
ResolveState::Resolved
|
ResolveState::Resolved
|
||||||
};
|
};
|
||||||
|
|
||||||
let project = project.clone();
|
|
||||||
let buffer = buffer.clone();
|
let buffer = buffer.clone();
|
||||||
cx.spawn(|mut cx| async move {
|
cx.spawn(|mut cx| async move {
|
||||||
InlayHints::lsp_to_project_hint(
|
InlayHints::lsp_to_project_hint(
|
||||||
lsp_hint,
|
lsp_hint,
|
||||||
&project,
|
|
||||||
&buffer,
|
&buffer,
|
||||||
server_id,
|
server_id,
|
||||||
resolve_state,
|
resolve_state,
|
||||||
|
@ -2359,12 +2275,12 @@ impl LspCommand for InlayHints {
|
||||||
_: &mut Project,
|
_: &mut Project,
|
||||||
_: PeerId,
|
_: PeerId,
|
||||||
buffer_version: &clock::Global,
|
buffer_version: &clock::Global,
|
||||||
cx: &mut AppContext,
|
_: &mut AppContext,
|
||||||
) -> proto::InlayHintsResponse {
|
) -> proto::InlayHintsResponse {
|
||||||
proto::InlayHintsResponse {
|
proto::InlayHintsResponse {
|
||||||
hints: response
|
hints: response
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|response_hint| InlayHints::project_to_proto_hint(response_hint, cx))
|
.map(|response_hint| InlayHints::project_to_proto_hint(response_hint))
|
||||||
.collect(),
|
.collect(),
|
||||||
version: serialize_version(buffer_version),
|
version: serialize_version(buffer_version),
|
||||||
}
|
}
|
||||||
|
@ -2373,7 +2289,7 @@ impl LspCommand for InlayHints {
|
||||||
async fn response_from_proto(
|
async fn response_from_proto(
|
||||||
self,
|
self,
|
||||||
message: proto::InlayHintsResponse,
|
message: proto::InlayHintsResponse,
|
||||||
project: ModelHandle<Project>,
|
_: ModelHandle<Project>,
|
||||||
buffer: ModelHandle<Buffer>,
|
buffer: ModelHandle<Buffer>,
|
||||||
mut cx: AsyncAppContext,
|
mut cx: AsyncAppContext,
|
||||||
) -> anyhow::Result<Vec<InlayHint>> {
|
) -> anyhow::Result<Vec<InlayHint>> {
|
||||||
|
@ -2385,7 +2301,7 @@ impl LspCommand for InlayHints {
|
||||||
|
|
||||||
let mut hints = Vec::new();
|
let mut hints = Vec::new();
|
||||||
for message_hint in message.hints {
|
for message_hint in message.hints {
|
||||||
hints.push(InlayHints::proto_to_project_hint(message_hint, &project, &mut cx).await?);
|
hints.push(InlayHints::proto_to_project_hint(message_hint)?);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(hints)
|
Ok(hints)
|
||||||
|
|
|
@ -369,7 +369,7 @@ pub enum InlayHintLabel {
|
||||||
pub struct InlayHintLabelPart {
|
pub struct InlayHintLabelPart {
|
||||||
pub value: String,
|
pub value: String,
|
||||||
pub tooltip: Option<InlayHintLabelPartTooltip>,
|
pub tooltip: Option<InlayHintLabelPartTooltip>,
|
||||||
pub location: Option<Location>,
|
pub location: Option<(LanguageServerId, lsp::Location)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
|
@ -1708,7 +1708,7 @@ impl Project {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// LanguageServerName is owned, because it is inserted into a map
|
/// LanguageServerName is owned, because it is inserted into a map
|
||||||
fn open_local_buffer_via_lsp(
|
pub fn open_local_buffer_via_lsp(
|
||||||
&mut self,
|
&mut self,
|
||||||
abs_path: lsp::Url,
|
abs_path: lsp::Url,
|
||||||
language_server_id: LanguageServerId,
|
language_server_id: LanguageServerId,
|
||||||
|
@ -5069,16 +5069,15 @@ impl Project {
|
||||||
}
|
}
|
||||||
|
|
||||||
let buffer_snapshot = buffer.snapshot();
|
let buffer_snapshot = buffer.snapshot();
|
||||||
cx.spawn(|project, mut cx| async move {
|
cx.spawn(|_, mut cx| async move {
|
||||||
let resolve_task = lang_server.request::<lsp::request::InlayHintResolveRequest>(
|
let resolve_task = lang_server.request::<lsp::request::InlayHintResolveRequest>(
|
||||||
InlayHints::project_to_lsp_hint(hint, &project, &buffer_snapshot, &cx),
|
InlayHints::project_to_lsp_hint(hint, &buffer_snapshot),
|
||||||
);
|
);
|
||||||
let resolved_hint = resolve_task
|
let resolved_hint = resolve_task
|
||||||
.await
|
.await
|
||||||
.context("inlay hint resolve LSP request")?;
|
.context("inlay hint resolve LSP request")?;
|
||||||
let resolved_hint = InlayHints::lsp_to_project_hint(
|
let resolved_hint = InlayHints::lsp_to_project_hint(
|
||||||
resolved_hint,
|
resolved_hint,
|
||||||
&project,
|
|
||||||
&buffer_handle,
|
&buffer_handle,
|
||||||
server_id,
|
server_id,
|
||||||
ResolveState::Resolved,
|
ResolveState::Resolved,
|
||||||
|
@ -5094,19 +5093,16 @@ impl Project {
|
||||||
project_id,
|
project_id,
|
||||||
buffer_id: buffer_handle.read(cx).remote_id(),
|
buffer_id: buffer_handle.read(cx).remote_id(),
|
||||||
language_server_id: server_id.0 as u64,
|
language_server_id: server_id.0 as u64,
|
||||||
hint: Some(InlayHints::project_to_proto_hint(hint.clone(), cx)),
|
hint: Some(InlayHints::project_to_proto_hint(hint.clone())),
|
||||||
};
|
};
|
||||||
cx.spawn(|project, mut cx| async move {
|
cx.spawn(|_, _| async move {
|
||||||
let response = client
|
let response = client
|
||||||
.request(request)
|
.request(request)
|
||||||
.await
|
.await
|
||||||
.context("inlay hints proto request")?;
|
.context("inlay hints proto request")?;
|
||||||
match response.hint {
|
match response.hint {
|
||||||
Some(resolved_hint) => {
|
Some(resolved_hint) => InlayHints::proto_to_project_hint(resolved_hint)
|
||||||
InlayHints::proto_to_project_hint(resolved_hint, &project, &mut cx)
|
.context("inlay hints proto resolve response conversion"),
|
||||||
.await
|
|
||||||
.context("inlay hints proto resolve response conversion")
|
|
||||||
}
|
|
||||||
None => Ok(hint),
|
None => Ok(hint),
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -7091,8 +7087,7 @@ impl Project {
|
||||||
.payload
|
.payload
|
||||||
.hint
|
.hint
|
||||||
.expect("incorrect protobuf resolve inlay hint message: missing the inlay hint");
|
.expect("incorrect protobuf resolve inlay hint message: missing the inlay hint");
|
||||||
let hint = InlayHints::proto_to_project_hint(proto_hint, &this, &mut cx)
|
let hint = InlayHints::proto_to_project_hint(proto_hint)
|
||||||
.await
|
|
||||||
.context("resolved proto inlay hint conversion")?;
|
.context("resolved proto inlay hint conversion")?;
|
||||||
let buffer = this.update(&mut cx, |this, cx| {
|
let buffer = this.update(&mut cx, |this, cx| {
|
||||||
this.opened_buffers
|
this.opened_buffers
|
||||||
|
@ -7111,10 +7106,8 @@ impl Project {
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
.context("inlay hints fetch")?;
|
.context("inlay hints fetch")?;
|
||||||
let resolved_hint = cx.read(|cx| InlayHints::project_to_proto_hint(response_hint, cx));
|
|
||||||
|
|
||||||
Ok(proto::ResolveInlayHintResponse {
|
Ok(proto::ResolveInlayHintResponse {
|
||||||
hint: Some(resolved_hint),
|
hint: Some(InlayHints::project_to_proto_hint(response_hint)),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7882,7 +7875,7 @@ impl Project {
|
||||||
self.language_servers_for_buffer(buffer, cx).next()
|
self.language_servers_for_buffer(buffer, cx).next()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn language_server_for_buffer(
|
pub fn language_server_for_buffer(
|
||||||
&self,
|
&self,
|
||||||
buffer: &Buffer,
|
buffer: &Buffer,
|
||||||
server_id: LanguageServerId,
|
server_id: LanguageServerId,
|
||||||
|
|
|
@ -773,7 +773,10 @@ message InlayHintLabelParts {
|
||||||
message InlayHintLabelPart {
|
message InlayHintLabelPart {
|
||||||
string value = 1;
|
string value = 1;
|
||||||
InlayHintLabelPartTooltip tooltip = 2;
|
InlayHintLabelPartTooltip tooltip = 2;
|
||||||
Location location = 3;
|
optional string location_url = 3;
|
||||||
|
PointUtf16 location_range_start = 4;
|
||||||
|
PointUtf16 location_range_end = 5;
|
||||||
|
optional uint64 language_server_id = 6;
|
||||||
}
|
}
|
||||||
|
|
||||||
message InlayHintTooltip {
|
message InlayHintTooltip {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue