From 3bad5587c8cd17cd7dfae9796c8a01f47307214f Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Sat, 25 Apr 2020 12:30:28 +0800 Subject: Compare timestamp --- crates/ra_proc_macro_srv/src/lib.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'crates/ra_proc_macro_srv') diff --git a/crates/ra_proc_macro_srv/src/lib.rs b/crates/ra_proc_macro_srv/src/lib.rs index 0954bd6b5..121f531fd 100644 --- a/crates/ra_proc_macro_srv/src/lib.rs +++ b/crates/ra_proc_macro_srv/src/lib.rs @@ -23,12 +23,14 @@ use proc_macro::bridge::client::TokenStream; use ra_proc_macro::{ExpansionResult, ExpansionTask, ListMacrosResult, ListMacrosTask}; use std::{ collections::{hash_map::Entry, HashMap}, + fs::metadata, path::{Path, PathBuf}, + time::SystemTime, }; #[derive(Default)] pub(crate) struct ProcMacroSrv { - expanders: HashMap, + expanders: HashMap<(PathBuf, SystemTime), dylib::Expander>, } impl ProcMacroSrv { @@ -48,7 +50,11 @@ impl ProcMacroSrv { } fn expander(&mut self, path: &Path) -> Result<&dylib::Expander, String> { - Ok(match self.expanders.entry(path.to_path_buf()) { + let time = metadata(path) + .and_then(|it| it.modified()) + .map_err(|err| format!("Failed to file metadata for {}: {:?}", path.display(), err))?; + + Ok(match self.expanders.entry((path.to_path_buf(), time)) { Entry::Vacant(v) => v.insert(dylib::Expander::new(path).map_err(|err| { format!("Cannot create expander for {}: {:?}", path.display(), err) })?), -- cgit v1.2.3