contextRootContaining method
Return the context root containing the file at the given filePath
.
Implementation
ContextRoot? contextRootContaining(String filePath) {
var pathContext = resourceProvider.pathContext;
/// Return `true` if the given [child] is either the same as or within the
/// given [parent].
bool isOrWithin(String parent, String child) {
return parent == child || pathContext.isWithin(parent, child);
}
/// Return `true` if the given context [root] contains the target [file].
bool ownsFile(ContextRoot root) {
if (isOrWithin(root.root, filePath)) {
var excludedPaths = root.exclude;
for (var excludedPath in excludedPaths) {
if (isOrWithin(excludedPath, filePath)) {
return false;
}
}
return true;
}
return false;
}
for (var root in driverMap.keys) {
if (ownsFile(root)) {
return root;
}
}
return null;
}