Struct ide::Semantics

source ·
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§

source§

impl<DB> Semantics<'_, DB>
where DB: HirDatabase,

source

pub fn new(db: &DB) -> Semantics<'_, DB>

source

pub fn hir_file_for(&self, syntax_node: &SyntaxNode<RustLanguage>) -> HirFileId

source

pub fn token_ancestors_with_macros( &self, token: SyntaxToken<RustLanguage>, ) -> impl Iterator<Item = SyntaxNode<RustLanguage>>

source

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

source

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

source

pub fn find_nodes_at_offset_with_descend<'slf, N>( &'slf self, node: &SyntaxNode<RustLanguage>, offset: TextSize, ) -> impl Iterator<Item = N> + 'slf
where N: AstNode + 'slf,

Find an AstNode by offset inside SyntaxNode, if it is inside an attribute macro call, descend it and find again

source

pub fn resolve_range_pat(&self, range_pat: &RangePat) -> Option<Struct>

source

pub fn resolve_range_expr(&self, range_expr: &RangeExpr) -> Option<Struct>

source

pub fn resolve_await_to_poll(&self, await_expr: &AwaitExpr) -> Option<Function>

source

pub fn resolve_prefix_expr(&self, prefix_expr: &PrefixExpr) -> Option<Function>

source

pub fn resolve_index_expr(&self, index_expr: &IndexExpr) -> Option<Function>

source

pub fn resolve_bin_expr(&self, bin_expr: &BinExpr) -> Option<Function>

source

pub fn resolve_try_expr(&self, try_expr: &TryExpr) -> Option<Function>

source

pub fn resolve_variant(&self, record_lit: RecordExpr) -> Option<VariantDef>

source

pub fn file_to_module_def(&self, file: impl Into<FileId>) -> Option<Module>

source

pub fn file_to_module_defs( &self, file: impl Into<FileId>, ) -> impl Iterator<Item = Module>

source

pub fn to_adt_def(&self, a: &Adt) -> Option<Adt>

source

pub fn to_const_def(&self, c: &Const) -> Option<Const>

source

pub fn to_enum_def(&self, e: &Enum) -> Option<Enum>

source

pub fn to_enum_variant_def(&self, v: &Variant) -> Option<Variant>

source

pub fn to_fn_def(&self, f: &Fn) -> Option<Function>

source

pub fn to_impl_def(&self, i: &Impl) -> Option<Impl>

source

pub fn to_macro_def(&self, m: &Macro) -> Option<Macro>

source

pub fn to_module_def(&self, m: &Module) -> Option<Module>

source

pub fn to_static_def(&self, s: &Static) -> Option<Static>

source

pub fn to_struct_def(&self, s: &Struct) -> Option<Struct>

source

pub fn to_trait_alias_def(&self, t: &TraitAlias) -> Option<TraitAlias>

source

pub fn to_trait_def(&self, t: &Trait) -> Option<Trait>

source

pub fn to_type_alias_def(&self, t: &TypeAlias) -> Option<TypeAlias>

source

pub fn to_union_def(&self, u: &Union) -> Option<Union>

Methods from Deref<Target = SemanticsImpl<'db>>§

source

pub fn parse(&self, file_id: EditionedFileId) -> SourceFile

source

pub fn attach_first_edition(&self, file: FileId) -> Option<EditionedFileId>

source

pub fn parse_guess_edition(&self, file_id: FileId) -> SourceFile

source

pub fn find_parent_file( &self, file_id: HirFileId, ) -> Option<InFileWrapper<HirFileId, SyntaxNode<RustLanguage>>>

source

pub fn module_definition_node( &self, module: Module, ) -> InFileWrapper<HirFileId, SyntaxNode<RustLanguage>>

Returns the SyntaxNode of the module. If this is a file module, returns the SyntaxNode of the definition file, not of the declaration.

source

pub fn parse_or_expand(&self, file_id: HirFileId) -> SyntaxNode<RustLanguage>

source

pub fn expand(&self, macro_call: &MacroCall) -> Option<SyntaxNode<RustLanguage>>

source

pub fn check_cfg_attr(&self, attr: &TokenTree) -> Option<bool>

source

pub fn expand_allowed_builtins( &self, macro_call: &MacroCall, ) -> Option<SyntaxNode<RustLanguage>>

Expands the macro if it isn’t one of the built-in ones that expand to custom syntax or dummy expansions.

source

pub fn expand_attr_macro(&self, item: &Item) -> Option<SyntaxNode<RustLanguage>>

If item has an attribute macro attached to it, expands it.

source

pub fn expand_derive_as_pseudo_attr_macro( &self, attr: &Attr, ) -> Option<SyntaxNode<RustLanguage>>

source

pub fn resolve_derive_macro(&self, attr: &Attr) -> Option<Vec<Option<Macro>>>

source

pub fn expand_derive_macro( &self, attr: &Attr, ) -> Option<Vec<SyntaxNode<RustLanguage>>>

source

pub fn is_derive_annotated(&self, adt: &Adt) -> bool

source

pub fn derive_helper(&self, attr: &Attr) -> Option<Vec<(Macro, MacroFileId)>>

source

pub fn is_attr_macro_call(&self, item: &Item) -> bool

source

pub fn speculative_expand( &self, actual_macro_call: &MacroCall, speculative_args: &TokenTree, token_to_map: SyntaxToken<RustLanguage>, ) -> Option<(SyntaxNode<RustLanguage>, SyntaxToken<RustLanguage>)>

Expand the macro call with a different token tree, mapping the token_to_map down into the expansion. token_to_map should be a token from the speculative args node.

source

pub fn speculative_expand_raw( &self, macro_file: MacroFileId, speculative_args: &SyntaxNode<RustLanguage>, token_to_map: SyntaxToken<RustLanguage>, ) -> Option<(SyntaxNode<RustLanguage>, SyntaxToken<RustLanguage>)>

source

pub fn speculative_expand_attr_macro( &self, actual_macro_call: &Item, speculative_args: &Item, token_to_map: SyntaxToken<RustLanguage>, ) -> Option<(SyntaxNode<RustLanguage>, SyntaxToken<RustLanguage>)>

Expand the macro call with a different item as the input, mapping the token_to_map down into the expansion. token_to_map should be a token from the speculative args node.

source

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>)>

source

pub fn as_format_args_parts( &self, string: &String, ) -> Option<Vec<(TextRange, Option<Either<PathResolution, InlineAsmOperand>>)>>

Retrieves all the formatting parts of the format_args! (or asm!) template string.

source

pub fn check_for_format_args_template( &self, original_token: SyntaxToken<RustLanguage>, offset: TextSize, ) -> Option<(TextRange, Option<Either<PathResolution, InlineAsmOperand>>)>

Retrieves the formatting part of the format_args! template string at the given offset.

source

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.

source

pub fn might_be_inside_macro_call( &self, token: &SyntaxToken<RustLanguage>, ) -> bool

Does a syntactic traversal to check whether this token might be inside a macro call

source

pub fn descend_into_macros_cb( &self, token: SyntaxToken<RustLanguage>, cb: impl FnMut(InFileWrapper<HirFileId, SyntaxToken<RustLanguage>>, SyntaxContextId), )

source

pub fn descend_into_macros( &self, token: SyntaxToken<RustLanguage>, ) -> SmallVec<[SyntaxToken<RustLanguage>; 1]>

source

pub fn descend_into_macros_no_opaque( &self, token: SyntaxToken<RustLanguage>, ) -> SmallVec<[SyntaxToken<RustLanguage>; 1]>

source

pub fn descend_into_macros_breakable<T>( &self, token: InFileWrapper<EditionedFileId, SyntaxToken<RustLanguage>>, cb: impl FnMut(InFileWrapper<HirFileId, SyntaxToken<RustLanguage>>, SyntaxContextId) -> ControlFlow<T>, ) -> Option<T>

source

pub fn descend_into_macros_exact( &self, token: SyntaxToken<RustLanguage>, ) -> SmallVec<[SyntaxToken<RustLanguage>; 1]>

Descends the token into expansions, returning the tokens that matches the input token’s [SyntaxKind] and text.

source

pub fn descend_into_macros_single_exact( &self, token: SyntaxToken<RustLanguage>, ) -> SyntaxToken<RustLanguage>

Descends the token into expansions, returning the first token that matches the input token’s [SyntaxKind] and text.

source

pub fn original_range( &self, node: &SyntaxNode<RustLanguage>, ) -> FileRangeWrapper<EditionedFileId>

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.

source

pub fn original_range_opt( &self, node: &SyntaxNode<RustLanguage>, ) -> Option<FileRangeWrapper<EditionedFileId>>

Attempts to map the node out of macro expanded files returning the original file range.

source

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.

source

pub fn original_syntax_node_rooted( &self, node: &SyntaxNode<RustLanguage>, ) -> Option<SyntaxNode<RustLanguage>>

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.

source

pub fn diagnostics_display_range( &self, src: InFileWrapper<HirFileId, SyntaxNodePtr<RustLanguage>>, ) -> FileRangeWrapper<EditionedFileId>

source

pub fn ancestors_with_macros( &self, node: SyntaxNode<RustLanguage>, ) -> impl Iterator<Item = SyntaxNode<RustLanguage>> + Clone

Iterates the ancestors of the given node, climbing up macro expansions while doing so.

source

pub fn ancestors_at_offset_with_macros( &self, node: &SyntaxNode<RustLanguage>, offset: TextSize, ) -> impl Iterator<Item = SyntaxNode<RustLanguage>>

source

pub fn resolve_lifetime_param( &self, lifetime: &Lifetime, ) -> Option<LifetimeParam>

source

pub fn resolve_label(&self, label: &Lifetime) -> Option<Label>

source

pub fn resolve_type(&self, ty: &Type) -> Option<Type>

source

pub fn resolve_trait(&self, path: &Path) -> Option<Trait>

source

