| 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 import 'dart:async'; | 5 import 'dart:async'; |
| 6 | 6 |
| 7 import 'package:analysis_server/protocol/protocol.dart'; | 7 import 'package:analysis_server/protocol/protocol.dart'; |
| 8 import 'package:analysis_server/protocol/protocol_generated.dart'; | 8 import 'package:analysis_server/protocol/protocol_generated.dart'; |
| 9 import 'package:analysis_server/src/analysis_server.dart'; | 9 import 'package:analysis_server/src/analysis_server.dart'; |
| 10 import 'package:analysis_server/src/constants.dart'; | 10 import 'package:analysis_server/src/constants.dart'; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 int offset = params.offset; | 80 int offset = params.offset; |
| 81 AnalysisDriver driver = server.getAnalysisDriver(file); | 81 AnalysisDriver driver = server.getAnalysisDriver(file); |
| 82 if (driver != null) { | 82 if (driver != null) { |
| 83 requestParams = new plugin.CompletionGetSuggestionsParams(file, offset); | 83 requestParams = new plugin.CompletionGetSuggestionsParams(file, offset); |
| 84 pluginFutures = server.pluginManager | 84 pluginFutures = server.pluginManager |
| 85 .broadcastRequest(requestParams, contextRoot: driver.contextRoot); | 85 .broadcastRequest(requestParams, contextRoot: driver.contextRoot); |
| 86 } | 86 } |
| 87 // | 87 // |
| 88 // Compute completions generated by server. | 88 // Compute completions generated by server. |
| 89 // | 89 // |
| 90 Iterable<CompletionContributor> newContributors = | |
| 91 server.serverPlugin.completionContributors; | |
| 92 List<CompletionSuggestion> suggestions = <CompletionSuggestion>[]; | 90 List<CompletionSuggestion> suggestions = <CompletionSuggestion>[]; |
| 91 if (request.result != null) { |
| 92 Iterable<CompletionContributor> newContributors = |
| 93 server.serverPlugin.completionContributors; |
| 93 | 94 |
| 94 const COMPUTE_SUGGESTIONS_TAG = 'computeSuggestions'; | 95 const COMPUTE_SUGGESTIONS_TAG = 'computeSuggestions'; |
| 95 performance.logStartTime(COMPUTE_SUGGESTIONS_TAG); | 96 performance.logStartTime(COMPUTE_SUGGESTIONS_TAG); |
| 96 | 97 |
| 97 for (CompletionContributor contributor in newContributors) { | 98 for (CompletionContributor contributor in newContributors) { |
| 98 String contributorTag = 'computeSuggestions - ${contributor.runtimeType}'; | 99 String contributorTag = 'computeSuggestions - ${contributor |
| 99 performance.logStartTime(contributorTag); | 100 .runtimeType}'; |
| 100 try { | 101 performance.logStartTime(contributorTag); |
| 101 suggestions.addAll(await contributor.computeSuggestions(request)); | 102 try { |
| 102 } on AbortCompletion { | 103 suggestions.addAll(await contributor.computeSuggestions(request)); |
| 103 suggestions.clear(); | 104 } on AbortCompletion { |
| 104 break; | 105 suggestions.clear(); |
| 106 break; |
| 107 } |
| 108 performance.logElapseTime(contributorTag); |
| 105 } | 109 } |
| 106 performance.logElapseTime(contributorTag); | 110 performance.logElapseTime(COMPUTE_SUGGESTIONS_TAG); |
| 107 } | 111 } |
| 108 performance.logElapseTime(COMPUTE_SUGGESTIONS_TAG); | |
| 109 | |
| 110 // TODO (danrubel) if request is obsolete (processAnalysisRequest returns | 112 // TODO (danrubel) if request is obsolete (processAnalysisRequest returns |
| 111 // false) then send empty results | 113 // false) then send empty results |
| 112 | 114 |
| 113 // | 115 // |
| 114 // Add the fixes produced by plugins to the server-generated fixes. | 116 // Add the fixes produced by plugins to the server-generated fixes. |
| 115 // | 117 // |
| 116 if (pluginFutures != null) { | 118 if (pluginFutures != null) { |
| 117 List<plugin.Response> responses = await waitForResponses(pluginFutures, | 119 List<plugin.Response> responses = await waitForResponses(pluginFutures, |
| 118 requestParameters: requestParams); | 120 requestParameters: requestParams); |
| 119 for (plugin.Response response in responses) { | 121 for (plugin.Response response in responses) { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 | 156 |
| 155 /** | 157 /** |
| 156 * Process a `completion.getSuggestions` request. | 158 * Process a `completion.getSuggestions` request. |
| 157 */ | 159 */ |
| 158 Future<Null> processRequest(Request request) async { | 160 Future<Null> processRequest(Request request) async { |
| 159 performance = new CompletionPerformance(); | 161 performance = new CompletionPerformance(); |
| 160 | 162 |
| 161 // extract and validate params | 163 // extract and validate params |
| 162 CompletionGetSuggestionsParams params = | 164 CompletionGetSuggestionsParams params = |
| 163 new CompletionGetSuggestionsParams.fromRequest(request); | 165 new CompletionGetSuggestionsParams.fromRequest(request); |
| 166 String filePath = params.file; |
| 167 int offset = params.offset; |
| 164 | 168 |
| 165 AnalysisResult result = await server.getAnalysisResult(params.file); | 169 AnalysisResult result = await server.getAnalysisResult(filePath); |
| 170 Source source; |
| 166 | 171 |
| 167 if (result == null || !result.exists) { | 172 if (result == null || !result.exists) { |
| 168 if (server.onNoAnalysisCompletion != null) { | 173 if (server.onNoAnalysisCompletion != null) { |
| 169 String completionId = (_nextCompletionId++).toString(); | 174 String completionId = (_nextCompletionId++).toString(); |
| 170 await server.onNoAnalysisCompletion( | 175 await server.onNoAnalysisCompletion( |
| 171 request, this, params, performance, completionId); | 176 request, this, params, performance, completionId); |
| 172 return; | 177 return; |
| 173 } else { | 178 } |
| 174 server.sendResponse(new Response.unknownSource(request)); | 179 source = server.resourceProvider.getFile(filePath).createSource(); |
| 180 } else { |
| 181 if (offset < 0 || offset > result.content.length) { |
| 182 server.sendResponse(new Response.invalidParameter( |
| 183 request, |
| 184 'params.offset', |
| 185 'Expected offset between 0 and source length inclusive,' |
| 186 ' but found ${offset}')); |
| 175 return; | 187 return; |
| 176 } | 188 } |
| 189 source = |
| 190 server.resourceProvider.getFile(result.path).createSource(result.uri); |
| 191 |
| 192 recordRequest(performance, source, result.content, offset); |
| 177 } | 193 } |
| 178 | |
| 179 if (params.offset < 0 || params.offset > result.content.length) { | |
| 180 server.sendResponse(new Response.invalidParameter( | |
| 181 request, | |
| 182 'params.offset', | |
| 183 'Expected offset between 0 and source length inclusive,' | |
| 184 ' but found ${params.offset}')); | |
| 185 return; | |
| 186 } | |
| 187 | |
| 188 Source source = | |
| 189 server.resourceProvider.getFile(result.path).createSource(result.uri); | |
| 190 | |
| 191 recordRequest(performance, source, result.content, params.offset); | |
| 192 | |
| 193 CompletionRequestImpl completionRequest = new CompletionRequestImpl( | 194 CompletionRequestImpl completionRequest = new CompletionRequestImpl( |
| 194 result, | 195 result, |
| 195 server.resourceProvider, | 196 server.resourceProvider, |
| 196 source, | 197 source, |
| 197 params.offset, | 198 offset, |
| 198 performance, | 199 performance, |
| 199 server.ideOptions); | 200 server.ideOptions); |
| 200 | 201 |
| 201 String completionId = (_nextCompletionId++).toString(); | 202 String completionId = (_nextCompletionId++).toString(); |
| 202 | 203 |
| 203 setNewRequest(completionRequest); | 204 setNewRequest(completionRequest); |
| 204 | 205 |
| 205 // initial response without results | 206 // initial response without results |
| 206 server.sendResponse(new CompletionGetSuggestionsResult(completionId) | 207 server.sendResponse(new CompletionGetSuggestionsResult(completionId) |
| 207 .toResponse(request.id)); | 208 .toResponse(request.id)); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 final int replacementOffset; | 288 final int replacementOffset; |
| 288 | 289 |
| 289 /** | 290 /** |
| 290 * The suggested completions. | 291 * The suggested completions. |
| 291 */ | 292 */ |
| 292 final List<CompletionSuggestion> suggestions; | 293 final List<CompletionSuggestion> suggestions; |
| 293 | 294 |
| 294 CompletionResult( | 295 CompletionResult( |
| 295 this.replacementOffset, this.replacementLength, this.suggestions); | 296 this.replacementOffset, this.replacementLength, this.suggestions); |
| 296 } | 297 } |
| OLD | NEW |