Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/load-cargo/src/lib.rs')
-rw-r--r--crates/load-cargo/src/lib.rs22
1 files changed, 18 insertions, 4 deletions
diff --git a/crates/load-cargo/src/lib.rs b/crates/load-cargo/src/lib.rs
index e043e4ac76..a7b22b0d6a 100644
--- a/crates/load-cargo/src/lib.rs
+++ b/crates/load-cargo/src/lib.rs
@@ -23,11 +23,17 @@ use ide_db::{
prime_caches,
};
use itertools::Itertools;
-use proc_macro_api::{MacroDylib, ProcMacroClient};
+use proc_macro_api::{
+ MacroDylib, ProcMacroClient,
+ bidirectional_protocol::{
+ msg::{SubRequest, SubResponse},
+ reject_subrequests,
+ },
+};
use project_model::{CargoConfig, PackageRoot, ProjectManifest, ProjectWorkspace};
use span::Span;
use vfs::{
- AbsPath, AbsPathBuf, VfsPath,
+ AbsPath, AbsPathBuf, FileId, VfsPath,
file_set::FileSetConfig,
loader::{Handle, LoadingProgress},
};
@@ -427,7 +433,7 @@ pub fn load_proc_macro(
) -> ProcMacroLoadResult {
let res: Result<Vec<_>, _> = (|| {
let dylib = MacroDylib::new(path.to_path_buf());
- let vec = server.load_dylib(dylib).map_err(|e| {
+ let vec = server.load_dylib(dylib, Some(&mut reject_subrequests)).map_err(|e| {
ProcMacroLoadingError::ProcMacroSrvError(format!("{e}").into_boxed_str())
})?;
if vec.is_empty() {
@@ -533,8 +539,15 @@ impl ProcMacroExpander for Expander {
mixed_site: Span,
current_dir: String,
) -> Result<tt::TopSubtree<Span>, ProcMacroExpansionError> {
+ let mut cb = |req| match req {
+ SubRequest::SourceText { file_id, start, end } => {
+ let file = FileId::from_raw(file_id);
+ let text = db.file_text(file).text(db);
+ let slice = text.get(start as usize..end as usize).map(ToOwned::to_owned);
+ Ok(SubResponse::SourceTextResult { text: slice })
+ }
+ };
match self.0.expand(
- db,
subtree.view(),
attrs.map(|attrs| attrs.view()),
env.clone().into(),
@@ -542,6 +555,7 @@ impl ProcMacroExpander for Expander {
call_site,
mixed_site,
current_dir,
+ Some(&mut cb),
) {
Ok(Ok(subtree)) => Ok(subtree),
Ok(Err(err)) => Err(ProcMacroExpansionError::Panic(err)),