Fix minor issues in plugin and project raised during review
This commit is contained in:
parent
bc94d0d1a9
commit
be41ad44a7
2 changed files with 12 additions and 13 deletions
|
@ -119,7 +119,8 @@ impl PluginBuilder {
|
||||||
let buffer = WasiBuffer::from_u64(packed_buffer);
|
let buffer = WasiBuffer::from_u64(packed_buffer);
|
||||||
|
|
||||||
// get the args passed from Guest
|
// 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)?;
|
let args: A = Plugin::deserialize_to_type(&args)?;
|
||||||
|
|
||||||
|
@ -477,19 +478,18 @@ impl Plugin {
|
||||||
Ok(result)
|
Ok(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: don't allocate a new `Vec`!
|
|
||||||
/// Takes a `(ptr, len)` pair and returns the corresponding deserialized buffer.
|
/// Takes a `(ptr, len)` pair and returns the corresponding deserialized buffer.
|
||||||
fn buffer_to_bytes<'a>(
|
fn buffer_to_bytes<'a>(
|
||||||
plugin_memory: &'a Memory,
|
plugin_memory: &'a Memory,
|
||||||
store: impl AsContext<Data = WasiCtxAlloc> + 'a,
|
store: wasmtime::StoreContext<'a, WasiCtxAlloc>,
|
||||||
buffer: &WasiBuffer,
|
buffer: &'a WasiBuffer,
|
||||||
) -> Result<Vec<u8>, Error> {
|
) -> Result<&'a [u8], Error> {
|
||||||
let buffer_start = buffer.ptr as usize;
|
let buffer_start = buffer.ptr as usize;
|
||||||
let buffer_end = buffer_start + buffer.len as usize;
|
let buffer_end = buffer_start + buffer.len as usize;
|
||||||
|
|
||||||
// read the buffer at this point into a byte array
|
// read the buffer at this point into a byte array
|
||||||
// deserialize the byte array into the provided serde type
|
// 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)
|
Ok(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -519,7 +519,6 @@ impl Plugin {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: dont' use as for conversions
|
|
||||||
/// Asynchronously calls a function defined Guest-side.
|
/// Asynchronously calls a function defined Guest-side.
|
||||||
pub async fn call<A: Serialize, R: DeserializeOwned>(
|
pub async fn call<A: Serialize, R: DeserializeOwned>(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
|
|
@ -1806,7 +1806,7 @@ impl Project {
|
||||||
fn register_buffer_with_language_server(
|
fn register_buffer_with_language_server(
|
||||||
&mut self,
|
&mut self,
|
||||||
buffer_handle: &ModelHandle<Buffer>,
|
buffer_handle: &ModelHandle<Buffer>,
|
||||||
cx: &mut ModelContext<'_, Self>,
|
cx: &mut ModelContext<Self>,
|
||||||
) {
|
) {
|
||||||
let buffer = buffer_handle.read(cx);
|
let buffer = buffer_handle.read(cx);
|
||||||
let buffer_id = buffer.remote_id();
|
let buffer_id = buffer.remote_id();
|
||||||
|
@ -1901,7 +1901,7 @@ impl Project {
|
||||||
&mut self,
|
&mut self,
|
||||||
buffer: ModelHandle<Buffer>,
|
buffer: ModelHandle<Buffer>,
|
||||||
event: &BufferEvent,
|
event: &BufferEvent,
|
||||||
cx: &mut ModelContext<'_, Self>,
|
cx: &mut ModelContext<Self>,
|
||||||
) -> Option<()> {
|
) -> Option<()> {
|
||||||
match event {
|
match event {
|
||||||
BufferEvent::Operation(operation) => {
|
BufferEvent::Operation(operation) => {
|
||||||
|
@ -2508,12 +2508,12 @@ impl Project {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let same_token =
|
let is_disk_based_diagnostics_progress =
|
||||||
Some(token.as_ref()) == disk_based_diagnostics_progress_token.as_ref().map(|x| &**x);
|
Some(token.as_ref()) == disk_based_diagnostics_progress_token.as_ref().map(|x| &**x);
|
||||||
|
|
||||||
match progress {
|
match progress {
|
||||||
lsp::WorkDoneProgress::Begin(report) => {
|
lsp::WorkDoneProgress::Begin(report) => {
|
||||||
if same_token {
|
if is_disk_based_diagnostics_progress {
|
||||||
language_server_status.has_pending_diagnostic_updates = true;
|
language_server_status.has_pending_diagnostic_updates = true;
|
||||||
self.disk_based_diagnostics_started(server_id, cx);
|
self.disk_based_diagnostics_started(server_id, cx);
|
||||||
self.broadcast_language_server_update(
|
self.broadcast_language_server_update(
|
||||||
|
@ -2544,7 +2544,7 @@ impl Project {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lsp::WorkDoneProgress::Report(report) => {
|
lsp::WorkDoneProgress::Report(report) => {
|
||||||
if !same_token {
|
if !is_disk_based_diagnostics_progress {
|
||||||
self.on_lsp_work_progress(
|
self.on_lsp_work_progress(
|
||||||
server_id,
|
server_id,
|
||||||
token.clone(),
|
token.clone(),
|
||||||
|
@ -2570,7 +2570,7 @@ impl Project {
|
||||||
lsp::WorkDoneProgress::End(_) => {
|
lsp::WorkDoneProgress::End(_) => {
|
||||||
language_server_status.progress_tokens.remove(&token);
|
language_server_status.progress_tokens.remove(&token);
|
||||||
|
|
||||||
if same_token {
|
if is_disk_based_diagnostics_progress {
|
||||||
language_server_status.has_pending_diagnostic_updates = false;
|
language_server_status.has_pending_diagnostic_updates = false;
|
||||||
self.disk_based_diagnostics_finished(server_id, cx);
|
self.disk_based_diagnostics_finished(server_id, cx);
|
||||||
self.broadcast_language_server_update(
|
self.broadcast_language_server_update(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue