Test fixes

Keith Simmons created

Change summary

crates/editor/src/editor.rs | 75 +++++++++++++++++++++-----------------
crates/editor/src/test.rs   | 20 ---------
2 files changed, 43 insertions(+), 52 deletions(-)

Detailed changes

crates/editor/src/editor.rs 🔗

@@ -6156,6 +6156,7 @@ mod tests {
     };
 
     use super::*;
+    use futures::StreamExt;
     use gpui::{
         geometry::rect::RectF,
         platform::{WindowBounds, WindowOptions},
@@ -6165,7 +6166,6 @@ mod tests {
     use lsp::FakeLanguageServer;
     use project::{FakeFs, HoverBlock};
     use settings::LanguageOverride;
-    use smol::stream::StreamExt;
     use std::{cell::RefCell, rc::Rc, time::Instant};
     use text::Point;
     use unindent::Unindent;
@@ -9413,6 +9413,7 @@ mod tests {
         let hover_point = cx.display_point(indoc! {"
             fn test()
                 print|ln!();"});
+
         cx.update_editor(|editor, cx| {
             hover_at(
                 editor,
@@ -9428,21 +9429,23 @@ mod tests {
         let symbol_range = cx.lsp_range(indoc! {"
             fn test()
                 [println!]();"});
-        cx.handle_request::<lsp::request::HoverRequest, _>(move |_| {
-            Some(lsp::Hover {
-                contents: lsp::HoverContents::Markup(lsp::MarkupContent {
-                    kind: lsp::MarkupKind::Markdown,
-                    value: indoc! {"
+        let mut requests =
+            cx.lsp
+                .handle_request::<lsp::request::HoverRequest, _, _>(move |_, _| async move {
+                    Ok(Some(lsp::Hover {
+                        contents: lsp::HoverContents::Markup(lsp::MarkupContent {
+                            kind: lsp::MarkupKind::Markdown,
+                            value: indoc! {"
                         # Some basic docs
                         Some test documentation"}
-                    .to_string(),
-                }),
-                range: Some(symbol_range),
-            })
-        })
-        .await;
+                            .to_string(),
+                        }),
+                        range: Some(symbol_range),
+                    }))
+                });
         cx.foreground()
             .advance_clock(Duration::from_millis(HOVER_DELAY_MILLIS + 100));
+        requests.next().await;
 
         cx.editor(|editor, _| {
             assert!(editor.hover_state.visible());
@@ -9474,7 +9477,9 @@ mod tests {
                 cx,
             )
         });
-        cx.handle_request::<lsp::request::HoverRequest, _>(move |_| None)
+        cx.lsp
+            .handle_request::<lsp::request::HoverRequest, _, _>(|_, _| async move { Ok(None) })
+            .next()
             .await;
         cx.foreground().run_until_parked();
         cx.editor(|editor, _| {
@@ -9491,19 +9496,21 @@ mod tests {
         let symbol_range = cx.lsp_range(indoc! {"
             [fn] test()
                 println!();"});
-        cx.handle_request::<lsp::request::HoverRequest, _>(move |_| {
-            Some(lsp::Hover {
-                contents: lsp::HoverContents::Markup(lsp::MarkupContent {
-                    kind: lsp::MarkupKind::Markdown,
-                    value: indoc! {"
+        cx.lsp
+            .handle_request::<lsp::request::HoverRequest, _, _>(move |_, _| async move {
+                Ok(Some(lsp::Hover {
+                    contents: lsp::HoverContents::Markup(lsp::MarkupContent {
+                        kind: lsp::MarkupKind::Markdown,
+                        value: indoc! {"
                         # Some other basic docs
                         Some other test documentation"}
-                    .to_string(),
-                }),
-                range: Some(symbol_range),
+                        .to_string(),
+                    }),
+                    range: Some(symbol_range),
+                }))
             })
-        })
-        .await;
+            .next()
+            .await;
         cx.foreground().run_until_parked();
         cx.editor(|editor, _| {
             assert!(editor.hover_state.visible());
@@ -9539,19 +9546,21 @@ mod tests {
         let symbol_range = cx.lsp_range(indoc! {"
             fn test()
                 [println!]();"});
-        cx.handle_request::<lsp::request::HoverRequest, _>(move |_| {
-            Some(lsp::Hover {
-                contents: lsp::HoverContents::Markup(lsp::MarkupContent {
-                    kind: lsp::MarkupKind::Markdown,
-                    value: indoc! {"
+        cx.lsp
+            .handle_request::<lsp::request::HoverRequest, _, _>(move |_, _| async move {
+                Ok(Some(lsp::Hover {
+                    contents: lsp::HoverContents::Markup(lsp::MarkupContent {
+                        kind: lsp::MarkupKind::Markdown,
+                        value: indoc! {"
                         # Some third basic docs
                         Some third test documentation"}
-                    .to_string(),
-                }),
-                range: Some(symbol_range),
+                        .to_string(),
+                    }),
+                    range: Some(symbol_range),
+                }))
             })
-        })
-        .await;
+            .next()
+            .await;
         cx.foreground().run_until_parked();
         // No delay as the popover is already visible
 

crates/editor/src/test.rs 🔗

@@ -9,7 +9,6 @@ use indoc::indoc;
 use collections::BTreeMap;
 use gpui::{keymap::Keystroke, AppContext, ModelHandle, ViewContext, ViewHandle};
 use language::{point_to_lsp, FakeLspAdapter, Language, LanguageConfig, Selection};
-use lsp::request;
 use project::{FakeFs, Project};
 use settings::Settings;
 use util::{
@@ -390,7 +389,7 @@ impl<'a> DerefMut for EditorTestContext<'a> {
 
 pub struct EditorLspTestContext<'a> {
     pub cx: EditorTestContext<'a>,
-    lsp: lsp::FakeLanguageServer,
+    pub lsp: lsp::FakeLanguageServer,
 }
 
 impl<'a> EditorLspTestContext<'a> {
@@ -449,7 +448,6 @@ impl<'a> EditorLspTestContext<'a> {
         }
     }
 
-    #[cfg(feature = "test-support")]
     pub async fn new_rust(
         capabilities: lsp::ServerCapabilities,
         cx: &'a mut gpui::TestAppContext,
@@ -466,22 +464,6 @@ impl<'a> EditorLspTestContext<'a> {
         Self::new(language, capabilities, cx).await
     }
 
-    pub async fn handle_request<T, F>(&mut self, mut construct_result: F)
-    where
-        T: 'static + request::Request,
-        T::Params: 'static + Send,
-        T::Result: 'static + Send + Clone,
-        F: 'static + Send + FnMut(T::Params) -> T::Result,
-    {
-        self.lsp
-            .handle_request::<T, _, _>(move |params, _| {
-                let result = construct_result(params);
-                async move { Ok(result.clone()) }
-            })
-            .next()
-            .await;
-    }
-
     // Constructs lsp range using a marked string with '[', ']' range delimiters
     pub fn lsp_range(&mut self, marked_text: &str) -> lsp::Range {
         let (unmarked, mut ranges) = marked_text_ranges_by(marked_text, vec![('[', ']').into()]);