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

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

Issue 2499693002: Fixes for URI and Object completions with the new driver. (Closed)
Patch Set: Created 4 years, 1 month 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 unified diff | Download patch
OLDNEW
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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 if (end == data.length) { 70 if (end == data.length) {
71 String ch = data[end - 1]; 71 String ch = data[end - 1];
72 if (ch != '"' && ch != "'") { 72 if (ch != '"' && ch != "'") {
73 // Insertion point at end of file 73 // Insertion point at end of file
74 // and missing closing quote on non-empty string 74 // and missing closing quote on non-empty string
75 visitSimpleStringLiteral(uri); 75 visitSimpleStringLiteral(uri);
76 } 76 }
77 } 77 }
78 } 78 }
79 } 79 }
80 } 80 } else if (offset == start && offset == end) {
81 else if (offset == start && offset == end) {
82 String data = request.source.contents.data; 81 String data = request.source.contents.data;
83 if (end == data.length) { 82 if (end == data.length) {
84 String ch = data[end - 1]; 83 String ch = data[end - 1];
85 if (ch == '"' || ch == "'") { 84 if (ch == '"' || ch == "'") {
86 // Insertion point at end of file 85 // Insertion point at end of file
87 // and missing closing quote on empty string 86 // and missing closing quote on empty string
88 visitSimpleStringLiteral(uri); 87 visitSimpleStringLiteral(uri);
89 } 88 }
90 } 89 }
91 } 90 }
(...skipping 13 matching lines...) Expand all
105 } else if (parent is PartDirective && parent.uri == node) { 104 } else if (parent is PartDirective && parent.uri == node) {
106 String partialUri = _extractPartialUri(node); 105 String partialUri = _extractPartialUri(node);
107 if (partialUri != null) { 106 if (partialUri != null) {
108 _addFileSuggestions(partialUri); 107 _addFileSuggestions(partialUri);
109 } 108 }
110 } 109 }
111 } 110 }
112 111
113 void _addDartSuggestions() { 112 void _addDartSuggestions() {
114 _addSuggestion('dart:'); 113 _addSuggestion('dart:');
115 SourceFactory factory = request.context.sourceFactory; 114 SourceFactory factory = request.sourceFactory;
116 for (SdkLibrary lib in factory.dartSdk.sdkLibraries) { 115 for (SdkLibrary lib in factory.dartSdk.sdkLibraries) {
117 if (!lib.isInternal && !lib.isImplementation) { 116 if (!lib.isInternal && !lib.isImplementation) {
118 if (!lib.shortName.startsWith('dart:_')) { 117 if (!lib.shortName.startsWith('dart:_')) {
119 _addSuggestion(lib.shortName, 118 _addSuggestion(lib.shortName,
120 relevance: lib.shortName == 'dart:core' 119 relevance: lib.shortName == 'dart:core'
121 ? DART_RELEVANCE_LOW 120 ? DART_RELEVANCE_LOW
122 : DART_RELEVANCE_DEFAULT); 121 : DART_RELEVANCE_DEFAULT);
123 } 122 }
124 } 123 }
125 } 124 }
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 if (partial.startsWith(childPrefix)) { 184 if (partial.startsWith(childPrefix)) {
186 _addPackageFolderSuggestions(partial, childPrefix, child); 185 _addPackageFolderSuggestions(partial, childPrefix, child);
187 } 186 }
188 } else { 187 } else {
189 _addSuggestion('$prefix${child.shortName}'); 188 _addSuggestion('$prefix${child.shortName}');
190 } 189 }
191 } 190 }
192 } 191 }
193 192
194 void _addPackageSuggestions(String partial) { 193 void _addPackageSuggestions(String partial) {
195 SourceFactory factory = request.context.sourceFactory; 194 SourceFactory factory = request.sourceFactory;
196 Map<String, List<Folder>> packageMap = factory.packageMap; 195 Map<String, List<Folder>> packageMap = factory.packageMap;
197 if (packageMap != null) { 196 if (packageMap != null) {
198 _addSuggestion('package:'); 197 _addSuggestion('package:');
199 packageMap.forEach((String pkgName, List<Folder> folders) { 198 packageMap.forEach((String pkgName, List<Folder> folders) {
200 String prefix = 'package:$pkgName/'; 199 String prefix = 'package:$pkgName/';
201 _addSuggestion(prefix); 200 _addSuggestion(prefix);
202 for (Folder folder in folders) { 201 for (Folder folder in folders) {
203 if (folder.exists) { 202 if (folder.exists) {
204 _addPackageFolderSuggestions(partial, prefix, folder); 203 _addPackageFolderSuggestions(partial, prefix, folder);
205 } 204 }
206 } 205 }
207 }); 206 });
208 } 207 }
209 } 208 }
210 209
211 void _addSuggestion(String completion, 210 void _addSuggestion(String completion,
212 {int relevance: DART_RELEVANCE_DEFAULT}) { 211 {int relevance: DART_RELEVANCE_DEFAULT}) {
213 suggestions.add(new CompletionSuggestion(CompletionSuggestionKind.IMPORT, 212 suggestions.add(new CompletionSuggestion(CompletionSuggestionKind.IMPORT,
214 relevance, completion, completion.length, 0, false, false)); 213 relevance, completion, completion.length, 0, false, false));
215 } 214 }
216 215
217 String _extractPartialUri(SimpleStringLiteral node) { 216 String _extractPartialUri(SimpleStringLiteral node) {
218 if (request.offset < node.contentsOffset) { 217 if (request.offset < node.contentsOffset) {
219 return null; 218 return null;
220 } 219 }
221 return node.literal.lexeme.substring( 220 return node.literal.lexeme.substring(
222 node.contentsOffset - node.offset, request.offset - node.offset); 221 node.contentsOffset - node.offset, request.offset - node.offset);
223 } 222 }
224 } 223 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698