Unnamed repository; edit this file 'description' to name the repository.
refactor subreq/resp variants to carry span
| -rw-r--r-- | crates/proc-macro-api/src/bidirectional_protocol/msg.rs | 7 | ||||
| -rw-r--r-- | crates/proc-macro-srv-cli/src/main_loop.rs | 13 | ||||
| -rw-r--r-- | crates/proc-macro-srv/src/lib.rs | 6 | ||||
| -rw-r--r-- | crates/proc-macro-srv/src/server_impl/rust_analyzer_span.rs | 13 |
4 files changed, 17 insertions, 22 deletions
diff --git a/crates/proc-macro-api/src/bidirectional_protocol/msg.rs b/crates/proc-macro-api/src/bidirectional_protocol/msg.rs index 558954f761..73cf58bd9e 100644 --- a/crates/proc-macro-api/src/bidirectional_protocol/msg.rs +++ b/crates/proc-macro-api/src/bidirectional_protocol/msg.rs @@ -2,6 +2,7 @@ use paths::Utf8PathBuf; use serde::{Deserialize, Serialize}; +use tt::Span; use crate::{ ProcMacroKind, @@ -10,9 +11,9 @@ use crate::{ #[derive(Debug, Serialize, Deserialize)] pub enum SubRequest { - FilePath { file_id: u32 }, - SourceText { file_id: u32, start: u32, end: u32 }, - LocalFilePath { file_id: u32 }, + FilePath { span: Span }, + SourceText { span: Span }, + LocalFilePath { span: Span }, } #[derive(Debug, Serialize, Deserialize)] diff --git a/crates/proc-macro-srv-cli/src/main_loop.rs b/crates/proc-macro-srv-cli/src/main_loop.rs index 8fe3e93e47..a5bf84df04 100644 --- a/crates/proc-macro-srv-cli/src/main_loop.rs +++ b/crates/proc-macro-srv-cli/src/main_loop.rs @@ -6,6 +6,7 @@ use proc_macro_api::{ transport::codec::{json::JsonProtocol, postcard::PostcardProtocol}, version::CURRENT_API_VERSION, }; +use span::Span; use std::io; use legacy::Message; @@ -185,8 +186,8 @@ impl<'a, C: Codec> ProcMacroClientHandle<'a, C> { } impl<C: Codec> proc_macro_srv::ProcMacroClientInterface for ProcMacroClientHandle<'_, C> { - fn file(&mut self, file_id: u32) -> String { - match self.roundtrip(bidirectional::SubRequest::FilePath { file_id }) { + fn file(&mut self, span: Span) -> String { + match self.roundtrip(bidirectional::SubRequest::FilePath { span }) { Some(bidirectional::BidirectionalMessage::SubResponse( bidirectional::SubResponse::FilePathResult { name }, )) => name, @@ -194,8 +195,8 @@ impl<C: Codec> proc_macro_srv::ProcMacroClientInterface for ProcMacroClientHandl } } - fn source_text(&mut self, file_id: u32, start: u32, end: u32) -> Option<String> { - match self.roundtrip(bidirectional::SubRequest::SourceText { file_id, start, end }) { + fn source_text(&mut self, span: Span) -> Option<String> { + match self.roundtrip(bidirectional::SubRequest::SourceText { span }) { Some(bidirectional::BidirectionalMessage::SubResponse( bidirectional::SubResponse::SourceTextResult { text }, )) => text, @@ -203,8 +204,8 @@ impl<C: Codec> proc_macro_srv::ProcMacroClientInterface for ProcMacroClientHandl } } - fn local_file(&mut self, file_id: u32) -> Option<String> { - match self.roundtrip(bidirectional::SubRequest::LocalFilePath { file_id }) { + fn local_file(&mut self, span: Span) -> Option<String> { + match self.roundtrip(bidirectional::SubRequest::LocalFilePath { span }) { Some(bidirectional::BidirectionalMessage::SubResponse( bidirectional::SubResponse::LocalFilePathResult { name }, )) => name, diff --git a/crates/proc-macro-srv/src/lib.rs b/crates/proc-macro-srv/src/lib.rs index 8de712dbd3..6620800779 100644 --- a/crates/proc-macro-srv/src/lib.rs +++ b/crates/proc-macro-srv/src/lib.rs @@ -94,9 +94,9 @@ impl<'env> ProcMacroSrv<'env> { pub type ProcMacroClientHandle<'a> = &'a mut (dyn ProcMacroClientInterface + Sync + Send); pub trait ProcMacroClientInterface { - fn file(&mut self, file_id: u32) -> String; - fn source_text(&mut self, file_id: u32, start: u32, end: u32) -> Option<String>; - fn local_file(&mut self, file_id: u32) -> Option<String>; + fn file(&mut self, span: Span) -> String; + fn source_text(&mut self, span: Span) -> Option<String>; + fn local_file(&mut self, span: Span) -> Option<String>; } const EXPANDER_STACK_SIZE: usize = 8 * 1024 * 1024; 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 7a9d655431..c4392a9ae1 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 @@ -128,13 +128,10 @@ impl server::Span for RaSpanServer<'_> { format!("{:?}", span) } fn file(&mut self, span: Self::Span) -> String { - self.callback - .as_mut() - .map(|cb| cb.file(span.anchor.file_id.file_id().index())) - .unwrap_or_default() + self.callback.as_mut().map(|cb| cb.file(span)).unwrap_or_default() } fn local_file(&mut self, span: Self::Span) -> Option<String> { - self.callback.as_mut().and_then(|cb| cb.local_file(span.anchor.file_id.file_id().index())) + self.callback.as_mut().and_then(|cb| cb.local_file(span)) } fn save_span(&mut self, _span: Self::Span) -> usize { // FIXME, quote is incompatible with third-party tools @@ -153,11 +150,7 @@ 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> { - 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) + self.callback.as_mut()?.source_text(span) } fn parent(&mut self, _span: Self::Span) -> Option<Self::Span> { |