]> git.lizzy.rs Git - rust.git/blobdiff - crates/ide-completion/src/context.rs
internal: Split flyimport into its 3 applicable contexts
[rust.git] / crates / ide-completion / src / context.rs
index e2bf4284f50091716a58d9eb66830d6d1a231a7e..5c408c0cc0594a95dc0db2b872948471d2c20c2e 100644 (file)
@@ -64,6 +64,8 @@ pub(crate) struct PathCompletionCtx {
     pub(super) kind: PathKind,
     /// Whether the path segment has type args or not.
     pub(super) has_type_args: bool,
+    /// Whether the qualifier comes from a use tree parent or not
+    pub(crate) use_tree_parent: bool,
 }
 
 impl PathCompletionCtx {
@@ -149,24 +151,18 @@ pub(super) enum ItemListKind {
 #[derive(Debug)]
 pub(super) enum Qualified {
     No,
-    With(PathQualifierCtx),
+    With {
+        path: ast::Path,
+        resolution: Option<PathResolution>,
+        /// Whether this path consists solely of `super` segments
+        is_super_chain: bool,
+    },
     /// <_>::
     Infer,
     /// Whether the path is an absolute path
     Absolute,
 }
 
-/// The path qualifier state of the path we are completing.
-#[derive(Debug)]
-pub(crate) struct PathQualifierCtx {
-    pub(crate) path: ast::Path,
-    pub(crate) resolution: Option<PathResolution>,
-    /// Whether this path consists solely of `super` segments
-    pub(crate) is_super_chain: bool,
-    /// Whether the qualifier comes from a use tree parent or not
-    pub(crate) use_tree_parent: bool,
-}
-
 /// The state of the pattern we are completing.
 #[derive(Debug)]
 pub(super) struct PatternContext {
@@ -332,8 +328,8 @@ pub(crate) struct CompletionContext<'a> {
     // FIXME: This shouldn't exist
     pub(super) previous_token: Option<SyntaxToken>,
 
+    // We might wanna split these out of CompletionContext
     pub(super) ident_ctx: IdentContext,
-
     pub(super) pattern_ctx: Option<PatternContext>,
     pub(super) qualifier_ctx: QualifierCtx,
 
@@ -366,55 +362,6 @@ pub(crate) fn famous_defs(&self) -> FamousDefs {
         FamousDefs(&self.sema, self.krate)
     }
 
-    pub(super) fn nameref_ctx(&self) -> Option<&NameRefContext> {
-        match &self.ident_ctx {
-            IdentContext::NameRef(it) => Some(it),
-            _ => None,
-        }
-    }
-
-    pub(super) fn name_ctx(&self) -> Option<&NameContext> {
-        match &self.ident_ctx {
-            IdentContext::Name(it) => Some(it),
-            _ => None,
-        }
-    }
-
-    pub(super) fn lifetime_ctx(&self) -> Option<&LifetimeContext> {
-        match &self.ident_ctx {
-            IdentContext::Lifetime(it) => Some(it),
-            _ => None,
-        }
-    }
-
-    pub(crate) fn dot_receiver(&self) -> Option<&ast::Expr> {
-        match self.nameref_ctx() {
-            Some(NameRefContext {
-                kind: Some(NameRefKind::DotAccess(DotAccess { receiver, .. })),
-                ..
-            }) => receiver.as_ref(),
-            _ => None,
-        }
-    }
-
-    pub(crate) fn has_dot_receiver(&self) -> bool {
-        self.dot_receiver().is_some()
-    }
-
-    pub(crate) fn path_context(&self) -> Option<&PathCompletionCtx> {
-        self.nameref_ctx().and_then(|ctx| match &ctx.kind {
-            Some(NameRefKind::Path(path)) => Some(path),
-            _ => None,
-        })
-    }
-
-    pub(crate) fn path_qual(&self) -> Option<&ast::Path> {
-        self.path_context().and_then(|it| match &it.qualified {
-            Qualified::With(it) => Some(&it.path),
-            _ => None,
-        })
-    }
-
     /// Checks if an item is visible and not `doc(hidden)` at the completion site.
     pub(crate) fn is_visible<I>(&self, item: &I) -> Visible
     where