parseFile function

ParseStringResult parseFile (
  1. {@required String path,
  2. ResourceProvider resourceProvider,
  3. @required FeatureSet featureSet,
  4. bool throwIfDiagnostics: true}

Return the result of parsing the file at the given path.

If a resourceProvider is given, it will be used to access the file system.

featureSet determines what set of features will be assumed by the parser. This parameter is required because the analyzer does not yet have a performant way of computing the correct feature set for a single file to be parsed. Callers that need the feature set to be strictly correct must create an AnalysisContextCollection, query it to get an AnalysisContext, query it to get an AnalysisSession, and then call getParsedUnit.

Callers that don't need the feature set to be strictly correct can pass in FeatureSet.fromEnableFlags([]) to enable the default set of features; this is much more performant than using an analysis session, because it doesn't require the analyzer to process the SDK.

If throwIfDiagnostics is true (the default), then if any diagnostics are produced because of syntactic errors in the content an ArgumentError will be thrown. If the parameter is false, then the caller can check the result to see whether there are any errors.


ParseStringResult parseFile(
    {@required String path,
    ResourceProvider resourceProvider,
    @required FeatureSet featureSet,
    bool throwIfDiagnostics = true}) {
  if (featureSet == null) {
    throw ArgumentError('A non-null feature set must be provided.');
  resourceProvider ??= PhysicalResourceProvider.INSTANCE;
  var content = (resourceProvider.getResource(path) as File).readAsStringSync();
  return parseString(
      content: content,
      path: path,
      featureSet: featureSet,
      throwIfDiagnostics: throwIfDiagnostics);