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' hide Resource; | 8 import 'dart:core' hide Resource; |
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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 if (parentUri != '.' && !parentUri.endsWith('/')) { | 109 if (parentUri != '.' && !parentUri.endsWith('/')) { |
110 parentUri = '$parentUri/'; | 110 parentUri = '$parentUri/'; |
111 } | 111 } |
112 } | 112 } |
113 String uriPrefix = parentUri == '.' ? '' : parentUri; | 113 String uriPrefix = parentUri == '.' ? '' : parentUri; |
114 | 114 |
115 String dirPath = resContext.normalize(parentUri); | 115 String dirPath = resContext.normalize(parentUri); |
116 if (resContext.isRelative(dirPath)) { | 116 if (resContext.isRelative(dirPath)) { |
117 String sourceDirPath = resContext.dirname(source.fullName); | 117 String sourceDirPath = resContext.dirname(source.fullName); |
118 if (resContext.isAbsolute(sourceDirPath)) { | 118 if (resContext.isAbsolute(sourceDirPath)) { |
119 dirPath = resContext.join(sourceDirPath, dirPath); | 119 dirPath = resContext.normalize(resContext.join(sourceDirPath, dirPath)); |
120 } else { | 120 } else { |
121 return; | 121 return; |
122 } | 122 } |
| 123 // Do not suggest relative paths reaching outside the 'lib' directory. |
| 124 bool srcInLib = resContext.split(sourceDirPath).contains('lib'); |
| 125 bool dstInLib = resContext.split(dirPath).contains('lib'); |
| 126 if (srcInLib && !dstInLib) { |
| 127 return; |
| 128 } |
123 } | 129 } |
124 if (dirPath.endsWith('\\.')) { | 130 if (dirPath.endsWith('\\.')) { |
125 dirPath = dirPath.substring(0, dirPath.length - 1); | 131 dirPath = dirPath.substring(0, dirPath.length - 1); |
126 } | 132 } |
127 | 133 |
128 Resource dir = resProvider.getResource(dirPath); | 134 Resource dir = resProvider.getResource(dirPath); |
129 if (dir is Folder) { | 135 if (dir is Folder) { |
130 for (Resource child in dir.getChildren()) { | 136 for (Resource child in dir.getChildren()) { |
131 String completion; | 137 String completion; |
132 if (child is Folder) { | 138 if (child is Folder) { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 } | 186 } |
181 | 187 |
182 String _extractPartialUri(SimpleStringLiteral node) { | 188 String _extractPartialUri(SimpleStringLiteral node) { |
183 if (request.offset < node.contentsOffset) { | 189 if (request.offset < node.contentsOffset) { |
184 return null; | 190 return null; |
185 } | 191 } |
186 return node.literal.lexeme.substring( | 192 return node.literal.lexeme.substring( |
187 node.contentsOffset - node.offset, request.offset - node.offset); | 193 node.contentsOffset - node.offset, request.offset - node.offset); |
188 } | 194 } |
189 } | 195 } |
OLD | NEW |