diff --git a/crates/plugin_runtime/src/plugin.rs b/crates/plugin_runtime/src/plugin.rs index 4c8773cf9c9566bab25b9cebfb46bd67850a1d68..7473577d8497e66b827df29911b6bd416033147a 100644 --- a/crates/plugin_runtime/src/plugin.rs +++ b/crates/plugin_runtime/src/plugin.rs @@ -119,7 +119,8 @@ impl PluginBuilder { let buffer = WasiBuffer::from_u64(packed_buffer); // get the args passed from Guest - let args = Plugin::buffer_to_bytes(&mut plugin_memory, &mut caller, &buffer)?; + let args = + Plugin::buffer_to_bytes(&mut plugin_memory, caller.as_context(), &buffer)?; let args: A = Plugin::deserialize_to_type(&args)?; @@ -477,19 +478,18 @@ impl Plugin { Ok(result) } - // TODO: don't allocate a new `Vec`! /// Takes a `(ptr, len)` pair and returns the corresponding deserialized buffer. fn buffer_to_bytes<'a>( plugin_memory: &'a Memory, - store: impl AsContext + 'a, - buffer: &WasiBuffer, - ) -> Result, Error> { + store: wasmtime::StoreContext<'a, WasiCtxAlloc>, + buffer: &'a WasiBuffer, + ) -> Result<&'a [u8], Error> { let buffer_start = buffer.ptr as usize; let buffer_end = buffer_start + buffer.len as usize; // read the buffer at this point into a byte array // deserialize the byte array into the provided serde type - let result = plugin_memory.data(store.as_context())[buffer_start..buffer_end].to_vec(); + let result = &plugin_memory.data(store)[buffer_start..buffer_end]; Ok(result) } @@ -519,7 +519,6 @@ impl Plugin { }) } - // TODO: dont' use as for conversions /// Asynchronously calls a function defined Guest-side. pub async fn call( &mut self, diff --git a/crates/project/src/project.rs b/crates/project/src/project.rs index a479d2607644e860323df8df46e7f10516a76162..e09ded315fdedbb289e7b7f4ed004689ddf7ce24 100644 --- a/crates/project/src/project.rs +++ b/crates/project/src/project.rs @@ -1806,7 +1806,7 @@ impl Project { fn register_buffer_with_language_server( &mut self, buffer_handle: &ModelHandle, - cx: &mut ModelContext<'_, Self>, + cx: &mut ModelContext, ) { let buffer = buffer_handle.read(cx); let buffer_id = buffer.remote_id(); @@ -1901,7 +1901,7 @@ impl Project { &mut self, buffer: ModelHandle, event: &BufferEvent, - cx: &mut ModelContext<'_, Self>, + cx: &mut ModelContext, ) -> Option<()> { match event { BufferEvent::Operation(operation) => { @@ -2508,12 +2508,12 @@ impl Project { return; } - let same_token = + let is_disk_based_diagnostics_progress = Some(token.as_ref()) == disk_based_diagnostics_progress_token.as_ref().map(|x| &**x); match progress { lsp::WorkDoneProgress::Begin(report) => { - if same_token { + if is_disk_based_diagnostics_progress { language_server_status.has_pending_diagnostic_updates = true; self.disk_based_diagnostics_started(server_id, cx); self.broadcast_language_server_update( @@ -2544,7 +2544,7 @@ impl Project { } } lsp::WorkDoneProgress::Report(report) => { - if !same_token { + if !is_disk_based_diagnostics_progress { self.on_lsp_work_progress( server_id, token.clone(), @@ -2570,7 +2570,7 @@ impl Project { lsp::WorkDoneProgress::End(_) => { language_server_status.progress_tokens.remove(&token); - if same_token { + if is_disk_based_diagnostics_progress { language_server_status.has_pending_diagnostic_updates = false; self.disk_based_diagnostics_finished(server_id, cx); self.broadcast_language_server_update(