Skip to content

Commit 94162a2

Browse files
committed
Version 2.13.0-211.6.beta
* Cherry-pick e8d53cf to beta * Cherry-pick ea9c648 to beta * Cherry-pick c8b3fb1 to beta * Cherry-pick ce5a1c2 to beta * Cherry-pick adc36a6 to beta
2 parents c619f1e + 4e7f583 commit 94162a2

19 files changed

+286
-153
lines changed

CHANGELOG.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,6 @@
8282

8383
#### dart format
8484

85-
* Flatten indentation on nested chains of conditional (`?:`) operators.
86-
8785
* Correct constructor initializer indentation after `required` named
8886
parameters.
8987

@@ -117,6 +115,12 @@ Updated the Linter to `1.2.1`, which includes:
117115

118116
[#44211]: https://github.com/dart-lang/sdk/issues/44211
119117

118+
## 2.12.3 - 2021-04-12
119+
120+
This is a patch release that fixes a vulnerability in `dart:html` related to
121+
DOM clobbering. Thanks again to **Vincenzo di Cicco** for finding and reporting
122+
this vulnerability.
123+
120124
## 2.12.2 - 2021-03-17
121125

122126
This is a patch release that fixes crashes reported by Flutter 2 users (issue

DEPS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ vars = {
9898
# and land the review.
9999
#
100100
# For more details, see https://github.com/dart-lang/sdk/issues/30164
101-
"dart_style_rev": "0067cfcc5bfa64cf59888c3fed34c71d1272555a",
101+
"dart_style_rev": "f17c23e0eea9a870601c19d904e2a9c1a7c81470",
102102

103103
"chromedriver_tag": "83.0.4103.39",
104104
"browser_launcher_rev": "12ab9f351a44ac803de9bc17bb2180bb312a9dd7",

pkg/analysis_server/lib/src/context_manager.dart

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,10 @@ class ContextManagerImpl implements ContextManager {
254254

255255
@override
256256
void setRoots(List<String> includedPaths, List<String> excludedPaths) {
257+
if (_rootsAreUnchanged(includedPaths, excludedPaths)) {
258+
return;
259+
}
260+
257261
this.includedPaths = includedPaths;
258262
this.excludedPaths = excludedPaths;
259263

@@ -588,6 +592,21 @@ class ContextManagerImpl implements ContextManager {
588592
return resourceProvider.getFile(path).readAsStringSync();
589593
}
590594

595+
/// Checks whether the current roots were built using the same paths as
596+
/// [includedPaths]/[excludedPaths].
597+
bool _rootsAreUnchanged(
598+
List<String> includedPaths, List<String> excludedPaths) {
599+
if (includedPaths.length != this.includedPaths.length ||
600+
excludedPaths.length != this.excludedPaths.length) {
601+
return false;
602+
}
603+
final existingIncludedSet = this.includedPaths.toSet();
604+
final existingExcludedSet = this.excludedPaths.toSet();
605+
606+
return existingIncludedSet.containsAll(includedPaths) &&
607+
existingExcludedSet.containsAll(excludedPaths);
608+
}
609+
591610
/// Listens to files generated by Bazel that were found or searched for.
592611
///
593612
/// This is handled specially because the files are outside the package

pkg/analysis_server/lib/src/lsp/handlers/handler_change_workspace_folders.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class WorkspaceFoldersHandler
4040
?.map((wf) => Uri.parse(wf.uri).toFilePath())
4141
?.toList();
4242

43-
server.updateAnalysisRoots(added, removed);
43+
server.updateWorkspaceFolders(added, removed);
4444

4545
return success();
4646
}

pkg/analysis_server/lib/src/lsp/handlers/handler_initialized.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class IntializedMessageHandler extends MessageHandler<InitializedParams, void> {
3333
await server.fetchClientConfigurationAndPerformDynamicRegistration();
3434

3535
if (!server.initializationOptions.onlyAnalyzeProjectsWithOpenFiles) {
36-
server.updateAnalysisRoots(openWorkspacePaths, const []);
36+
server.updateWorkspaceFolders(openWorkspacePaths, const []);
3737
}
3838

3939
return success();

pkg/analysis_server/lib/src/lsp/handlers/handler_text_document_changes.dart

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,6 @@ import 'package:analysis_server/src/lsp/handlers/handlers.dart';
1111
import 'package:analysis_server/src/lsp/lsp_analysis_server.dart';
1212
import 'package:analysis_server/src/lsp/mapping.dart';
1313
import 'package:analysis_server/src/lsp/source_edits.dart';
14-
import 'package:analyzer/file_system/file_system.dart';
15-
import 'package:analyzer/src/util/file_paths.dart' as file_paths;
16-
import 'package:path/path.dart' show dirname, join;
17-
18-
/// Finds the nearest ancestor to [filePath] that contains a pubspec/.packages/build file.
19-
String _findProjectFolder(ResourceProvider resourceProvider, String filePath) {
20-
// TODO(dantup): Is there something we can reuse for this?
21-
var folder = dirname(filePath);
22-
while (folder != dirname(folder)) {
23-
final pubspec =
24-
resourceProvider.getFile(join(folder, file_paths.pubspecYaml));
25-
final packages =
26-
resourceProvider.getFile(join(folder, file_paths.dotPackages));
27-
final build = resourceProvider.getFile(join(folder, 'BUILD'));
28-
29-
if (pubspec.exists || packages.exists || build.exists) {
30-
return folder;
31-
}
32-
folder = dirname(folder);
33-
}
34-
return null;
35-
}
3614

3715
class TextDocumentChangeHandler
3816
extends MessageHandler<DidChangeTextDocumentParams, void> {
@@ -95,7 +73,6 @@ class TextDocumentCloseHandler
9573
server.removePriorityFile(path);
9674
server.documentVersions.remove(path);
9775
server.onOverlayDestroyed(path);
98-
server.removeTemporaryAnalysisRoot(path);
9976

10077
return success();
10178
});
@@ -127,22 +104,9 @@ class TextDocumentOpenHandler
127104
);
128105
server.onOverlayCreated(path, doc.text);
129106

130-
final driver = server.getAnalysisDriver(path);
131107
// If the file did not exist, and is "overlay only", it still should be
132108
// analyzed. Add it to driver to which it should have been added.
133-
134-
driver?.addFile(path);
135-
136-
// Figure out the best analysis root for this file and register it as a temporary
137-
// analysis root. We need to register it even if we found a driver, so that if
138-
// the driver existed only because of another open file, it will not be removed
139-
// when that file is closed.
140-
final analysisRoot = driver?.analysisContext?.contextRoot?.root?.path ??
141-
_findProjectFolder(server.resourceProvider, path) ??
142-
dirname(path);
143-
if (analysisRoot != null) {
144-
server.addTemporaryAnalysisRoot(path, analysisRoot);
145-
}
109+
server.contextManager.getDriverFor(path)?.addFile(path);
146110

147111
server.addPriorityFile(path);
148112

pkg/analysis_server/lib/src/lsp/lsp_analysis_server.dart

Lines changed: 43 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import 'package:analysis_server/src/server/error_notifier.dart';
3737
import 'package:analysis_server/src/services/completion/completion_performance.dart'
3838
show CompletionPerformance;
3939
import 'package:analysis_server/src/services/refactoring/refactoring.dart';
40+
import 'package:analyzer/dart/analysis/context_locator.dart';
4041
import 'package:analyzer/error/error.dart';
4142
import 'package:analyzer/exception/exception.dart';
4243
import 'package:analyzer/file_system/file_system.dart';
@@ -50,6 +51,7 @@ import 'package:analyzer_plugin/protocol/protocol_common.dart' as plugin;
5051
import 'package:analyzer_plugin/protocol/protocol_generated.dart' as plugin;
5152
import 'package:analyzer_plugin/src/protocol/protocol_internal.dart' as plugin;
5253
import 'package:http/http.dart' as http;
54+
import 'package:meta/meta.dart';
5355
import 'package:watcher/watcher.dart';
5456

5557
/// Instances of the class [LspAnalysisServer] implement an LSP-based server
@@ -104,29 +106,15 @@ class LspAnalysisServer extends AbstractAnalysisServer {
104106

105107
StreamSubscription _pluginChangeSubscription;
106108

107-
/// Temporary analysis roots for open files.
108-
///
109-
/// When a file is opened and there is no driver available (for example no
110-
/// folder was opened in the editor, so the set of analysis roots is empty)
111-
/// we add temporary roots for the project (or containing) folder. When the
112-
/// file is closed, it is removed from this map and if no other open file
113-
/// uses that root, it will be removed from the set of analysis roots.
114-
///
115-
/// key: file path of the open file
116-
/// value: folder to be used as a root.
117-
final _temporaryAnalysisRoots = <String, String>{};
118-
119-
/// The set of analysis roots explicitly added to the workspace.
120-
final _explicitAnalysisRoots = <String>{};
109+
/// The current workspace folders provided by the client. Used as analysis roots.
110+
final _workspaceFolders = <String>{};
121111

122112
/// A progress reporter for analysis status.
123113
ProgressReporter analyzingProgressReporter;
124114

125-
/// The last paths that were set as included analysis roots.
126-
Set<String> _lastIncludedRootPaths;
127-
128-
/// The last paths that were set as excluded analysis roots.
129-
Set<String> _lastExcludedRootPaths;
115+
/// The number of times contexts have been created/recreated.
116+
@visibleForTesting
117+
int contextBuilds = 0;
130118

131119
/// Initialize a newly created server to send and receive messages to the
132120
/// given [channel].
@@ -204,15 +192,10 @@ class LspAnalysisServer extends AbstractAnalysisServer {
204192
assert(didAdd);
205193
if (didAdd) {
206194
_updateDriversAndPluginsPriorityFiles();
195+
_refreshAnalysisRoots();
207196
}
208197
}
209198

210-
/// Adds a temporary analysis root for an open file.
211-
void addTemporaryAnalysisRoot(String filePath, String folderPath) {
212-
_temporaryAnalysisRoots[filePath] = folderPath;
213-
_refreshAnalysisRoots();
214-
}
215-
216199
/// The socket from which messages are being read has been closed.
217200
void done() {}
218201

@@ -479,15 +462,10 @@ class LspAnalysisServer extends AbstractAnalysisServer {
479462
assert(didRemove);
480463
if (didRemove) {
481464
_updateDriversAndPluginsPriorityFiles();
465+
_refreshAnalysisRoots();
482466
}
483467
}
484468

485-
/// Removes any temporary analysis root for a file that was closed.
486-
void removeTemporaryAnalysisRoot(String filePath) {
487-
_temporaryAnalysisRoots.remove(filePath);
488-
_refreshAnalysisRoots();
489-
}
490-
491469
void sendErrorResponse(Message message, ResponseError error) {
492470
if (message is RequestMessage) {
493471
channel.sendResponse(ResponseMessage(
@@ -651,10 +629,11 @@ class LspAnalysisServer extends AbstractAnalysisServer {
651629
sendServerErrorNotification('Socket error', error, stack);
652630
}
653631

654-
void updateAnalysisRoots(List<String> addedPaths, List<String> removedPaths) {
632+
void updateWorkspaceFolders(
633+
List<String> addedPaths, List<String> removedPaths) {
655634
// TODO(dantup): This is currently case-sensitive!
656635

657-
_explicitAnalysisRoots
636+
_workspaceFolders
658637
..addAll(addedPaths ?? const [])
659638
..removeAll(removedPaths ?? const []);
660639

@@ -671,14 +650,40 @@ class LspAnalysisServer extends AbstractAnalysisServer {
671650
notifyFlutterWidgetDescriptions(path);
672651
}
673652

653+
/// Computes analysis roots for a set of open files.
654+
///
655+
/// This is used when there are no workspace folders open directly.
656+
List<String> _getRootsForOpenFiles() {
657+
final openFiles = priorityFiles.toList();
658+
final contextLocator = ContextLocator(resourceProvider: resourceProvider);
659+
final roots = contextLocator.locateRoots(includedPaths: openFiles);
660+
661+
// For files in folders that don't have pubspecs, a root would be
662+
// produced for the root of the drive which we do not want, so filter those out.
663+
roots.removeWhere((root) => root.root.isRoot);
664+
665+
// Find any files that are no longer covered by roots because of the above
666+
// removal.
667+
final additionalFiles =
668+
openFiles.where((file) => !roots.any((root) => root.isAnalyzed(file)));
669+
670+
return [
671+
...roots.map((root) => root.root.path),
672+
...additionalFiles,
673+
];
674+
}
675+
674676
void _onPluginsChanged() {
675677
capabilitiesComputer.performDynamicRegistration();
676678
}
677679

678680
void _refreshAnalysisRoots() {
679-
// Always include any temporary analysis roots for open files.
680-
final includedPaths = _explicitAnalysisRoots.toSet()
681-
..addAll(_temporaryAnalysisRoots.values);
681+
// When there are open folders, they are always the roots. If there are no
682+
// open workspace folders, then we use the open (priority) files to compute
683+
// roots.
684+
final includedPaths = _workspaceFolders.isNotEmpty
685+
? _workspaceFolders.toSet()
686+
: _getRootsForOpenFiles();
682687

683688
final excludedPaths = clientConfiguration.analysisExcludedFolders
684689
.expand((excludePath) => resourceProvider.pathContext
@@ -688,25 +693,10 @@ class LspAnalysisServer extends AbstractAnalysisServer {
688693
// TODO(dantup): Consider supporting per-workspace config by
689694
// calling workspace/configuration whenever workspace folders change
690695
// and caching the config for each one.
691-
: _explicitAnalysisRoots.map(
696+
: _workspaceFolders.map(
692697
(root) => resourceProvider.pathContext.join(root, excludePath)))
693698
.toSet();
694699

695-
// If the roots didn't actually change from the last time they were set
696-
// (this can happen a lot as temporary roots are collected for open files)
697-
// we can avoid doing expensive work like discarding/re-scanning the
698-
// declarations.
699-
final rootsChanged =
700-
includedPaths.length != _lastIncludedRootPaths?.length ||
701-
!includedPaths.every(_lastIncludedRootPaths.contains) ||
702-
excludedPaths.length != _lastExcludedRootPaths?.length ||
703-
!excludedPaths.every(_lastExcludedRootPaths.contains);
704-
705-
if (!rootsChanged) return;
706-
707-
_lastIncludedRootPaths = includedPaths;
708-
_lastExcludedRootPaths = excludedPaths;
709-
710700
notificationManager.setAnalysisRoots(
711701
includedPaths.toList(), excludedPaths.toList());
712702
contextManager.setRoots(includedPaths.toList(), excludedPaths.toList());
@@ -780,6 +770,7 @@ class LspServerContextManagerCallbacks extends ContextManagerCallbacks {
780770

781771
@override
782772
void afterContextsCreated() {
773+
analysisServer.contextBuilds++;
783774
analysisServer.addContextsToDeclarationsTracker();
784775
}
785776

0 commit comments

Comments
 (0)