Re: [analyzer-discuss] await context.currentSession.getResolvedUnit( path ); returns empty result

34 views
Skip to first unread message

Konstantin Shcheglov

unread,
Oct 18, 2021, 11:36:05 AM10/18/21
to analyzer...@dartlang.org

  `SomeResolvedUnitResult` as its name implies, is just some, not fully specified result.
  There are a few implementations of it, returned depending on whether the arguments or state are valid or invalid.
  What you are looking for is `ResolvedUnitResult`, which is returned when the result is valid.

  So, check the result of `resolveFile`, e.g.
  if (result is ResolvedUnitResult) { ... }

On Sun, Oct 17, 2021 at 9:04 AM Jumamidin Tashaliev <juma...@gmail.com> wrote:
import 'package:analyzer/dart/analysis/analysis_context.dart';
import 'package:analyzer/dart/analysis/analysis_context_collection.dart';
import 'package:analyzer/dart/analysis/results.dart';
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/file_system/physical_file_system.dart';

void main(List<String> args) async {
   SomeResolvedUnitResult result = await resolveFile(args.first);
   // result has empty property or methods
   CompilationUnit resolvedUnit = result.????;
   CompilationUnitElement? element = resolvedUnit.declaredElement;
}

Future<SomeResolvedUnitResult> resolveFile(String path) async {
    AnalysisContextCollection collection = new AnalysisContextCollection(
includedPaths: <String>[path],
resourceProvider: PhysicalResourceProvider.INSTANCE,
);
    AnalysisContext context = collection.contextFor(path);
    return await context.currentSession.getResolvedUnit(path);
}

Why is this happening?

--
You received this message because you are subscribed to the Google Groups "Dart Analyzer Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to analyzer-discu...@dartlang.org.
To view this discussion on the web visit https://groups.google.com/a/dartlang.org/d/msgid/analyzer-discuss/c1e6b4ee-f101-4469-bc8f-48de80b3bc9bn%40dartlang.org.


--
Konstantin Scheglov
Software Engineer
Google, Inc.
Reply all
Reply to author
Forward
0 new messages