pub struct Semantics<'db, DB> {
pub db: &'db DB,
/* private fields */
}
Expand description
Primary API to get semantic information, like types, from syntax trees.
Fields
db: &'db DB
Implementations
sourceimpl<'db, DB> Semantics<'db, DB> where
DB: HirDatabase,
impl<'db, DB> Semantics<'db, DB> where
DB: HirDatabase,
pub fn new(db: &DB) -> Semantics<'_, DB>
pub fn parse(&self, file_id: FileId) -> SourceFile
pub fn parse_or_expand(
&self,
file_id: HirFileId
) -> Option<SyntaxNode<RustLanguage>>
pub fn expand(&self, macro_call: &MacroCall) -> Option<SyntaxNode<RustLanguage>>
sourcepub fn expand_attr_macro(&self, item: &Item) -> Option<SyntaxNode<RustLanguage>>
pub fn expand_attr_macro(&self, item: &Item) -> Option<SyntaxNode<RustLanguage>>
If item
has an attribute macro attached to it, expands it.
pub fn expand_derive_as_pseudo_attr_macro(
&self,
attr: &Attr
) -> Option<SyntaxNode<RustLanguage>>
pub fn resolve_derive_macro(
&self,
derive: &Attr
) -> Option<Vec<Option<Macro>, Global>>
pub fn expand_derive_macro(
&self,
derive: &Attr
) -> Option<Vec<SyntaxNode<RustLanguage>, Global>>
pub fn is_attr_macro_call(&self, item: &Item) -> bool
pub fn is_derive_annotated(&self, item: &Adt) -> bool
pub fn speculative_expand(
&self,
actual_macro_call: &MacroCall,
speculative_args: &TokenTree,
token_to_map: SyntaxToken<RustLanguage>
) -> Option<(SyntaxNode<RustLanguage>, SyntaxToken<RustLanguage>)>
pub fn speculative_expand_attr_macro(
&self,
actual_macro_call: &Item,
speculative_args: &Item,
token_to_map: SyntaxToken<RustLanguage>
) -> Option<(SyntaxNode<RustLanguage>, SyntaxToken<RustLanguage>)>
pub fn speculative_expand_derive_as_pseudo_attr_macro(
&self,
actual_macro_call: &Attr,
speculative_args: &Attr,
token_to_map: SyntaxToken<RustLanguage>
) -> Option<(SyntaxNode<RustLanguage>, SyntaxToken<RustLanguage>)>
sourcepub fn descend_into_macros_single(
&self,
token: SyntaxToken<RustLanguage>
) -> SyntaxToken<RustLanguage>
pub fn descend_into_macros_single(
&self,
token: SyntaxToken<RustLanguage>
) -> SyntaxToken<RustLanguage>
Descend the token into macrocalls to its first mapped counterpart.
sourcepub fn descend_into_macros(
&self,
token: SyntaxToken<RustLanguage>
) -> SmallVec<[SyntaxToken<RustLanguage>; 1]>
pub fn descend_into_macros(
&self,
token: SyntaxToken<RustLanguage>
) -> SmallVec<[SyntaxToken<RustLanguage>; 1]>
Descend the token into macrocalls to all its mapped counterparts.
sourcepub fn descend_into_macros_with_same_text(
&self,
token: SyntaxToken<RustLanguage>
) -> SmallVec<[SyntaxToken<RustLanguage>; 1]>
pub fn descend_into_macros_with_same_text(
&self,
token: SyntaxToken<RustLanguage>
) -> SmallVec<[SyntaxToken<RustLanguage>; 1]>
Descend the token into macrocalls to all its mapped counterparts that have the same text as the input token.
Returns the original non descended token if none of the mapped counterparts have the same text.
pub fn descend_into_macros_with_kind_preference(
&self,
token: SyntaxToken<RustLanguage>
) -> SyntaxToken<RustLanguage>
sourcepub fn descend_node_into_attributes<N>(&self, node: N) -> SmallVec<[N; 1]> where
N: AstNode,
pub fn descend_node_into_attributes<N>(&self, node: N) -> SmallVec<[N; 1]> where
N: AstNode,
Maps a node down by mapping its first and last token down.
sourcepub fn source<Def>(&self, def: Def) -> Option<InFile<<Def as HasSource>::Ast>> where
Def: HasSource,
<Def as HasSource>::Ast: AstNode,
pub fn source<Def>(&self, def: Def) -> Option<InFile<<Def as HasSource>::Ast>> where
Def: HasSource,
<Def as HasSource>::Ast: AstNode,
Search for a definition’s source and cache its syntax tree
pub fn hir_file_for(&self, syntax_node: &SyntaxNode<RustLanguage>) -> HirFileId
sourcepub fn original_range(&self, node: &SyntaxNode<RustLanguage>) -> FileRange
pub fn original_range(&self, node: &SyntaxNode<RustLanguage>) -> FileRange
Attempts to map the node out of macro expanded files returning the original file range. If upmapping is not possible, this will fall back to the range of the macro call of the macro file the node resides in.
sourcepub fn original_range_opt(
&self,
node: &SyntaxNode<RustLanguage>
) -> Option<FileRange>
pub fn original_range_opt(
&self,
node: &SyntaxNode<RustLanguage>
) -> Option<FileRange>
Attempts to map the node out of macro expanded files returning the original file range.
sourcepub fn original_ast_node<N>(&self, node: N) -> Option<N> where
N: AstNode,
pub fn original_ast_node<N>(&self, node: N) -> Option<N> where
N: AstNode,
Attempts to map the node out of macro expanded files. This only work for attribute expansions, as other ones do not have nodes as input.
pub fn diagnostics_display_range(
&self,
diagnostics: InFile<SyntaxNodePtr<RustLanguage>>
) -> FileRange
pub fn token_ancestors_with_macros(
&self,
token: SyntaxToken<RustLanguage>
) -> impl Iterator<Item = SyntaxNode<RustLanguage>>
sourcepub fn ancestors_with_macros(
&self,
node: SyntaxNode<RustLanguage>
) -> impl Iterator<Item = SyntaxNode<RustLanguage>>
pub fn ancestors_with_macros(
&self,
node: SyntaxNode<RustLanguage>
) -> impl Iterator<Item = SyntaxNode<RustLanguage>>
Iterates the ancestors of the given node, climbing up macro expansions while doing so.
pub fn ancestors_at_offset_with_macros(
&self,
node: &SyntaxNode<RustLanguage>,
offset: TextSize
) -> impl Iterator<Item = SyntaxNode<RustLanguage>>
sourcepub fn find_node_at_offset_with_macros<N>(
&self,
node: &SyntaxNode<RustLanguage>,
offset: TextSize
) -> Option<N> where
N: AstNode,
pub fn find_node_at_offset_with_macros<N>(
&self,
node: &SyntaxNode<RustLanguage>,
offset: TextSize
) -> Option<N> where
N: AstNode,
Find an AstNode by offset inside SyntaxNode, if it is inside Macrofile, search up until it is of the target AstNode type
sourcepub fn find_node_at_offset_with_descend<N>(
&self,
node: &SyntaxNode<RustLanguage>,
offset: TextSize
) -> Option<N> where
N: AstNode,
pub fn find_node_at_offset_with_descend<N>(
&self,
node: &SyntaxNode<RustLanguage>,
offset: TextSize
) -> Option<N> where
N: AstNode,
Find an AstNode by offset inside SyntaxNode, if it is inside MacroCall, descend it and find again
sourcepub fn find_nodes_at_offset_with_descend<'slf, N>(
&'slf self,
node: &SyntaxNode<RustLanguage>,
offset: TextSize
) -> impl Iterator<Item = N> + 'slf where
N: 'slf + AstNode,
pub fn find_nodes_at_offset_with_descend<'slf, N>(
&'slf self,
node: &SyntaxNode<RustLanguage>,
offset: TextSize
) -> impl Iterator<Item = N> + 'slf where
N: 'slf + AstNode,
Find an AstNode by offset inside SyntaxNode, if it is inside MacroCall, descend it and find again
pub fn resolve_lifetime_param(
&self,
lifetime: &Lifetime
) -> Option<LifetimeParam>
pub fn resolve_label(&self, lifetime: &Lifetime) -> Option<Label>
pub fn resolve_type(&self, ty: &Type) -> Option<Type>
pub fn is_implicit_reborrow(&self, expr: &Expr) -> Option<Mutability>
pub fn type_of_expr(&self, expr: &Expr) -> Option<TypeInfo>
pub fn type_of_pat(&self, pat: &Pat) -> Option<TypeInfo>
pub fn type_of_self(&self, param: &SelfParam) -> Option<Type>
pub fn pattern_adjustments(&self, pat: &Pat) -> SmallVec<[Type; 1]>
pub fn binding_mode_of_pat(&self, pat: &IdentPat) -> Option<BindingMode>
pub fn resolve_method_call(&self, call: &MethodCallExpr) -> Option<Function>
pub fn resolve_method_call_as_callable(
&self,
call: &MethodCallExpr
) -> Option<Callable>
pub fn resolve_field(&self, field: &FieldExpr) -> Option<Field>
pub fn resolve_record_field(
&self,
field: &RecordExprField
) -> Option<(Field, Option<Local>, Type)>
pub fn resolve_record_pat_field(&self, field: &RecordPatField) -> Option<Field>
pub fn resolve_macro_call(&self, macro_call: &MacroCall) -> Option<Macro>
pub fn is_unsafe_macro_call(&self, macro_call: &MacroCall) -> bool
pub fn resolve_attr_macro_call(&self, item: &Item) -> Option<Macro>
pub fn resolve_path(&self, path: &Path) -> Option<PathResolution>
pub fn resolve_extern_crate(&self, extern_crate: &ExternCrate) -> Option<Crate>
pub fn resolve_variant(&self, record_lit: RecordExpr) -> Option<VariantDef>
pub fn resolve_bind_pat_to_const(&self, pat: &IdentPat) -> Option<ModuleDef>
pub fn record_literal_missing_fields(
&self,
literal: &RecordExpr
) -> Vec<(Field, Type), Global>
pub fn record_pattern_missing_fields(
&self,
pattern: &RecordPat
) -> Vec<(Field, Type), Global>
pub fn to_def<T>(&self, src: &T) -> Option<<T as ToDef>::Def> where
T: ToDef,
pub fn to_module_def(&self, file: FileId) -> Option<Module>
pub fn to_module_defs(&self, file: FileId) -> impl Iterator<Item = Module>
pub fn scope(
&self,
node: &SyntaxNode<RustLanguage>
) -> Option<SemanticsScope<'db>>
pub fn scope_at_offset(
&self,
node: &SyntaxNode<RustLanguage>,
offset: TextSize
) -> Option<SemanticsScope<'db>>
pub fn scope_for_def(&self, def: Trait) -> SemanticsScope<'db>
pub fn assert_contains_node(&self, node: &SyntaxNode<RustLanguage>)
pub fn is_unsafe_method_call(&self, method_call_expr: &MethodCallExpr) -> bool
pub fn is_unsafe_ref_expr(&self, ref_expr: &RefExpr) -> bool
pub fn is_unsafe_ident_pat(&self, ident_pat: &IdentPat) -> bool
Trait Implementations
Auto Trait Implementations
impl<'db, DB> !RefUnwindSafe for Semantics<'db, DB>
impl<'db, DB> !Send for Semantics<'db, DB>
impl<'db, DB> !Sync for Semantics<'db, DB>
impl<'db, DB> Unpin for Semantics<'db, DB>
impl<'db, DB> !UnwindSafe for Semantics<'db, DB>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<T> Cast for T
impl<T> Cast for T
fn cast<U>(self, interner: <U as HasInterner>::Interner) -> U where
Self: CastTo<U>,
U: HasInterner,
fn cast<U>(self, interner: <U as HasInterner>::Interner) -> U where
Self: CastTo<U>,
U: HasInterner,
Cast a value to type U
using CastTo
.
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<T> Pointable for T
impl<T> Pointable for T
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more