Refactor LanguageSever::fake into FakeLanguageServer::new

This is just moving code around and doesn't change behaviour, but it's
something Julia and I bumped into yesterday while writing docs.
This commit is contained in:
Thorsten Ball 2024-01-18 10:59:32 +01:00
parent 29c81e08bb
commit 5e6d1a47b2
3 changed files with 24 additions and 20 deletions

View File

@ -369,10 +369,11 @@ impl Copilot {
#[cfg(any(test, feature = "test-support"))]
pub fn fake(cx: &mut gpui::TestAppContext) -> (Model<Self>, lsp::FakeLanguageServer) {
use lsp::FakeLanguageServer;
use node_runtime::FakeNodeRuntime;
let (server, fake_server) =
LanguageServer::fake("copilot".into(), Default::default(), cx.to_async());
FakeLanguageServer::new("copilot".into(), Default::default(), cx.to_async());
let http = util::http::FakeHttpClient::create(|_| async { unreachable!() });
let node_runtime = FakeNodeRuntime::new();
let this = cx.new_model(|cx| Self {

View File

@ -951,7 +951,7 @@ impl LanguageRegistry {
if language.fake_adapter.is_some() {
let task = cx.spawn(|cx| async move {
let (servers_tx, fake_adapter) = language.fake_adapter.as_ref().unwrap();
let (server, mut fake_server) = lsp::LanguageServer::fake(
let (server, mut fake_server) = lsp::FakeLanguageServer::new(
fake_adapter.name.to_string(),
fake_adapter.capabilities.clone(),
cx.clone(),

View File

@ -972,30 +972,18 @@ pub struct FakeLanguageServer {
}
#[cfg(any(test, feature = "test-support"))]
impl LanguageServer {
pub fn full_capabilities() -> ServerCapabilities {
ServerCapabilities {
document_highlight_provider: Some(OneOf::Left(true)),
code_action_provider: Some(CodeActionProviderCapability::Simple(true)),
document_formatting_provider: Some(OneOf::Left(true)),
document_range_formatting_provider: Some(OneOf::Left(true)),
definition_provider: Some(OneOf::Left(true)),
type_definition_provider: Some(TypeDefinitionProviderCapability::Simple(true)),
..Default::default()
}
}
impl FakeLanguageServer {
/// Construct a fake language server.
pub fn fake(
pub fn new(
name: String,
capabilities: ServerCapabilities,
cx: AsyncAppContext,
) -> (Self, FakeLanguageServer) {
) -> (LanguageServer, FakeLanguageServer) {
let (stdin_writer, stdin_reader) = async_pipe::pipe();
let (stdout_writer, stdout_reader) = async_pipe::pipe();
let (notifications_tx, notifications_rx) = channel::unbounded();
let server = Self::new_internal(
let server = LanguageServer::new_internal(
LanguageServerId(0),
stdin_writer,
stdout_reader,
@ -1008,7 +996,7 @@ impl LanguageServer {
|_| {},
);
let fake = FakeLanguageServer {
server: Arc::new(Self::new_internal(
server: Arc::new(LanguageServer::new_internal(
LanguageServerId(0),
stdout_writer,
stdin_reader,
@ -1053,6 +1041,21 @@ impl LanguageServer {
}
}
#[cfg(any(test, feature = "test-support"))]
impl LanguageServer {
pub fn full_capabilities() -> ServerCapabilities {
ServerCapabilities {
document_highlight_provider: Some(OneOf::Left(true)),
code_action_provider: Some(CodeActionProviderCapability::Simple(true)),
document_formatting_provider: Some(OneOf::Left(true)),
document_range_formatting_provider: Some(OneOf::Left(true)),
definition_provider: Some(OneOf::Left(true)),
type_definition_provider: Some(TypeDefinitionProviderCapability::Simple(true)),
..Default::default()
}
}
}
#[cfg(any(test, feature = "test-support"))]
impl FakeLanguageServer {
/// See [`LanguageServer::notify`].
@ -1188,7 +1191,7 @@ mod tests {
#[gpui::test]
async fn test_fake(cx: &mut TestAppContext) {
let (server, mut fake) =
LanguageServer::fake("the-lsp".to_string(), Default::default(), cx.to_async());
FakeLanguageServer::new("the-lsp".to_string(), Default::default(), cx.to_async());
let (message_tx, message_rx) = channel::unbounded();
let (diagnostics_tx, diagnostics_rx) = channel::unbounded();