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; |
+ } |
} |