Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 3870a33

Browse files
author
Dart CI
committed
Version 2.13.0-82.0.dev
Merge commit '8833cbed7d7021420e6a969eba48f006bb7050f4' into 'dev'
2 parents aa0fea7 + 8833cbe commit 3870a33

File tree

16 files changed

+191
-115
lines changed

16 files changed

+191
-115
lines changed

pkg/analysis_server/lib/src/analysis_server.dart

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -429,16 +429,6 @@ class AnalysisServer extends AbstractAnalysisServer {
429429
});
430430
}
431431

432-
/// Returns `true` if errors should be reported for [file] with the given
433-
/// absolute path.
434-
bool shouldSendErrorsNotificationFor(String file) {
435-
// Errors should not be reported for things that are explicitly skipped
436-
// during normal analysis (for example dot folders are skipped over in
437-
// _handleWatchEventImpl).
438-
return contextManager.isInAnalysisRoot(file) &&
439-
!contextManager.isContainedInDotFolder(file);
440-
}
441-
442432
Future<void> shutdown() {
443433
if (options.analytics != null) {
444434
options.analytics
@@ -674,7 +664,7 @@ class ServerContextManagerCallbacks extends ContextManagerCallbacks {
674664
analysisDriver.results.listen((result) {
675665
var path = result.path;
676666
filesToFlush.add(path);
677-
if (analysisServer.shouldSendErrorsNotificationFor(path)) {
667+
if (analysisServer.isAnalyzed(path)) {
678668
_notificationManager.recordAnalysisErrors(NotificationManager.serverId,
679669
path, server.doAnalysisError_listFromEngine(result));
680670
}

pkg/analysis_server/lib/src/analysis_server_abstract.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,12 @@ abstract class AbstractAnalysisServer {
348348
});
349349
}
350350

351+
/// Return `true` if the file or directory with the given [path] will be
352+
/// analyzed in one of the analysis contexts.
353+
bool isAnalyzed(String path) {
354+
return contextManager.isAnalyzed(path);
355+
}
356+
351357
void logExceptionResult(nd.ExceptionResult result) {
352358
var message = 'Analysis failed: ${result.filePath}';
353359
if (result.contextKey != null) {

pkg/analysis_server/lib/src/context_manager.dart

Lines changed: 8 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,9 @@ abstract class ContextManager {
8787
/// If no driver contains the given path, `null` is returned.
8888
AnalysisDriver getDriverFor(String path);
8989

90-
/// Determine whether the given [path], when interpreted relative to innermost
91-
/// context root, contains a folder whose name starts with '.'.
92-
///
93-
/// TODO(scheglov) Remove it, just [isInAnalysisRoot] should be enough.
94-
bool isContainedInDotFolder(String path);
95-
96-
/// Return `true` if the given absolute [path] is in one of the current
97-
/// root folders and is not excluded.
98-
bool isInAnalysisRoot(String path);
90+
/// Return `true` if the file or directory with the given [path] will be
91+
/// analyzed in one of the analysis contexts.
92+
bool isAnalyzed(String path);
9993

10094
/// Rebuild the set of contexts from scratch based on the data last sent to
10195
/// [setRoots].
@@ -221,21 +215,8 @@ class ContextManagerImpl implements ContextManager {
221215
return getContextFor(path)?.driver;
222216
}
223217

224-
/// Determine whether the given [path], when interpreted relative to innermost
225-
/// context root, contains a folder whose name starts with '.'.
226-
@override
227-
bool isContainedInDotFolder(String path) {
228-
for (var analysisContext in _collection.contexts) {
229-
var contextImpl = analysisContext as DriverBasedAnalysisContext;
230-
if (_isContainedInDotFolder(contextImpl.contextRoot.root.path, path)) {
231-
return true;
232-
}
233-
}
234-
return false;
235-
}
236-
237218
@override
238-
bool isInAnalysisRoot(String path) {
219+
bool isAnalyzed(String path) {
239220
var collection = _collection;
240221
if (collection == null) {
241222
return false;
@@ -431,9 +412,6 @@ class ContextManagerImpl implements ContextManager {
431412
_watchBazelFilesIfNeeded(rootFolder, driver);
432413

433414
for (var file in contextImpl.contextRoot.analyzedFiles()) {
434-
if (_isContainedInDotFolder(contextImpl.contextRoot.root.path, file)) {
435-
continue;
436-
}
437415
if (file_paths.isAndroidManifestXml(pathContext, file)) {
438416
_analyzeAndroidManifestXml(driver, file);
439417
} else if (file_paths.isDart(pathContext, file)) {
@@ -554,12 +532,11 @@ class ContextManagerImpl implements ContextManager {
554532
var analysisContext = analysisContext_ as DriverBasedAnalysisContext;
555533
switch (type) {
556534
case ChangeType.ADD:
557-
// TODO(scheglov) Why not `isInAnalysisRoot()`?
558-
if (_isContainedInDotFolder(
559-
analysisContext.contextRoot.root.path, path)) {
560-
return;
535+
if (analysisContext.contextRoot.isAnalyzed(path)) {
536+
analysisContext.driver.addFile(path);
537+
} else {
538+
analysisContext.driver.changeFile(path);
561539
}
562-
analysisContext.driver.addFile(path);
563540
break;
564541
case ChangeType.MODIFY:
565542
analysisContext.driver.changeFile(path);
@@ -592,25 +569,6 @@ class ContextManagerImpl implements ContextManager {
592569
refresh();
593570
}
594571

595-
/// Determine whether the given [path], when interpreted relative to the
596-
/// context root [root], contains a folder whose name starts with '.' but is
597-
/// not included in [exclude].
598-
bool _isContainedInDotFolder(String root, String path,
599-
{Set<String> exclude}) {
600-
var pathDir = pathContext.dirname(path);
601-
var rootPrefix = root + pathContext.separator;
602-
if (pathDir.startsWith(rootPrefix)) {
603-
var suffixPath = pathDir.substring(rootPrefix.length);
604-
for (var pathComponent in pathContext.split(suffixPath)) {
605-
if (pathComponent.startsWith('.') &&
606-
!(exclude?.contains(pathComponent) ?? false)) {
607-
return true;
608-
}
609-
}
610-
}
611-
return false;
612-
}
613-
614572
/// Read the contents of the file at the given [path], or throw an exception
615573
/// if the contents cannot be read.
616574
String _readFile(String path) {

pkg/analysis_server/lib/src/edit/edit_dartfix.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ class EditDartFix
175175
if (res is Folder) {
176176
for (var child in res.getChildren()) {
177177
if (!child.shortName.startsWith('.') &&
178-
contextManager.isInAnalysisRoot(child.path)) {
178+
server.isAnalyzed(child.path)) {
179179
resources.add(child);
180180
}
181181
}

pkg/analysis_server/lib/src/edit/edit_domain.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ class EditDomainHandler extends AbstractRequestHandler {
261261
return;
262262
}
263263

264-
if (!server.contextManager.isInAnalysisRoot(file)) {
264+
if (!server.isAnalyzed(file)) {
265265
server.sendResponse(Response.getFixesInvalidFile(request));
266266
return;
267267
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class CodeActionHandler extends MessageHandler<CodeActionParams,
4646
}
4747

4848
final path = pathOfDoc(params.textDocument);
49-
if (!path.isError && !server.isAnalyzedFile(path.result)) {
49+
if (!path.isError && !server.isAnalyzed(path.result)) {
5050
return success(const []);
5151
}
5252

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

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -338,14 +338,6 @@ class LspAnalysisServer extends AbstractAnalysisServer {
338338
}, socketError);
339339
}
340340

341-
/// Returns `true` if the [file] with the given absolute path is included
342-
/// in an analysis root and not excluded.
343-
bool isAnalyzedFile(String file) {
344-
return contextManager.isInAnalysisRoot(file) &&
345-
// Dot folders are not analyzed (skipped over in _handleWatchEventImpl)
346-
!contextManager.isContainedInDotFolder(file);
347-
}
348-
349341
/// Logs the error on the client using window/logMessage.
350342
void logErrorToClient(String message) {
351343
channel.sendNotification(NotificationMessage(
@@ -584,13 +576,7 @@ class LspAnalysisServer extends AbstractAnalysisServer {
584576
// workspace.
585577
return initializationOptions.closingLabels &&
586578
priorityFiles.contains(file) &&
587-
contextManager.isInAnalysisRoot(file);
588-
}
589-
590-
/// Returns `true` if errors should be reported for [file] with the given
591-
/// absolute path.
592-
bool shouldSendErrorsNotificationFor(String file) {
593-
return isAnalyzedFile(file);
579+
isAnalyzed(file);
594580
}
595581

596582
/// Returns `true` if Flutter outlines should be sent for [file] with the
@@ -817,7 +803,7 @@ class LspServerContextManagerCallbacks extends ContextManagerCallbacks {
817803
analysisDriver.results.listen((result) {
818804
var path = result.path;
819805
filesToFlush.add(path);
820-
if (analysisServer.shouldSendErrorsNotificationFor(path)) {
806+
if (analysisServer.isAnalyzed(path)) {
821807
final serverErrors = protocol.mapEngineErrors(
822808
result,
823809
result.errors.where(_shouldSendDiagnostic).toList(),

pkg/analysis_server/test/domain_analysis_test.dart

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,35 @@ analyzer:
454454
assertHasErrors(a_path);
455455
}
456456

457+
Future<void> test_fileSystem_addFile_dart_dotFolder() async {
458+
var a_path = '$projectPath/lib/.foo/a.dart';
459+
var b_path = '$projectPath/lib/b.dart';
460+
461+
newFile(b_path, content: r'''
462+
import '.foo/a.dart';
463+
void f(A a) {}
464+
''');
465+
466+
createProject();
467+
await pumpEventQueue();
468+
await server.onAnalysisComplete;
469+
470+
// We don't have a.dart, so the import cannot be resolved.
471+
assertHasErrors(b_path);
472+
473+
newFile(a_path, content: r'''
474+
class A {}
475+
''');
476+
await pumpEventQueue();
477+
await server.onAnalysisComplete;
478+
479+
// 'a.dart' is in a dot-folder, so excluded from analysis.
480+
assertNoErrorsNotification(a_path);
481+
482+
// We added a.dart with `A`, so no errors.
483+
assertNoErrors(b_path);
484+
}
485+
457486
Future<void> test_fileSystem_addFile_dart_excluded() async {
458487
var a_path = '$projectPath/lib/a.dart';
459488
var b_path = '$projectPath/lib/b.dart';
@@ -747,6 +776,42 @@ void f(A a) {}
747776
assertNoErrors(b_path);
748777
}
749778

779+
Future<void> test_fileSystem_changeFile_dart_dotFolder() async {
780+
var a_path = '$testPackageLibPath/.foo/a.dart';
781+
var b_path = '$testPackageLibPath/b.dart';
782+
783+
newFile(a_path, content: r'''
784+
class B {}
785+
''');
786+
787+
newFile(b_path, content: r'''
788+
import '.foo/a.dart';
789+
void f(A a) {}
790+
''');
791+
792+
setRoots(included: [workspaceRootPath], excluded: []);
793+
await pumpEventQueue();
794+
await server.onAnalysisComplete;
795+
796+
// 'a.dart' is in a dot-folder, so excluded from analysis.
797+
assertNoErrorsNotification(a_path);
798+
799+
// We have `B`, not `A`, in a.dart, so has errors.
800+
assertHasErrors(b_path);
801+
802+
newFile(a_path, content: r'''
803+
class A {}
804+
''');
805+
await pumpEventQueue();
806+
await server.onAnalysisComplete;
807+
808+
// 'a.dart' is in a dot-folder, so excluded from analysis.
809+
assertNoErrorsNotification(a_path);
810+
811+
// We changed a.dart, to have `A`, so no errors.
812+
assertNoErrors(b_path);
813+
}
814+
750815
Future<void> test_fileSystem_changeFile_dart_excluded() async {
751816
var a_path = '$testPackageLibPath/a.dart';
752817
var b_path = '$testPackageLibPath/b.dart';

pkg/analysis_server/test/src/cider/fixes_test.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,20 @@ class CiderFixesComputerTest extends CiderServiceTest {
3737
expect(resultContent, expected);
3838
}
3939

40+
Future<void> test_cachedResolvedFiles() async {
41+
await _compute(r'''
42+
var a = 0^ var b = 1
43+
''');
44+
45+
// Only the first fix is applied.
46+
assertHasFix(DartFixKind.INSERT_SEMICOLON, r'''
47+
var a = 0; var b = 1
48+
''');
49+
50+
// The file was resolved only once, even though we have 2 errors.
51+
expect(fileResolver.testView.resolvedFiles, [testPath]);
52+
}
53+
4054
Future<void> test_createMethod() async {
4155
await _compute(r'''
4256
class A {

pkg/analyzer/lib/src/context/packages.dart

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,6 @@ Packages parsePackageConfigJsonFile(ResourceProvider provider, File file) {
9999
jsonLanguageVersion.minor,
100100
0,
101101
);
102-
// New features were added in `2.2.2` over `2.2.0`.
103-
// But `2.2.2` is not representable, so we special case it.
104-
if (languageVersion.major == 2 && languageVersion.minor == 2) {
105-
languageVersion = Version(2, 2, 2);
106-
}
107102
}
108103

109104
map[name] = Package(

0 commit comments

Comments
 (0)