mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-29 06:23:25 +00:00
Auto merge of #13356 - WaffleLapkin:go_to_def_shadow_include, r=Veykril
minor: Fix go-to-def for shadowed `include*!` Add a check in go-to-def feature, so that we don't assume any macro named `include`/`include_str`/`include_bytes` is the builtin one.
This commit is contained in:
commit
f2f3528618
1 changed files with 30 additions and 3 deletions
|
@ -95,6 +95,14 @@ fn try_lookup_include_path(
|
||||||
if !matches!(&*name.text(), "include" | "include_str" | "include_bytes") {
|
if !matches!(&*name.text(), "include" | "include_str" | "include_bytes") {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ignore non-built-in macros to account for shadowing
|
||||||
|
if let Some(it) = sema.resolve_macro_call(¯o_call) {
|
||||||
|
if !matches!(it.kind(sema.db), hir::MacroKind::BuiltIn) {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let file_id = sema.db.resolve_path(AnchoredPath { anchor: file_id, path: &path })?;
|
let file_id = sema.db.resolve_path(AnchoredPath { anchor: file_id, path: &path })?;
|
||||||
let size = sema.db.file_text(file_id).len().try_into().ok()?;
|
let size = sema.db.file_text(file_id).len().try_into().ok()?;
|
||||||
Some(NavigationTarget {
|
Some(NavigationTarget {
|
||||||
|
@ -156,9 +164,6 @@ mod tests {
|
||||||
fn check(ra_fixture: &str) {
|
fn check(ra_fixture: &str) {
|
||||||
let (analysis, position, expected) = fixture::annotations(ra_fixture);
|
let (analysis, position, expected) = fixture::annotations(ra_fixture);
|
||||||
let navs = analysis.goto_definition(position).unwrap().expect("no definition found").info;
|
let navs = analysis.goto_definition(position).unwrap().expect("no definition found").info;
|
||||||
if navs.is_empty() {
|
|
||||||
panic!("unresolved reference")
|
|
||||||
}
|
|
||||||
|
|
||||||
let cmp = |&FileRange { file_id, range }: &_| (file_id, range.start());
|
let cmp = |&FileRange { file_id, range }: &_| (file_id, range.start());
|
||||||
let navs = navs
|
let navs = navs
|
||||||
|
@ -1348,6 +1353,10 @@ fn f(e: Enum) {
|
||||||
check(
|
check(
|
||||||
r#"
|
r#"
|
||||||
//- /main.rs
|
//- /main.rs
|
||||||
|
|
||||||
|
#[rustc_builtin_macro]
|
||||||
|
macro_rules! include_str {}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let str = include_str!("foo.txt$0");
|
let str = include_str!("foo.txt$0");
|
||||||
}
|
}
|
||||||
|
@ -1357,6 +1366,24 @@ fn main() {
|
||||||
"#,
|
"#,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn goto_shadow_include() {
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
//- /main.rs
|
||||||
|
macro_rules! include {
|
||||||
|
("included.rs") => {}
|
||||||
|
}
|
||||||
|
|
||||||
|
include!("included.rs$0");
|
||||||
|
|
||||||
|
//- /included.rs
|
||||||
|
// empty
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod goto_impl_of_trait_fn {
|
mod goto_impl_of_trait_fn {
|
||||||
use super::check;
|
use super::check;
|
||||||
|
|
Loading…
Reference in a new issue