mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-08-04 10:50:15 +00:00
Faster env snapshotting in proc-macro-srv
This commit is contained in:
parent
678420e66a
commit
2fb38ceb66
6 changed files with 147 additions and 117 deletions
|
@ -156,23 +156,26 @@ impl ProcMacro {
|
|||
let call_site = span_data_table.insert_full(call_site).0;
|
||||
let mixed_site = span_data_table.insert_full(mixed_site).0;
|
||||
let task = ExpandMacro {
|
||||
macro_body: FlatTree::new(subtree, version, &mut span_data_table),
|
||||
macro_name: self.name.to_string(),
|
||||
attributes: attr.map(|subtree| FlatTree::new(subtree, version, &mut span_data_table)),
|
||||
data: msg::ExpandMacroData {
|
||||
macro_body: FlatTree::new(subtree, version, &mut span_data_table),
|
||||
macro_name: self.name.to_string(),
|
||||
attributes: attr
|
||||
.map(|subtree| FlatTree::new(subtree, version, &mut span_data_table)),
|
||||
has_global_spans: ExpnGlobals {
|
||||
serialize: version >= HAS_GLOBAL_SPANS,
|
||||
def_site,
|
||||
call_site,
|
||||
mixed_site,
|
||||
},
|
||||
span_data_table: if version >= RUST_ANALYZER_SPAN_SUPPORT {
|
||||
serialize_span_data_index_map(&span_data_table)
|
||||
} else {
|
||||
Vec::new()
|
||||
},
|
||||
},
|
||||
lib: self.dylib_path.to_path_buf().into(),
|
||||
env: env.into(),
|
||||
current_dir,
|
||||
has_global_spans: ExpnGlobals {
|
||||
serialize: version >= HAS_GLOBAL_SPANS,
|
||||
def_site,
|
||||
call_site,
|
||||
mixed_site,
|
||||
},
|
||||
span_data_table: if version >= RUST_ANALYZER_SPAN_SUPPORT {
|
||||
serialize_span_data_index_map(&span_data_table)
|
||||
} else {
|
||||
Vec::new()
|
||||
},
|
||||
};
|
||||
|
||||
let response = self.process.send_task(msg::Request::ExpandMacro(Box::new(task)))?;
|
||||
|
|
|
@ -72,6 +72,16 @@ pub struct PanicMessage(pub String);
|
|||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct ExpandMacro {
|
||||
pub lib: Utf8PathBuf,
|
||||
/// Environment variables to set during macro expansion.
|
||||
pub env: Vec<(String, String)>,
|
||||
pub current_dir: Option<String>,
|
||||
#[serde(flatten)]
|
||||
pub data: ExpandMacroData,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct ExpandMacroData {
|
||||
/// Argument of macro call.
|
||||
///
|
||||
/// In custom derive this will be a struct or enum; in attribute-like macro - underlying
|
||||
|
@ -86,13 +96,6 @@ pub struct ExpandMacro {
|
|||
|
||||
/// Possible attributes for the attribute-like macros.
|
||||
pub attributes: Option<FlatTree>,
|
||||
|
||||
pub lib: Utf8PathBuf,
|
||||
|
||||
/// Environment variables to set during macro expansion.
|
||||
pub env: Vec<(String, String)>,
|
||||
|
||||
pub current_dir: Option<String>,
|
||||
/// marker for serde skip stuff
|
||||
#[serde(skip_serializing_if = "ExpnGlobals::skip_serializing_if")]
|
||||
#[serde(default)]
|
||||
|
@ -268,25 +271,30 @@ mod tests {
|
|||
let tt = fixture_token_tree();
|
||||
let mut span_data_table = Default::default();
|
||||
let task = ExpandMacro {
|
||||
macro_body: FlatTree::new(&tt, CURRENT_API_VERSION, &mut span_data_table),
|
||||
macro_name: Default::default(),
|
||||
attributes: None,
|
||||
data: ExpandMacroData {
|
||||
macro_body: FlatTree::new(&tt, CURRENT_API_VERSION, &mut span_data_table),
|
||||
macro_name: Default::default(),
|
||||
attributes: None,
|
||||
has_global_spans: ExpnGlobals {
|
||||
serialize: true,
|
||||
def_site: 0,
|
||||
call_site: 0,
|
||||
mixed_site: 0,
|
||||
},
|
||||
span_data_table: Vec::new(),
|
||||
},
|
||||
lib: Utf8PathBuf::from_path_buf(std::env::current_dir().unwrap()).unwrap(),
|
||||
env: Default::default(),
|
||||
current_dir: Default::default(),
|
||||
has_global_spans: ExpnGlobals {
|
||||
serialize: true,
|
||||
def_site: 0,
|
||||
call_site: 0,
|
||||
mixed_site: 0,
|
||||
},
|
||||
span_data_table: Vec::new(),
|
||||
};
|
||||
|
||||
let json = serde_json::to_string(&task).unwrap();
|
||||
// println!("{}", json);
|
||||
let back: ExpandMacro = serde_json::from_str(&json).unwrap();
|
||||
|
||||
assert_eq!(tt, back.macro_body.to_subtree_resolved(CURRENT_API_VERSION, &span_data_table));
|
||||
assert_eq!(
|
||||
tt,
|
||||
back.data.macro_body.to_subtree_resolved(CURRENT_API_VERSION, &span_data_table)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue