lsp-log: Reemit Editors search events.

NextMatch/PreviousMatch did not work due to us not updating the match index in the buffer search (that relied on an event being emitted).
This commit is contained in:
Piotr Osiewicz 2024-01-22 13:29:42 +01:00
parent 426ef75f4e
commit b5cb8323d4
2 changed files with 16 additions and 10 deletions

View file

@ -45,7 +45,7 @@ struct LanguageServerRpcState {
pub struct LspLogView { pub struct LspLogView {
pub(crate) editor: View<Editor>, pub(crate) editor: View<Editor>,
editor_subscription: Subscription, editor_subscriptions: Vec<Subscription>,
log_store: Model<LogStore>, log_store: Model<LogStore>,
current_server_id: Option<LanguageServerId>, current_server_id: Option<LanguageServerId>,
is_showing_rpc_trace: bool, is_showing_rpc_trace: bool,
@ -419,7 +419,7 @@ impl LspLogView {
} }
} }
}); });
let (editor, editor_subscription) = Self::editor_for_logs(String::new(), cx); let (editor, editor_subscriptions) = Self::editor_for_logs(String::new(), cx);
let focus_handle = cx.focus_handle(); let focus_handle = cx.focus_handle();
let focus_subscription = cx.on_focus(&focus_handle, |log_view, cx| { let focus_subscription = cx.on_focus(&focus_handle, |log_view, cx| {
@ -429,7 +429,7 @@ impl LspLogView {
let mut this = Self { let mut this = Self {
focus_handle, focus_handle,
editor, editor,
editor_subscription, editor_subscriptions,
project, project,
log_store, log_store,
current_server_id: None, current_server_id: None,
@ -449,7 +449,7 @@ impl LspLogView {
fn editor_for_logs( fn editor_for_logs(
log_contents: String, log_contents: String,
cx: &mut ViewContext<Self>, cx: &mut ViewContext<Self>,
) -> (View<Editor>, Subscription) { ) -> (View<Editor>, Vec<Subscription>) {
let editor = cx.new_view(|cx| { let editor = cx.new_view(|cx| {
let mut editor = Editor::multi_line(cx); let mut editor = Editor::multi_line(cx);
editor.set_text(log_contents, cx); editor.set_text(log_contents, cx);
@ -464,7 +464,13 @@ impl LspLogView {
cx.emit(event.clone()) cx.emit(event.clone())
}, },
); );
(editor, editor_subscription) let search_subscription = cx.subscribe(
&editor,
|_, _, event: &SearchEvent, cx: &mut ViewContext<'_, LspLogView>| {
cx.emit(event.clone())
},
);
(editor, vec![editor_subscription, search_subscription])
} }
pub(crate) fn menu_items<'a>(&'a self, cx: &'a AppContext) -> Option<Vec<LogMenuItem>> { pub(crate) fn menu_items<'a>(&'a self, cx: &'a AppContext) -> Option<Vec<LogMenuItem>> {
@ -521,9 +527,9 @@ impl LspLogView {
if let Some(log_contents) = log_contents { if let Some(log_contents) = log_contents {
self.current_server_id = Some(server_id); self.current_server_id = Some(server_id);
self.is_showing_rpc_trace = false; self.is_showing_rpc_trace = false;
let (editor, editor_subscription) = Self::editor_for_logs(log_contents, cx); let (editor, editor_subscriptions) = Self::editor_for_logs(log_contents, cx);
self.editor = editor; self.editor = editor;
self.editor_subscription = editor_subscription; self.editor_subscriptions = editor_subscriptions;
cx.notify(); cx.notify();
} }
cx.focus(&self.focus_handle); cx.focus(&self.focus_handle);
@ -542,7 +548,7 @@ impl LspLogView {
if let Some(rpc_log) = rpc_log { if let Some(rpc_log) = rpc_log {
self.current_server_id = Some(server_id); self.current_server_id = Some(server_id);
self.is_showing_rpc_trace = true; self.is_showing_rpc_trace = true;
let (editor, editor_subscription) = Self::editor_for_logs(rpc_log, cx); let (editor, editor_subscriptions) = Self::editor_for_logs(rpc_log, cx);
let language = self.project.read(cx).languages().language_for_name("JSON"); let language = self.project.read(cx).languages().language_for_name("JSON");
editor editor
.read(cx) .read(cx)
@ -564,7 +570,7 @@ impl LspLogView {
}); });
self.editor = editor; self.editor = editor;
self.editor_subscription = editor_subscription; self.editor_subscriptions = editor_subscriptions;
cx.notify(); cx.notify();
} }

View file

@ -11,7 +11,7 @@ use crate::{
ItemHandle, ItemHandle,
}; };
#[derive(Debug)] #[derive(Clone, Debug)]
pub enum SearchEvent { pub enum SearchEvent {
MatchesInvalidated, MatchesInvalidated,
ActiveMatchChanged, ActiveMatchChanged,