86 def _resolve_ref(self, ref: str) -> Optional[str]:
87 if ref.startswith('package:'):
88
89 uri = urlparse(ref)
90 (package_name, *path_to_file) = uri.path.split('/', 1)
91 package_path = self.packages[package_name]
92 if len(path_to_file) == 0:
93 return self._make_github_uri(package_path)
94 else:
95 return self._make_github_uri(
96 os.path.join(package_path, path_to_file[0]))
97 elif os.path.exists(ref):
98
99 return self._make_github_uri(ref)
100 else:
101
102 loc = self.symbols_index.try_resolve(ref)
103 if loc is not None:
104 return self._make_github_uri(loc.filename, loc.lineno)
105
106 logging.error('Failed to resolve xref %s', ref)
107 return None
108