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

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: merge and address comments Created 5 years, 4 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..b3a78e68fdf80bd80cfa8fa02724e3dfaa769b42 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,22 @@ 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) {
+ token = token.previous;
+ }
+ if (token != null) {
+ if (request.offset == token.offset && !isKeywordOrIdentifier(token)) {
+ // If the insertion point is at the beginning of the current token
+ // and the current token is not an identifier
+ // then check the previous token to see if it should be replaced
+ 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