Rollup merge of #111571 - jhpratt:proc-macro-span, r=m-ou-se

Implement proposed API for `proc_macro_span`

As proposed in [#54725 (comment)](https://github.com/rust-lang/rust/issues/54725#issuecomment-1546918161). I have omitted the byte-level API as it's already available as [`Span::byte_range`](https://doc.rust-lang.org/nightly/proc_macro/struct.Span.html#method.byte_range).

`@rustbot` label +A-proc-macros

r? `@m-ou-se`
This commit is contained in:
Dylan DPC 2023-06-28 18:28:46 +05:30 committed by GitHub
commit c770e4154d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 16 deletions

4
Cargo.lock generated
View file

@ -1304,9 +1304,9 @@ version = "0.0.0"
[[package]] [[package]]
name = "proc-macro2" name = "proc-macro2"
version = "1.0.56" version = "1.0.60"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2b63bdb0cd06f1f4dedf69b254734f9b45af66e4a031e42a7480257d9898b435" checksum = "dec2b086b7a862cf4de201096214fa870344cf922b2b30c167badb3af3195406"
dependencies = [ dependencies = [
"unicode-ident", "unicode-ident",
] ]

View file

@ -8,10 +8,7 @@
//! //!
//! FIXME: No span and source file information is implemented yet //! FIXME: No span and source file information is implemented yet
use proc_macro::{ use proc_macro::bridge::{self, server};
bridge::{self, server},
LineColumn,
};
mod token_stream; mod token_stream;
pub use token_stream::TokenStream; pub use token_stream::TokenStream;
@ -304,14 +301,6 @@ impl server::Span for RustAnalyzer {
// FIXME handle span // FIXME handle span
Range { start: 0, end: 0 } Range { start: 0, end: 0 }
} }
fn start(&mut self, _span: Self::Span) -> LineColumn {
// FIXME handle span
LineColumn { line: 0, column: 0 }
}
fn end(&mut self, _span: Self::Span) -> LineColumn {
// FIXME handle span
LineColumn { line: 0, column: 0 }
}
fn join(&mut self, first: Self::Span, _second: Self::Span) -> Option<Self::Span> { fn join(&mut self, first: Self::Span, _second: Self::Span) -> Option<Self::Span> {
// Just return the first span again, because some macros will unwrap the result. // Just return the first span again, because some macros will unwrap the result.
Some(first) Some(first)
@ -330,13 +319,23 @@ impl server::Span for RustAnalyzer {
tt::TokenId::unspecified() tt::TokenId::unspecified()
} }
fn after(&mut self, _self_: Self::Span) -> Self::Span { fn end(&mut self, _self_: Self::Span) -> Self::Span {
tt::TokenId::unspecified() tt::TokenId::unspecified()
} }
fn before(&mut self, _self_: Self::Span) -> Self::Span { fn start(&mut self, _self_: Self::Span) -> Self::Span {
tt::TokenId::unspecified() tt::TokenId::unspecified()
} }
fn line(&mut self, _span: Self::Span) -> usize {
// FIXME handle line
0
}
fn column(&mut self, _span: Self::Span) -> usize {
// FIXME handle column
0
}
} }
impl server::Symbol for RustAnalyzer { impl server::Symbol for RustAnalyzer {