GitHub

Original file line numberDiff line numberDiff line change

@@ -863,6 +863,33 @@ def expand_identifier(self, identifier: str) -> str:

863863

Returns:

864864

The expanded identifier.

865865

"""

866+

# Handle leading dots in the identifier:

867+

# - `.name` is a reference to the current object's `name` member.

868+

# - `..name` is a reference to the parent object's `name` member.

869+

# - etc.

870+

# TODO: We should update the protocol to allow modifying the title too.

871+

# In this case it would likely be better to strip dots from the title,

872+

# when it's not explicitly specified.

873+

if self.config.relative_crossrefs and identifier.startswith("."): # type: ignore[attr-defined]

874+

identifier = identifier[1:]

875+

obj = self.current_object

876+

while identifier and identifier[0] == ".":

877+

identifier = identifier[1:]

878+

obj = obj.parent # type: ignore[assignment]

879+

identifier = f"{obj.path}.{identifier}" if identifier else obj.path

880+
881+

# We resolve the identifier to its full path.

882+

# For this we take out the first name, resolve it, and then append the rest.

883+

if self.config.scoped_crossrefs: # type: ignore[attr-defined]

884+

if "." in identifier:

885+

identifier, remaining = identifier.split(".", 1)

886+

else:

887+

remaining = ""

888+

with suppress(Exception):

889+

identifier = self.current_object.resolve(identifier)

890+

if remaining:

891+

identifier = f"{identifier}.{remaining}"

892+
866893

return identifier

867894
868895

def get_context(self) -> AutorefsHookInterface.Context:

Read the original on github.com ↗