Test fixes
This commit is contained in:
parent
93158bfcff
commit
8378590d57
2 changed files with 43 additions and 52 deletions
|
@ -6156,6 +6156,7 @@ mod tests {
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use futures::StreamExt;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
geometry::rect::RectF,
|
geometry::rect::RectF,
|
||||||
platform::{WindowBounds, WindowOptions},
|
platform::{WindowBounds, WindowOptions},
|
||||||
|
@ -6165,7 +6166,6 @@ mod tests {
|
||||||
use lsp::FakeLanguageServer;
|
use lsp::FakeLanguageServer;
|
||||||
use project::{FakeFs, HoverBlock};
|
use project::{FakeFs, HoverBlock};
|
||||||
use settings::LanguageOverride;
|
use settings::LanguageOverride;
|
||||||
use smol::stream::StreamExt;
|
|
||||||
use std::{cell::RefCell, rc::Rc, time::Instant};
|
use std::{cell::RefCell, rc::Rc, time::Instant};
|
||||||
use text::Point;
|
use text::Point;
|
||||||
use unindent::Unindent;
|
use unindent::Unindent;
|
||||||
|
@ -9413,6 +9413,7 @@ mod tests {
|
||||||
let hover_point = cx.display_point(indoc! {"
|
let hover_point = cx.display_point(indoc! {"
|
||||||
fn test()
|
fn test()
|
||||||
print|ln!();"});
|
print|ln!();"});
|
||||||
|
|
||||||
cx.update_editor(|editor, cx| {
|
cx.update_editor(|editor, cx| {
|
||||||
hover_at(
|
hover_at(
|
||||||
editor,
|
editor,
|
||||||
|
@ -9428,21 +9429,23 @@ mod tests {
|
||||||
let symbol_range = cx.lsp_range(indoc! {"
|
let symbol_range = cx.lsp_range(indoc! {"
|
||||||
fn test()
|
fn test()
|
||||||
[println!]();"});
|
[println!]();"});
|
||||||
cx.handle_request::<lsp::request::HoverRequest, _>(move |_| {
|
let mut requests =
|
||||||
Some(lsp::Hover {
|
cx.lsp
|
||||||
contents: lsp::HoverContents::Markup(lsp::MarkupContent {
|
.handle_request::<lsp::request::HoverRequest, _, _>(move |_, _| async move {
|
||||||
kind: lsp::MarkupKind::Markdown,
|
Ok(Some(lsp::Hover {
|
||||||
value: indoc! {"
|
contents: lsp::HoverContents::Markup(lsp::MarkupContent {
|
||||||
|
kind: lsp::MarkupKind::Markdown,
|
||||||
|
value: indoc! {"
|
||||||
# Some basic docs
|
# Some basic docs
|
||||||
Some test documentation"}
|
Some test documentation"}
|
||||||
.to_string(),
|
.to_string(),
|
||||||
}),
|
}),
|
||||||
range: Some(symbol_range),
|
range: Some(symbol_range),
|
||||||
})
|
}))
|
||||||
})
|
});
|
||||||
.await;
|
|
||||||
cx.foreground()
|
cx.foreground()
|
||||||
.advance_clock(Duration::from_millis(HOVER_DELAY_MILLIS + 100));
|
.advance_clock(Duration::from_millis(HOVER_DELAY_MILLIS + 100));
|
||||||
|
requests.next().await;
|
||||||
|
|
||||||
cx.editor(|editor, _| {
|
cx.editor(|editor, _| {
|
||||||
assert!(editor.hover_state.visible());
|
assert!(editor.hover_state.visible());
|
||||||
|
@ -9474,7 +9477,9 @@ mod tests {
|
||||||
cx,
|
cx,
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
cx.handle_request::<lsp::request::HoverRequest, _>(move |_| None)
|
cx.lsp
|
||||||
|
.handle_request::<lsp::request::HoverRequest, _, _>(|_, _| async move { Ok(None) })
|
||||||
|
.next()
|
||||||
.await;
|
.await;
|
||||||
cx.foreground().run_until_parked();
|
cx.foreground().run_until_parked();
|
||||||
cx.editor(|editor, _| {
|
cx.editor(|editor, _| {
|
||||||
|
@ -9491,19 +9496,21 @@ mod tests {
|
||||||
let symbol_range = cx.lsp_range(indoc! {"
|
let symbol_range = cx.lsp_range(indoc! {"
|
||||||
[fn] test()
|
[fn] test()
|
||||||
println!();"});
|
println!();"});
|
||||||
cx.handle_request::<lsp::request::HoverRequest, _>(move |_| {
|
cx.lsp
|
||||||
Some(lsp::Hover {
|
.handle_request::<lsp::request::HoverRequest, _, _>(move |_, _| async move {
|
||||||
contents: lsp::HoverContents::Markup(lsp::MarkupContent {
|
Ok(Some(lsp::Hover {
|
||||||
kind: lsp::MarkupKind::Markdown,
|
contents: lsp::HoverContents::Markup(lsp::MarkupContent {
|
||||||
value: indoc! {"
|
kind: lsp::MarkupKind::Markdown,
|
||||||
|
value: indoc! {"
|
||||||
# Some other basic docs
|
# Some other basic docs
|
||||||
Some other test documentation"}
|
Some other test documentation"}
|
||||||
.to_string(),
|
.to_string(),
|
||||||
}),
|
}),
|
||||||
range: Some(symbol_range),
|
range: Some(symbol_range),
|
||||||
|
}))
|
||||||
})
|
})
|
||||||
})
|
.next()
|
||||||
.await;
|
.await;
|
||||||
cx.foreground().run_until_parked();
|
cx.foreground().run_until_parked();
|
||||||
cx.editor(|editor, _| {
|
cx.editor(|editor, _| {
|
||||||
assert!(editor.hover_state.visible());
|
assert!(editor.hover_state.visible());
|
||||||
|
@ -9539,19 +9546,21 @@ mod tests {
|
||||||
let symbol_range = cx.lsp_range(indoc! {"
|
let symbol_range = cx.lsp_range(indoc! {"
|
||||||
fn test()
|
fn test()
|
||||||
[println!]();"});
|
[println!]();"});
|
||||||
cx.handle_request::<lsp::request::HoverRequest, _>(move |_| {
|
cx.lsp
|
||||||
Some(lsp::Hover {
|
.handle_request::<lsp::request::HoverRequest, _, _>(move |_, _| async move {
|
||||||
contents: lsp::HoverContents::Markup(lsp::MarkupContent {
|
Ok(Some(lsp::Hover {
|
||||||
kind: lsp::MarkupKind::Markdown,
|
contents: lsp::HoverContents::Markup(lsp::MarkupContent {
|
||||||
value: indoc! {"
|
kind: lsp::MarkupKind::Markdown,
|
||||||
|
value: indoc! {"
|
||||||
# Some third basic docs
|
# Some third basic docs
|
||||||
Some third test documentation"}
|
Some third test documentation"}
|
||||||
.to_string(),
|
.to_string(),
|
||||||
}),
|
}),
|
||||||
range: Some(symbol_range),
|
range: Some(symbol_range),
|
||||||
|
}))
|
||||||
})
|
})
|
||||||
})
|
.next()
|
||||||
.await;
|
.await;
|
||||||
cx.foreground().run_until_parked();
|
cx.foreground().run_until_parked();
|
||||||
// No delay as the popover is already visible
|
// No delay as the popover is already visible
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,6 @@ use indoc::indoc;
|
||||||
use collections::BTreeMap;
|
use collections::BTreeMap;
|
||||||
use gpui::{keymap::Keystroke, AppContext, ModelHandle, ViewContext, ViewHandle};
|
use gpui::{keymap::Keystroke, AppContext, ModelHandle, ViewContext, ViewHandle};
|
||||||
use language::{point_to_lsp, FakeLspAdapter, Language, LanguageConfig, Selection};
|
use language::{point_to_lsp, FakeLspAdapter, Language, LanguageConfig, Selection};
|
||||||
use lsp::request;
|
|
||||||
use project::{FakeFs, Project};
|
use project::{FakeFs, Project};
|
||||||
use settings::Settings;
|
use settings::Settings;
|
||||||
use util::{
|
use util::{
|
||||||
|
@ -390,7 +389,7 @@ impl<'a> DerefMut for EditorTestContext<'a> {
|
||||||
|
|
||||||
pub struct EditorLspTestContext<'a> {
|
pub struct EditorLspTestContext<'a> {
|
||||||
pub cx: EditorTestContext<'a>,
|
pub cx: EditorTestContext<'a>,
|
||||||
lsp: lsp::FakeLanguageServer,
|
pub lsp: lsp::FakeLanguageServer,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> EditorLspTestContext<'a> {
|
impl<'a> EditorLspTestContext<'a> {
|
||||||
|
@ -449,7 +448,6 @@ impl<'a> EditorLspTestContext<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "test-support")]
|
|
||||||
pub async fn new_rust(
|
pub async fn new_rust(
|
||||||
capabilities: lsp::ServerCapabilities,
|
capabilities: lsp::ServerCapabilities,
|
||||||
cx: &'a mut gpui::TestAppContext,
|
cx: &'a mut gpui::TestAppContext,
|
||||||
|
@ -466,22 +464,6 @@ impl<'a> EditorLspTestContext<'a> {
|
||||||
Self::new(language, capabilities, cx).await
|
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
|
// Constructs lsp range using a marked string with '[', ']' range delimiters
|
||||||
pub fn lsp_range(&mut self, marked_text: &str) -> lsp::Range {
|
pub fn lsp_range(&mut self, marked_text: &str) -> lsp::Range {
|
||||||
let (unmarked, mut ranges) = marked_text_ranges_by(marked_text, vec![('[', ']').into()]);
|
let (unmarked, mut ranges) = marked_text_ranges_by(marked_text, vec![('[', ']').into()]);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue