mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 13:03:31 +00:00
switch expand to dyn Trait
This commit is contained in:
parent
3260639608
commit
99b6ecfab0
2 changed files with 9 additions and 9 deletions
|
@ -28,13 +28,13 @@ pub trait AstDatabase: SourceDatabase {
|
||||||
fn macro_expand(&self, macro_call: MacroCallId) -> Result<Arc<tt::Subtree>, String>;
|
fn macro_expand(&self, macro_call: MacroCallId) -> Result<Arc<tt::Subtree>, String>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn ast_id_map(db: &impl AstDatabase, file_id: HirFileId) -> Arc<AstIdMap> {
|
pub(crate) fn ast_id_map(db: &dyn AstDatabase, file_id: HirFileId) -> Arc<AstIdMap> {
|
||||||
let map =
|
let map =
|
||||||
db.parse_or_expand(file_id).map_or_else(AstIdMap::default, |it| AstIdMap::from_source(&it));
|
db.parse_or_expand(file_id).map_or_else(AstIdMap::default, |it| AstIdMap::from_source(&it));
|
||||||
Arc::new(map)
|
Arc::new(map)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn macro_def(db: &impl AstDatabase, id: MacroDefId) -> Option<Arc<MacroRules>> {
|
pub(crate) fn macro_def(db: &dyn AstDatabase, id: MacroDefId) -> Option<Arc<MacroRules>> {
|
||||||
let macro_call = id.ast_id.to_node(db);
|
let macro_call = id.ast_id.to_node(db);
|
||||||
let arg = macro_call.token_tree()?;
|
let arg = macro_call.token_tree()?;
|
||||||
let (tt, _) = mbe::ast_to_token_tree(&arg).or_else(|| {
|
let (tt, _) = mbe::ast_to_token_tree(&arg).or_else(|| {
|
||||||
|
@ -48,7 +48,7 @@ pub(crate) fn macro_def(db: &impl AstDatabase, id: MacroDefId) -> Option<Arc<Mac
|
||||||
Some(Arc::new(rules))
|
Some(Arc::new(rules))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn macro_arg(db: &impl AstDatabase, id: MacroCallId) -> Option<Arc<tt::Subtree>> {
|
pub(crate) fn macro_arg(db: &dyn AstDatabase, id: MacroCallId) -> Option<Arc<tt::Subtree>> {
|
||||||
let loc = db.lookup_intern_macro(id);
|
let loc = db.lookup_intern_macro(id);
|
||||||
let macro_call = loc.ast_id.to_node(db);
|
let macro_call = loc.ast_id.to_node(db);
|
||||||
let arg = macro_call.token_tree()?;
|
let arg = macro_call.token_tree()?;
|
||||||
|
@ -57,7 +57,7 @@ pub(crate) fn macro_arg(db: &impl AstDatabase, id: MacroCallId) -> Option<Arc<tt
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn macro_expand(
|
pub(crate) fn macro_expand(
|
||||||
db: &impl AstDatabase,
|
db: &dyn AstDatabase,
|
||||||
id: MacroCallId,
|
id: MacroCallId,
|
||||||
) -> Result<Arc<tt::Subtree>, String> {
|
) -> Result<Arc<tt::Subtree>, String> {
|
||||||
let loc = db.lookup_intern_macro(id);
|
let loc = db.lookup_intern_macro(id);
|
||||||
|
@ -73,7 +73,7 @@ pub(crate) fn macro_expand(
|
||||||
Ok(Arc::new(tt))
|
Ok(Arc::new(tt))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn parse_or_expand(db: &impl AstDatabase, file_id: HirFileId) -> Option<SyntaxNode> {
|
pub(crate) fn parse_or_expand(db: &dyn AstDatabase, file_id: HirFileId) -> Option<SyntaxNode> {
|
||||||
match file_id.0 {
|
match file_id.0 {
|
||||||
HirFileIdRepr::FileId(file_id) => Some(db.parse(file_id).tree().syntax().clone()),
|
HirFileIdRepr::FileId(file_id) => Some(db.parse(file_id).tree().syntax().clone()),
|
||||||
HirFileIdRepr::MacroFile(macro_file) => {
|
HirFileIdRepr::MacroFile(macro_file) => {
|
||||||
|
@ -83,7 +83,7 @@ pub(crate) fn parse_or_expand(db: &impl AstDatabase, file_id: HirFileId) -> Opti
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn parse_macro(
|
pub(crate) fn parse_macro(
|
||||||
db: &impl AstDatabase,
|
db: &dyn AstDatabase,
|
||||||
macro_file: MacroFile,
|
macro_file: MacroFile,
|
||||||
) -> Option<Parse<SyntaxNode>> {
|
) -> Option<Parse<SyntaxNode>> {
|
||||||
let _p = profile("parse_macro_query");
|
let _p = profile("parse_macro_query");
|
||||||
|
|
|
@ -63,7 +63,7 @@ impl From<MacroFile> for HirFileId {
|
||||||
impl HirFileId {
|
impl HirFileId {
|
||||||
/// For macro-expansion files, returns the file original source file the
|
/// For macro-expansion files, returns the file original source file the
|
||||||
/// expansion originated from.
|
/// expansion originated from.
|
||||||
pub fn original_file(self, db: &impl AstDatabase) -> FileId {
|
pub fn original_file(self, db: &dyn AstDatabase) -> FileId {
|
||||||
match self.0 {
|
match self.0 {
|
||||||
HirFileIdRepr::FileId(file_id) => file_id,
|
HirFileIdRepr::FileId(file_id) => file_id,
|
||||||
HirFileIdRepr::MacroFile(macro_file) => {
|
HirFileIdRepr::MacroFile(macro_file) => {
|
||||||
|
@ -74,7 +74,7 @@ impl HirFileId {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the crate which the macro lives in, if it is a macro file.
|
/// Get the crate which the macro lives in, if it is a macro file.
|
||||||
pub fn macro_crate(self, db: &impl AstDatabase) -> Option<CrateId> {
|
pub fn macro_crate(self, db: &dyn AstDatabase) -> Option<CrateId> {
|
||||||
match self.0 {
|
match self.0 {
|
||||||
HirFileIdRepr::FileId(_) => None,
|
HirFileIdRepr::FileId(_) => None,
|
||||||
HirFileIdRepr::MacroFile(macro_file) => {
|
HirFileIdRepr::MacroFile(macro_file) => {
|
||||||
|
@ -160,7 +160,7 @@ impl<N: AstNode> AstId<N> {
|
||||||
self.file_id
|
self.file_id
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_node(&self, db: &impl AstDatabase) -> N {
|
pub fn to_node(&self, db: &dyn AstDatabase) -> N {
|
||||||
let root = db.parse_or_expand(self.file_id).unwrap();
|
let root = db.parse_or_expand(self.file_id).unwrap();
|
||||||
db.ast_id_map(self.file_id).get(self.file_ast_id).to_node(&root)
|
db.ast_id_map(self.file_id).get(self.file_ast_id).to_node(&root)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue