fix: remove duplicate metadata processing in MagicFileMetaPlugin
Co-authored-by: aider (openai/andrew/openrouter/qwen/qwen3-coder) <aider@aider.chat>
This commit is contained in:
@@ -9,7 +9,7 @@ use crate::meta_plugin::MetaPlugin;
|
|||||||
pub struct MagicFileMetaPlugin {
|
pub struct MagicFileMetaPlugin {
|
||||||
buffer: Vec<u8>,
|
buffer: Vec<u8>,
|
||||||
max_buffer_size: usize,
|
max_buffer_size: usize,
|
||||||
is_saved: bool,
|
is_finalized: bool,
|
||||||
cookie: Option<Cookie>,
|
cookie: Option<Cookie>,
|
||||||
base: crate::meta_plugin::BaseMetaPlugin,
|
base: crate::meta_plugin::BaseMetaPlugin,
|
||||||
}
|
}
|
||||||
@@ -51,7 +51,7 @@ impl MagicFileMetaPlugin {
|
|||||||
MagicFileMetaPlugin {
|
MagicFileMetaPlugin {
|
||||||
buffer: Vec::new(),
|
buffer: Vec::new(),
|
||||||
max_buffer_size,
|
max_buffer_size,
|
||||||
is_saved: false,
|
is_finalized: false,
|
||||||
cookie: None,
|
cookie: None,
|
||||||
base,
|
base,
|
||||||
}
|
}
|
||||||
@@ -119,6 +119,13 @@ impl MagicFileMetaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl MetaPlugin for MagicFileMetaPlugin {
|
impl MetaPlugin for MagicFileMetaPlugin {
|
||||||
|
fn is_finalized(&self) -> bool {
|
||||||
|
self.is_finalized
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_finalized(&mut self, finalized: bool) {
|
||||||
|
self.is_finalized = finalized;
|
||||||
|
}
|
||||||
|
|
||||||
fn initialize(&mut self) -> crate::meta_plugin::MetaPluginResponse {
|
fn initialize(&mut self) -> crate::meta_plugin::MetaPluginResponse {
|
||||||
// Initialize the magic cookie once
|
// Initialize the magic cookie once
|
||||||
@@ -146,7 +153,18 @@ impl MetaPlugin for MagicFileMetaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn finalize(&mut self) -> crate::meta_plugin::MetaPluginResponse {
|
fn finalize(&mut self) -> crate::meta_plugin::MetaPluginResponse {
|
||||||
|
// If already finalized, don't process again
|
||||||
|
if self.is_finalized {
|
||||||
|
return crate::meta_plugin::MetaPluginResponse {
|
||||||
|
metadata: Vec::new(),
|
||||||
|
is_finalized: true,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
let metadata = self.process_magic_types();
|
let metadata = self.process_magic_types();
|
||||||
|
|
||||||
|
// Mark as finalized
|
||||||
|
self.is_finalized = true;
|
||||||
|
|
||||||
crate::meta_plugin::MetaPluginResponse {
|
crate::meta_plugin::MetaPluginResponse {
|
||||||
metadata,
|
metadata,
|
||||||
@@ -155,6 +173,14 @@ impl MetaPlugin for MagicFileMetaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn update(&mut self, data: &[u8]) -> crate::meta_plugin::MetaPluginResponse {
|
fn update(&mut self, data: &[u8]) -> crate::meta_plugin::MetaPluginResponse {
|
||||||
|
// If already finalized, don't process more data
|
||||||
|
if self.is_finalized {
|
||||||
|
return crate::meta_plugin::MetaPluginResponse {
|
||||||
|
metadata: Vec::new(),
|
||||||
|
is_finalized: true,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
let mut metadata = Vec::new();
|
let mut metadata = Vec::new();
|
||||||
|
|
||||||
// Only collect up to max_buffer_size
|
// Only collect up to max_buffer_size
|
||||||
@@ -166,6 +192,9 @@ impl MetaPlugin for MagicFileMetaPlugin {
|
|||||||
// Check if we've reached our buffer limit and return metadata
|
// Check if we've reached our buffer limit and return metadata
|
||||||
if self.buffer.len() >= self.max_buffer_size {
|
if self.buffer.len() >= self.max_buffer_size {
|
||||||
metadata = self.process_magic_types();
|
metadata = self.process_magic_types();
|
||||||
|
|
||||||
|
// Mark as finalized when we've processed enough data
|
||||||
|
self.is_finalized = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user