Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 domain.completion; | 5 library domain.completion; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analysis_server/plugin/protocol/protocol.dart'; | 9 import 'package:analysis_server/plugin/protocol/protocol.dart'; |
| 10 import 'package:analysis_server/src/analysis_server.dart'; | 10 import 'package:analysis_server/src/analysis_server.dart'; |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 84 String contributorTag = 'computeSuggestions - ${contributor.runtimeType}'; | 84 String contributorTag = 'computeSuggestions - ${contributor.runtimeType}'; |
| 85 performance.logStartTime(contributorTag); | 85 performance.logStartTime(contributorTag); |
| 86 try { | 86 try { |
| 87 suggestions.addAll(await contributor.computeSuggestions(request)); | 87 suggestions.addAll(await contributor.computeSuggestions(request)); |
| 88 } on AbortCompletion { | 88 } on AbortCompletion { |
| 89 suggestions.clear(); | 89 suggestions.clear(); |
| 90 break; | 90 break; |
| 91 } | 91 } |
| 92 performance.logElapseTime(contributorTag); | 92 performance.logElapseTime(contributorTag); |
| 93 } | 93 } |
| 94 | |
| 95 performance.logElapseTime(COMPUTE_SUGGESTIONS_TAG); | 94 performance.logElapseTime(COMPUTE_SUGGESTIONS_TAG); |
| 96 | 95 |
| 97 // TODO (danrubel) if request is obsolete | 96 // TODO (danrubel) if request is obsolete |
| 98 // (processAnalysisRequest returns false) | 97 // (processAnalysisRequest returns false) |
| 99 // then send empty results | 98 // then send empty results |
| 100 | 99 |
| 101 return new CompletionResult( | 100 return new CompletionResult( |
| 102 request.replacementOffset, request.replacementLength, suggestions); | 101 request.replacementOffset, request.replacementLength, suggestions); |
| 103 } | 102 } |
| 104 | 103 |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 132 CompletionGetSuggestionsParams params = | 131 CompletionGetSuggestionsParams params = |
| 133 new CompletionGetSuggestionsParams.fromRequest(request); | 132 new CompletionGetSuggestionsParams.fromRequest(request); |
| 134 | 133 |
| 135 AnalysisResult result; | 134 AnalysisResult result; |
| 136 AnalysisContext context; | 135 AnalysisContext context; |
| 137 Source source; | 136 Source source; |
| 138 if (server.options.enableNewAnalysisDriver) { | 137 if (server.options.enableNewAnalysisDriver) { |
| 139 result = await server.getAnalysisResult(params.file); | 138 result = await server.getAnalysisResult(params.file); |
| 140 | 139 |
| 141 if (result == null || !result.exists) { | 140 if (result == null || !result.exists) { |
| 142 server.sendResponse(new Response.unknownSource(request)); | 141 if (server.onNoAnalysisCompletion != null) { |
| 143 return; | 142 String completionId = (_nextCompletionId++).toString(); |
| 143 await server.onNoAnalysisCompletion(request, this, params, performance , completionId,); | |
|
scheglov
2017/04/26 19:35:04
Extra comma at the end?
| |
| 144 return; | |
| 145 } else { | |
| 146 server.sendResponse(new Response.unknownSource(request)); | |
| 147 return; | |
| 148 } | |
| 144 } | 149 } |
| 145 | 150 |
| 146 if (params.offset < 0 || params.offset > result.content.length) { | 151 if (params.offset < 0 || params.offset > result.content.length) { |
| 147 server.sendResponse(new Response.invalidParameter( | 152 server.sendResponse(new Response.invalidParameter( |
| 148 request, | 153 request, |
| 149 'params.offset', | 154 'params.offset', |
| 150 'Expected offset between 0 and source length inclusive,' | 155 'Expected offset between 0 and source length inclusive,' |
| 151 ' but found ${params.offset}')); | 156 ' but found ${params.offset}')); |
| 152 return; | 157 return; |
| 153 } | 158 } |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 180 | 185 |
| 181 CompletionRequestImpl completionRequest = new CompletionRequestImpl( | 186 CompletionRequestImpl completionRequest = new CompletionRequestImpl( |
| 182 result, | 187 result, |
| 183 context, | 188 context, |
| 184 server.resourceProvider, | 189 server.resourceProvider, |
| 185 server.searchEngine, | 190 server.searchEngine, |
| 186 source, | 191 source, |
| 187 params.offset, | 192 params.offset, |
| 188 performance, | 193 performance, |
| 189 server.ideOptions); | 194 server.ideOptions); |
| 195 | |
| 190 String completionId = (_nextCompletionId++).toString(); | 196 String completionId = (_nextCompletionId++).toString(); |
| 191 | 197 |
| 192 _abortCurrentRequest(); | 198 setNewRequest(completionRequest); |
| 193 _currentRequest = completionRequest; | |
| 194 | 199 |
| 195 // initial response without results | 200 // initial response without results |
| 196 server.sendResponse(new CompletionGetSuggestionsResult(completionId) | 201 server.sendResponse(new CompletionGetSuggestionsResult(completionId) |
| 197 .toResponse(request.id)); | 202 .toResponse(request.id)); |
| 198 | 203 |
| 199 // Compute suggestions in the background | 204 // Compute suggestions in the background |
| 200 computeSuggestions(completionRequest).then((CompletionResult result) { | 205 computeSuggestions(completionRequest).then((CompletionResult result) { |
| 201 const SEND_NOTIFICATION_TAG = 'send notification'; | 206 const SEND_NOTIFICATION_TAG = 'send notification'; |
| 202 performance.logStartTime(SEND_NOTIFICATION_TAG); | 207 performance.logStartTime(SEND_NOTIFICATION_TAG); |
| 203 sendCompletionNotification(completionId, result.replacementOffset, | 208 sendCompletionNotification(completionId, result.replacementOffset, |
| 204 result.replacementLength, result.suggestions); | 209 result.replacementLength, result.suggestions); |
| 205 performance.logElapseTime(SEND_NOTIFICATION_TAG); | 210 performance.logElapseTime(SEND_NOTIFICATION_TAG); |
| 206 | |
| 207 performance.notificationCount = 1; | 211 performance.notificationCount = 1; |
| 208 performance.logFirstNotificationComplete('notification 1 complete'); | 212 performance.logFirstNotificationComplete('notification 1 complete'); |
| 209 performance.suggestionCountFirst = result.suggestions.length; | 213 performance.suggestionCountFirst = result.suggestions.length; |
| 210 performance.suggestionCountLast = result.suggestions.length; | 214 performance.suggestionCountLast = result.suggestions.length; |
| 211 performance.complete(); | 215 performance.complete(); |
| 212 }).whenComplete(() { | 216 }).whenComplete(() { |
| 213 if (_currentRequest == completionRequest) { | 217 ifMatchesRequestClear(completionRequest); |
| 214 _currentRequest = null; | |
| 215 } | |
| 216 }); | 218 }); |
| 217 } | 219 } |
| 218 | 220 |
| 221 void setNewRequest(CompletionRequest completionRequest) { | |
| 222 _abortCurrentRequest(); | |
| 223 _currentRequest = completionRequest; | |
| 224 } | |
| 225 | |
| 226 void ifMatchesRequestClear(CompletionRequest completionRequest) { | |
| 227 if (_currentRequest == completionRequest) { | |
| 228 _currentRequest = null; | |
| 229 } | |
| 230 } | |
| 231 | |
| 219 /** | 232 /** |
| 220 * If tracking code completion performance over time, then | 233 * If tracking code completion performance over time, then |
| 221 * record addition information about the request in the performance record. | 234 * record addition information about the request in the performance record. |
| 222 */ | 235 */ |
| 223 void recordRequest(CompletionPerformance performance, AnalysisContext context, | 236 void recordRequest(CompletionPerformance performance, AnalysisContext context, |
| 224 Source source, int offset) { | 237 Source source, int offset) { |
| 225 performance.source = source; | 238 performance.source = source; |
| 226 if (performanceListMaxLength == 0 || context == null || source == null) { | 239 if (performanceListMaxLength == 0 || context == null || source == null) { |
| 227 return; | 240 return; |
| 228 } | 241 } |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 278 final int replacementOffset; | 291 final int replacementOffset; |
| 279 | 292 |
| 280 /** | 293 /** |
| 281 * The suggested completions. | 294 * The suggested completions. |
| 282 */ | 295 */ |
| 283 final List<CompletionSuggestion> suggestions; | 296 final List<CompletionSuggestion> suggestions; |
| 284 | 297 |
| 285 CompletionResult( | 298 CompletionResult( |
| 286 this.replacementOffset, this.replacementLength, this.suggestions); | 299 this.replacementOffset, this.replacementLength, this.suggestions); |
| 287 } | 300 } |
| OLD | NEW |