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

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

Issue 1271723002: fix completion replacement offset/length for invalid token in switch statement (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/analysis_server/test/services/completion/completion_target_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analysis_server/lib/src/services/completion/dart_completion_manager.dart
diff --git a/pkg/analysis_server/lib/src/services/completion/dart_completion_manager.dart b/pkg/analysis_server/lib/src/services/completion/dart_completion_manager.dart
index 9fb70bab53b14f87d7c808befc55bf91e758584f..7f3af3fe998cb9c43bb958f4c97db688f726c8b8 100644
--- a/pkg/analysis_server/lib/src/services/completion/dart_completion_manager.dart
+++ b/pkg/analysis_server/lib/src/services/completion/dart_completion_manager.dart
@@ -127,6 +127,9 @@ class DartCompletionManager extends CompletionManager {
*/
List<DartCompletionContributor> computeFast(
DartCompletionRequest request, CompletionPerformance performance) {
+ bool isKeywordOrIdentifier(Token token) =>
+ token.type == TokenType.KEYWORD || token.type == TokenType.IDENTIFIER;
+
return performance.logElapseTime('computeFast', () {
CompilationUnit unit = context.parseCompilationUnit(source);
request.unit = unit;
@@ -140,12 +143,19 @@ class DartCompletionManager extends CompletionManager {
var entity = request.target.entity;
Token token = entity is AstNode ? entity.beginToken : entity;
- if (token != null &&
- token.offset <= request.offset &&
- (token.type == TokenType.KEYWORD ||
- token.type == TokenType.IDENTIFIER)) {
- request.replacementOffset = token.offset;
- request.replacementLength = token.length;
+ 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
+ token = token.previous;
+ }
+ if (token != null) {
+ 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.
+ token = token.previous;
+ }
+ if (token != null && isKeywordOrIdentifier(token)) {
+ if (token.offset <= request.offset && request.offset <= token.end) {
+ request.replacementOffset = token.offset;
+ request.replacementLength = token.length;
+ }
+ }
}
List<DartCompletionContributor> todo = new List.from(contributors);
« no previous file with comments | « no previous file | pkg/analysis_server/test/services/completion/completion_target_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698