mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-02 06:41:48 +00:00
Auto merge of #16439 - wasd96040501:feat/gotodef3, r=Veykril
feat: Support for GOTO def from *inside* files included with include! macro close #14937 Try to implement goto def from *inside* files included with include! macro. This implementation has two limitations: 1. Only **one** file which calls include! will be tracked. (I think multiple file be included is a rare case and we may let it go for now) 2. Mapping token from included file to macro call file (semantics.rs:646~658) works fine but I am not sure is this the correct way to implement.
This commit is contained in:
commit
22b6f9679d
7 changed files with 163 additions and 12 deletions
|
@ -1,9 +1,10 @@
|
|||
//! Defines database & queries for name resolution.
|
||||
use base_db::{salsa, CrateId, SourceDatabase, Upcast};
|
||||
use base_db::{salsa, CrateId, FileId, SourceDatabase, Upcast};
|
||||
use either::Either;
|
||||
use hir_expand::{db::ExpandDatabase, HirFileId, MacroDefId};
|
||||
use intern::Interned;
|
||||
use la_arena::ArenaMap;
|
||||
use span::MacroCallId;
|
||||
use syntax::{ast, AstPtr};
|
||||
use triomphe::Arc;
|
||||
|
||||
|
@ -234,6 +235,22 @@ pub trait DefDatabase: InternDatabase + ExpandDatabase + Upcast<dyn ExpandDataba
|
|||
fn crate_notable_traits(&self, krate: CrateId) -> Option<Arc<[TraitId]>>;
|
||||
|
||||
fn crate_supports_no_std(&self, crate_id: CrateId) -> bool;
|
||||
|
||||
fn include_macro_invoc(&self, crate_id: CrateId) -> Vec<(MacroCallId, FileId)>;
|
||||
}
|
||||
|
||||
// return: macro call id and include file id
|
||||
fn include_macro_invoc(db: &dyn DefDatabase, krate: CrateId) -> Vec<(MacroCallId, FileId)> {
|
||||
db.crate_def_map(krate)
|
||||
.modules
|
||||
.values()
|
||||
.flat_map(|m| m.scope.iter_macro_invoc())
|
||||
.filter_map(|invoc| {
|
||||
db.lookup_intern_macro_call(*invoc.1)
|
||||
.include_file_id(db.upcast(), *invoc.1)
|
||||
.map(|x| (*invoc.1, x))
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn crate_def_map_wait(db: &dyn DefDatabase, krate: CrateId) -> Arc<DefMap> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue