CompletionContext

Struct CompletionContext 

Source
pub(crate) struct CompletionContext<'a> {
Show 22 fields pub(crate) sema: Semantics<'a, RootDatabase>, pub(crate) scope: SemanticsScope<'a>, pub(crate) db: &'a RootDatabase, pub(crate) config: &'a CompletionConfig<'a>, pub(crate) position: FilePosition, pub(crate) trigger_character: Option<char>, pub(crate) original_token: SyntaxToken, pub(crate) token: SyntaxToken, pub(crate) krate: Crate, pub(crate) display_target: DisplayTarget, pub(crate) module: Module, pub(crate) containing_function: Option<Function>, pub(crate) is_nightly: bool, pub(crate) edition: Edition, pub(crate) expected_name: Option<NameOrNameRef>, pub(crate) expected_type: Option<Type<'a>>, pub(crate) qualifier_ctx: QualifierCtx, pub(crate) locals: FxHashMap<Name, Local>, pub(crate) depth_from_crate_root: usize, pub(crate) exclude_flyimport: FxHashMap<ModuleDef, AutoImportExclusionType>, pub(crate) exclude_traits: FxHashSet<Trait>, pub(crate) complete_semicolon: CompleteSemicolon,
}
Expand description

CompletionContext is created early during completion to figure out, where exactly is the cursor, syntax-wise.

Fields§

§sema: Semantics<'a, RootDatabase>§scope: SemanticsScope<'a>§db: &'a RootDatabase§config: &'a CompletionConfig<'a>§position: FilePosition§trigger_character: Option<char>§original_token: SyntaxToken

The token before the cursor, in the original file.

§token: SyntaxToken

The token before the cursor, in the macro-expanded file.

§krate: Crate

The crate of the current file.

§display_target: DisplayTarget§module: Module

The module of the scope.

§containing_function: Option<Function>

The function where we’re completing, if inside a function.

§is_nightly: bool

Whether nightly toolchain is used. Cached since this is looked up a lot.

§edition: Edition

The edition of the current crate

§expected_name: Option<NameOrNameRef>

The expected name of what we are completing. This is usually the parameter name of the function argument we are completing.

§expected_type: Option<Type<'a>>

The expected type of what we are completing.

§qualifier_ctx: QualifierCtx§locals: FxHashMap<Name, Local>§depth_from_crate_root: usize

The module depth of the current module of the cursor position.

  • crate-root
  • mod foo
  • mod bar

Here depth will be 2

§exclude_flyimport: FxHashMap<ModuleDef, AutoImportExclusionType>

Traits whose methods will be excluded from flyimport. Flyimport should not suggest importing those traits.

Note the trait themselves are not excluded, only their methods are.

§exclude_traits: FxHashSet<Trait>

Traits whose methods should always be excluded, even when in scope (compare exclude_flyimport_traits). They will not be excluded, however, if they are available as a generic bound.

Note the trait themselves are not excluded, only their methods are.

§complete_semicolon: CompleteSemicolon

Whether and how to complete semicolon for unit-returning functions.

Implementations§

Source§

impl CompletionContext<'_>

Source

pub(crate) fn source_range(&self) -> TextRange

The range of the identifier that is being completed.

Source

pub(crate) fn famous_defs(&self) -> FamousDefs<'_, '_>

Source

pub(crate) fn def_is_visible(&self, item: &ScopeDef) -> Visible

Checks if an item is visible and not doc(hidden) at the completion site.

Source

pub(crate) fn is_visible<I>(&self, item: &I) -> Visible
where I: HasVisibility + HasAttrs + HasCrate + Copy,

Checks if an item is visible, not doc(hidden) and stable at the completion site.

Source

pub(crate) fn doc_aliases<I>(&self, item: &I) -> Vec<SmolStr>
where I: HasAttrs + Copy,

Source

pub(crate) fn is_item_hidden(&self, item: &ItemInNs) -> bool

Check if an item is #[doc(hidden)].

Source

pub(crate) fn check_stability(&self, attrs: Option<&AttrsWithOwner>) -> bool

Checks whether this item should be listed in regards to stability. Returns true if we should.

Source

pub(crate) fn check_stability_and_hidden<I>(&self, item: I) -> bool
where I: HasAttrs + HasCrate,

Source

pub(crate) fn is_ops_trait(&self, trait_: Trait) -> bool

Whether the given trait is an operator trait or not.

Source

pub(crate) fn is_doc_notable_trait(&self, trait_: Trait) -> bool

Whether the given trait has #[doc(notable_trait)]

Source

pub(crate) fn traits_in_scope(&self) -> VisibleTraits

Returns the traits in scope, with the Drop trait removed.

Source

pub(crate) fn iterate_path_candidates( &self, ty: &Type<'_>, cb: impl FnMut(AssocItem), )

Source

pub(crate) fn process_all_names( &self, f: &mut dyn FnMut(Name, ScopeDef, Vec<SmolStr>), )

A version of [SemanticsScope::process_all_names] that filters out #[doc(hidden)] items and passes all doc-aliases along, to funnel it into Completions::add_path_resolution.

Source

pub(crate) fn process_all_names_raw(&self, f: &mut dyn FnMut(Name, ScopeDef))

Source

fn is_scope_def_hidden(&self, scope_def: ScopeDef) -> bool

Source

fn is_visible_impl( &self, vis: &Visibility, attrs: &AttrsWithOwner, defining_crate: Crate, ) -> Visible

Source

pub(crate) fn is_doc_hidden( &self, attrs: &AttrsWithOwner, defining_crate: Crate, ) -> bool

Source

pub(crate) fn doc_aliases_in_scope(&self, scope_def: ScopeDef) -> Vec<SmolStr>

Source§

impl<'db> CompletionContext<'db>

Source

pub(crate) fn new( db: &'db RootDatabase, position: FilePosition, config: &'db CompletionConfig<'db>, trigger_character: Option<char>, ) -> Option<(CompletionContext<'db>, CompletionAnalysis<'db>)>

Trait Implementations§

Source§

impl<'a> Debug for CompletionContext<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> !Freeze for CompletionContext<'a>

§

impl<'a> !RefUnwindSafe for CompletionContext<'a>

§

impl<'a> !Send for CompletionContext<'a>

§

impl<'a> !Sync for CompletionContext<'a>

§

impl<'a> Unpin for CompletionContext<'a>

§

impl<'a> !UnwindSafe for CompletionContext<'a>

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, R> CollectAndApply<T, R> for T

§

fn collect_and_apply<I, F>(iter: I, f: F) -> R
where I: Iterator<Item = T>, F: FnOnce(&[T]) -> R,

Equivalent to f(&iter.collect::<Vec<_>>()).

§

type Output = R

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<I, T, U> Upcast<I, U> for T
where U: UpcastFrom<I, T>,

§

fn upcast(self, interner: I) -> U

§

impl<I, T> UpcastFrom<I, T> for T

§

fn upcast_from(from: T, _tcx: I) -> T

§

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,