@@ -22,6 +22,14 @@ class Modules {
22
22
23
23
// The Dart server path to library import uri
24
24
final _sourceToLibrary = < String , Uri > {};
25
+
26
+ // The Dart server path to library/part import uri
27
+ final _sourceToLibraryOrPart = < String , Uri > {};
28
+
29
+ // Library import uri to list of script (parts) dart server path for the
30
+ // library.
31
+ final _scriptsForLibrary = < Uri , List <String >> {};
32
+
25
33
var _moduleMemoizer = AsyncMemoizer <void >();
26
34
27
35
final Map <String , String > _libraryToModule = {};
@@ -45,7 +53,18 @@ class Modules {
45
53
assert (_entrypoint == entrypoint);
46
54
for (final library in modifiedModuleReport.modifiedLibraries) {
47
55
final libraryServerPath = _getLibraryServerPath (library);
48
- _sourceToLibrary.remove (libraryServerPath);
56
+ final libraryUri = _sourceToLibrary.remove (libraryServerPath);
57
+ _sourceToLibraryOrPart.remove (libraryServerPath);
58
+ if (libraryUri != null ) {
59
+ final scriptServerPaths = _scriptsForLibrary[libraryUri];
60
+ if (scriptServerPaths != null ) {
61
+ for (final scriptServerPath in scriptServerPaths) {
62
+ _sourceToLibraryOrPart.remove (scriptServerPath);
63
+ _sourceToLibrary.remove (scriptServerPath);
64
+ }
65
+ _scriptsForLibrary.remove (libraryUri);
66
+ }
67
+ }
49
68
_sourceToModule.remove (libraryServerPath);
50
69
_libraryToModule.remove (library);
51
70
}
@@ -57,6 +76,8 @@ class Modules {
57
76
}
58
77
_entrypoint = entrypoint;
59
78
_sourceToLibrary.clear ();
79
+ _sourceToLibraryOrPart.clear ();
80
+ _scriptsForLibrary.clear ();
60
81
_sourceToModule.clear ();
61
82
_libraryToModule.clear ();
62
83
_moduleToSources.clear ();
@@ -81,6 +102,13 @@ class Modules {
81
102
return _sourceToLibrary[serverPath];
82
103
}
83
104
105
+ /// Returns the importUri of the library or part for the provided Dart server
106
+ /// path.
107
+ Future <Uri ?> libraryOrPartForSource (String serverPath) async {
108
+ await _moduleMemoizer.runOnce (_initializeMapping);
109
+ return _sourceToLibraryOrPart[serverPath];
110
+ }
111
+
84
112
Future <String ?> moduleForLibrary (String libraryUri) async {
85
113
await _moduleMemoizer.runOnce (_initializeMapping);
86
114
return _libraryToModule[libraryUri];
@@ -106,7 +134,8 @@ class Modules {
106
134
? library
107
135
: DartUri (library, _root).serverPath;
108
136
109
- /// Initializes [_sourceToModule] , [_moduleToSources] , and [_sourceToLibrary] .
137
+ /// Initializes [_sourceToModule] , [_moduleToSources] , [_sourceToLibrary] and
138
+ /// [_sourceToLibraryOrPart] .
110
139
///
111
140
/// If [modifiedModuleReport] is not null, only updates the maps for the
112
141
/// modified libraries in the report.
@@ -126,6 +155,7 @@ class Modules {
126
155
// it, so it's okay to only process the modified libraries.
127
156
continue ;
128
157
}
158
+ final libraryUri = Uri .parse (library);
129
159
final scripts = libraryToScripts[library]! ;
130
160
final libraryServerPath = _getLibraryServerPath (library);
131
161
@@ -134,15 +164,17 @@ class Modules {
134
164
135
165
_sourceToModule[libraryServerPath] = module;
136
166
_moduleToSources.putIfAbsent (module, () => {}).add (libraryServerPath);
137
- _sourceToLibrary[libraryServerPath] = Uri .parse (library);
167
+ _sourceToLibrary[libraryServerPath] = libraryUri;
168
+ _sourceToLibraryOrPart[libraryServerPath] = libraryUri;
138
169
_libraryToModule[library] = module;
139
170
140
171
for (final script in scripts) {
141
172
final scriptServerPath = _getLibraryServerPath (script);
142
-
143
173
_sourceToModule[scriptServerPath] = module;
144
174
_moduleToSources[module]! .add (scriptServerPath);
145
- _sourceToLibrary[scriptServerPath] = Uri .parse (library);
175
+ _sourceToLibrary[scriptServerPath] = libraryUri;
176
+ _sourceToLibraryOrPart[scriptServerPath] = Uri .parse (script);
177
+ (_scriptsForLibrary[libraryUri] ?? = []).add (scriptServerPath);
146
178
}
147
179
} else {
148
180
_logger.warning ('No module found for library $library ' );
0 commit comments