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

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

Issue 2713533003: Initial integration of NotificationManager into server (Closed)
Patch Set: Created 3 years, 10 months 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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'; 9 import 'dart:core';
10 import 'dart:io' as io; 10 import 'dart:io' as io;
11 import 'dart:math' show max; 11 import 'dart:math' show max;
12 12
13 import 'package:analysis_server/plugin/protocol/protocol.dart' 13 import 'package:analysis_server/plugin/protocol/protocol.dart'
14 hide AnalysisOptions, Element; 14 hide AnalysisOptions, Element;
15 import 'package:analysis_server/src/analysis_logger.dart'; 15 import 'package:analysis_server/src/analysis_logger.dart';
16 import 'package:analysis_server/src/channel/channel.dart'; 16 import 'package:analysis_server/src/channel/channel.dart';
17 import 'package:analysis_server/src/computer/computer_highlights.dart';
18 import 'package:analysis_server/src/computer/computer_highlights2.dart';
19 import 'package:analysis_server/src/computer/computer_outline.dart';
17 import 'package:analysis_server/src/computer/new_notifications.dart'; 20 import 'package:analysis_server/src/computer/new_notifications.dart';
18 import 'package:analysis_server/src/context_manager.dart'; 21 import 'package:analysis_server/src/context_manager.dart';
22 import 'package:analysis_server/src/domains/analysis/navigation.dart';
23 import 'package:analysis_server/src/domains/analysis/navigation_dart.dart';
24 import 'package:analysis_server/src/domains/analysis/occurrences.dart';
25 import 'package:analysis_server/src/domains/analysis/occurrences_dart.dart';
19 import 'package:analysis_server/src/operation/operation.dart'; 26 import 'package:analysis_server/src/operation/operation.dart';
20 import 'package:analysis_server/src/operation/operation_analysis.dart'; 27 import 'package:analysis_server/src/operation/operation_analysis.dart';
21 import 'package:analysis_server/src/operation/operation_queue.dart'; 28 import 'package:analysis_server/src/operation/operation_queue.dart';
29 import 'package:analysis_server/src/plugin/notification_manager.dart';
22 import 'package:analysis_server/src/plugin/server_plugin.dart'; 30 import 'package:analysis_server/src/plugin/server_plugin.dart';
31 import 'package:analysis_server/src/protocol_server.dart' as server;
23 import 'package:analysis_server/src/server/diagnostic_server.dart'; 32 import 'package:analysis_server/src/server/diagnostic_server.dart';
24 import 'package:analysis_server/src/services/correction/namespace.dart'; 33 import 'package:analysis_server/src/services/correction/namespace.dart';
25 import 'package:analysis_server/src/services/index/index.dart'; 34 import 'package:analysis_server/src/services/index/index.dart';
26 import 'package:analysis_server/src/services/search/search_engine.dart'; 35 import 'package:analysis_server/src/services/search/search_engine.dart';
27 import 'package:analysis_server/src/services/search/search_engine_internal.dart' ; 36 import 'package:analysis_server/src/services/search/search_engine_internal.dart' ;
28 import 'package:analysis_server/src/services/search/search_engine_internal2.dart '; 37 import 'package:analysis_server/src/services/search/search_engine_internal2.dart ';
29 import 'package:analysis_server/src/single_context_manager.dart'; 38 import 'package:analysis_server/src/single_context_manager.dart';
30 import 'package:analysis_server/src/utilities/null_string_sink.dart'; 39 import 'package:analysis_server/src/utilities/null_string_sink.dart';
31 import 'package:analyzer/dart/ast/ast.dart'; 40 import 'package:analyzer/dart/ast/ast.dart';
32 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; 41 import 'package:analyzer/dart/ast/standard_resolution_map.dart';
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 */ 115 */
107 AnalysisServerOptions options; 116 AnalysisServerOptions options;
108 117
109 /** 118 /**
110 * The channel from which requests are received and to which responses should 119 * The channel from which requests are received and to which responses should
111 * be sent. 120 * be sent.
112 */ 121 */
113 final ServerCommunicationChannel channel; 122 final ServerCommunicationChannel channel;
114 123
115 /** 124 /**
125 * The object used to manage sending a subset of notifications to the client.
126 * The subset of notifications are those to which plugins may contribute.
127 * This field is `null` when the new plugin support is disabled.
128 */
129 final NotificationManager notificationManager = null;
130
131 /**
116 * The [ResourceProvider] using which paths are converted into [Resource]s. 132 * The [ResourceProvider] using which paths are converted into [Resource]s.
117 */ 133 */
118 final ResourceProvider resourceProvider; 134 final ResourceProvider resourceProvider;
119 135
120 /** 136 /**
121 * The [Index] for this server, may be `null` if indexing is disabled. 137 * The [Index] for this server, may be `null` if indexing is disabled.
122 */ 138 */
123 final Index index; 139 final Index index;
124 140
125 /** 141 /**
(...skipping 1714 matching lines...) Expand 10 before | Expand all | Expand 10 after
1840 */ 1856 */
1841 final ResourceProvider resourceProvider; 1857 final ResourceProvider resourceProvider;
1842 1858
1843 ServerContextManagerCallbacks(this.analysisServer, this.resourceProvider); 1859 ServerContextManagerCallbacks(this.analysisServer, this.resourceProvider);
1844 1860
1845 @override 1861 @override
1846 nd.AnalysisDriver addAnalysisDriver(Folder folder, AnalysisOptions options) { 1862 nd.AnalysisDriver addAnalysisDriver(Folder folder, AnalysisOptions options) {
1847 ContextBuilder builder = createContextBuilder(folder, options); 1863 ContextBuilder builder = createContextBuilder(folder, options);
1848 nd.AnalysisDriver analysisDriver = builder.buildDriver(folder.path); 1864 nd.AnalysisDriver analysisDriver = builder.buildDriver(folder.path);
1849 analysisDriver.results.listen((result) { 1865 analysisDriver.results.listen((result) {
1850 new_sendErrorNotification(analysisServer, result); 1866 NotificationManager notificationManager =
1867 analysisServer.notificationManager;
1851 String path = result.path; 1868 String path = result.path;
1869 if (notificationManager != null) {
1870 notificationManager.recordAnalysisErrors(
1871 NotificationManager.serverId,
1872 path,
1873 server.doAnalysisError_listFromEngine(
1874 result.driver.analysisOptions, result.lineInfo, result.errors));
1875 } else {
1876 new_sendErrorNotification(analysisServer, result);
1877 }
1852 CompilationUnit unit = result.unit; 1878 CompilationUnit unit = result.unit;
1853 if (unit != null) { 1879 if (unit != null) {
1854 if (analysisServer._hasAnalysisServiceSubscription( 1880 if (notificationManager != null) {
1855 AnalysisService.HIGHLIGHTS, path)) { 1881 if (analysisServer._hasAnalysisServiceSubscription(
1856 _runDelayed(() { 1882 AnalysisService.HIGHLIGHTS, path)) {
1857 sendAnalysisNotificationHighlights(analysisServer, path, unit); 1883 _runDelayed(() {
1858 }); 1884 notificationManager.recordHighlightRegions(
1859 } 1885 NotificationManager.serverId,
1860 if (analysisServer._hasAnalysisServiceSubscription( 1886 path,
1861 AnalysisService.NAVIGATION, path)) { 1887 _computeHighlightRegions(unit));
1862 _runDelayed(() { 1888 });
1863 new_sendDartNotificationNavigation(analysisServer, result); 1889 }
1864 }); 1890 if (analysisServer._hasAnalysisServiceSubscription(
1865 } 1891 AnalysisService.NAVIGATION, path)) {
1866 if (analysisServer._hasAnalysisServiceSubscription( 1892 _runDelayed(() {
1867 AnalysisService.OCCURRENCES, path)) { 1893 notificationManager.recordNavigationParams(
1868 _runDelayed(() { 1894 NotificationManager.serverId,
1869 new_sendDartNotificationOccurrences(analysisServer, result); 1895 path,
1870 }); 1896 _computeNavigationParams(path, unit));
1871 } 1897 });
1872 if (analysisServer._hasAnalysisServiceSubscription( 1898 }
1873 AnalysisService.OVERRIDES, path)) { 1899 if (analysisServer._hasAnalysisServiceSubscription(
1874 _runDelayed(() { 1900 AnalysisService.OCCURRENCES, path)) {
1875 sendAnalysisNotificationOverrides(analysisServer, path, unit); 1901 _runDelayed(() {
1876 }); 1902 notificationManager.recordOccurrences(
1903 NotificationManager.serverId,
1904 path,
1905 _computeOccurrences(unit));
1906 });
1907 }
1908 // if (analysisServer._hasAnalysisServiceSubscription(
1909 // AnalysisService.OUTLINE, path)) {
1910 // _runDelayed(() {
1911 // // TODO(brianwilkerson) Change NotificationManager to store para ms
1912 // // so that fileKind and libraryName can be recorded / passed alo ng.
1913 // notificationManager.recordOutlines(NotificationManager.serverId,
1914 // path, _computeOutlineParams(path, unit, result.lineInfo));
1915 // });
1916 // }
1917 } else {
1918 if (analysisServer._hasAnalysisServiceSubscription(
1919 AnalysisService.HIGHLIGHTS, path)) {
1920 _runDelayed(() {
1921 sendAnalysisNotificationHighlights(analysisServer, path, unit);
1922 });
1923 }
1924 if (analysisServer._hasAnalysisServiceSubscription(
1925 AnalysisService.NAVIGATION, path)) {
1926 _runDelayed(() {
1927 new_sendDartNotificationNavigation(analysisServer, result);
1928 });
1929 }
1930 if (analysisServer._hasAnalysisServiceSubscription(
1931 AnalysisService.OCCURRENCES, path)) {
1932 _runDelayed(() {
1933 new_sendDartNotificationOccurrences(analysisServer, result);
1934 });
1935 }
1877 } 1936 }
1878 if (analysisServer._hasAnalysisServiceSubscription( 1937 if (analysisServer._hasAnalysisServiceSubscription(
1879 AnalysisService.OUTLINE, path)) { 1938 AnalysisService.OUTLINE, path)) {
1880 _runDelayed(() { 1939 _runDelayed(() {
1881 SourceKind sourceKind = 1940 SourceKind sourceKind =
1882 unit.directives.any((d) => d is PartOfDirective) 1941 unit.directives.any((d) => d is PartOfDirective)
1883 ? SourceKind.PART 1942 ? SourceKind.PART
1884 : SourceKind.LIBRARY; 1943 : SourceKind.LIBRARY;
1885 sendAnalysisNotificationOutline( 1944 sendAnalysisNotificationOutline(
1886 analysisServer, path, result.lineInfo, sourceKind, unit); 1945 analysisServer, path, result.lineInfo, sourceKind, unit);
1887 }); 1946 });
1888 } 1947 }
1948 if (analysisServer._hasAnalysisServiceSubscription(
1949 AnalysisService.OVERRIDES, path)) {
1950 _runDelayed(() {
1951 sendAnalysisNotificationOverrides(analysisServer, path, unit);
1952 });
1953 }
1954 // TODO(scheglov) Implement notifications for AnalysisService.IMPLEMENTE D.
1889 } 1955 }
1890 // TODO(scheglov) Implement more notifications.
1891 // IMPLEMENTED
1892 }); 1956 });
1893 analysisDriver.exceptions.listen((nd.ExceptionResult result) { 1957 analysisDriver.exceptions.listen((nd.ExceptionResult result) {
1894 String message = 'Analysis failed: ${result.path}'; 1958 String message = 'Analysis failed: ${result.path}';
1895 if (result.contextKey != null) { 1959 if (result.contextKey != null) {
1896 message += ' context: ${result.contextKey}'; 1960 message += ' context: ${result.contextKey}';
1897 } 1961 }
1898 AnalysisEngine.instance.logger.logError(message, result.exception); 1962 AnalysisEngine.instance.logger.logError(message, result.exception);
1899 }); 1963 });
1900 analysisServer.driverMap[folder] = analysisDriver; 1964 analysisServer.driverMap[folder] = analysisDriver;
1901 return analysisDriver; 1965 return analysisDriver;
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
2013 } 2077 }
2014 } 2078 }
2015 2079
2016 @override 2080 @override
2017 void updateContextPackageUriResolver(AnalysisContext context) { 2081 void updateContextPackageUriResolver(AnalysisContext context) {
2018 analysisServer._onContextsChangedController 2082 analysisServer._onContextsChangedController
2019 .add(new ContextsChangedEvent(changed: [context])); 2083 .add(new ContextsChangedEvent(changed: [context]));
2020 analysisServer.schedulePerformAnalysisOperation(context); 2084 analysisServer.schedulePerformAnalysisOperation(context);
2021 } 2085 }
2022 2086
2087 List<server.HighlightRegion> _computeHighlightRegions(CompilationUnit unit) {
2088 if (analysisServer.options.useAnalysisHighlight2) {
2089 return new DartUnitHighlightsComputer2(unit).compute();
2090 } else {
2091 return new DartUnitHighlightsComputer(unit).compute();
2092 }
2093 }
2094
2095 String _computeLibraryName(CompilationUnit unit) {
2096 for (Directive directive in unit.directives) {
2097 if (directive is LibraryDirective && directive.name != null) {
2098 return directive.name.name;
2099 }
2100 }
2101 for (Directive directive in unit.directives) {
2102 if (directive is PartOfDirective && directive.libraryName != null) {
2103 return directive.libraryName.name;
2104 }
2105 }
2106 return null;
2107 }
2108
2109 server.AnalysisNavigationParams _computeNavigationParams(
2110 String path, CompilationUnit unit) {
2111 NavigationCollectorImpl collector = new NavigationCollectorImpl();
2112 computeDartNavigation(collector, unit, null, null);
2113 collector.createRegions();
2114 return new server.AnalysisNavigationParams(
2115 path, collector.regions, collector.targets, collector.files);
2116 }
2117
2118 List<Occurrences> _computeOccurrences(CompilationUnit unit) {
2119 OccurrencesCollectorImpl collector = new OccurrencesCollectorImpl();
2120 addDartOccurrences(collector, unit);
2121 return collector.allOccurrences;
2122 }
2123
2124 server.AnalysisOutlineParams _computeOutlineParams(
2125 String path, CompilationUnit unit, LineInfo lineInfo) {
2126 // compute FileKind
2127 SourceKind sourceKind = unit.directives.any((d) => d is PartOfDirective)
2128 ? SourceKind.PART
2129 : SourceKind.LIBRARY;
2130 server.FileKind fileKind = server.FileKind.LIBRARY;
2131 if (sourceKind == SourceKind.LIBRARY) {
2132 fileKind = server.FileKind.LIBRARY;
2133 } else if (sourceKind == SourceKind.PART) {
2134 fileKind = server.FileKind.PART;
2135 }
2136 // compute library name
2137 String libraryName = _computeLibraryName(unit);
2138 // compute Outline
2139 DartUnitOutlineComputer computer =
2140 new DartUnitOutlineComputer(path, lineInfo, unit);
2141 server.Outline outline = computer.compute();
2142 return new server.AnalysisOutlineParams(path, fileKind, outline,
2143 libraryName: libraryName);
2144 }
2145
2023 /** 2146 /**
2024 * Run [f] in a new [Future]. 2147 * Run [f] in a new [Future].
2025 * 2148 *
2026 * This method is used to delay sending notifications. If there is a more 2149 * This method is used to delay sending notifications. If there is a more
2027 * important consumer of an analysis results, specifically a code completion 2150 * important consumer of an analysis results, specifically a code completion
2028 * computer, we want it to run before spending time of sending notifications. 2151 * computer, we want it to run before spending time of sending notifications.
2029 * 2152 *
2030 * TODO(scheglov) Consider replacing this with full priority based scheduler. 2153 * TODO(scheglov) Consider replacing this with full priority based scheduler.
2031 * 2154 *
2032 * TODO(scheglov) Alternatively, if code completion work in a way that does 2155 * TODO(scheglov) Alternatively, if code completion work in a way that does
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
2134 /** 2257 /**
2135 * The [PerformanceTag] for time spent in server request handlers. 2258 * The [PerformanceTag] for time spent in server request handlers.
2136 */ 2259 */
2137 static PerformanceTag serverRequests = new PerformanceTag('serverRequests'); 2260 static PerformanceTag serverRequests = new PerformanceTag('serverRequests');
2138 2261
2139 /** 2262 /**
2140 * The [PerformanceTag] for time spent in split store microtasks. 2263 * The [PerformanceTag] for time spent in split store microtasks.
2141 */ 2264 */
2142 static PerformanceTag splitStore = new PerformanceTag('splitStore'); 2265 static PerformanceTag splitStore = new PerformanceTag('splitStore');
2143 } 2266 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698