Module references

Module references 

Source
Expand description

This module implements a reference search. First, the element at the cursor position must be either an ast::Name or ast::NameRef. If it’s an ast::NameRef, at the classification step we try to resolve the direct tree parent of this element, otherwise we already have a definition and just need to get its HIR together with some information that is needed for further steps of searching. After that, we collect files that might contain references and look for text occurrences of the identifier. If there’s an ast::NameRef at the index that the match starts at and its tree parent is resolved to the search element definition, we get a reference.

Special handling for constructors/initializations: When searching for references to a struct/enum/variant, if the cursor is positioned on:

  • { after a struct/enum/variant definition
  • ( for tuple structs/variants
  • ; for unit structs
  • The type name in a struct/enum/variant definition Then only constructor/initialization usages will be shown, filtering out other references.

Structs§

Declaration
Information about the declaration site of a searched item.
FindAllRefsConfig
ReferenceSearchResult
Result of a reference search operation.

Functions§

find_all_refs 🔒
Find all references to the item at the given position.
find_defs 🔒
handle_control_flow_keywords 🔒
is_enum_lit_name_ref 🔒
Checks if a name reference is part of an enum variant literal expression. Used to filter references when searching for enum variant constructors.
is_lit_name_ref 🔒
Checks if a name reference is used in a literal (constructor) context. Used to filter references when searching for struct/variant constructors.
name_for_constructor_search 🔒
Returns Some if the cursor is at a position where we should search for constructor/initialization usages. This is used to implement the special constructor search behavior when the cursor is on specific tokens in a struct/enum/variant definition.
path_ends_with 🔒
Checks if a path ends with the given name reference. Helper function for checking constructor usage patterns.
retain_adt_literal_usages 🔒
Filter out all non-literal usages for adt-defs