Use InlayHint instead of Inlay where appropriate
This commit is contained in:
parent
1938fd85e8
commit
f9131f657e
6 changed files with 50 additions and 45 deletions
|
@ -7867,7 +7867,7 @@ async fn test_mutual_editor_inlay_hint_cache_update(
|
||||||
.insert_tree(
|
.insert_tree(
|
||||||
"/a",
|
"/a",
|
||||||
json!({
|
json!({
|
||||||
"main.rs": "fn main() { a } // and some long comment to ensure inlays are not trimmed out",
|
"main.rs": "fn main() { a } // and some long comment to ensure inlay hints are not trimmed out",
|
||||||
"other.rs": "// Test file",
|
"other.rs": "// Test file",
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
@ -8177,7 +8177,7 @@ async fn test_inlay_hint_refresh_is_forwarded(
|
||||||
.insert_tree(
|
.insert_tree(
|
||||||
"/a",
|
"/a",
|
||||||
json!({
|
json!({
|
||||||
"main.rs": "fn main() { a } // and some long comment to ensure inlays are not trimmed out",
|
"main.rs": "fn main() { a } // and some long comment to ensure inlay hints are not trimmed out",
|
||||||
"other.rs": "// Test file",
|
"other.rs": "// Test file",
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|
|
@ -302,7 +302,7 @@ actions!(
|
||||||
Hover,
|
Hover,
|
||||||
Format,
|
Format,
|
||||||
ToggleSoftWrap,
|
ToggleSoftWrap,
|
||||||
ToggleInlays,
|
ToggleInlayHints,
|
||||||
RevealInFinder,
|
RevealInFinder,
|
||||||
CopyPath,
|
CopyPath,
|
||||||
CopyRelativePath,
|
CopyRelativePath,
|
||||||
|
@ -447,7 +447,7 @@ pub fn init(cx: &mut AppContext) {
|
||||||
cx.add_action(Editor::toggle_code_actions);
|
cx.add_action(Editor::toggle_code_actions);
|
||||||
cx.add_action(Editor::open_excerpts);
|
cx.add_action(Editor::open_excerpts);
|
||||||
cx.add_action(Editor::toggle_soft_wrap);
|
cx.add_action(Editor::toggle_soft_wrap);
|
||||||
cx.add_action(Editor::toggle_inlays);
|
cx.add_action(Editor::toggle_inlay_hints);
|
||||||
cx.add_action(Editor::reveal_in_finder);
|
cx.add_action(Editor::reveal_in_finder);
|
||||||
cx.add_action(Editor::copy_path);
|
cx.add_action(Editor::copy_path);
|
||||||
cx.add_action(Editor::copy_relative_path);
|
cx.add_action(Editor::copy_relative_path);
|
||||||
|
@ -1239,7 +1239,7 @@ enum GotoDefinitionKind {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
enum InlayRefreshReason {
|
enum InlayHintRefreshReason {
|
||||||
Toggle(bool),
|
Toggle(bool),
|
||||||
SettingsChange(InlayHintSettings),
|
SettingsChange(InlayHintSettings),
|
||||||
NewLinesShown,
|
NewLinesShown,
|
||||||
|
@ -1357,8 +1357,8 @@ impl Editor {
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
project_subscriptions.push(cx.subscribe(project, |editor, _, event, cx| {
|
project_subscriptions.push(cx.subscribe(project, |editor, _, event, cx| {
|
||||||
if let project::Event::RefreshInlays = event {
|
if let project::Event::RefreshInlayHints = event {
|
||||||
editor.refresh_inlays(InlayRefreshReason::RefreshRequested, cx);
|
editor.refresh_inlay_hints(InlayHintRefreshReason::RefreshRequested, cx);
|
||||||
};
|
};
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
@ -2672,24 +2672,24 @@ impl Editor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn toggle_inlays(&mut self, _: &ToggleInlays, cx: &mut ViewContext<Self>) {
|
pub fn toggle_inlay_hints(&mut self, _: &ToggleInlayHints, cx: &mut ViewContext<Self>) {
|
||||||
self.refresh_inlays(
|
self.refresh_inlay_hints(
|
||||||
InlayRefreshReason::Toggle(!self.inlay_hint_cache.enabled),
|
InlayHintRefreshReason::Toggle(!self.inlay_hint_cache.enabled),
|
||||||
cx,
|
cx,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn inlays_enabled(&self) -> bool {
|
pub fn inlay_hints_enabled(&self) -> bool {
|
||||||
self.inlay_hint_cache.enabled
|
self.inlay_hint_cache.enabled
|
||||||
}
|
}
|
||||||
|
|
||||||
fn refresh_inlays(&mut self, reason: InlayRefreshReason, cx: &mut ViewContext<Self>) {
|
fn refresh_inlay_hints(&mut self, reason: InlayHintRefreshReason, cx: &mut ViewContext<Self>) {
|
||||||
if self.project.is_none() || self.mode != EditorMode::Full {
|
if self.project.is_none() || self.mode != EditorMode::Full {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let (invalidate_cache, required_languages) = match reason {
|
let (invalidate_cache, required_languages) = match reason {
|
||||||
InlayRefreshReason::Toggle(enabled) => {
|
InlayHintRefreshReason::Toggle(enabled) => {
|
||||||
self.inlay_hint_cache.enabled = enabled;
|
self.inlay_hint_cache.enabled = enabled;
|
||||||
if enabled {
|
if enabled {
|
||||||
(InvalidationStrategy::RefreshRequested, None)
|
(InvalidationStrategy::RefreshRequested, None)
|
||||||
|
@ -2706,7 +2706,7 @@ impl Editor {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
InlayRefreshReason::SettingsChange(new_settings) => {
|
InlayHintRefreshReason::SettingsChange(new_settings) => {
|
||||||
match self.inlay_hint_cache.update_settings(
|
match self.inlay_hint_cache.update_settings(
|
||||||
&self.buffer,
|
&self.buffer,
|
||||||
new_settings,
|
new_settings,
|
||||||
|
@ -2724,11 +2724,13 @@ impl Editor {
|
||||||
ControlFlow::Continue(()) => (InvalidationStrategy::RefreshRequested, None),
|
ControlFlow::Continue(()) => (InvalidationStrategy::RefreshRequested, None),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
InlayRefreshReason::NewLinesShown => (InvalidationStrategy::None, None),
|
InlayHintRefreshReason::NewLinesShown => (InvalidationStrategy::None, None),
|
||||||
InlayRefreshReason::BufferEdited(buffer_languages) => {
|
InlayHintRefreshReason::BufferEdited(buffer_languages) => {
|
||||||
(InvalidationStrategy::BufferEdited, Some(buffer_languages))
|
(InvalidationStrategy::BufferEdited, Some(buffer_languages))
|
||||||
}
|
}
|
||||||
InlayRefreshReason::RefreshRequested => (InvalidationStrategy::RefreshRequested, None),
|
InlayHintRefreshReason::RefreshRequested => {
|
||||||
|
(InvalidationStrategy::RefreshRequested, None)
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(InlaySplice {
|
if let Some(InlaySplice {
|
||||||
|
@ -7728,8 +7730,8 @@ impl Editor {
|
||||||
.cloned()
|
.cloned()
|
||||||
.collect::<HashSet<_>>();
|
.collect::<HashSet<_>>();
|
||||||
if !languages_affected.is_empty() {
|
if !languages_affected.is_empty() {
|
||||||
self.refresh_inlays(
|
self.refresh_inlay_hints(
|
||||||
InlayRefreshReason::BufferEdited(languages_affected),
|
InlayHintRefreshReason::BufferEdited(languages_affected),
|
||||||
cx,
|
cx,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -7767,8 +7769,8 @@ impl Editor {
|
||||||
|
|
||||||
fn settings_changed(&mut self, cx: &mut ViewContext<Self>) {
|
fn settings_changed(&mut self, cx: &mut ViewContext<Self>) {
|
||||||
self.refresh_copilot_suggestions(true, cx);
|
self.refresh_copilot_suggestions(true, cx);
|
||||||
self.refresh_inlays(
|
self.refresh_inlay_hints(
|
||||||
InlayRefreshReason::SettingsChange(inlay_hint_settings(
|
InlayHintRefreshReason::SettingsChange(inlay_hint_settings(
|
||||||
self.selections.newest_anchor().head(),
|
self.selections.newest_anchor().head(),
|
||||||
&self.buffer.read(cx).snapshot(cx),
|
&self.buffer.read(cx).snapshot(cx),
|
||||||
cx,
|
cx,
|
||||||
|
|
|
@ -2684,7 +2684,7 @@ all hints should be invalidated and requeried for all of its visible excerpts"
|
||||||
}
|
}
|
||||||
|
|
||||||
#[gpui::test]
|
#[gpui::test]
|
||||||
async fn test_toggle_inlays(cx: &mut gpui::TestAppContext) {
|
async fn test_toggle_inlay_hints(cx: &mut gpui::TestAppContext) {
|
||||||
init_test(cx, |settings| {
|
init_test(cx, |settings| {
|
||||||
settings.defaults.inlay_hints = Some(InlayHintSettings {
|
settings.defaults.inlay_hints = Some(InlayHintSettings {
|
||||||
enabled: false,
|
enabled: false,
|
||||||
|
@ -2697,7 +2697,7 @@ all hints should be invalidated and requeried for all of its visible excerpts"
|
||||||
let (file_with_hints, editor, fake_server) = prepare_test_objects(cx).await;
|
let (file_with_hints, editor, fake_server) = prepare_test_objects(cx).await;
|
||||||
|
|
||||||
editor.update(cx, |editor, cx| {
|
editor.update(cx, |editor, cx| {
|
||||||
editor.toggle_inlays(&crate::ToggleInlays, cx)
|
editor.toggle_inlay_hints(&crate::ToggleInlayHints, cx)
|
||||||
});
|
});
|
||||||
cx.foreground().start_waiting();
|
cx.foreground().start_waiting();
|
||||||
let lsp_request_count = Arc::new(AtomicU32::new(0));
|
let lsp_request_count = Arc::new(AtomicU32::new(0));
|
||||||
|
@ -2743,7 +2743,7 @@ all hints should be invalidated and requeried for all of its visible excerpts"
|
||||||
});
|
});
|
||||||
|
|
||||||
editor.update(cx, |editor, cx| {
|
editor.update(cx, |editor, cx| {
|
||||||
editor.toggle_inlays(&crate::ToggleInlays, cx)
|
editor.toggle_inlay_hints(&crate::ToggleInlayHints, cx)
|
||||||
});
|
});
|
||||||
cx.foreground().run_until_parked();
|
cx.foreground().run_until_parked();
|
||||||
editor.update(cx, |editor, cx| {
|
editor.update(cx, |editor, cx| {
|
||||||
|
@ -2776,7 +2776,7 @@ all hints should be invalidated and requeried for all of its visible excerpts"
|
||||||
});
|
});
|
||||||
|
|
||||||
editor.update(cx, |editor, cx| {
|
editor.update(cx, |editor, cx| {
|
||||||
editor.toggle_inlays(&crate::ToggleInlays, cx)
|
editor.toggle_inlay_hints(&crate::ToggleInlayHints, cx)
|
||||||
});
|
});
|
||||||
cx.foreground().run_until_parked();
|
cx.foreground().run_until_parked();
|
||||||
editor.update(cx, |editor, cx| {
|
editor.update(cx, |editor, cx| {
|
||||||
|
@ -2789,7 +2789,7 @@ all hints should be invalidated and requeried for all of its visible excerpts"
|
||||||
});
|
});
|
||||||
|
|
||||||
editor.update(cx, |editor, cx| {
|
editor.update(cx, |editor, cx| {
|
||||||
editor.toggle_inlays(&crate::ToggleInlays, cx)
|
editor.toggle_inlay_hints(&crate::ToggleInlayHints, cx)
|
||||||
});
|
});
|
||||||
cx.foreground().run_until_parked();
|
cx.foreground().run_until_parked();
|
||||||
editor.update(cx, |editor, cx| {
|
editor.update(cx, |editor, cx| {
|
||||||
|
|
|
@ -19,7 +19,7 @@ use crate::{
|
||||||
display_map::{DisplaySnapshot, ToDisplayPoint},
|
display_map::{DisplaySnapshot, ToDisplayPoint},
|
||||||
hover_popover::hide_hover,
|
hover_popover::hide_hover,
|
||||||
persistence::DB,
|
persistence::DB,
|
||||||
Anchor, DisplayPoint, Editor, EditorMode, Event, InlayRefreshReason, MultiBufferSnapshot,
|
Anchor, DisplayPoint, Editor, EditorMode, Event, InlayHintRefreshReason, MultiBufferSnapshot,
|
||||||
ToPoint,
|
ToPoint,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -301,7 +301,7 @@ impl Editor {
|
||||||
cx.spawn(|editor, mut cx| async move {
|
cx.spawn(|editor, mut cx| async move {
|
||||||
editor
|
editor
|
||||||
.update(&mut cx, |editor, cx| {
|
.update(&mut cx, |editor, cx| {
|
||||||
editor.refresh_inlays(InlayRefreshReason::NewLinesShown, cx)
|
editor.refresh_inlay_hints(InlayHintRefreshReason::NewLinesShown, cx)
|
||||||
})
|
})
|
||||||
.ok()
|
.ok()
|
||||||
})
|
})
|
||||||
|
@ -333,7 +333,7 @@ impl Editor {
|
||||||
cx,
|
cx,
|
||||||
);
|
);
|
||||||
|
|
||||||
self.refresh_inlays(InlayRefreshReason::NewLinesShown, cx);
|
self.refresh_inlay_hints(InlayHintRefreshReason::NewLinesShown, cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn scroll_position(&self, cx: &mut ViewContext<Self>) -> Vector2F {
|
pub fn scroll_position(&self, cx: &mut ViewContext<Self>) -> Vector2F {
|
||||||
|
|
|
@ -282,7 +282,7 @@ pub enum Event {
|
||||||
new_peer_id: proto::PeerId,
|
new_peer_id: proto::PeerId,
|
||||||
},
|
},
|
||||||
CollaboratorLeft(proto::PeerId),
|
CollaboratorLeft(proto::PeerId),
|
||||||
RefreshInlays,
|
RefreshInlayHints,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum LanguageServerState {
|
pub enum LanguageServerState {
|
||||||
|
@ -2872,7 +2872,7 @@ impl Project {
|
||||||
.upgrade(&cx)
|
.upgrade(&cx)
|
||||||
.ok_or_else(|| anyhow!("project dropped"))?;
|
.ok_or_else(|| anyhow!("project dropped"))?;
|
||||||
this.update(&mut cx, |project, cx| {
|
this.update(&mut cx, |project, cx| {
|
||||||
cx.emit(Event::RefreshInlays);
|
cx.emit(Event::RefreshInlayHints);
|
||||||
project.remote_id().map(|project_id| {
|
project.remote_id().map(|project_id| {
|
||||||
project.client.send(proto::RefreshInlayHints { project_id })
|
project.client.send(proto::RefreshInlayHints { project_id })
|
||||||
})
|
})
|
||||||
|
@ -3436,7 +3436,7 @@ impl Project {
|
||||||
cx: &mut ModelContext<Self>,
|
cx: &mut ModelContext<Self>,
|
||||||
) {
|
) {
|
||||||
if let Some(status) = self.language_server_statuses.get_mut(&language_server_id) {
|
if let Some(status) = self.language_server_statuses.get_mut(&language_server_id) {
|
||||||
cx.emit(Event::RefreshInlays);
|
cx.emit(Event::RefreshInlayHints);
|
||||||
status.pending_work.remove(&token);
|
status.pending_work.remove(&token);
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
|
@ -6810,7 +6810,7 @@ impl Project {
|
||||||
mut cx: AsyncAppContext,
|
mut cx: AsyncAppContext,
|
||||||
) -> Result<proto::Ack> {
|
) -> Result<proto::Ack> {
|
||||||
this.update(&mut cx, |_, cx| {
|
this.update(&mut cx, |_, cx| {
|
||||||
cx.emit(Event::RefreshInlays);
|
cx.emit(Event::RefreshInlayHints);
|
||||||
});
|
});
|
||||||
Ok(proto::Ack {})
|
Ok(proto::Ack {})
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ use workspace::{item::ItemHandle, ToolbarItemLocation, ToolbarItemView};
|
||||||
pub struct QuickActionBar {
|
pub struct QuickActionBar {
|
||||||
buffer_search_bar: ViewHandle<BufferSearchBar>,
|
buffer_search_bar: ViewHandle<BufferSearchBar>,
|
||||||
active_item: Option<Box<dyn ItemHandle>>,
|
active_item: Option<Box<dyn ItemHandle>>,
|
||||||
_inlays_enabled_subscription: Option<Subscription>,
|
_inlay_hints_enabled_subscription: Option<Subscription>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl QuickActionBar {
|
impl QuickActionBar {
|
||||||
|
@ -19,7 +19,7 @@ impl QuickActionBar {
|
||||||
Self {
|
Self {
|
||||||
buffer_search_bar,
|
buffer_search_bar,
|
||||||
active_item: None,
|
active_item: None,
|
||||||
_inlays_enabled_subscription: None,
|
_inlay_hints_enabled_subscription: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,17 +42,20 @@ impl View for QuickActionBar {
|
||||||
fn render(&mut self, cx: &mut gpui::ViewContext<'_, '_, Self>) -> gpui::AnyElement<Self> {
|
fn render(&mut self, cx: &mut gpui::ViewContext<'_, '_, Self>) -> gpui::AnyElement<Self> {
|
||||||
let Some(editor) = self.active_editor() else { return Empty::new().into_any(); };
|
let Some(editor) = self.active_editor() else { return Empty::new().into_any(); };
|
||||||
|
|
||||||
let inlays_enabled = editor.read(cx).inlays_enabled();
|
let inlay_hints_enabled = editor.read(cx).inlay_hints_enabled();
|
||||||
let mut bar = Flex::row().with_child(render_quick_action_bar_button(
|
let mut bar = Flex::row().with_child(render_quick_action_bar_button(
|
||||||
0,
|
0,
|
||||||
"icons/hamburger_15.svg",
|
"icons/hamburger_15.svg",
|
||||||
inlays_enabled,
|
inlay_hints_enabled,
|
||||||
("Inlays".to_string(), Some(Box::new(editor::ToggleInlays))),
|
(
|
||||||
|
"Inlay hints".to_string(),
|
||||||
|
Some(Box::new(editor::ToggleInlayHints)),
|
||||||
|
),
|
||||||
cx,
|
cx,
|
||||||
|this, cx| {
|
|this, cx| {
|
||||||
if let Some(editor) = this.active_editor() {
|
if let Some(editor) = this.active_editor() {
|
||||||
editor.update(cx, |editor, cx| {
|
editor.update(cx, |editor, cx| {
|
||||||
editor.toggle_inlays(&editor::ToggleInlays, cx);
|
editor.toggle_inlay_hints(&editor::ToggleInlayHints, cx);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -135,15 +138,15 @@ impl ToolbarItemView for QuickActionBar {
|
||||||
match active_pane_item {
|
match active_pane_item {
|
||||||
Some(active_item) => {
|
Some(active_item) => {
|
||||||
self.active_item = Some(active_item.boxed_clone());
|
self.active_item = Some(active_item.boxed_clone());
|
||||||
self._inlays_enabled_subscription.take();
|
self._inlay_hints_enabled_subscription.take();
|
||||||
|
|
||||||
if let Some(editor) = active_item.downcast::<Editor>() {
|
if let Some(editor) = active_item.downcast::<Editor>() {
|
||||||
let mut inlays_enabled = editor.read(cx).inlays_enabled();
|
let mut inlay_hints_enabled = editor.read(cx).inlay_hints_enabled();
|
||||||
self._inlays_enabled_subscription =
|
self._inlay_hints_enabled_subscription =
|
||||||
Some(cx.observe(&editor, move |_, editor, cx| {
|
Some(cx.observe(&editor, move |_, editor, cx| {
|
||||||
let new_inlays_enabled = editor.read(cx).inlays_enabled();
|
let new_inlay_hints_enabled = editor.read(cx).inlay_hints_enabled();
|
||||||
if inlays_enabled != new_inlays_enabled {
|
if inlay_hints_enabled != new_inlay_hints_enabled {
|
||||||
inlays_enabled = new_inlays_enabled;
|
inlay_hints_enabled = new_inlay_hints_enabled;
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue