Skip to content

Commit 8ecb6df

Browse files
committed
Auto merge of #14960 - jneem:group-delim-span, r=Veykril
Add span to group. This appears to fix #14959, but I've never contributed to rust-analyzer before and there were some things that confused me: - I had to add the `fn byte_range` method to get it to build. This was added to rust in [April](rust-lang/rust#109002), so I don't understand why it wasn't needed until now - When testing, I ran into the fact that rust recently updated its `METADATA_VERSION`, so I had to test this with nightly-2023-05-20. But then I noticed that rust has its own copy of `rust-analyzer`, and the metadata version bump has already been [handled there](rust-lang/rust@60e95e7). So I guess I don't really understand the relationship between the code there and the code here.
2 parents 993299e + ad2a0d1 commit 8ecb6df

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

crates/proc-macro-srv/src/server.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ impl server::TokenStream for RustAnalyzer {
9797
match tree {
9898
bridge::TokenTree::Group(group) => {
9999
let group = Group {
100-
delimiter: delim_to_internal(group.delimiter),
100+
delimiter: delim_to_internal(group.delimiter, group.span),
101101
token_trees: match group.stream {
102102
Some(stream) => stream.into_iter().collect(),
103103
None => Vec::new(),
@@ -221,14 +221,14 @@ impl server::TokenStream for RustAnalyzer {
221221
}
222222
}
223223

224-
fn delim_to_internal(d: proc_macro::Delimiter) -> tt::Delimiter {
224+
fn delim_to_internal(d: proc_macro::Delimiter, span: bridge::DelimSpan<Span>) -> tt::Delimiter {
225225
let kind = match d {
226226
proc_macro::Delimiter::Parenthesis => tt::DelimiterKind::Parenthesis,
227227
proc_macro::Delimiter::Brace => tt::DelimiterKind::Brace,
228228
proc_macro::Delimiter::Bracket => tt::DelimiterKind::Bracket,
229229
proc_macro::Delimiter::None => tt::DelimiterKind::Invisible,
230230
};
231-
tt::Delimiter { open: tt::TokenId::unspecified(), close: tt::TokenId::unspecified(), kind }
231+
tt::Delimiter { open: span.open, close: span.close, kind }
232232
}
233233

234234
fn delim_to_external(d: tt::Delimiter) -> proc_macro::Delimiter {

crates/rust-analyzer/src/cli/diagnostics.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,15 @@ impl flags::Diagnostics {
1717
pub fn run(self) -> anyhow::Result<()> {
1818
let mut cargo_config = CargoConfig::default();
1919
cargo_config.sysroot = Some(RustLibSource::Discover);
20+
let with_proc_macro_server = if let Some(p) = &self.proc_macro_srv {
21+
let path = vfs::AbsPathBuf::assert(std::env::current_dir()?.join(&p));
22+
ProcMacroServerChoice::Explicit(path)
23+
} else {
24+
ProcMacroServerChoice::Sysroot
25+
};
2026
let load_cargo_config = LoadCargoConfig {
2127
load_out_dirs_from_check: !self.disable_build_scripts,
22-
with_proc_macro_server: ProcMacroServerChoice::Sysroot,
28+
with_proc_macro_server,
2329
prefill_caches: false,
2430
};
2531
let (host, _vfs, _proc_macro) =

crates/rust-analyzer/src/cli/flags.rs

+3
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ xflags::xflags! {
9292
optional --disable-build-scripts
9393
/// Don't use expand proc macros.
9494
optional --disable-proc-macros
95+
/// Run a custom proc-macro-srv binary.
96+
optional --proc-macro-srv path: PathBuf
9597
}
9698

9799
cmd ssr {
@@ -189,6 +191,7 @@ pub struct Diagnostics {
189191

190192
pub disable_build_scripts: bool,
191193
pub disable_proc_macros: bool,
194+
pub proc_macro_srv: Option<PathBuf>,
192195
}
193196

194197
#[derive(Debug)]

0 commit comments

Comments
 (0)