@@ -27,7 +27,10 @@ use ide_db::SymbolKind;
2727use syntax:: ast;
2828
2929use crate :: {
30- context:: Visible ,
30+ context:: {
31+ ItemListKind , NameContext , NameKind , NameRefContext , NameRefKind , PathKind , PatternContext ,
32+ TypeLocation , Visible ,
33+ } ,
3134 item:: Builder ,
3235 render:: {
3336 const_:: render_const,
@@ -437,3 +440,120 @@ fn enum_variants_with_paths(
437440 }
438441 }
439442}
443+
444+ pub ( super ) fn complete_name (
445+ acc : & mut Completions ,
446+ ctx : & CompletionContext ,
447+ NameContext { name, kind } : & NameContext ,
448+ ) {
449+ match kind {
450+ NameKind :: Const => {
451+ item_list:: trait_impl:: complete_trait_impl_const ( acc, ctx, name) ;
452+ }
453+ NameKind :: Function => {
454+ item_list:: trait_impl:: complete_trait_impl_fn ( acc, ctx, name) ;
455+ }
456+ NameKind :: IdentPat ( pattern_ctx) => complete_patterns ( acc, ctx, pattern_ctx) ,
457+ NameKind :: Module ( mod_under_caret) => {
458+ mod_:: complete_mod ( acc, ctx, mod_under_caret) ;
459+ }
460+ NameKind :: TypeAlias => {
461+ item_list:: trait_impl:: complete_trait_impl_type_alias ( acc, ctx, name) ;
462+ }
463+ NameKind :: RecordField => {
464+ field:: complete_field_list_record_variant ( acc, ctx) ;
465+ }
466+ NameKind :: ConstParam
467+ | NameKind :: Enum
468+ | NameKind :: MacroDef
469+ | NameKind :: MacroRules
470+ | NameKind :: Rename
471+ | NameKind :: SelfParam
472+ | NameKind :: Static
473+ | NameKind :: Struct
474+ | NameKind :: Trait
475+ | NameKind :: TypeParam
476+ | NameKind :: Union
477+ | NameKind :: Variant => ( ) ,
478+ }
479+ }
480+
481+ pub ( super ) fn complete_name_ref (
482+ acc : & mut Completions ,
483+ ctx : & CompletionContext ,
484+ NameRefContext { nameref, kind } : & NameRefContext ,
485+ ) {
486+ match kind {
487+ NameRefKind :: Path ( path_ctx) => {
488+ flyimport:: import_on_the_fly_path ( acc, ctx, path_ctx) ;
489+ match & path_ctx. kind {
490+ PathKind :: Expr { expr_ctx } => {
491+ dot:: complete_undotted_self ( acc, ctx, path_ctx, expr_ctx) ;
492+ expr:: complete_expr_path ( acc, ctx, path_ctx, expr_ctx) ;
493+ item_list:: complete_item_list_in_expr ( acc, ctx, path_ctx, expr_ctx) ;
494+ record:: complete_record_expr_func_update ( acc, ctx, path_ctx, expr_ctx) ;
495+ snippet:: complete_expr_snippet ( acc, ctx, path_ctx, expr_ctx) ;
496+ }
497+ PathKind :: Type { location } => {
498+ r#type:: complete_type_path ( acc, ctx, path_ctx, location) ;
499+ match location {
500+ TypeLocation :: TupleField => {
501+ field:: complete_field_list_tuple_variant ( acc, ctx, path_ctx) ;
502+ }
503+ TypeLocation :: TypeAscription ( ascription) => {
504+ r#type:: complete_ascribed_type ( acc, ctx, path_ctx, ascription) ;
505+ }
506+ TypeLocation :: GenericArgList ( _)
507+ | TypeLocation :: TypeBound
508+ | TypeLocation :: ImplTarget
509+ | TypeLocation :: ImplTrait
510+ | TypeLocation :: Other => ( ) ,
511+ }
512+ }
513+ PathKind :: Attr { attr_ctx } => {
514+ attribute:: complete_attribute ( acc, ctx, path_ctx, attr_ctx) ;
515+ }
516+ PathKind :: Derive { existing_derives } => {
517+ attribute:: complete_derive ( acc, ctx, path_ctx, existing_derives) ;
518+ }
519+ PathKind :: Item { kind } => {
520+ item_list:: complete_item_list ( acc, ctx, path_ctx, kind) ;
521+ snippet:: complete_item_snippet ( acc, ctx, path_ctx, kind) ;
522+ if let ItemListKind :: TraitImpl ( impl_) = kind {
523+ item_list:: trait_impl:: complete_trait_impl_item_by_name (
524+ acc, ctx, path_ctx, nameref, impl_,
525+ ) ;
526+ }
527+ }
528+ PathKind :: Pat { .. } => {
529+ pattern:: complete_pattern_path ( acc, ctx, path_ctx) ;
530+ }
531+ PathKind :: Vis { has_in_token } => {
532+ vis:: complete_vis_path ( acc, ctx, path_ctx, has_in_token) ;
533+ }
534+ PathKind :: Use => {
535+ use_:: complete_use_tree ( acc, ctx, path_ctx, nameref) ;
536+ }
537+ }
538+ }
539+ NameRefKind :: DotAccess ( dot_access) => {
540+ flyimport:: import_on_the_fly_dot ( acc, ctx, dot_access) ;
541+ dot:: complete_dot ( acc, ctx, dot_access) ;
542+ postfix:: complete_postfix ( acc, ctx, dot_access) ;
543+ }
544+ NameRefKind :: Keyword ( item) => {
545+ keyword:: complete_for_and_where ( acc, ctx, item) ;
546+ }
547+ NameRefKind :: RecordExpr ( record_expr) => {
548+ record:: complete_record_expr_fields ( acc, ctx, record_expr) ;
549+ }
550+ NameRefKind :: Pattern ( pattern_ctx) => complete_patterns ( acc, ctx, pattern_ctx) ,
551+ }
552+ }
553+
554+ fn complete_patterns ( acc : & mut Completions , ctx : & CompletionContext , pattern_ctx : & PatternContext ) {
555+ flyimport:: import_on_the_fly_pat ( acc, ctx, pattern_ctx) ;
556+ fn_param:: complete_fn_param ( acc, ctx, pattern_ctx) ;
557+ pattern:: complete_pattern ( acc, ctx, pattern_ctx) ;
558+ record:: complete_record_pattern_fields ( acc, ctx, pattern_ctx) ;
559+ }
0 commit comments