mirror of
https://github.com/dart-lang/sdk
synced 2024-10-04 16:44:59 +00:00
Remove more dead code from analysis server
R=devoncarew@google.com Review-Url: https://codereview.chromium.org/2949103003 .
This commit is contained in:
parent
e28064f405
commit
a420a1fbb5
|
@ -25,15 +25,11 @@
|
|||
* ...
|
||||
* }
|
||||
*/
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:analysis_server/protocol/protocol_generated.dart'
|
||||
show AnalysisService;
|
||||
import 'package:analysis_server/src/plugin/server_plugin.dart';
|
||||
import 'package:analyzer/src/generated/engine.dart'
|
||||
show AnalysisContext, ResultChangedEvent;
|
||||
import 'package:analyzer/src/generated/engine.dart' show AnalysisContext;
|
||||
import 'package:analyzer/src/generated/source.dart' show Source;
|
||||
import 'package:analyzer/task/model.dart' show ResultDescriptor;
|
||||
import 'package:plugin/plugin.dart';
|
||||
|
||||
/**
|
||||
|
@ -58,17 +54,6 @@ typedef void SetAnalysisDomain(AnalysisDomain domain);
|
|||
* Clients may not extend, implement or mix-in this class.
|
||||
*/
|
||||
abstract class AnalysisDomain {
|
||||
/**
|
||||
* Return the stream that is notified when a new value for the given
|
||||
* [result] is computed or invalidated.
|
||||
*
|
||||
* This method should be used by plugins that need to perform some additional
|
||||
* processing after analysis has completed. One example would be a plugin that
|
||||
* needed to send a notification to the client because some data was now
|
||||
* invalidated.
|
||||
*/
|
||||
Stream<ResultChangedEvent> onResultChanged(ResultDescriptor result);
|
||||
|
||||
/**
|
||||
* Schedule sending the given [service] notifications for the given [source]
|
||||
* in the given [context].
|
||||
|
|
|
@ -319,12 +319,6 @@ class AnalysisServer {
|
|||
*/
|
||||
final AnalysisOptionsImpl defaultContextOptions = new AnalysisOptionsImpl();
|
||||
|
||||
/**
|
||||
* The controller for sending [ContextsChangedEvent]s.
|
||||
*/
|
||||
StreamController<ContextsChangedEvent> _onContextsChangedController =
|
||||
new StreamController<ContextsChangedEvent>.broadcast();
|
||||
|
||||
/**
|
||||
* The file resolver provider used to override the way file URI's are
|
||||
* resolved in some contexts.
|
||||
|
@ -483,13 +477,6 @@ class AnalysisServer {
|
|||
handlers = serverPlugin.createDomains(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the [AnalysisContext]s that are being used to analyze the analysis
|
||||
* roots.
|
||||
*/
|
||||
Iterable<AnalysisContext> get analysisContexts =>
|
||||
contextManager.analysisContexts;
|
||||
|
||||
/**
|
||||
* Return a list of the globs used to determine which files should be analyzed.
|
||||
*/
|
||||
|
@ -516,12 +503,6 @@ class AnalysisServer {
|
|||
*/
|
||||
Map<Folder, nd.AnalysisDriver> get driverMap => contextManager.driverMap;
|
||||
|
||||
/**
|
||||
* Return a table mapping [Folder]s to the [AnalysisContext]s associated with
|
||||
* them.
|
||||
*/
|
||||
Map<Folder, AnalysisContext> get folderMap => contextManager.folderMap;
|
||||
|
||||
/**
|
||||
* The [Future] that completes when analysis is complete.
|
||||
*/
|
||||
|
@ -542,12 +523,6 @@ class AnalysisServer {
|
|||
return _onAnalysisStartedController.stream;
|
||||
}
|
||||
|
||||
/**
|
||||
* The stream that is notified when contexts are added or removed.
|
||||
*/
|
||||
Stream<ContextsChangedEvent> get onContextsChanged =>
|
||||
_onContextsChangedController.stream;
|
||||
|
||||
/**
|
||||
* The stream that is notified when a single file has been added. This exists
|
||||
* as a temporary stopgap for plugins, until the official plugin API is
|
||||
|
@ -686,19 +661,6 @@ class AnalysisServer {
|
|||
return new AstProviderForDriver(analysisDriver);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the [AnalysisContext] for the "innermost" context whose associated
|
||||
* folder is or contains the given path. ("innermost" refers to the nesting
|
||||
* of contexts, so if there is a context for path /foo and a context for
|
||||
* path /foo/bar, then the innermost context containing /foo/bar/baz.dart is
|
||||
* the context for /foo/bar.)
|
||||
*
|
||||
* If no context contains the given path, `null` is returned.
|
||||
*/
|
||||
AnalysisContext getContainingContext(String path) {
|
||||
return contextManager.getContextFor(path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the [nd.AnalysisDriver] for the "innermost" context whose associated
|
||||
* folder is or contains the given path. ("innermost" refers to the nesting
|
||||
|
@ -770,23 +732,6 @@ class AnalysisServer {
|
|||
return result?.unit;
|
||||
}
|
||||
|
||||
// TODO(brianwilkerson) Add the following method after 'prioritySources' has
|
||||
// been added to InternalAnalysisContext.
|
||||
// /**
|
||||
// * Return a list containing the full names of all of the sources that are
|
||||
// * priority sources.
|
||||
// */
|
||||
// List<String> getPriorityFiles() {
|
||||
// List<String> priorityFiles = new List<String>();
|
||||
// folderMap.values.forEach((ContextDirectory directory) {
|
||||
// InternalAnalysisContext context = directory.context;
|
||||
// context.prioritySources.forEach((Source source) {
|
||||
// priorityFiles.add(source.fullName);
|
||||
// });
|
||||
// });
|
||||
// return priorityFiles;
|
||||
// }
|
||||
|
||||
/**
|
||||
* Handle a [request] that was read from the communication channel.
|
||||
*/
|
||||
|
@ -924,9 +869,12 @@ class AnalysisServer {
|
|||
if (roots == null) {
|
||||
operationQueue.clear();
|
||||
} else {
|
||||
for (AnalysisContext context in _getContexts(roots)) {
|
||||
operationQueue.contextRemoved(context);
|
||||
}
|
||||
// TODO(brianwilkerson) All of the contexts returned by _getContexts will
|
||||
// be null. If we are still using the operation queue, then this needs to
|
||||
// be changed to use drivers.
|
||||
// for (AnalysisContext context in _getContexts(roots)) {
|
||||
// operationQueue.contextRemoved(context);
|
||||
// }
|
||||
}
|
||||
// Instruct the contextDirectoryManager to rebuild all contexts from
|
||||
// scratch.
|
||||
|
@ -1314,20 +1262,6 @@ class AnalysisServer {
|
|||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a set of all contexts whose associated folder is contained within,
|
||||
* or equal to, one of the resources in the given list of [resources].
|
||||
*/
|
||||
Set<AnalysisContext> _getContexts(List<Resource> resources) {
|
||||
Set<AnalysisContext> contexts = new HashSet<AnalysisContext>();
|
||||
resources.forEach((Resource resource) {
|
||||
if (resource is Folder) {
|
||||
contexts.addAll(contextManager.contextsInAnalysisRoot(resource));
|
||||
}
|
||||
});
|
||||
return contexts;
|
||||
}
|
||||
|
||||
bool _hasAnalysisServiceSubscription(AnalysisService service, String file) {
|
||||
return analysisServices[service]?.contains(file) ?? false;
|
||||
}
|
||||
|
@ -1378,10 +1312,10 @@ class AnalysisServer {
|
|||
if (index == null) {
|
||||
return;
|
||||
}
|
||||
onContextsChanged.listen((ContextsChangedEvent event) {
|
||||
// TODO(brianwilkerson) `onContextsChanged` should never have anything
|
||||
// written to it. Figure out whether we need something like this under the
|
||||
// new analysis driver, and remove this method if not.
|
||||
// TODO(brianwilkerson) onContextsChanged never has anything written to it.
|
||||
// Figure out whether we need something like this under the new analysis
|
||||
// driver, and remove this method if not.
|
||||
// onContextsChanged.listen((ContextsChangedEvent event) {
|
||||
// for (AnalysisContext context in event.added) {
|
||||
// context
|
||||
// .onResultChanged(RESOLVED_UNIT3)
|
||||
|
@ -1405,7 +1339,7 @@ class AnalysisServer {
|
|||
// for (AnalysisContext context in event.removed) {
|
||||
// index.removeContext(context);
|
||||
// }
|
||||
});
|
||||
// });
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1423,27 +1357,6 @@ class AnalysisServerOptions {
|
|||
bool enableVerboseFlutterCompletions = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Information about a file - an [AnalysisContext] that analyses the file,
|
||||
* and the [Source] representing the file in this context.
|
||||
*/
|
||||
class ContextSourcePair {
|
||||
/**
|
||||
* A context that analysis the file.
|
||||
* May be `null` if the file is not analyzed by any context.
|
||||
*/
|
||||
final AnalysisContext context;
|
||||
|
||||
/**
|
||||
* The source that corresponds to the file.
|
||||
* May be `null` if the file is not a regular file.
|
||||
* If the file cannot be found in the [context], then it has a `file` uri.
|
||||
*/
|
||||
final Source source;
|
||||
|
||||
ContextSourcePair(this.context, this.source);
|
||||
}
|
||||
|
||||
/**
|
||||
* A [PriorityChangeEvent] indicates the set the priority files has changed.
|
||||
*/
|
||||
|
@ -1579,19 +1492,6 @@ class ServerContextManagerCallbacks extends ContextManagerCallbacks {
|
|||
return analysisDriver;
|
||||
}
|
||||
|
||||
@override
|
||||
AnalysisContext addContext(Folder folder, AnalysisOptions options) {
|
||||
ContextBuilder builder = createContextBuilder(folder, options);
|
||||
AnalysisContext context = builder.buildContext(folder.path);
|
||||
|
||||
analysisServer.folderMap[folder] = context;
|
||||
analysisServer._onContextsChangedController
|
||||
.add(new ContextsChangedEvent(added: [context]));
|
||||
analysisServer.schedulePerformAnalysisOperation(context);
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
@override
|
||||
void applyChangesToContext(Folder contextFolder, ChangeSet changeSet) {
|
||||
nd.AnalysisDriver analysisDriver = analysisServer.driverMap[contextFolder];
|
||||
|
@ -1674,13 +1574,6 @@ class ServerContextManagerCallbacks extends ContextManagerCallbacks {
|
|||
driver.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
void updateContextPackageUriResolver(AnalysisContext context) {
|
||||
analysisServer._onContextsChangedController
|
||||
.add(new ContextsChangedEvent(changed: [context]));
|
||||
analysisServer.schedulePerformAnalysisOperation(context);
|
||||
}
|
||||
|
||||
List<HighlightRegion> _computeHighlightRegions(CompilationUnit unit) {
|
||||
if (analysisServer.options.useAnalysisHighlight2) {
|
||||
return new DartUnitHighlightsComputer2(unit).compute();
|
||||
|
|
|
@ -93,11 +93,6 @@ class ContextInfo {
|
|||
*/
|
||||
AnalysisDriver analysisDriver;
|
||||
|
||||
/**
|
||||
* The analysis context that was created for the [folder].
|
||||
*/
|
||||
AnalysisContext context;
|
||||
|
||||
/**
|
||||
* Map from full path to the [Source] object, for each source that has been
|
||||
* added to the context.
|
||||
|
@ -225,7 +220,6 @@ abstract class ContextManager {
|
|||
// setting the default analysis options
|
||||
// setting the default content cache
|
||||
// setting the default SDK
|
||||
// maintaining AnalysisContext.folderMap (or remove it)
|
||||
// telling server when a context has been added or removed (see onContextsChanged)
|
||||
// telling server when a context needs to be re-analyzed
|
||||
// notifying the client when results should be flushed
|
||||
|
@ -233,12 +227,6 @@ abstract class ContextManager {
|
|||
//
|
||||
// TODO(brianwilkerson) Move this class to a public library.
|
||||
|
||||
/**
|
||||
* Return the [AnalysisContext]s that are being used to analyze the analysis
|
||||
* roots.
|
||||
*/
|
||||
Iterable<AnalysisContext> get analysisContexts;
|
||||
|
||||
/**
|
||||
* Get the callback interface used to create, destroy, and update contexts.
|
||||
*/
|
||||
|
@ -260,12 +248,6 @@ abstract class ContextManager {
|
|||
*/
|
||||
List<String> get excludedPaths;
|
||||
|
||||
/**
|
||||
* Return a table mapping [Folder]s to the [AnalysisContext]s associated with
|
||||
* them.
|
||||
*/
|
||||
Map<Folder, AnalysisContext> get folderMap;
|
||||
|
||||
/**
|
||||
* Return the list of included paths (folders and files) most recently passed
|
||||
* to [setRoots].
|
||||
|
@ -273,16 +255,8 @@ abstract class ContextManager {
|
|||
List<String> get includedPaths;
|
||||
|
||||
/**
|
||||
* Return a list of all of the contexts reachable from the given
|
||||
* [analysisRoot] (the context associated with [analysisRoot] and all of its
|
||||
* descendants).
|
||||
*/
|
||||
List<AnalysisContext> contextsInAnalysisRoot(Folder analysisRoot);
|
||||
|
||||
/**
|
||||
* Like [getDriverFor] and [getContextFor], but returns the [Folder] which
|
||||
* allows plugins to create & manage their own tree of drivers just like using
|
||||
* [getDriverFor].
|
||||
* Like [getDriverFor], but returns the [Folder] which allows plugins to
|
||||
* create & manage their own tree of drivers just like using [getDriverFor].
|
||||
*
|
||||
* This folder should be the root of analysis context, not just the containing
|
||||
* folder of the path (like basename), as this is NOT just a file API.
|
||||
|
@ -292,17 +266,6 @@ abstract class ContextManager {
|
|||
*/
|
||||
Folder getContextFolderFor(String path);
|
||||
|
||||
/**
|
||||
* Return the [AnalysisContext] for the "innermost" context whose associated
|
||||
* folder is or contains the given path. ("innermost" refers to the nesting
|
||||
* of contexts, so if there is a context for path /foo and a context for
|
||||
* path /foo/bar, then the innermost context containing /foo/bar/baz.dart is
|
||||
* the context for /foo/bar.)
|
||||
*
|
||||
* If no context contains the given path, `null` is returned.
|
||||
*/
|
||||
AnalysisContext getContextFor(String path);
|
||||
|
||||
/**
|
||||
* Return the [AnalysisDriver] for the "innermost" context whose associated
|
||||
* folder is or contains the given path. ("innermost" refers to the nesting
|
||||
|
@ -333,6 +296,12 @@ abstract class ContextManager {
|
|||
*/
|
||||
bool isInAnalysisRoot(String path);
|
||||
|
||||
/**
|
||||
* Return the number of contexts reachable from the given [analysisRoot] (the
|
||||
* context associated with [analysisRoot] and all of its descendants).
|
||||
*/
|
||||
int numberOfContextsInAnalysisRoot(Folder analysisRoot);
|
||||
|
||||
/**
|
||||
* Rebuild the set of contexts from scratch based on the data last sent to
|
||||
* [setRoots]. Only contexts contained in the given list of analysis [roots]
|
||||
|
@ -372,12 +341,6 @@ abstract class ContextManagerCallbacks {
|
|||
AnalysisDriver addAnalysisDriver(
|
||||
Folder folder, ContextRoot contextRoot, AnalysisOptions options);
|
||||
|
||||
/**
|
||||
* Create and return a new analysis context rooted at the given [folder], with
|
||||
* the given analysis [options].
|
||||
*/
|
||||
AnalysisContext addContext(Folder folder, AnalysisOptions options);
|
||||
|
||||
/**
|
||||
* Called when the set of files associated with a context have changed (or
|
||||
* some of those files have been modified). [changeSet] is the set of
|
||||
|
@ -419,11 +382,6 @@ abstract class ContextManagerCallbacks {
|
|||
* (they will no longer be analyzed by any context).
|
||||
*/
|
||||
void removeContext(Folder folder, List<String> flushedFiles);
|
||||
|
||||
/**
|
||||
* Called when the package resolution for the given [context] has changed.
|
||||
*/
|
||||
void updateContextPackageUriResolver(AnalysisContext context);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -569,37 +527,6 @@ class ContextManagerImpl implements ContextManager {
|
|||
pathContext = resourceProvider.pathContext;
|
||||
}
|
||||
|
||||
@override
|
||||
Iterable<AnalysisContext> get analysisContexts => folderMap.values;
|
||||
|
||||
Map<Folder, AnalysisContext> get folderMap {
|
||||
throw new StateError('Should not be used with the new analysis driver');
|
||||
}
|
||||
|
||||
@override
|
||||
List<AnalysisContext> contextsInAnalysisRoot(Folder analysisRoot) {
|
||||
List<AnalysisContext> contexts = <AnalysisContext>[];
|
||||
ContextInfo innermostContainingInfo =
|
||||
_getInnermostContextInfoFor(analysisRoot.path);
|
||||
void addContextAndDescendants(ContextInfo info) {
|
||||
contexts.add(info.context);
|
||||
info.children.forEach(addContextAndDescendants);
|
||||
}
|
||||
|
||||
if (innermostContainingInfo != null) {
|
||||
if (analysisRoot == innermostContainingInfo.folder) {
|
||||
addContextAndDescendants(innermostContainingInfo);
|
||||
} else {
|
||||
for (ContextInfo info in innermostContainingInfo.children) {
|
||||
if (analysisRoot.isOrContains(info.folder.path)) {
|
||||
addContextAndDescendants(info);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return contexts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if this map defines embedded libraries.
|
||||
*/
|
||||
|
@ -609,11 +536,6 @@ class ContextManagerImpl implements ContextManager {
|
|||
return _getInnermostContextInfoFor(path)?.folder;
|
||||
}
|
||||
|
||||
@override
|
||||
AnalysisContext getContextFor(String path) {
|
||||
return _getInnermostContextInfoFor(path)?.context;
|
||||
}
|
||||
|
||||
/**
|
||||
* For testing: get the [ContextInfo] object for the given [folder], if any.
|
||||
*/
|
||||
|
@ -684,51 +606,28 @@ class ContextManagerImpl implements ContextManager {
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process [options] for the given context [info].
|
||||
*/
|
||||
void processOptionsForContext(ContextInfo info, Map<String, Object> options,
|
||||
{bool optionsRemoved: false}) {
|
||||
if (options == null && !optionsRemoved) {
|
||||
return;
|
||||
@override
|
||||
int numberOfContextsInAnalysisRoot(Folder analysisRoot) {
|
||||
int count = 0;
|
||||
void addContextAndDescendants(ContextInfo info) {
|
||||
count++;
|
||||
info.children.forEach(addContextAndDescendants);
|
||||
}
|
||||
|
||||
AnalysisOptionsImpl analysisOptions;
|
||||
if (optionsRemoved) {
|
||||
// In case options files are removed, revert to defaults.
|
||||
analysisOptions = new AnalysisOptionsImpl.from(defaultContextOptions);
|
||||
// Apply inherited options.
|
||||
options = _toStringMap(_getEmbeddedOptions(info));
|
||||
} else {
|
||||
analysisOptions =
|
||||
new AnalysisOptionsImpl.from(info.context.analysisOptions);
|
||||
// Check for embedded options.
|
||||
Map embeddedOptions = _getEmbeddedOptions(info);
|
||||
if (embeddedOptions != null) {
|
||||
options = _toStringMap(new Merger().merge(embeddedOptions, options));
|
||||
}
|
||||
}
|
||||
if (options != null) {
|
||||
applyToAnalysisOptions(analysisOptions, options);
|
||||
}
|
||||
info.context.analysisOptions = analysisOptions;
|
||||
|
||||
// Nothing more to do.
|
||||
if (options == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
var analyzer = options[AnalyzerOptions.analyzer];
|
||||
if (analyzer is Map) {
|
||||
// Set ignore patterns.
|
||||
var exclude = analyzer[AnalyzerOptions.exclude];
|
||||
if (exclude is YamlList) {
|
||||
List<String> excludeList = toStringList(exclude);
|
||||
if (excludeList != null) {
|
||||
setIgnorePatternsForContext(info, excludeList);
|
||||
ContextInfo innermostContainingInfo =
|
||||
_getInnermostContextInfoFor(analysisRoot.path);
|
||||
if (innermostContainingInfo != null) {
|
||||
if (analysisRoot == innermostContainingInfo.folder) {
|
||||
addContextAndDescendants(innermostContainingInfo);
|
||||
} else {
|
||||
for (ContextInfo info in innermostContainingInfo.children) {
|
||||
if (analysisRoot.isOrContains(info.folder.path)) {
|
||||
addContextAndDescendants(info);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -924,7 +823,7 @@ class ContextManagerImpl implements ContextManager {
|
|||
continue;
|
||||
}
|
||||
// do add the file
|
||||
Source source = createSourceInContext(info.context, child);
|
||||
Source source = createSourceInContext(info.analysisDriver, child);
|
||||
changeSet.addedSource(source);
|
||||
info.sources[path] = source;
|
||||
} else if (child is Folder) {
|
||||
|
@ -962,7 +861,7 @@ class ContextManagerImpl implements ContextManager {
|
|||
// add files, recurse into folders
|
||||
if (child is File) {
|
||||
if (_shouldFileBeAnalyzed(child)) {
|
||||
Source source = createSourceInContext(info.context, child);
|
||||
Source source = createSourceInContext(info.analysisDriver, child);
|
||||
changeSet.addedSource(source);
|
||||
info.sources[path] = source;
|
||||
}
|
||||
|
@ -1256,10 +1155,9 @@ class ContextManagerImpl implements ContextManager {
|
|||
|
||||
/**
|
||||
* Set up a [SourceFactory] that resolves packages as appropriate for the
|
||||
* given [disposition].
|
||||
* given [folder].
|
||||
*/
|
||||
SourceFactory _createSourceFactory(
|
||||
InternalAnalysisContext context, AnalysisOptions options, Folder folder) {
|
||||
SourceFactory _createSourceFactory(AnalysisOptions options, Folder folder) {
|
||||
ContextBuilder builder = callbacks.createContextBuilder(folder, options);
|
||||
return builder.createSourceFactory(folder.path, options);
|
||||
}
|
||||
|
@ -1665,59 +1563,26 @@ class ContextManagerImpl implements ContextManager {
|
|||
ContextInfo info = getContextInfoFor(contextFolder);
|
||||
AnalysisDriver driver = info.analysisDriver;
|
||||
SourceFactory sourceFactory =
|
||||
_createSourceFactory(null, driver.analysisOptions, contextFolder);
|
||||
_createSourceFactory(driver.analysisOptions, contextFolder);
|
||||
driver.configure(sourceFactory: sourceFactory);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create and return a source representing the given [file] within the given
|
||||
* [context].
|
||||
* [driver].
|
||||
*/
|
||||
static Source createSourceInContext(AnalysisContext context, File file) {
|
||||
static Source createSourceInContext(AnalysisDriver driver, File file) {
|
||||
// TODO(brianwilkerson) Optimize this, by allowing support for source
|
||||
// factories to restore URI's from a file path rather than a source.
|
||||
Source source = file.createSource();
|
||||
if (context == null) {
|
||||
if (driver == null) {
|
||||
return source;
|
||||
}
|
||||
Uri uri = context.sourceFactory.restoreUri(source);
|
||||
Uri uri = driver.sourceFactory.restoreUri(source);
|
||||
return file.createSource(uri);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* An indication that one or more contexts were added, changed, or removed.
|
||||
*
|
||||
* The lists of [added], [changed] and [removed] contexts will not contain
|
||||
* duplications (that is, a single context will not be in any list multiple
|
||||
* times), nor will there be any overlap between the lists (that is, a single
|
||||
* context will not be in more than one list).
|
||||
*/
|
||||
class ContextsChangedEvent {
|
||||
/**
|
||||
* The contexts that were added to the server.
|
||||
*/
|
||||
final List<AnalysisContext> added;
|
||||
|
||||
/**
|
||||
* The contexts that were changed.
|
||||
*/
|
||||
final List<AnalysisContext> changed;
|
||||
|
||||
/**
|
||||
* The contexts that were removed from the server.
|
||||
*/
|
||||
final List<AnalysisContext> removed;
|
||||
|
||||
/**
|
||||
* Initialize a newly created event to indicate which contexts have changed.
|
||||
*/
|
||||
ContextsChangedEvent(
|
||||
{this.added: AnalysisContext.EMPTY_LIST,
|
||||
this.changed: AnalysisContext.EMPTY_LIST,
|
||||
this.removed: AnalysisContext.EMPTY_LIST});
|
||||
}
|
||||
|
||||
/**
|
||||
* Concrete [FolderDisposition] object indicating that the context for a given
|
||||
* folder should resolve package URIs using a custom URI resolver.
|
||||
|
@ -1752,8 +1617,8 @@ class CustomPackageResolverDisposition extends FolderDisposition {
|
|||
|
||||
/**
|
||||
* An instance of the class [FolderDisposition] represents the information
|
||||
* gathered by the [ContextManagerImpl] to determine how to create an
|
||||
* [AnalysisContext] for a given folder.
|
||||
* gathered by the [ContextManagerImpl] to determine how to create an analysis
|
||||
* driver for a given folder.
|
||||
*
|
||||
* Note: [ContextManagerImpl] may use equality testing and hash codes to
|
||||
* determine when two folders should share the same context, so derived classes
|
||||
|
|
|
@ -20,7 +20,6 @@ import 'package:analysis_server/src/plugin/request_converter.dart';
|
|||
import 'package:analysis_server/src/plugin/result_merger.dart';
|
||||
import 'package:analysis_server/src/protocol/protocol_internal.dart';
|
||||
import 'package:analysis_server/src/protocol_server.dart';
|
||||
import 'package:analysis_server/src/services/dependencies/library_dependencies.dart';
|
||||
import 'package:analyzer/dart/ast/ast.dart';
|
||||
import 'package:analyzer/error/error.dart' as engine;
|
||||
import 'package:analyzer/exception/exception.dart';
|
||||
|
@ -103,22 +102,26 @@ class AnalysisDomainHandler extends AbstractRequestHandler {
|
|||
new AnalysisGetHoverResult(hovers).toResponse(request.id));
|
||||
}
|
||||
|
||||
/// Implement the `analysis.getLibraryDependencies` request.
|
||||
/**
|
||||
* Implement the `analysis.getLibraryDependencies` request.
|
||||
*/
|
||||
Response getLibraryDependencies(Request request) {
|
||||
server.onAnalysisComplete.then((_) {
|
||||
LibraryDependencyCollector collector =
|
||||
new LibraryDependencyCollector(server.analysisContexts);
|
||||
Set<String> libraries = collector.collectLibraryDependencies();
|
||||
Map<String, Map<String, List<String>>> packageMap =
|
||||
collector.calculatePackageMap(server.folderMap);
|
||||
server.sendResponse(new AnalysisGetLibraryDependenciesResult(
|
||||
libraries.toList(growable: false), packageMap)
|
||||
.toResponse(request.id));
|
||||
}).catchError((error, st) {
|
||||
server.sendResponse(new Response.serverError(request, error, st));
|
||||
});
|
||||
// delay response
|
||||
return Response.DELAYED_RESPONSE;
|
||||
return new Response.unsupportedFeature(request.id,
|
||||
'Please contact the Dart analyzer team if you need this request.');
|
||||
// server.onAnalysisComplete.then((_) {
|
||||
// LibraryDependencyCollector collector =
|
||||
// new LibraryDependencyCollector(server.analysisContexts);
|
||||
// Set<String> libraries = collector.collectLibraryDependencies();
|
||||
// Map<String, Map<String, List<String>>> packageMap =
|
||||
// collector.calculatePackageMap(server.folderMap);
|
||||
// server.sendResponse(new AnalysisGetLibraryDependenciesResult(
|
||||
// libraries.toList(growable: false), packageMap)
|
||||
// .toResponse(request.id));
|
||||
// }).catchError((error, st) {
|
||||
// server.sendResponse(new Response.serverError(request, error, st));
|
||||
// });
|
||||
// // delay response
|
||||
// return Response.DELAYED_RESPONSE;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -429,20 +432,12 @@ class AnalysisDomainImpl implements AnalysisDomain {
|
|||
<ResultDescriptor, StreamController<engine.ResultChangedEvent>>{};
|
||||
|
||||
AnalysisDomainImpl(this.server) {
|
||||
server.onContextsChanged.listen((ContextsChangedEvent event) {
|
||||
event.added.forEach(_subscribeForContext);
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Stream<engine.ResultChangedEvent> onResultChanged(
|
||||
ResultDescriptor descriptor) {
|
||||
Stream<engine.ResultChangedEvent> stream =
|
||||
controllers.putIfAbsent(descriptor, () {
|
||||
return new StreamController<engine.ResultChangedEvent>.broadcast();
|
||||
}).stream;
|
||||
server.analysisContexts.forEach(_subscribeForContext);
|
||||
return stream;
|
||||
// TODO(brianwilkerson) The onContextsChanged stream is no longer written to.
|
||||
// Figure out whether this code still needs to be here and convert it to use
|
||||
// the analysis driver if it does.
|
||||
// server.onContextsChanged.listen((ContextsChangedEvent event) {
|
||||
// event.added.forEach(_subscribeForContext);
|
||||
// });
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
|
@ -91,11 +91,14 @@ void scheduleNotificationOperations(
|
|||
CompilationUnit parsedDartUnit,
|
||||
CompilationUnit resolvedDartUnit,
|
||||
List<AnalysisError> errors) {
|
||||
// TODO(brianwilkerson) The `containingContext` will always be `null`. If this
|
||||
// check is still useful, we should re-write it to use drivers.
|
||||
//
|
||||
// If the file belongs to any analysis root, check whether we're in it now.
|
||||
AnalysisContext containingContext = server.getContainingContext(file);
|
||||
if (containingContext != null && context != containingContext) {
|
||||
return;
|
||||
}
|
||||
// AnalysisContext containingContext = server.getContainingContext(file);
|
||||
// if (containingContext != null && context != containingContext) {
|
||||
// return;
|
||||
// }
|
||||
// Dart
|
||||
CompilationUnit dartUnit = resolvedDartUnit ?? parsedDartUnit;
|
||||
if (resolvedDartUnit != null) {
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
library test.context.directory.manager;
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:collection';
|
||||
|
||||
import 'package:analysis_server/src/context_manager.dart';
|
||||
import 'package:analysis_server/src/plugin/notification_manager.dart';
|
||||
|
@ -169,10 +168,9 @@ test_pack:lib/''');
|
|||
manager.setRoots(<String>[projPath], <String>[], <String, String>{});
|
||||
await pumpEventQueue();
|
||||
// Confirm that one context was created.
|
||||
var contexts =
|
||||
manager.contextsInAnalysisRoot(resourceProvider.newFolder(projPath));
|
||||
expect(contexts, isNotNull);
|
||||
expect(contexts.length, equals(1));
|
||||
int count = manager
|
||||
.numberOfContextsInAnalysisRoot(resourceProvider.newFolder(projPath));
|
||||
expect(count, equals(1));
|
||||
var source = sourceFactory.forUri('dart:foobar');
|
||||
expect(source, isNotNull);
|
||||
expect(source.fullName, '/my/proj/sdk_ext/entry.dart');
|
||||
|
@ -402,10 +400,9 @@ test_pack:lib/''');
|
|||
// Setup context.
|
||||
manager.setRoots(<String>[projPath], <String>[], <String, String>{});
|
||||
// Confirm that one context was created.
|
||||
var contexts =
|
||||
manager.contextsInAnalysisRoot(resourceProvider.newFolder(projPath));
|
||||
expect(contexts, isNotNull);
|
||||
expect(contexts.length, equals(1));
|
||||
int count = manager
|
||||
.numberOfContextsInAnalysisRoot(resourceProvider.newFolder(projPath));
|
||||
expect(count, equals(1));
|
||||
var source = sourceFactory.forUri('dart:foobar');
|
||||
expect(source.fullName, equals('/my/proj/sdk_ext/entry.dart'));
|
||||
}
|
||||
|
@ -1762,12 +1759,8 @@ abstract class ContextManagerTest {
|
|||
* TODO(brianwilkerson) This doesn't add the strong mode processor when using
|
||||
* the new analysis driver.
|
||||
*/
|
||||
ErrorProcessor getProcessor(AnalysisError error) =>
|
||||
callbacks.currentDriver == null
|
||||
? ErrorProcessor.getProcessor(
|
||||
callbacks.currentContext.analysisOptions, error)
|
||||
: errorProcessors.firstWhere((ErrorProcessor p) => p.appliesTo(error),
|
||||
orElse: () => null);
|
||||
ErrorProcessor getProcessor(AnalysisError error) => errorProcessors
|
||||
.firstWhere((ErrorProcessor p) => p.appliesTo(error), orElse: () => null);
|
||||
|
||||
String newFile(List<String> pathComponents, [String content = '']) {
|
||||
String filePath = path.posix.joinAll(pathComponents);
|
||||
|
@ -2118,10 +2111,9 @@ linter:
|
|||
await pumpEventQueue();
|
||||
|
||||
// Confirm that one context was created.
|
||||
var contexts =
|
||||
manager.contextsInAnalysisRoot(resourceProvider.newFolder(projPath));
|
||||
expect(contexts, isNotNull);
|
||||
expect(contexts, hasLength(1));
|
||||
int count = manager
|
||||
.numberOfContextsInAnalysisRoot(resourceProvider.newFolder(projPath));
|
||||
expect(count, equals(1));
|
||||
|
||||
// Verify options.
|
||||
// * from `_embedder.yaml`:
|
||||
|
@ -2530,11 +2522,6 @@ class TestContextManagerCallbacks extends ContextManagerCallbacks {
|
|||
*/
|
||||
int now = 0;
|
||||
|
||||
/**
|
||||
* The analysis context that was created.
|
||||
*/
|
||||
AnalysisContext currentContext;
|
||||
|
||||
/**
|
||||
* The analysis driver that was created.
|
||||
*/
|
||||
|
@ -2602,9 +2589,7 @@ class TestContextManagerCallbacks extends ContextManagerCallbacks {
|
|||
/**
|
||||
* Return the current set of analysis options.
|
||||
*/
|
||||
AnalysisOptions get analysisOptions => currentDriver == null
|
||||
? currentContext.analysisOptions
|
||||
: currentDriver.analysisOptions;
|
||||
AnalysisOptions get analysisOptions => currentDriver?.analysisOptions;
|
||||
|
||||
/**
|
||||
* Return the paths to the context roots that currently exist.
|
||||
|
@ -2618,14 +2603,7 @@ class TestContextManagerCallbacks extends ContextManagerCallbacks {
|
|||
*/
|
||||
Iterable<String> get currentFilePaths {
|
||||
if (currentDriver == null) {
|
||||
if (currentContext == null) {
|
||||
return <String>[];
|
||||
}
|
||||
Map<String, int> fileMap = currentContextFilePaths[currentContext.name];
|
||||
if (fileMap == null) {
|
||||
return <String>[];
|
||||
}
|
||||
return fileMap.keys;
|
||||
return <String>[];
|
||||
}
|
||||
return currentDriver.addedFiles;
|
||||
}
|
||||
|
@ -2633,9 +2611,7 @@ class TestContextManagerCallbacks extends ContextManagerCallbacks {
|
|||
/**
|
||||
* Return the current source factory.
|
||||
*/
|
||||
SourceFactory get sourceFactory => currentDriver == null
|
||||
? currentContext.sourceFactory
|
||||
: currentDriver.sourceFactory;
|
||||
SourceFactory get sourceFactory => currentDriver?.sourceFactory;
|
||||
|
||||
@override
|
||||
AnalysisDriver addAnalysisDriver(
|
||||
|
@ -2670,20 +2646,6 @@ class TestContextManagerCallbacks extends ContextManagerCallbacks {
|
|||
return currentDriver;
|
||||
}
|
||||
|
||||
@override
|
||||
AnalysisContext addContext(Folder folder, AnalysisOptions options) {
|
||||
String path = folder.path;
|
||||
expect(currentContextRoots, isNot(contains(path)));
|
||||
currentContextTimestamps[path] = now;
|
||||
currentContextFilePaths[path] = <String, int>{};
|
||||
currentContextSources[path] = new HashSet<Source>();
|
||||
|
||||
ContextBuilder builder = createContextBuilder(folder, options);
|
||||
currentContext = builder.buildContext(path);
|
||||
currentContext.name = path;
|
||||
return currentContext;
|
||||
}
|
||||
|
||||
@override
|
||||
void applyChangesToContext(Folder contextFolder, ChangeSet changeSet) {
|
||||
AnalysisDriver driver = driverMap[contextFolder.path];
|
||||
|
@ -2697,26 +2659,6 @@ class TestContextManagerCallbacks extends ContextManagerCallbacks {
|
|||
changeSet.removedSources.forEach((source) {
|
||||
driver.removeFile(source.fullName);
|
||||
});
|
||||
} else {
|
||||
Map<String, int> filePaths = currentContextFilePaths[contextFolder.path];
|
||||
Set<Source> sources = currentContextSources[contextFolder.path];
|
||||
|
||||
for (Source source in changeSet.addedSources) {
|
||||
expect(filePaths, isNot(contains(source.fullName)));
|
||||
filePaths[source.fullName] = now;
|
||||
sources.add(source);
|
||||
}
|
||||
for (Source source in changeSet.removedSources) {
|
||||
expect(filePaths, contains(source.fullName));
|
||||
filePaths.remove(source.fullName);
|
||||
sources.remove(source);
|
||||
}
|
||||
for (Source source in changeSet.changedSources) {
|
||||
expect(filePaths, contains(source.fullName));
|
||||
filePaths[source.fullName] = now;
|
||||
}
|
||||
|
||||
currentContext.applyChanges(changeSet);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2759,11 +2701,7 @@ class TestContextManagerCallbacks extends ContextManagerCallbacks {
|
|||
*/
|
||||
Iterable<Source> currentFileSources(String contextPath) {
|
||||
if (currentDriver == null) {
|
||||
if (currentContext == null) {
|
||||
return <Source>[];
|
||||
}
|
||||
Set<Source> sources = currentContextSources[contextPath];
|
||||
return sources ?? <Source>[];
|
||||
return <Source>[];
|
||||
}
|
||||
AnalysisDriver driver = driverMap[contextPath];
|
||||
SourceFactory sourceFactory = driver.sourceFactory;
|
||||
|
@ -2780,14 +2718,7 @@ class TestContextManagerCallbacks extends ContextManagerCallbacks {
|
|||
*/
|
||||
Iterable<String> getCurrentFilePaths(String contextPath) {
|
||||
if (currentDriver == null) {
|
||||
if (currentContext == null) {
|
||||
return <String>[];
|
||||
}
|
||||
Map<String, int> fileMap = currentContextFilePaths[contextPath];
|
||||
if (fileMap == null) {
|
||||
return <String>[];
|
||||
}
|
||||
return fileMap.keys;
|
||||
return <String>[];
|
||||
}
|
||||
return driverMap[contextPath].addedFiles;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue