getSymbolsForPackage method

Future<List<ImportedSymbolSyntheticElement>> getSymbolsForPackage({
  1. required Package package,
})

Implementation

Future<List<ImportedSymbolSyntheticElement>> getSymbolsForPackage({required Package package}) async {
  final uri = getUriFromPackage(package);

  if (uri == null) {
    throw _SymbolResolvingException(package);
  }

  // TODO(mateusfccp): Improve this
  if (uri == '.') {
    return [];
  }

  final library = await analysisContextCollection.contexts.first.currentSession.getResolvedLibrary(uri);

  if (library is ResolvedLibraryResult) {
    return [
      for (var element in library.element.exportNamespace.definedNames.values) //
        if (_dartElementToPintoElement(element) case final element?) element,
    ];
  } else {
    throw _SymbolResolvingException(package);
  }
}