Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(134)

Side by Side Diff: pkg/analysis_server/lib/src/analysis_server.dart

Issue 1413643006: Rework analyzed files support to use globs (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Address comments Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library analysis.server; 5 library analysis.server;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:collection'; 8 import 'dart:collection';
9 import 'dart:core' hide Resource; 9 import 'dart:core' hide Resource;
10 import 'dart:math' show max; 10 import 'dart:math' show max;
(...skipping 11 matching lines...) Expand all
22 import 'package:analysis_server/src/services/correction/namespace.dart'; 22 import 'package:analysis_server/src/services/correction/namespace.dart';
23 import 'package:analysis_server/src/services/index/index.dart'; 23 import 'package:analysis_server/src/services/index/index.dart';
24 import 'package:analysis_server/src/services/search/search_engine.dart'; 24 import 'package:analysis_server/src/services/search/search_engine.dart';
25 import 'package:analyzer/file_system/file_system.dart'; 25 import 'package:analyzer/file_system/file_system.dart';
26 import 'package:analyzer/instrumentation/instrumentation.dart'; 26 import 'package:analyzer/instrumentation/instrumentation.dart';
27 import 'package:analyzer/source/pub_package_map_provider.dart'; 27 import 'package:analyzer/source/pub_package_map_provider.dart';
28 import 'package:analyzer/src/generated/ast.dart'; 28 import 'package:analyzer/src/generated/ast.dart';
29 import 'package:analyzer/src/generated/element.dart'; 29 import 'package:analyzer/src/generated/element.dart';
30 import 'package:analyzer/src/generated/engine.dart'; 30 import 'package:analyzer/src/generated/engine.dart';
31 import 'package:analyzer/src/generated/java_engine.dart'; 31 import 'package:analyzer/src/generated/java_engine.dart';
32 import 'package:analyzer/src/generated/java_io.dart';
32 import 'package:analyzer/src/generated/sdk.dart'; 33 import 'package:analyzer/src/generated/sdk.dart';
33 import 'package:analyzer/src/generated/source.dart'; 34 import 'package:analyzer/src/generated/source.dart';
34 import 'package:analyzer/src/generated/source_io.dart'; 35 import 'package:analyzer/src/generated/source_io.dart';
35 import 'package:analyzer/src/generated/utilities_general.dart'; 36 import 'package:analyzer/src/generated/utilities_general.dart';
37 import 'package:glob/glob.dart';
36 import 'package:plugin/plugin.dart'; 38 import 'package:plugin/plugin.dart';
37 39
38 typedef void OptionUpdater(AnalysisOptionsImpl options); 40 typedef void OptionUpdater(AnalysisOptionsImpl options);
39 41
40 /** 42 /**
41 * Enum representing reasons why analysis might be done for a given file. 43 * Enum representing reasons why analysis might be done for a given file.
42 */ 44 */
43 class AnalysisDoneReason { 45 class AnalysisDoneReason {
44 /** 46 /**
45 * Analysis of the file completed successfully. 47 * Analysis of the file completed successfully.
(...skipping 1351 matching lines...) Expand 10 before | Expand all | Expand 10 after
1397 } 1399 }
1398 1400
1399 class ServerContextManagerCallbacks extends ContextManagerCallbacks { 1401 class ServerContextManagerCallbacks extends ContextManagerCallbacks {
1400 final AnalysisServer analysisServer; 1402 final AnalysisServer analysisServer;
1401 1403
1402 /** 1404 /**
1403 * The [ResourceProvider] by which paths are converted into [Resource]s. 1405 * The [ResourceProvider] by which paths are converted into [Resource]s.
1404 */ 1406 */
1405 final ResourceProvider resourceProvider; 1407 final ResourceProvider resourceProvider;
1406 1408
1409 /**
1410 * A list of the globs used to determine which files should be analyzed. The
1411 * list is lazily created and should be accessed using [analyzedFilesGlobs].
1412 */
1413 List<Glob> _analyzedFilesGlobs = null;
1414
1407 ServerContextManagerCallbacks(this.analysisServer, this.resourceProvider); 1415 ServerContextManagerCallbacks(this.analysisServer, this.resourceProvider);
1408 1416
1417 /**
1418 * Return a list of the globs used to determine which files should be analyzed .
1419 */
1420 List<Glob> get analyzedFilesGlobs {
1421 if (_analyzedFilesGlobs == null) {
1422 _analyzedFilesGlobs = <Glob>[];
1423 List<String> patterns = analysisServer.serverPlugin.analyzedFilePatterns;
1424 for (String pattern in patterns) {
1425 try {
1426 _analyzedFilesGlobs
1427 .add(new Glob(pattern, context: JavaFile.pathContext));
1428 } catch (exception, stackTrace) {
1429 AnalysisEngine.instance.logger.logError(
1430 'Invalid glob pattern: "$pattern"',
1431 new CaughtException(exception, stackTrace));
1432 }
1433 }
1434 }
1435 return _analyzedFilesGlobs;
1436 }
1437
1409 @override 1438 @override
1410 AnalysisContext addContext(Folder folder, FolderDisposition disposition) { 1439 AnalysisContext addContext(Folder folder, FolderDisposition disposition) {
1411 InternalAnalysisContext context = 1440 InternalAnalysisContext context =
1412 AnalysisEngine.instance.createAnalysisContext(); 1441 AnalysisEngine.instance.createAnalysisContext();
1413 context.contentCache = analysisServer.overlayState; 1442 context.contentCache = analysisServer.overlayState;
1414 analysisServer.folderMap[folder] = context; 1443 analysisServer.folderMap[folder] = context;
1415 context.sourceFactory = _createSourceFactory(disposition); 1444 context.sourceFactory = _createSourceFactory(disposition);
1416 context.analysisOptions = 1445 context.analysisOptions =
1417 new AnalysisOptionsImpl.from(analysisServer.defaultContextOptions); 1446 new AnalysisOptionsImpl.from(analysisServer.defaultContextOptions);
1418 analysisServer._onContextsChangedController 1447 analysisServer._onContextsChangedController
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1456 analysisServer.operationQueue.contextRemoved(context); 1485 analysisServer.operationQueue.contextRemoved(context);
1457 analysisServer._onContextsChangedController 1486 analysisServer._onContextsChangedController
1458 .add(new ContextsChangedEvent(removed: [context])); 1487 .add(new ContextsChangedEvent(removed: [context]));
1459 analysisServer.sendContextAnalysisDoneNotifications( 1488 analysisServer.sendContextAnalysisDoneNotifications(
1460 context, AnalysisDoneReason.CONTEXT_REMOVED); 1489 context, AnalysisDoneReason.CONTEXT_REMOVED);
1461 context.dispose(); 1490 context.dispose();
1462 } 1491 }
1463 1492
1464 @override 1493 @override
1465 bool shouldFileBeAnalyzed(File file) { 1494 bool shouldFileBeAnalyzed(File file) {
1466 List<ShouldAnalyzeFile> functions = 1495 for (Glob glob in analyzedFilesGlobs) {
1467 analysisServer.serverPlugin.analyzeFileFunctions; 1496 if (glob.matches(file.path)) {
1468 for (ShouldAnalyzeFile shouldAnalyzeFile in functions) {
1469 if (shouldAnalyzeFile(file)) {
1470 // Emacs creates dummy links to track the fact that a file is open for 1497 // Emacs creates dummy links to track the fact that a file is open for
1471 // editing and has unsaved changes (e.g. having unsaved changes to 1498 // editing and has unsaved changes (e.g. having unsaved changes to
1472 // 'foo.dart' causes a link '.#foo.dart' to be created, which points to 1499 // 'foo.dart' causes a link '.#foo.dart' to be created, which points to
1473 // the non-existent file 'username@hostname.pid'. To avoid these dummy 1500 // the non-existent file 'username@hostname.pid'. To avoid these dummy
1474 // links causing the analyzer to thrash, just ignore links to 1501 // links causing the analyzer to thrash, just ignore links to
1475 // non-existent files. 1502 // non-existent files.
1476 return file.exists; 1503 return file.exists;
1477 } 1504 }
1478 } 1505 }
1479 return false; 1506 return false;
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
1606 /** 1633 /**
1607 * The [PerformanceTag] for time spent in server request handlers. 1634 * The [PerformanceTag] for time spent in server request handlers.
1608 */ 1635 */
1609 static PerformanceTag serverRequests = new PerformanceTag('serverRequests'); 1636 static PerformanceTag serverRequests = new PerformanceTag('serverRequests');
1610 1637
1611 /** 1638 /**
1612 * The [PerformanceTag] for time spent in split store microtasks. 1639 * The [PerformanceTag] for time spent in split store microtasks.
1613 */ 1640 */
1614 static PerformanceTag splitStore = new PerformanceTag('splitStore'); 1641 static PerformanceTag splitStore = new PerformanceTag('splitStore');
1615 } 1642 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/plugin/analysis/analyzed_files.dart ('k') | pkg/analysis_server/lib/src/plugin/server_plugin.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698