@@ -38,6 +38,7 @@ import 'package:analyzer/src/summary/format.dart';
3838import 'package:analyzer/src/summary/idl.dart' ;
3939import 'package:analyzer/src/summary/package_bundle_reader.dart' ;
4040import 'package:analyzer/src/summary2/informative_data.dart' ;
41+ import 'package:analyzer/src/workspace/workspace.dart' ;
4142import 'package:convert/convert.dart' ;
4243import 'package:crypto/crypto.dart' ;
4344import 'package:meta/meta.dart' ;
@@ -91,6 +92,11 @@ class FileState {
9192 /// The [Source] of the file with the [uri] .
9293 final Source source;
9394
95+ /// The [WorkspacePackage] that contains this file.
96+ ///
97+ /// It might be `null` if the file is outside of the workspace.
98+ final WorkspacePackage workspacePackage;
99+
94100 /// Return `true` if this file is a stub created for a file in the provided
95101 /// external summary store. The values of most properties are not the same
96102 /// as they would be if the file were actually read from the file system.
@@ -144,6 +150,7 @@ class FileState {
144150 this .path,
145151 this .uri,
146152 this .source,
153+ this .workspacePackage,
147154 this ._contextFeatureSet,
148155 this ._packageLanguageVersion,
149156 ) : isInExternalSummaries = false ;
@@ -152,6 +159,7 @@ class FileState {
152159 : isInExternalSummaries = true ,
153160 path = null ,
154161 source = null ,
162+ workspacePackage = null ,
155163 _exists = true ,
156164 _contextFeatureSet = null ,
157165 _packageLanguageVersion = null {
@@ -734,6 +742,7 @@ class FileSystemState {
734742 final ByteStore _byteStore;
735743 final FileContentOverlay _contentOverlay;
736744 final SourceFactory _sourceFactory;
745+ final Workspace _workspace;
737746 final AnalysisOptions _analysisOptions;
738747 final DeclaredVariables _declaredVariables;
739748 final Uint32List _saltForUnlinked;
@@ -793,6 +802,7 @@ class FileSystemState {
793802 this ._resourceProvider,
794803 this .contextName,
795804 this ._sourceFactory,
805+ this ._workspace,
796806 this ._analysisOptions,
797807 this ._declaredVariables,
798808 this ._saltForUnlinked,
@@ -814,8 +824,8 @@ class FileSystemState {
814824 FileState get unresolvedFile {
815825 if (_unresolvedFile == null ) {
816826 var featureSet = FeatureSet .fromEnableFlags ([]);
817- _unresolvedFile = FileState ._(
818- this , null , null , null , featureSet, ExperimentStatus .currentVersion);
827+ _unresolvedFile = FileState ._(this , null , null , null , null , featureSet,
828+ ExperimentStatus .currentVersion);
819829 _unresolvedFile.refresh ();
820830 }
821831 return _unresolvedFile;
@@ -841,11 +851,12 @@ class FileSystemState {
841851 }
842852 // Create a new file.
843853 FileSource uriSource = FileSource (resource, uri);
854+ WorkspacePackage workspacePackage = _workspace? .findPackageFor (path);
844855 FeatureSet featureSet = featureSetProvider.getFeatureSet (path, uri);
845856 Version packageLanguageVersion =
846857 featureSetProvider.getLanguageVersion (path, uri);
847- file = FileState ._(
848- this , path, uri, uriSource, featureSet, packageLanguageVersion);
858+ file = FileState ._(this , path, uri, uriSource, workspacePackage,
859+ featureSet, packageLanguageVersion);
849860 _uriToFile[uri] = file;
850861 _addFileWithPath (path, file);
851862 _pathToCanonicalFile[path] = file;
@@ -884,11 +895,12 @@ class FileSystemState {
884895 String path = uriSource.fullName;
885896 File resource = _resourceProvider.getFile (path);
886897 FileSource source = FileSource (resource, uri);
898+ WorkspacePackage workspacePackage = _workspace? .findPackageFor (path);
887899 FeatureSet featureSet = featureSetProvider.getFeatureSet (path, uri);
888900 Version packageLanguageVersion =
889901 featureSetProvider.getLanguageVersion (path, uri);
890- file = FileState ._(
891- this , path, uri, source, featureSet, packageLanguageVersion);
902+ file = FileState ._(this , path, uri, source, workspacePackage, featureSet,
903+ packageLanguageVersion);
892904 _uriToFile[uri] = file;
893905 _addFileWithPath (path, file);
894906 file.refresh (allowCached: true );
0 commit comments