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

Side by Side Diff: pkg/analysis_server/lib/src/services/completion/dart_completion_manager.dart

Issue 758953003: update computeFast/Full now that completion manager is long lived (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: merge Created 6 years 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 | Annotate | Revision Log
« 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 services.completion.dart; 5 library services.completion.dart;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analysis_server/src/protocol.dart'; 9 import 'package:analysis_server/src/protocol.dart';
10 import 'package:analysis_server/src/services/completion/arglist_computer.dart'; 10 import 'package:analysis_server/src/services/completion/arglist_computer.dart';
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 return new DartCompletionManager( 71 return new DartCompletionManager(
72 context, 72 context,
73 searchEngine, 73 searchEngine,
74 source, 74 source,
75 new DartCompletionCache(context, source)); 75 new DartCompletionCache(context, source));
76 } 76 }
77 77
78 /** 78 /**
79 * Compute suggestions based upon cached information only 79 * Compute suggestions based upon cached information only
80 * then send an initial response to the client. 80 * then send an initial response to the client.
81 * Return a list of computers for which [computeFull] should be called
81 */ 82 */
82 void computeFast(DartCompletionRequest request) { 83 List<DartCompletionComputer> computeFast(DartCompletionRequest request) {
83 request.performance.logElapseTime('computeFast', () { 84 return request.performance.logElapseTime('computeFast', () {
84 CompilationUnit unit = context.parseCompilationUnit(source); 85 CompilationUnit unit = context.parseCompilationUnit(source);
85 request.unit = unit; 86 request.unit = unit;
86 request.node = new NodeLocator.con1(request.offset).searchWithin(unit); 87 request.node = new NodeLocator.con1(request.offset).searchWithin(unit);
87 request.node.accept(new _ReplacementOffsetBuilder(request)); 88 request.node.accept(new _ReplacementOffsetBuilder(request));
88 computers.removeWhere((DartCompletionComputer c) { 89 List<DartCompletionComputer> todo = new List.from(computers);
90 todo.removeWhere((DartCompletionComputer c) {
89 return request.performance.logElapseTime( 91 return request.performance.logElapseTime(
90 'computeFast ${c.runtimeType}', 92 'computeFast ${c.runtimeType}',
91 () { 93 () {
92 return c.computeFast(request); 94 return c.computeFast(request);
93 }); 95 });
94 }); 96 });
95 sendResults(request, computers.isEmpty); 97 sendResults(request, todo.isEmpty);
98 return todo;
96 }); 99 });
97 } 100 }
98 101
99 /** 102 /**
100 * If there is remaining work to be done, then wait for the unit to be 103 * If there is remaining work to be done, then wait for the unit to be
101 * resolved and request that each remaining computer finish their work. 104 * resolved and request that each remaining computer finish their work.
102 */ 105 */
103 void computeFull(DartCompletionRequest request) { 106 void computeFull(DartCompletionRequest request,
107 List<DartCompletionComputer> todo) {
104 request.performance.logStartTime('waitForAnalysis'); 108 request.performance.logStartTime('waitForAnalysis');
105 waitForAnalysis().then((CompilationUnit unit) { 109 waitForAnalysis().then((CompilationUnit unit) {
106 request.performance.logElapseTime('waitForAnalysis'); 110 request.performance.logElapseTime('waitForAnalysis');
107 if (unit == null) { 111 if (unit == null) {
108 sendResults(request, true); 112 sendResults(request, true);
109 return; 113 return;
110 } 114 }
111 request.performance.logElapseTime('computeFull', () { 115 request.performance.logElapseTime('computeFull', () {
112 request.unit = unit; 116 request.unit = unit;
113 request.node = new NodeLocator.con1(request.offset).searchWithin(unit); 117 request.node = new NodeLocator.con1(request.offset).searchWithin(unit);
114 int count = computers.length; 118 int count = todo.length;
115 computers.forEach((DartCompletionComputer c) { 119 todo.forEach((DartCompletionComputer c) {
116 String name = c.runtimeType.toString(); 120 String name = c.runtimeType.toString();
117 String completeTag = 'computeFull $name complete'; 121 String completeTag = 'computeFull $name complete';
118 request.performance.logStartTime(completeTag); 122 request.performance.logStartTime(completeTag);
119 request.performance.logElapseTime('computeFull $name', () { 123 request.performance.logElapseTime('computeFull $name', () {
120 c.computeFull(request).then((bool changed) { 124 c.computeFull(request).then((bool changed) {
121 request.performance.logElapseTime(completeTag); 125 request.performance.logElapseTime(completeTag);
122 bool last = --count == 0; 126 bool last = --count == 0;
123 if (changed || last) { 127 if (changed || last) {
124 sendResults(request, last); 128 sendResults(request, last);
125 } 129 }
126 }); 130 });
127 }); 131 });
128 }); 132 });
129 }); 133 });
130 }); 134 });
131 } 135 }
132 136
133 @override 137 @override
134 void computeSuggestions(CompletionRequest completionRequest) { 138 void computeSuggestions(CompletionRequest completionRequest) {
135 DartCompletionRequest request = new DartCompletionRequest( 139 DartCompletionRequest request = new DartCompletionRequest(
136 context, 140 context,
137 searchEngine, 141 searchEngine,
138 source, 142 source,
139 completionRequest.offset, 143 completionRequest.offset,
140 cache, 144 cache,
141 completionRequest.performance); 145 completionRequest.performance);
142 request.performance.logElapseTime('compute', () { 146 request.performance.logElapseTime('compute', () {
143 computeFast(request); 147 List<DartCompletionComputer> todo = computeFast(request);
144 if (!computers.isEmpty) { 148 if (!todo.isEmpty) {
145 computeFull(request); 149 computeFull(request, todo);
146 } 150 }
147 }); 151 });
148 } 152 }
149 153
150 /** 154 /**
151 * Send the current list of suggestions to the client. 155 * Send the current list of suggestions to the client.
152 */ 156 */
153 void sendResults(DartCompletionRequest request, bool last) { 157 void sendResults(DartCompletionRequest request, bool last) {
154 controller.add( 158 controller.add(
155 new CompletionResult( 159 new CompletionResult(
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 _ReplacementOffsetBuilder(this.request) { 258 _ReplacementOffsetBuilder(this.request) {
255 request.replacementOffset = request.offset; 259 request.replacementOffset = request.offset;
256 request.replacementLength = 0; 260 request.replacementLength = 0;
257 } 261 }
258 262
259 visitSimpleIdentifier(SimpleIdentifier node) { 263 visitSimpleIdentifier(SimpleIdentifier node) {
260 request.replacementOffset = node.offset; 264 request.replacementOffset = node.offset;
261 request.replacementLength = node.length; 265 request.replacementLength = node.length;
262 } 266 }
263 } 267 }
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