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.contributor.dart.importuri; | 5 library services.completion.contributor.dart.importuri; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:core'; | 8 import 'dart:core'; |
9 | 9 |
10 import 'package:analysis_server/src/provisional/completion/dart/completion_dart.
dart'; | 10 import 'package:analysis_server/src/provisional/completion/dart/completion_dart.
dart'; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 | 48 |
49 @override | 49 @override |
50 visitImportDirective(ImportDirective node) { | 50 visitImportDirective(ImportDirective node) { |
51 visitNamespaceDirective(node); | 51 visitNamespaceDirective(node); |
52 } | 52 } |
53 | 53 |
54 visitNamespaceDirective(NamespaceDirective node) { | 54 visitNamespaceDirective(NamespaceDirective node) { |
55 StringLiteral uri = node.uri; | 55 StringLiteral uri = node.uri; |
56 if (uri is SimpleStringLiteral) { | 56 if (uri is SimpleStringLiteral) { |
57 int offset = request.offset; | 57 int offset = request.offset; |
58 if (uri.offset < offset && | 58 int start = uri.offset; |
59 (offset < uri.end || offset == uri.offset + 1)) { | 59 int end = uri.end; |
60 // Handle degenerate case where import or export is only line in file | 60 if (offset > start) { |
61 // and there is no semicolon | 61 if (offset < end) { |
62 visitSimpleStringLiteral(uri); | 62 // Quoted non-empty string |
| 63 visitSimpleStringLiteral(uri); |
| 64 } else if (offset == end) { |
| 65 if (end == start + 1) { |
| 66 // Quoted empty string |
| 67 visitSimpleStringLiteral(uri); |
| 68 } else { |
| 69 String data = request.source.contents.data; |
| 70 if (end == data.length) { |
| 71 String ch = data[end - 1]; |
| 72 if (ch != '"' && ch != "'") { |
| 73 // Insertion point at end of file |
| 74 // and missing closing quote on non-empty string |
| 75 visitSimpleStringLiteral(uri); |
| 76 } |
| 77 } |
| 78 } |
| 79 } |
| 80 } |
| 81 else if (offset == start && offset == end) { |
| 82 String data = request.source.contents.data; |
| 83 if (end == data.length) { |
| 84 String ch = data[end - 1]; |
| 85 if (ch == '"' || ch == "'") { |
| 86 // Insertion point at end of file |
| 87 // and missing closing quote on empty string |
| 88 visitSimpleStringLiteral(uri); |
| 89 } |
| 90 } |
63 } | 91 } |
64 } | 92 } |
65 } | 93 } |
66 | 94 |
67 @override | 95 @override |
68 visitSimpleStringLiteral(SimpleStringLiteral node) { | 96 visitSimpleStringLiteral(SimpleStringLiteral node) { |
69 AstNode parent = node.parent; | 97 AstNode parent = node.parent; |
70 if (parent is NamespaceDirective && parent.uri == node) { | 98 if (parent is NamespaceDirective && parent.uri == node) { |
71 String partialUri = _extractPartialUri(node); | 99 String partialUri = _extractPartialUri(node); |
72 if (partialUri != null) { | 100 if (partialUri != null) { |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 } | 215 } |
188 | 216 |
189 String _extractPartialUri(SimpleStringLiteral node) { | 217 String _extractPartialUri(SimpleStringLiteral node) { |
190 if (request.offset < node.contentsOffset) { | 218 if (request.offset < node.contentsOffset) { |
191 return null; | 219 return null; |
192 } | 220 } |
193 return node.literal.lexeme.substring( | 221 return node.literal.lexeme.substring( |
194 node.contentsOffset - node.offset, request.offset - node.offset); | 222 node.contentsOffset - node.offset, request.offset - node.offset); |
195 } | 223 } |
196 } | 224 } |
OLD | NEW |