Skip to content

Commit

Permalink
Rollup merge of #111571 - jhpratt:proc-macro-span, r=m-ou-se
Browse files Browse the repository at this point in the history
Implement proposed API for `proc_macro_span`

As proposed in [#54725 (comment)](rust-lang/rust#54725 (comment)). 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`
  • Loading branch information
Dylan-DPC authored Jun 28, 2023
2 parents 846c12b + 638f6a0 commit 40c0da1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 13 additions & 14 deletions crates/proc-macro-srv/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@
//!
//! FIXME: No span and source file information is implemented yet

use proc_macro::{
bridge::{self, server},
LineColumn,
};
use proc_macro::bridge::{self, server};

mod token_stream;
pub use token_stream::TokenStream;
Expand Down Expand Up @@ -304,14 +301,6 @@ impl server::Span for RustAnalyzer {
// FIXME handle span
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> {
// Just return the first span again, because some macros will unwrap the result.
Some(first)
Expand All @@ -330,13 +319,23 @@ impl server::Span for RustAnalyzer {
tt::TokenId::unspecified()
}

fn after(&mut self, _self_: Self::Span) -> Self::Span {
fn end(&mut self, _self_: Self::Span) -> Self::Span {
tt::TokenId::unspecified()
}

fn before(&mut self, _self_: Self::Span) -> Self::Span {
fn start(&mut self, _self_: Self::Span) -> Self::Span {
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 {
Expand Down

0 comments on commit 40c0da1

Please sign in to comment.