pub fn expr_adjustments(&self, expr: &Expr) -> Option<Vec<Adjustment>>

source

pub fn type_of_expr(&self, expr: &Expr) -> Option<TypeInfo>

source

pub fn type_of_pat(&self, pat: &Pat) -> Option<TypeInfo>

source

pub fn type_of_binding_in_pat(&self, pat: &IdentPat) -> Option<Type>

It also includes the changes that binding mode makes in the type. For example in let ref x @ Some(_) = None the result of type_of_pat is Option<T> but the result of this function is &mut Option<T>

source

pub fn type_of_self(&self, param: &SelfParam) -> Option<Type>

source

pub fn pattern_adjustments(&self, pat: &Pat) -> SmallVec<[Type; 1]>

source

pub fn binding_mode_of_pat(&self, pat: &IdentPat) -> Option<BindingMode>

source

pub fn resolve_expr_as_callable(&self, call: &Expr) -> Option<Callable>

source

pub fn resolve_method_call(&self, call: &MethodCallExpr) -> Option<Function>

source

pub fn resolve_method_call_fallback( &self, call: &MethodCallExpr, ) -> Option<Either<Function, Field>>

Attempts to resolve this call expression as a method call falling back to resolving it as a field.

source

pub fn resolve_method_call_as_callable( &self, call: &MethodCallExpr, ) -> Option<Callable>

source

pub fn resolve_field( &self, field: &FieldExpr, ) -> Option<Either<Field, TupleField>>

source

pub fn resolve_field_fallback( &self, field: &FieldExpr, ) -> Option<Either<Either<Field, TupleField>, Function>>

source

pub fn resolve_record_field( &self, field: &RecordExprField, ) -> Option<(Field, Option<Local>, Type)>

source

pub fn resolve_record_pat_field( &self, field: &RecordPatField, ) -> Option<(Field, Type)>

source

pub fn resolve_macro_call(&self, macro_call: &MacroCall) -> Option<Macro>

source

pub fn is_proc_macro_call(&self, macro_call: &MacroCall) -> bool

source

pub fn resolve_macro_call_arm(&self, macro_call: &MacroCall) -> Option<u32>

source

pub fn is_unsafe_macro_call(&self, macro_call: &MacroCall) -> bool

source

pub fn resolve_attr_macro_call(&self, item: &Item) -> Option<Macro>

source

pub fn resolve_path(&self, path: &Path) -> Option<PathResolution>

source

pub fn resolve_mod_path( &self, scope: &SyntaxNode<RustLanguage>, path: &ModPath, ) -> Option<impl Iterator<Item = ItemInNs>>

source

pub fn resolve_bind_pat_to_const(&self, pat: &IdentPat) -> Option<ModuleDef>

source

pub fn record_literal_missing_fields( &self, literal: &RecordExpr, ) -> Vec<(Field, Type)>

source

pub fn record_pattern_missing_fields( &self, pattern: &RecordPat, ) -> Vec<(Field, Type)>

source

pub fn to_def<T>(&self, src: &T) -> Option<<T as ToDef>::Def>
where T: ToDef,

source

pub fn scope( &self, node: &SyntaxNode<RustLanguage>, ) -> Option<SemanticsScope<'db>>

source

pub fn scope_at_offset( &self, node: &SyntaxNode<RustLanguage>, offset: TextSize, ) -> Option<SemanticsScope<'db>>

source

pub fn source<Def>( &self, def: Def, ) -> Option<InFileWrapper<HirFileId, <Def as HasSource>::Ast>>
where Def: HasSource, <Def as HasSource>::Ast: AstNode,

Search for a definition’s source and cache its syntax tree

source

pub fn assert_contains_node(&self, node: &SyntaxNode<RustLanguage>)

source

pub fn is_unsafe_method_call(&self, method_call_expr: &MethodCallExpr) -> bool

source

pub fn is_unsafe_ref_expr(&self, ref_expr: &RefExpr) -> bool

source

pub fn is_unsafe_ident_pat(&self, ident_pat: &IdentPat) -> bool

source

pub fn is_inside_unsafe(&self, expr: &Expr) -> bool

Returns true if the node is inside an unsafe context.

Trait Implementations§

source§

impl<DB> Debug for Semantics<'_, DB>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl<'db, DB> Deref for Semantics<'db, DB>

source§

type Target = SemanticsImpl<'db>

The resulting type after dereferencing.
source§

fn deref(&self) -> &<Semantics<'db, DB> as Deref>::Target

Dereferences the value.

Auto Trait Implementations§

§

impl<'db, DB> !Freeze for Semantics<'db, DB>

§

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§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> Cast for T

§

fn cast<U>(self, interner: <U as HasInterner>::Interner) -> U
where Self: CastTo<U>, U: HasInterner,

Cast a value to type U using CastTo.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> IntoBox<dyn Any> for T
where T: Any,

§

fn into_box(self) -> Box<dyn Any>

Convert self into the appropriate boxed form.
source§

impl<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<'a, T> Captures<'a> for T
where T: ?Sized,