Update DeclarationsTracker when a context options change.

E.g. when .packages changes, we want to re-scan the context for new
available libraries. We also don't want to discard all context, and
resend everything.

R=brianwilkerson@google.com

Bug: https://github.com/Dart-Code/Dart-Code/issues/1723
Change-Id: I19ee71c1d021fb9bcda9d02d86b7cbb078704aa7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/103320
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
Konstantin Shcheglov
2019-05-21 18:43:36 +00:00
committed by commit-bot@chromium.org
parent 181685b852
commit cfdcfe2bfe
6 changed files with 55 additions and 25 deletions
@@ -891,6 +891,11 @@ class ServerContextManagerCallbacks extends ContextManagerCallbacks {
analysisServer._onAnalysisSetChangedController.add(null);
}
@override
void analysisOptionsUpdated(nd.AnalysisDriver driver) {
analysisServer.updateContextInDeclarationsTracker(driver);
}
@override
void applyChangesToContext(Folder contextFolder, ChangeSet changeSet) {
nd.AnalysisDriver analysisDriver = analysisServer.driverMap[contextFolder];
@@ -291,4 +291,9 @@ abstract class AbstractAnalysisServer {
declarationsTracker?.changeFile(path);
analysisDriverScheduler.notify(null);
}
void updateContextInDeclarationsTracker(nd.AnalysisDriver driver) {
declarationsTracker?.discardContext(driver.analysisContext);
declarationsTracker?.addContext(driver.analysisContext);
}
}
@@ -354,6 +354,11 @@ abstract class ContextManagerCallbacks {
*/
void afterWatchEvent(WatchEvent event);
/**
* Called when analysis options or URI resolution in the [driver] are changed.
*/
void analysisOptionsUpdated(AnalysisDriver driver);
/**
* 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
@@ -1630,6 +1635,7 @@ class ContextManagerImpl implements ContextManager {
contextRoot: driver.contextRoot);
SourceFactory factory = builder.createSourceFactory(contextRoot, options);
driver.configure(analysisOptions: options, sourceFactory: factory);
callbacks.analysisOptionsUpdated(driver);
}
void _updateContextPackageUriResolver(Folder contextFolder) {
@@ -88,9 +88,6 @@ class LspAnalysisServer extends AbstractAnalysisServer {
*/
RefactoringWorkspace _refactoringWorkspace;
RefactoringWorkspace get refactoringWorkspace => _refactoringWorkspace ??=
new RefactoringWorkspace(driverMap.values, searchEngine);
/**
* The versions of each document known to the server (keyed by path), used to
* send back to the client for server-initiated edits so that the client can
@@ -199,6 +196,9 @@ class LspAnalysisServer extends AbstractAnalysisServer {
Future<void> get exited => channel.closed;
RefactoringWorkspace get refactoringWorkspace => _refactoringWorkspace ??=
new RefactoringWorkspace(driverMap.values, searchEngine);
addPriorityFile(String path) {
final didAdd = priorityFiles.add(path);
assert(didAdd);
@@ -328,6 +328,28 @@ class LspAnalysisServer extends AbstractAnalysisServer {
));
}
/// Logs an exception by sending it to the client (window/logMessage) and
/// recording it in a buffer on the server for diagnostics.
void logException(String message, exception, stackTrace) {
if (exception is CaughtException) {
stackTrace ??= exception.stackTrace;
}
final fullError = stackTrace == null ? message : '$message\n$stackTrace';
// Log the full message since showMessage above may be truncated or formatted
// badly (eg. VS Code takes the newlines out).
logErrorToClient(fullError);
// remember the last few exceptions
exceptions.add(new ServerException(
message,
exception,
stackTrace is StackTrace ? stackTrace : null,
false,
));
}
void publishDiagnostics(String path, List<Diagnostic> errors) {
final params =
new PublishDiagnosticsParams(Uri.file(path).toString(), errors);
@@ -416,28 +438,6 @@ class LspAnalysisServer extends AbstractAnalysisServer {
logException(message, exception, stackTrace);
}
/// Logs an exception by sending it to the client (window/logMessage) and
/// recording it in a buffer on the server for diagnostics.
void logException(String message, exception, stackTrace) {
if (exception is CaughtException) {
stackTrace ??= exception.stackTrace;
}
final fullError = stackTrace == null ? message : '$message\n$stackTrace';
// Log the full message since showMessage above may be truncated or formatted
// badly (eg. VS Code takes the newlines out).
logErrorToClient(fullError);
// remember the last few exceptions
exceptions.add(new ServerException(
message,
exception,
stackTrace is StackTrace ? stackTrace : null,
false,
));
}
/// Send status notification to the client. The state of analysis is given by
/// the [status] information.
void sendStatusNotification(nd.AnalysisStatus status) {
@@ -575,6 +575,11 @@ class LspServerContextManagerCallbacks extends ContextManagerCallbacks {
// TODO: implement afterWatchEvent
}
@override
void analysisOptionsUpdated(nd.AnalysisDriver driver) {
// TODO: implement analysisOptionsUpdated
}
@override
void applyChangesToContext(Folder contextFolder, ChangeSet changeSet) {
nd.AnalysisDriver analysisDriver = analysisServer.driverMap[contextFolder];
@@ -2518,6 +2518,9 @@ class TestContextManagerCallbacks extends ContextManagerCallbacks {
@override
void afterWatchEvent(WatchEvent event) {}
@override
void analysisOptionsUpdated(AnalysisDriver driver) {}
@override
void applyChangesToContext(Folder contextFolder, ChangeSet changeSet) {
AnalysisDriver driver = driverMap[contextFolder.path];
@@ -474,6 +474,12 @@ class DeclarationsTracker {
_changedPaths.add(path);
}
/// Discard the [analysisContext], but don't discard any libraries that it
/// might have in its dependencies.
void discardContext(AnalysisContext analysisContext) {
_contexts.remove(analysisContext);
}
/// Discard all contexts and libraries, notify the [changes] stream that
/// these libraries are removed.
void discardContexts() {