Skip to content

Commit d2d5de6

Browse files
jonasfjCommit Queue
authored andcommitted
Avoid context confusion in ServerPlugin.analyzeFiles
Change-Id: Ib2500c17e4abe2a485fb8325134276f803113db4 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/388701 Commit-Queue: Samuel Rawlins <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]> Reviewed-by: Samuel Rawlins <[email protected]>
1 parent 5b01285 commit d2d5de6

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

pkg/analyzer_plugin/lib/plugin/plugin.dart

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,12 @@ abstract class ServerPlugin {
107107

108108
// First analyze priority files.
109109
for (var path in priorityPaths) {
110-
pathSet.remove(path);
111-
await analyzeFile(
112-
analysisContext: analysisContext,
113-
path: path,
114-
);
110+
if (pathSet.remove(path)) {
111+
await analyzeFile(
112+
analysisContext: analysisContext,
113+
path: path,
114+
);
115+
}
115116
}
116117

117118
// Then analyze the remaining files.

pkg/analyzer_plugin/test/plugin/plugin_test.dart

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,30 @@ void main(List<String> args, SendPort sendPort) {
401401
expect(removeResult, isNotNull);
402402
}
403403

404+
Future<void> test_onRequest_analyzeFileIsNotContextConfused() async {
405+
var plugin = this.plugin as _TestServerPlugin;
406+
var confusedPaths = <String>[];
407+
plugin.analyzeFileHandler = ({
408+
required AnalysisContext analysisContext,
409+
required String path,
410+
}) {
411+
// Test that path actually belongs to analysisContext
412+
if (!analysisContext.contextRoot.isAnalyzed(path)) {
413+
confusedPaths.add(
414+
'$path analyzed in context for'
415+
' ${analysisContext.contextRoot.root.path}',
416+
);
417+
}
418+
};
419+
420+
var result = await channel
421+
.sendRequest(AnalysisSetPriorityFilesParams([filePath1, filePath2]));
422+
expect(result, isNotNull);
423+
await channel.sendRequest(
424+
AnalysisSetContextRootsParams([contextRoot1, contextRoot2]));
425+
expect(confusedPaths, []);
426+
}
427+
404428
Future<void> test_onRequest_completionGetSuggestions() async {
405429
await channel.sendRequest(AnalysisSetContextRootsParams([contextRoot1]));
406430

0 commit comments

Comments
 (0)