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

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

Issue 1514603002: suggest after import prefix in part files - fixes #25023 (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: merge Created 5 years 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) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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.dart.manager; 5 library services.completion.dart.manager;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analysis_server/plugin/protocol/protocol.dart'; 9 import 'package:analysis_server/plugin/protocol/protocol.dart';
10 import 'package:analysis_server/src/provisional/completion/completion_core.dart' 10 import 'package:analysis_server/src/provisional/completion/completion_core.dart'
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 return suggestions; 53 return suggestions;
54 } 54 }
55 } 55 }
56 56
57 /** 57 /**
58 * The information about a requested list of completions within a Dart file. 58 * The information about a requested list of completions within a Dart file.
59 */ 59 */
60 class DartCompletionRequestImpl extends CompletionRequestImpl 60 class DartCompletionRequestImpl extends CompletionRequestImpl
61 implements DartCompletionRequest { 61 implements DartCompletionRequest {
62 /** 62 /**
63 * The source for the library containing the completion request.
64 * This may be different from the source in which the completion is requested
65 * if the completion is being requested in a part file.
66 * This may be `null` if the library for a part file cannot be determined.
67 */
68 Source _librarySource;
69
70 /**
63 * The cached completion target or `null` if not computed yet. 71 * The cached completion target or `null` if not computed yet.
64 */ 72 */
65 CompletionTarget _target; 73 CompletionTarget _target;
66 74
67 /** 75 /**
68 * The [DartType] for Object in dart:core 76 * The [DartType] for Object in dart:core
69 */ 77 */
70 InterfaceType _objectType; 78 InterfaceType _objectType;
71 79
72 /** 80 /**
(...skipping 13 matching lines...) Expand all
86 request.source, 94 request.source,
87 request.offset); 95 request.offset);
88 } 96 }
89 97
90 DartCompletionRequestImpl._( 98 DartCompletionRequestImpl._(
91 AnalysisContext context, 99 AnalysisContext context,
92 ResourceProvider resourceProvider, 100 ResourceProvider resourceProvider,
93 SearchEngine searchEngine, 101 SearchEngine searchEngine,
94 Source source, 102 Source source,
95 int offset) 103 int offset)
96 : super(context, resourceProvider, searchEngine, source, offset); 104 : super(context, resourceProvider, searchEngine, source, offset) {
105 if (target.unit.directives.any((d) => d is PartOfDirective)) {
106 List<Source> libraries = context.getLibrariesContaining(source);
107 if (libraries.isNotEmpty) {
108 _librarySource = libraries[0];
109 }
110 } else {
111 _librarySource = source;
112 }
113 }
97 114
98 @override 115 @override
99 Future<LibraryElement> get libraryElement async { 116 Future<LibraryElement> get libraryElement async {
100 //TODO(danrubel) build the library element rather than all the declarations 117 //TODO(danrubel) build the library element rather than all the declarations
101 CompilationUnit unit = await resolveDeclarationsInScope(); 118 CompilationUnit unit = await resolveDeclarationsInScope();
102 if (unit != null) { 119 if (unit != null) {
103 CompilationUnitElement elem = unit.element; 120 CompilationUnitElement elem = unit.element;
104 if (elem != null) { 121 if (elem != null) {
105 return elem.library; 122 return elem.library;
106 } 123 }
(...skipping 20 matching lines...) Expand all
127 return _target; 144 return _target;
128 } 145 }
129 146
130 @override 147 @override
131 Future<CompilationUnit> resolveDeclarationsInScope() async { 148 Future<CompilationUnit> resolveDeclarationsInScope() async {
132 CompilationUnit unit = target.unit; 149 CompilationUnit unit = target.unit;
133 if (_haveResolveDeclarationsInScope) { 150 if (_haveResolveDeclarationsInScope) {
134 return unit; 151 return unit;
135 } 152 }
136 153
137 // Determine the library source 154 // Gracefully degrade if librarySource cannot be determined
138 Source librarySource; 155 if (_librarySource == null) {
139 if (unit.directives.any((d) => d is PartOfDirective)) { 156 return null;
140 List<Source> libraries = context.getLibrariesContaining(source);
141 if (libraries.isEmpty) {
142 return null;
143 }
144 librarySource = libraries[0];
145 } else {
146 librarySource = source;
147 } 157 }
148 158
149 // Resolve declarations in the target unit 159 // Resolve declarations in the target unit
150 CompilationUnit resolvedUnit = 160 CompilationUnit resolvedUnit =
151 await new AnalysisFutureHelper<CompilationUnit>( 161 await new AnalysisFutureHelper<CompilationUnit>(context,
152 context, 162 new LibrarySpecificUnit(_librarySource, source), RESOLVED_UNIT3)
153 new LibrarySpecificUnit(librarySource, source), 163 .computeAsync();
154 RESOLVED_UNIT3).computeAsync();
155 164
156 // TODO(danrubel) determine if the underlying source has been modified 165 // TODO(danrubel) determine if the underlying source has been modified
157 // in a way that invalidates the completion request 166 // in a way that invalidates the completion request
158 // and return null 167 // and return null
159 168
160 // Gracefully degrade if unit cannot be resolved 169 // Gracefully degrade if unit cannot be resolved
161 if (resolvedUnit == null) { 170 if (resolvedUnit == null) {
162 return null; 171 return null;
163 } 172 }
164 173
165 // Recompute the target for the newly resolved unit 174 // Recompute the target for the newly resolved unit
166 _target = new CompletionTarget.forOffset(resolvedUnit, offset); 175 _target = new CompletionTarget.forOffset(resolvedUnit, offset);
167 _haveResolveDeclarationsInScope = true; 176 _haveResolveDeclarationsInScope = true;
168 return resolvedUnit; 177 return resolvedUnit;
169 } 178 }
170 179
171 @override 180 @override
181 Future<List<Directive>> resolveDirectives() async {
182 CompilationUnit libUnit;
183 if (_librarySource == source) {
184 libUnit = await resolveDeclarationsInScope();
185 } else if (_librarySource != null) {
186 libUnit =
187 await new AnalysisFutureHelper<CompilationUnit>(
188 context,
189 new LibrarySpecificUnit(_librarySource, _librarySource),
190 RESOLVED_UNIT3)
191 .computeAsync();
192 }
193 return libUnit?.directives;
194 }
195
196 @override
172 Future resolveExpression(Expression expression) async { 197 Future resolveExpression(Expression expression) async {
173 //TODO(danrubel) resolve the expression or containing method 198 //TODO(danrubel) resolve the expression or containing method
174 // rather than the entire complilation unit 199 // rather than the entire complilation unit
175 200
176 CompilationUnit unit = target.unit; 201 // Gracefully degrade if librarySource cannot be determined
177 202 if (_librarySource == null) {
178 // Determine the library source 203 return null;
179 Source librarySource;
180 if (unit.directives.any((d) => d is PartOfDirective)) {
181 List<Source> libraries = context.getLibrariesContaining(source);
182 if (libraries.isEmpty) {
183 return;
184 }
185 librarySource = libraries[0];
186 } else {
187 librarySource = source;
188 } 204 }
189 205
190 // Resolve declarations in the target unit 206 // Resolve declarations in the target unit
191 CompilationUnit resolvedUnit = 207 CompilationUnit resolvedUnit =
192 await new AnalysisFutureHelper<CompilationUnit>( 208 await new AnalysisFutureHelper<CompilationUnit>(context,
193 context, 209 new LibrarySpecificUnit(_librarySource, source), RESOLVED_UNIT)
194 new LibrarySpecificUnit(librarySource, source), 210 .computeAsync();
195 RESOLVED_UNIT).computeAsync();
196 211
197 // TODO(danrubel) determine if the underlying source has been modified 212 // TODO(danrubel) determine if the underlying source has been modified
198 // in a way that invalidates the completion request 213 // in a way that invalidates the completion request
199 // and return null 214 // and return null
200 215
201 // Gracefully degrade if unit cannot be resolved 216 // Gracefully degrade if unit cannot be resolved
202 if (resolvedUnit == null) { 217 if (resolvedUnit == null) {
203 return; 218 return null;
204 } 219 }
205 220
206 // Recompute the target for the newly resolved unit 221 // Recompute the target for the newly resolved unit
207 _target = new CompletionTarget.forOffset(resolvedUnit, offset); 222 _target = new CompletionTarget.forOffset(resolvedUnit, offset);
208 _haveResolveDeclarationsInScope = true; 223 _haveResolveDeclarationsInScope = true;
209 } 224 }
210 } 225 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698