diff --git a/internal/core/platform.rs b/internal/core/platform.rs index a969901b8..a739c8302 100644 --- a/internal/core/platform.rs +++ b/internal/core/platform.rs @@ -74,21 +74,7 @@ pub trait Platform { /// should direct the output to some developer visible terminal. The default implementation /// uses stderr if available, or `console.log` when targeting wasm. fn debug_log(&self, _arguments: core::fmt::Arguments) { - cfg_if::cfg_if! { - if #[cfg(target_arch = "wasm32")] { - use wasm_bindgen::prelude::*; - - #[wasm_bindgen] - extern "C" { - #[wasm_bindgen(js_namespace = console)] - pub fn log(s: &str); - } - - log(&_arguments.to_string()); - } else if #[cfg(feature = "std")] { - eprintln!("{}", _arguments); - } - } + crate::tests::default_debug_log(_arguments); } } diff --git a/internal/core/tests.rs b/internal/core/tests.rs index ae7a80aee..fba343edf 100644 --- a/internal/core/tests.rs +++ b/internal/core/tests.rs @@ -88,7 +88,29 @@ pub extern "C" fn send_keyboard_string_sequence( /// implementation details for debug_log() #[doc(hidden)] pub fn debug_log_impl(args: core::fmt::Arguments) { - crate::platform::PLATFORM_INSTANCE.with(|p| p.get().map(|p| p.debug_log(args))); + crate::platform::PLATFORM_INSTANCE.with(|p| match p.get() { + Some(platform) => platform.debug_log(args), + None => default_debug_log(args), + }); +} + +#[doc(hidden)] +pub fn default_debug_log(_arguments: core::fmt::Arguments) { + cfg_if::cfg_if! { + if #[cfg(target_arch = "wasm32")] { + use wasm_bindgen::prelude::*; + + #[wasm_bindgen] + extern "C" { + #[wasm_bindgen(js_namespace = console)] + pub fn log(s: &str); + } + + log(&_arguments.to_string()); + } else if #[cfg(feature = "std")] { + eprintln!("{}", _arguments); + } + } } #[macro_export] diff --git a/tools/lsp/Cargo.toml b/tools/lsp/Cargo.toml index 29a2c5c82..78c81e5a2 100644 --- a/tools/lsp/Cargo.toml +++ b/tools/lsp/Cargo.toml @@ -49,7 +49,7 @@ backend-gl-all = ["backend-winit", "renderer-winit-femtovg"] backend-gl-wayland = ["backend-winit-wayland", "renderer-winit-femtovg"] backend-gl-x11 = ["backend-winit-x11", "renderer-winit-femtovg"] -preview = ["slint-interpreter", "i-slint-backend-selector"] +preview = ["slint-interpreter", "i-slint-core", "i-slint-backend-selector"] default = ["backend-qt", "backend-winit", "renderer-winit-femtovg", "preview"] @@ -60,10 +60,10 @@ euclid = "0.22" lsp-types = { version = "0.93.0", features = ["proposed"] } serde = "1.0.118" serde_json = "1.0.60" -i-slint-core = { version = "=0.3.1", path = "../../internal/core" } # for the preview +i-slint-core = { version = "=0.3.1", path = "../../internal/core", optional = true } slint-interpreter = { version = "=0.3.1", path = "../../internal/interpreter", default-features = false, features = ["compat-0-3-0"], optional = true } i-slint-backend-selector = { version = "=0.3.1", path="../../internal/backends/selector", optional = true } diff --git a/tools/lsp/wasm_main.rs b/tools/lsp/wasm_main.rs index 5c7ebc49d..d23389139 100644 --- a/tools/lsp/wasm_main.rs +++ b/tools/lsp/wasm_main.rs @@ -12,8 +12,6 @@ mod server_loop; mod util; use i_slint_compiler::CompilerConfiguration; -#[cfg(not(feature = "preview"))] -use i_slint_core::window::WindowAdapter; use js_sys::Function; use lsp_types::InitializeParams; use serde::Serialize; @@ -145,11 +143,6 @@ pub fn create( ) -> Result { console_error_panic_hook::set_once(); - // make sure the backend is initialized for logging - #[cfg(not(feature = "preview"))] - i_slint_core::platform::set_platform(Box::new(DummyBackend {})) - .expect("platform already initialized"); - let init_param = init_param.into_serde()?; let mut compiler_config = @@ -239,13 +232,3 @@ async fn load_file(path: String, load_file: &Function) -> std::io::Result Rc { - unimplemented!() - } -}