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: SyntaxTokenThe token before the cursor, in the original file.
token: SyntaxTokenThe token before the cursor, in the macro-expanded file.
krate: CrateThe crate of the current file.
display_target: DisplayTarget§module: ModuleThe module of the scope.
containing_function: Option<Function>The function where we’re completing, if inside a function.
is_nightly: boolWhether nightly toolchain is used. Cached since this is looked up a lot.
edition: EditionThe 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: usizeThe 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: CompleteSemicolonWhether and how to complete semicolon for unit-returning functions.
Implementations§
Source§impl CompletionContext<'_>
impl CompletionContext<'_>
Sourcepub(crate) fn source_range(&self) -> TextRange
pub(crate) fn source_range(&self) -> TextRange
The range of the identifier that is being completed.
pub(crate) fn famous_defs(&self) -> FamousDefs<'_, '_>
Sourcepub(crate) fn def_is_visible(&self, item: &ScopeDef) -> Visible
pub(crate) fn def_is_visible(&self, item: &ScopeDef) -> Visible
Checks if an item is visible and not doc(hidden) at the completion site.
Sourcepub(crate) fn is_visible<I>(&self, item: &I) -> Visiblewhere
I: HasVisibility + HasAttrs + HasCrate + Copy,
pub(crate) fn is_visible<I>(&self, item: &I) -> Visiblewhere
I: HasVisibility + HasAttrs + HasCrate + Copy,
Checks if an item is visible, not doc(hidden) and stable at the completion site.
pub(crate) fn doc_aliases<I>(&self, item: &I) -> Vec<SmolStr>where
I: HasAttrs + Copy,
Check if an item is #[doc(hidden)].
Sourcepub(crate) fn check_stability(&self, attrs: Option<&AttrsWithOwner>) -> bool
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.
Sourcepub(crate) fn is_ops_trait(&self, trait_: Trait) -> bool
pub(crate) fn is_ops_trait(&self, trait_: Trait) -> bool
Whether the given trait is an operator trait or not.
Sourcepub(crate) fn is_doc_notable_trait(&self, trait_: Trait) -> bool
pub(crate) fn is_doc_notable_trait(&self, trait_: Trait) -> bool
Whether the given trait has #[doc(notable_trait)]
Sourcepub(crate) fn traits_in_scope(&self) -> VisibleTraits
pub(crate) fn traits_in_scope(&self) -> VisibleTraits
Returns the traits in scope, with the Drop trait removed.
pub(crate) fn iterate_path_candidates( &self, ty: &Type<'_>, cb: impl FnMut(AssocItem), )
Sourcepub(crate) fn process_all_names(
&self,
f: &mut dyn FnMut(Name, ScopeDef, Vec<SmolStr>),
)
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.
pub(crate) fn process_all_names_raw(&self, f: &mut dyn FnMut(Name, ScopeDef))
fn is_visible_impl( &self, vis: &Visibility, attrs: &AttrsWithOwner, defining_crate: Crate, ) -> Visible
pub(crate) fn doc_aliases_in_scope(&self, scope_def: ScopeDef) -> Vec<SmolStr>
Source§impl<'db> CompletionContext<'db>
impl<'db> CompletionContext<'db>
pub(crate) fn new( db: &'db RootDatabase, position: FilePosition, config: &'db CompletionConfig<'db>, trigger_character: Option<char>, ) -> Option<(CompletionContext<'db>, CompletionAnalysis<'db>)>
Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T, R> CollectAndApply<T, R> for T
impl<T, R> CollectAndApply<T, R> for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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