pub(crate) fn parent_module(db: &RootDatabase, position: FilePosition) -> Vec<NavigationTarget> {
    let sema = Semantics::new(db);
    let source_file = sema.parse(position.file_id);

    let mut module = find_node_at_offset::<ast::Module>(source_file.syntax(), position.offset);

    // If cursor is literally on `mod foo`, go to the grandpa.
    if let Some(m) = &module {
        if !m
            .item_list()
            .map_or(false, |it| it.syntax().text_range().contains_inclusive(position.offset))
        {
            mark::hit!(test_resolve_parent_module_on_module_decl);
            module = m.syntax().ancestors().skip(1).find_map(ast::Module::cast);
        }
    }

    let module = match module {
        Some(module) => sema.to_def(&module),
        None => sema.to_module_def(position.file_id),
    };
    let module = match module {
        None => return Vec::new(),
        Some(it) => it,
    };
    let nav = NavigationTarget::from_module_to_decl(db, module);
    vec![nav]
}
/// This returns `Vec` because a module may be included from several places. We
/// don't handle this case yet though, so the Vec has length at most one.
This returns `Vec` because a module may be included from several places. We
don't handle this case yet though, so the Vec has length at most one.
This returns ` Vec ` because a module may be included from several places . We don ' t handle this case yet though so the Vec has length at most one .
pub(crate) fn parent_module(db: &RootDatabase, position: FilePosition) -> Vec<NavigationTarget> {
    let sema = Semantics::new(db);
    let source_file = sema.parse(position.file_id);
    let mut module = find_node_at_offset::<ast::Module>(source_file.syntax(), position.offset);
    // If cursor is literally on `mod foo`, go to the grandpa.
    if let Some(m) = &module {
        if !m
            .item_list()
            .map_or(false, |it| it.syntax().text_range().contains_inclusive(position.offset))
        {
            mark::hit!(test_resolve_parent_module_on_module_decl);
            module = m.syntax().ancestors().skip(1).find_map(ast::Module::cast);
        }
    }
    let module = match module {
        Some(module) => sema.to_def(&module),
        None => sema.to_module_def(position.file_id),
    };
    let module = match module {
        None => return Vec::new(),
        Some(it) => it,
    };
    let nav = NavigationTarget::from_module_to_decl(db, module);
    vec![nav]
}
pub ( crate ) fn parent_module ( db : & RootDatabase , position : FilePosition ) -> Vec < NavigationTarget > { let sema = Semantics :: new ( db ) ; let source_file = sema . parse ( position . file_id ) ; let mut module = find_node_at_offset :: < ast :: Module > ( source_file . syntax ( ) , position . offset ) ; // If cursor is literally on `mod foo`, go to the grandpa. if let Some ( m ) = & module { if ! m . item_list ( ) . map_or ( false , | it | it . syntax ( ) . text_range ( ) . contains_inclusive ( position . offset ) ) { mark :: hit ! ( test_resolve_parent_module_on_module_decl ) ; module = m . syntax ( ) . ancestors ( ) . skip ( 1 ) . find_map ( ast :: Module :: cast ) ; } } let module = match module { Some ( module ) => sema . to_def ( & module ) , None => sema . to_module_def ( position . file_id ) , } ; let module = match module { None => return Vec :: new ( ) , Some ( it ) => it , } ; let nav = NavigationTarget :: from_module_to_decl ( db , module ) ; vec ! [ nav ] }
This returns `Vec` because a module may be included from several places.
This returns ` Vec ` because a module may be included from several places .
db
&RootDatabase
position
FilePosition
db
&RootDatabase
position
FilePosition