Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/proc-macro-srv/src/server_impl/rust_analyzer_span.rs')
| -rw-r--r-- | crates/proc-macro-srv/src/server_impl/rust_analyzer_span.rs | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/crates/proc-macro-srv/src/server_impl/rust_analyzer_span.rs b/crates/proc-macro-srv/src/server_impl/rust_analyzer_span.rs index 7c685c2da7..5d9090c060 100644 --- a/crates/proc-macro-srv/src/server_impl/rust_analyzer_span.rs +++ b/crates/proc-macro-srv/src/server_impl/rust_analyzer_span.rs @@ -14,13 +14,14 @@ use proc_macro::bridge::server; use span::{FIXUP_ERASED_FILE_AST_ID_MARKER, Span, TextRange, TextSize}; use crate::{ + ProcMacroClientHandle, bridge::{Diagnostic, ExpnGlobals, Literal, TokenTree}, server_impl::literal_from_str, }; pub struct FreeFunctions; -pub struct RaSpanServer { +pub struct RaSpanServer<'a> { // FIXME: Report this back to the caller to track as dependencies pub tracked_env_vars: HashMap<Box<str>, Option<Box<str>>>, // FIXME: Report this back to the caller to track as dependencies @@ -28,16 +29,17 @@ pub struct RaSpanServer { pub call_site: Span, pub def_site: Span, pub mixed_site: Span, + pub callback: Option<ProcMacroClientHandle<'a>>, } -impl server::Types for RaSpanServer { +impl server::Types for RaSpanServer<'_> { type FreeFunctions = FreeFunctions; type TokenStream = crate::token_stream::TokenStream<Span>; type Span = Span; type Symbol = Symbol; } -impl server::FreeFunctions for RaSpanServer { +impl server::FreeFunctions for RaSpanServer<'_> { fn injected_env_var(&mut self, _: &str) -> Option<std::string::String> { None } @@ -58,7 +60,7 @@ impl server::FreeFunctions for RaSpanServer { } } -impl server::TokenStream for RaSpanServer { +impl server::TokenStream for RaSpanServer<'_> { fn is_empty(&mut self, stream: &Self::TokenStream) -> bool { stream.is_empty() } @@ -121,7 +123,7 @@ impl server::TokenStream for RaSpanServer { } } -impl server::Span for RaSpanServer { +impl server::Span for RaSpanServer<'_> { fn debug(&mut self, span: Self::Span) -> String { format!("{:?}", span) } @@ -149,9 +151,12 @@ impl server::Span for RaSpanServer { /// /// See PR: /// https://github.com/rust-lang/rust/pull/55780 - fn source_text(&mut self, _span: Self::Span) -> Option<String> { - // FIXME requires db, needs special handling wrt fixup spans - None + fn source_text(&mut self, span: Self::Span) -> Option<String> { + let file_id = span.anchor.file_id; + let start: u32 = span.range.start().into(); + let end: u32 = span.range.end().into(); + + self.callback.as_mut()?.source_text(file_id.file_id().index(), start, end) } fn parent(&mut self, _span: Self::Span) -> Option<Self::Span> { @@ -269,14 +274,14 @@ impl server::Span for RaSpanServer { } } -impl server::Symbol for RaSpanServer { +impl server::Symbol for RaSpanServer<'_> { fn normalize_and_validate_ident(&mut self, string: &str) -> Result<Self::Symbol, ()> { // FIXME: nfc-normalize and validate idents Ok(<Self as server::Server>::intern_symbol(string)) } } -impl server::Server for RaSpanServer { +impl server::Server for RaSpanServer<'_> { fn globals(&mut self) -> ExpnGlobals<Self::Span> { ExpnGlobals { def_site: self.def_site, |