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

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

Issue 1418123004: fix import uri completion exception - fixes #24709 (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 2 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/uri_contributor_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/uri_contributor.dart
diff --git a/pkg/analysis_server/lib/src/services/completion/uri_contributor.dart b/pkg/analysis_server/lib/src/services/completion/uri_contributor.dart
index 6d1926093c2436ba7166b74035bfae4365ecdbab..c6b20d3cf73fb69ed5ab02edd9d2602babdfa81a 100644
--- a/pkg/analysis_server/lib/src/services/completion/uri_contributor.dart
+++ b/pkg/analysis_server/lib/src/services/completion/uri_contributor.dart
@@ -74,19 +74,17 @@ class _UriSuggestionBuilder extends SimpleAstVisitor {
visitSimpleStringLiteral(SimpleStringLiteral node) {
AstNode parent = node.parent;
if (parent is NamespaceDirective && parent.uri == node) {
- String partial = node.literal.lexeme.substring(
- node.contentsOffset - node.offset, request.offset - node.offset);
- request.replacementOffset = node.contentsOffset;
- request.replacementLength = node.contentsEnd - node.contentsOffset;
- _addDartSuggestions();
- _addPackageSuggestions(partial);
- _addFileSuggestions(partial);
+ String partialUri = _extractPartialUri(node);
+ if (partialUri != null) {
+ _addDartSuggestions();
+ _addPackageSuggestions(partialUri);
+ _addFileSuggestions(partialUri);
+ }
} else if (parent is PartDirective && parent.uri == node) {
- String partial = node.literal.lexeme.substring(
- node.contentsOffset - node.offset, request.offset - node.offset);
- request.replacementOffset = node.contentsOffset;
- request.replacementLength = node.contentsEnd - node.contentsOffset;
- _addFileSuggestions(partial);
+ String partialUri = _extractPartialUri(node);
+ if (partialUri != null) {
+ _addFileSuggestions(partialUri);
+ }
}
}
@@ -190,4 +188,15 @@ class _UriSuggestionBuilder extends SimpleAstVisitor {
false,
false));
}
+
+ String _extractPartialUri(SimpleStringLiteral node) {
+ if (request.offset < node.contentsOffset) {
+ return null;
+ }
+ String partial = node.literal.lexeme.substring(
+ node.contentsOffset - node.offset, request.offset - node.offset);
+ request.replacementOffset = node.contentsOffset;
+ request.replacementLength = node.contentsEnd - node.contentsOffset;
+ return partial;
+ }
}
« no previous file with comments | « no previous file | pkg/analysis_server/test/services/completion/uri_contributor_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698