Skip to content

Commit

Permalink
Fix failing server tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dannymcgee committed May 14, 2024
1 parent a8fe08a commit ae73874
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/server/src/declarations/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ fn find_imports(
expect_decl!((found, needle, uri) == Function "skin_model" @ "modules/skinning.wgsl":9 );

// Imported namespace `mesh_functions`
let needle = testing::token!(Module "mesh_functions" (52:24..52:38));
let needle = testing::token!(Module "mesh_functions" (62:26..62:40));
let found = find_decl(
&needle,
&uri,
Expand Down
50 changes: 45 additions & 5 deletions packages/server/src/testing.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
use std::path::{Path, PathBuf};

use anyhow::anyhow;
use bevy_app::{App, Plugin, PreStartup, ScheduleRunnerPlugin};
use bevy_app::{App, Plugin, PreStartup, PreUpdate, ScheduleRunnerPlugin};
use bevy_derive::{Deref, DerefMut};
use bevy_ecs::{
system::{IntoSystem, Resource},
event::EventWriter,
system::{IntoSystem, Res, Resource},
world::World,
};
use crossbeam::channel::Receiver;
use lsp_server::Message;
use lsp_types::{DidOpenTextDocumentParams, TextDocumentItem, Url, WorkspaceFolder};
use lsp_types::{
request::{Request, WorkspaceConfiguration},
ConfigurationParams, DidOpenTextDocumentParams, TextDocumentItem, Url, WorkspaceFolder,
};

use crate::{
ipc::{notify, request, Ipc},
ipc::{self, notify, request, Ipc},
workspace::Workspace,
};

Expand Down Expand Up @@ -67,6 +71,7 @@ pub fn setup_e2e_harness() -> App {

notify::register_events(&mut app);
request::register_events(&mut app);
app.add_event::<ipc::Response>();

let root = test_files_root().unwrap();

Expand All @@ -76,7 +81,8 @@ pub fn setup_e2e_harness() -> App {
name: "test-files".into(),
uri: Url::from_directory_path(root).unwrap(),
}]))
.add_systems(PreStartup, open_test_files.map(unwrap));
.add_systems(PreStartup, open_test_files.map(unwrap))
.add_systems(PreUpdate, handle_server_requests.map(unwrap));

app
}
Expand Down Expand Up @@ -122,6 +128,40 @@ fn open_test_files(world: &mut World) -> anyhow::Result<()> {
])
}

fn handle_server_requests(
r_client: Res<MockClient>,
mut ew_responses: EventWriter<ipc::Response>,
) -> anyhow::Result<()> {
while let Ok(msg) = r_client.try_recv() {
if let Message::Request(r) = msg {
match &r.method[..] {
WorkspaceConfiguration::METHOD => {
let (id, _) =
r.extract::<ConfigurationParams>(WorkspaceConfiguration::METHOD)?;

let response = serde_json::json!([{
"preprocessor": {
"globalShaderDefs": {
"MORPH_TARGETS": "",
"SKINNED": "",
"VERTEX_POSITIONS": "",
},
"shaderDefs": {},
}
}]);

ew_responses.send(ipc::Response(id, Ok(response)));
}
other => {
eprintln!("WARNING: Unhandled server request: {other}");
}
}
}
}

Ok(())
}

pub fn unwrap<E: core::fmt::Display>(result: Result<(), E>) {
if let Err(err) = result {
panic!("{err}");
Expand Down

0 comments on commit ae73874

Please sign in to comment.