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 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/completion/completion_core.dart' | 9 import 'package:analysis_server/completion/completion_core.dart' |
| 10 show CompletionRequest; | 10 show CompletionRequest; |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 120 }); | 120 }); |
| 121 } | 121 } |
| 122 | 122 |
| 123 /** | 123 /** |
| 124 * Compute suggestions based upon cached information only | 124 * Compute suggestions based upon cached information only |
| 125 * then send an initial response to the client. | 125 * then send an initial response to the client. |
| 126 * Return a list of contributors for which [computeFull] should be called | 126 * Return a list of contributors for which [computeFull] should be called |
| 127 */ | 127 */ |
| 128 List<DartCompletionContributor> computeFast( | 128 List<DartCompletionContributor> computeFast( |
| 129 DartCompletionRequest request, CompletionPerformance performance) { | 129 DartCompletionRequest request, CompletionPerformance performance) { |
| 130 bool isKeywordOrIdentifier(Token token) => | |
| 131 token.type == TokenType.KEYWORD || token.type == TokenType.IDENTIFIER; | |
| 132 | |
| 130 return performance.logElapseTime('computeFast', () { | 133 return performance.logElapseTime('computeFast', () { |
| 131 CompilationUnit unit = context.parseCompilationUnit(source); | 134 CompilationUnit unit = context.parseCompilationUnit(source); |
| 132 request.unit = unit; | 135 request.unit = unit; |
| 133 request.target = new CompletionTarget.forOffset(unit, request.offset); | 136 request.target = new CompletionTarget.forOffset(unit, request.offset); |
| 134 request.replacementOffset = request.offset; | 137 request.replacementOffset = request.offset; |
| 135 request.replacementLength = 0; | 138 request.replacementLength = 0; |
| 136 if (request.offset < 0 || request.offset > unit.end) { | 139 if (request.offset < 0 || request.offset > unit.end) { |
| 137 sendResults(request, true); | 140 sendResults(request, true); |
| 138 return []; | 141 return []; |
| 139 } | 142 } |
| 140 | 143 |
| 141 var entity = request.target.entity; | 144 var entity = request.target.entity; |
| 142 Token token = entity is AstNode ? entity.beginToken : entity; | 145 Token token = entity is AstNode ? entity.beginToken : entity; |
| 143 if (token != null && | 146 if (token != null && request.offset < token.offset) { |
|
Brian Wilkerson
2015/08/03 13:53:07
Does this need to be a loop, or is the previous to
danrubel
2015/08/03 21:00:12
I considered that but did not have a test case tha
| |
| 144 token.offset <= request.offset && | 147 token = token.previous; |
| 145 (token.type == TokenType.KEYWORD || | 148 } |
| 146 token.type == TokenType.IDENTIFIER)) { | 149 if (token != null) { |
| 147 request.replacementOffset = token.offset; | 150 if (request.offset == token.offset && !isKeywordOrIdentifier(token)) { |
|
Brian Wilkerson
2015/08/03 13:53:07
A comment about why this is necessary would be goo
danrubel
2015/08/03 21:00:12
Good point. Added.
| |
| 148 request.replacementLength = token.length; | 151 token = token.previous; |
| 152 } | |
| 153 if (token != null && isKeywordOrIdentifier(token)) { | |
| 154 if (token.offset <= request.offset && request.offset <= token.end) { | |
| 155 request.replacementOffset = token.offset; | |
| 156 request.replacementLength = token.length; | |
| 157 } | |
| 158 } | |
| 149 } | 159 } |
| 150 | 160 |
| 151 List<DartCompletionContributor> todo = new List.from(contributors); | 161 List<DartCompletionContributor> todo = new List.from(contributors); |
| 152 todo.removeWhere((DartCompletionContributor c) { | 162 todo.removeWhere((DartCompletionContributor c) { |
| 153 return performance.logElapseTime('computeFast ${c.runtimeType}', () { | 163 return performance.logElapseTime('computeFast ${c.runtimeType}', () { |
| 154 return c.computeFast(request); | 164 return c.computeFast(request); |
| 155 }); | 165 }); |
| 156 }); | 166 }); |
| 157 commonUsageComputer.computeFast(request); | 167 commonUsageComputer.computeFast(request); |
| 158 sendResults(request, todo.isEmpty); | 168 sendResults(request, todo.isEmpty); |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 373 parameterNames: suggestion.parameterNames, | 383 parameterNames: suggestion.parameterNames, |
| 374 parameterTypes: suggestion.parameterTypes, | 384 parameterTypes: suggestion.parameterTypes, |
| 375 requiredParameterCount: suggestion.requiredParameterCount, | 385 requiredParameterCount: suggestion.requiredParameterCount, |
| 376 hasNamedParameters: suggestion.hasNamedParameters, | 386 hasNamedParameters: suggestion.hasNamedParameters, |
| 377 returnType: suggestion.returnType, | 387 returnType: suggestion.returnType, |
| 378 element: suggestion.element); | 388 element: suggestion.element); |
| 379 } | 389 } |
| 380 } | 390 } |
| 381 } | 391 } |
| 382 } | 392 } |
| OLD | NEW |