Trait ra_ap_hir::db::AstDatabase
source · pub trait AstDatabase: Database + HasQueryGroup<AstDatabaseStorage> + SourceDatabase {
fn ast_id_map(&self, file_id: HirFileId) -> Arc<AstIdMap>;
fn parse_or_expand(
&self,
file_id: HirFileId
) -> Option<SyntaxNode<RustLanguage>>;
fn parse_macro_expansion(
&self,
macro_file: MacroFile
) -> ValueResult<Option<(Parse<SyntaxNode<RustLanguage>>, Arc<TokenMap>)>, ExpandError>;
fn intern_macro_call(&self, macro_call: MacroCallLoc) -> MacroCallId;
fn lookup_intern_macro_call(&self, key: MacroCallId) -> MacroCallLoc;
fn macro_arg(
&self,
id: MacroCallId
) -> Option<Arc<(Subtree, TokenMap, SyntaxFixupUndoInfo)>>;
fn macro_arg_text(&self, id: MacroCallId) -> Option<GreenNode>;
fn macro_def(&self, id: MacroDefId) -> Result<Arc<TokenExpander>, ParseError>;
fn macro_expand(
&self,
macro_call: MacroCallId
) -> ValueResult<Option<Arc<Subtree>>, ExpandError>;
fn expand_proc_macro(
&self,
call: MacroCallId
) -> ValueResult<Subtree, ExpandError>;
fn macro_expand_error(&self, macro_call: MacroCallId) -> Option<ExpandError>;
fn hygiene_frame(&self, file_id: HirFileId) -> Arc<HygieneFrame>;
}
Required Methods§
fn ast_id_map(&self, file_id: HirFileId) -> Arc<AstIdMap>
sourcefn parse_or_expand(&self, file_id: HirFileId) -> Option<SyntaxNode<RustLanguage>>
fn parse_or_expand(&self, file_id: HirFileId) -> Option<SyntaxNode<RustLanguage>>
Main public API – parses a hir file, not caring whether it’s a real file or a macro expansion.
sourcefn parse_macro_expansion(
&self,
macro_file: MacroFile
) -> ValueResult<Option<(Parse<SyntaxNode<RustLanguage>>, Arc<TokenMap>)>, ExpandError>
fn parse_macro_expansion(
&self,
macro_file: MacroFile
) -> ValueResult<Option<(Parse<SyntaxNode<RustLanguage>>, Arc<TokenMap>)>, ExpandError>
Implementation for the macro case.
sourcefn intern_macro_call(&self, macro_call: MacroCallLoc) -> MacroCallId
fn intern_macro_call(&self, macro_call: MacroCallLoc) -> MacroCallId
Macro ids. That’s probably the tricksiest bit in rust-analyzer, and the reason why we use salsa at all.
We encode macro definitions into ids of macro calls, this what allows us to be incremental.
fn lookup_intern_macro_call(&self, key: MacroCallId) -> MacroCallLoc
sourcefn macro_arg(
&self,
id: MacroCallId
) -> Option<Arc<(Subtree, TokenMap, SyntaxFixupUndoInfo)>>
fn macro_arg(
&self,
id: MacroCallId
) -> Option<Arc<(Subtree, TokenMap, SyntaxFixupUndoInfo)>>
Lowers syntactic macro call to a token tree representation.
sourcefn macro_arg_text(&self, id: MacroCallId) -> Option<GreenNode>
fn macro_arg_text(&self, id: MacroCallId) -> Option<GreenNode>
Extracts syntax node, corresponding to a macro call. That’s a firewall query, only typing in the macro call itself changes the returned subtree.
sourcefn macro_def(&self, id: MacroDefId) -> Result<Arc<TokenExpander>, ParseError>
fn macro_def(&self, id: MacroDefId) -> Result<Arc<TokenExpander>, ParseError>
Gets the expander for this macro. This compiles declarative macros, and just fetches procedural ones.
sourcefn macro_expand(
&self,
macro_call: MacroCallId
) -> ValueResult<Option<Arc<Subtree>>, ExpandError>
fn macro_expand(
&self,
macro_call: MacroCallId
) -> ValueResult<Option<Arc<Subtree>>, ExpandError>
Expand macro call to a token tree. This query is LRUed (we keep 128 or so results in memory)
sourcefn expand_proc_macro(
&self,
call: MacroCallId
) -> ValueResult<Subtree, ExpandError>
fn expand_proc_macro(
&self,
call: MacroCallId
) -> ValueResult<Subtree, ExpandError>
Special case of the previous query for procedural macros. We can’t LRU proc macros, since they are not deterministic in general, and non-determinism breaks salsa in a very, very, very bad way. @edwin0cheng heroically debugged this once!
sourcefn macro_expand_error(&self, macro_call: MacroCallId) -> Option<ExpandError>
fn macro_expand_error(&self, macro_call: MacroCallId) -> Option<ExpandError>
Firewall query that returns the error from the macro_expand
query.