Skip to content

Commit a348c85

Browse files
scheglovCommit Queue
authored andcommitted
Elements. Migrate DartCompletionManager and VisibilityTracker.
Change-Id: I0582c52608d29373af778ff2f1ba869fb2ef3703 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/398953 Reviewed-by: Phil Quitslund <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent 6687af5 commit a348c85

File tree

15 files changed

+145
-93
lines changed

15 files changed

+145
-93
lines changed

pkg/analysis_server/analyzer_use_new_elements.txt

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,16 @@ lib/src/lsp/handlers/commands/abstract_refactor.dart
1919
lib/src/lsp/handlers/handler_completion.dart
2020
lib/src/lsp/handlers/handler_completion_resolve.dart
2121
lib/src/lsp/handlers/handler_definition.dart
22-
lib/src/lsp/handlers/handler_document_color_presentation.dart
2322
lib/src/lsp/handlers/handler_implementation.dart
2423
lib/src/lsp/handlers/handler_references.dart
2524
lib/src/lsp/handlers/handler_rename.dart
2625
lib/src/operation/operation_analysis.dart
2726
lib/src/protocol_server.dart
2827
lib/src/search/element_references.dart
2928
lib/src/search/type_hierarchy.dart
30-
lib/src/services/completion/dart/completion_manager.dart
3129
lib/src/services/completion/dart/declaration_helper.dart
32-
lib/src/services/completion/dart/identifier_helper.dart
33-
lib/src/services/completion/dart/visibility_tracker.dart
3430
lib/src/services/correction/namespace.dart
3531
lib/src/services/correction/util.dart
36-
lib/src/services/flutter/class_description.dart
37-
lib/src/services/flutter/property.dart
38-
lib/src/services/flutter/widget_descriptions.dart
3932
lib/src/services/kythe/kythe_visitors.dart
4033
lib/src/services/refactoring/agnostic/change_method_signature.dart
4134
lib/src/services/refactoring/framework/formal_parameter.dart

pkg/analysis_server/lib/src/cider/completion.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import 'package:analysis_server/src/protocol_server.dart';
77
import 'package:analysis_server/src/services/completion/dart/completion_manager.dart';
88
import 'package:analysis_server/src/services/completion/dart/fuzzy_filter_sort.dart';
99
import 'package:analysis_server/src/services/completion/dart/suggestion_builder.dart';
10-
import 'package:analyzer/dart/element/element.dart'
11-
show CompilationUnitElement, LibraryElement;
10+
import 'package:analyzer/dart/element/element.dart' show LibraryElement;
11+
import 'package:analyzer/dart/element/element2.dart';
1212
import 'package:analyzer/src/dart/analysis/performance_logger.dart';
1313
import 'package:analyzer/src/dart/analysis/results.dart';
1414
import 'package:analyzer/src/dart/micro/resolve_file.dart';
@@ -84,7 +84,7 @@ class CiderCompletionComputer {
8484
fileState: resolvedUnit.fileState,
8585
filePath: resolvedUnit.path,
8686
fileContent: resolvedUnit.content,
87-
unitElement: resolvedUnit.unitElement,
87+
libraryFragment: resolvedUnit.unitElement,
8888
enclosingNode: enclosingNode,
8989
offset: offset,
9090
unit: resolvedUnit.parsedUnit,
@@ -167,19 +167,19 @@ class CiderCompletionComputer {
167167
// TODO(scheglov): Implement show / hide combinators.
168168
// TODO(scheglov): Implement prefixes.
169169
List<CompletionSuggestionBuilder> _importedLibrariesSuggestions({
170-
required CompilationUnitElement target,
170+
required LibraryFragment target,
171171
required OperationPerformanceImpl performance,
172172
}) {
173173
var suggestionBuilders = <CompletionSuggestionBuilder>[];
174174
var importedLibraries =
175-
target.withEnclosing
176-
.expand((fragment) => fragment.libraryImports)
177-
.map((import) => import.importedLibrary)
175+
target.withEnclosing2
176+
.expand((fragment) => fragment.libraryImports2)
177+
.map((import) => import.importedLibrary2)
178178
.nonNulls
179179
.toSet();
180180
for (var importedLibrary in importedLibraries) {
181181
var importedSuggestions = _importedLibrarySuggestions(
182-
element: importedLibrary,
182+
element: importedLibrary.asElement,
183183
performance: performance,
184184
);
185185
suggestionBuilders.addAll(importedSuggestions);

pkg/analysis_server/lib/src/cider/local_library_contributor.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class LibraryElementSuggestionBuilder
6161
@override
6262
void visitClassElement(ClassElement2 element) {
6363
AstNode node = request.target.containingNode;
64-
var libraryElement = request.libraryElement2;
64+
var libraryElement = request.libraryElement;
6565
if (node is ExtendsClause && !element.isExtendableIn2(libraryElement)) {
6666
return;
6767
} else if (node is ImplementsClause &&
@@ -130,7 +130,7 @@ class LibraryElementSuggestionBuilder
130130
visitMixinElement(MixinElement2 element) {
131131
AstNode node = request.target.containingNode;
132132
if (node is ImplementsClause &&
133-
!element.isImplementableIn2(request.libraryElement2)) {
133+
!element.isImplementableIn2(request.libraryElement)) {
134134
return;
135135
}
136136
_visitInterfaceElement(element);
@@ -219,13 +219,13 @@ class LibraryElementSuggestionBuilder
219219
}
220220
}
221221
if (opType.includeReturnValueSuggestions) {
222-
var typeSystem = request.libraryElement2.typeSystem;
222+
var typeSystem = request.libraryElement.typeSystem;
223223
var contextType = request.contextType;
224224
if (contextType is InterfaceType) {
225225
// TODO(scheglov): This looks not ideal - we should suggest getters.
226226
for (var field in element.fields2) {
227227
if (field.isStatic &&
228-
field.isAccessibleIn2(request.libraryElement2) &&
228+
field.isAccessibleIn2(request.libraryElement) &&
229229
typeSystem.isSubtypeOf(field.type, contextType)) {
230230
if (field.isSynthetic) {
231231
var getter = field.getter2;

pkg/analysis_server/lib/src/handler/legacy/completion_get_suggestions2.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ class CompletionGetSuggestions2Handler extends CompletionHandler
182182
fileState: resolvedUnit.fileState,
183183
filePath: resolvedUnit.path,
184184
fileContent: resolvedUnit.content,
185-
unitElement: resolvedUnit.unitElement,
185+
libraryFragment: resolvedUnit.unitElement,
186186
enclosingNode: enclosingNode,
187187
offset: offset,
188188
unit: resolvedUnit.parsedUnit,

pkg/analysis_server/lib/src/services/completion/dart/completion_manager.dart

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import 'package:analyzer/dart/analysis/results.dart';
1919
import 'package:analyzer/dart/analysis/session.dart';
2020
import 'package:analyzer/dart/ast/ast.dart';
2121
import 'package:analyzer/dart/ast/token.dart';
22-
import 'package:analyzer/dart/element/element.dart';
2322
import 'package:analyzer/dart/element/element2.dart';
2423
import 'package:analyzer/dart/element/type.dart';
2524
import 'package:analyzer/file_system/file_system.dart';
@@ -35,7 +34,6 @@ import 'package:analyzer/src/generated/source.dart' show SourceFactory;
3534
import 'package:analyzer/src/util/file_paths.dart' as file_paths;
3635
import 'package:analyzer/src/util/performance/operation_performance.dart';
3736
import 'package:analyzer/src/utilities/completion_matcher.dart';
38-
import 'package:analyzer/src/utilities/extensions/element.dart';
3937
import 'package:analyzer/src/utilities/fuzzy_matcher.dart';
4038
import 'package:analyzer_plugin/src/utilities/completion/completion_target.dart';
4139
import 'package:analyzer_plugin/src/utilities/completion/optype.dart';
@@ -247,10 +245,10 @@ class DartCompletionRequest {
247245
final FeatureComputer featureComputer;
248246

249247
/// The library element of the file in which completion is requested.
250-
final LibraryElement libraryElement;
248+
final LibraryElement2 libraryElement;
251249

252250
/// The library fragment of the file in which completion is requested.
253-
final CompilationUnitElement libraryFragment;
251+
final LibraryFragment libraryFragment;
254252

255253
/// Return the offset within the source at which the completion is being
256254
/// requested.
@@ -298,7 +296,7 @@ class DartCompletionRequest {
298296
required FileState fileState,
299297
required String filePath,
300298
required String fileContent,
301-
required CompilationUnitElement unitElement,
299+
required LibraryFragment libraryFragment,
302300
required AstNode enclosingNode,
303301
required int offset,
304302
required CompilationUnit unit,
@@ -307,7 +305,7 @@ class DartCompletionRequest {
307305
}) {
308306
var target = CompletionTarget.forOffset(enclosingNode, offset);
309307

310-
var libraryElement = unitElement.library;
308+
var libraryElement = libraryFragment.element;
311309
var featureComputer = FeatureComputer(
312310
libraryElement.typeSystem,
313311
libraryElement.typeProvider,
@@ -333,13 +331,13 @@ class DartCompletionRequest {
333331
),
334332
featureComputer: featureComputer,
335333
libraryElement: libraryElement,
336-
libraryFragment: unitElement,
334+
libraryFragment: libraryFragment,
337335
offset: offset,
338336
opType: opType,
339337
fileState: fileState,
340338
path: filePath,
341339
replacementRange: target.computeReplacementRange(offset),
342-
source: unitElement.source,
340+
source: libraryFragment.source,
343341
target: target,
344342
unit: unit,
345343
);
@@ -357,7 +355,7 @@ class DartCompletionRequest {
357355
fileState: resolvedUnit.fileState,
358356
filePath: resolvedUnit.path,
359357
fileContent: resolvedUnit.content,
360-
unitElement: resolvedUnit.unit.declaredElement!,
358+
libraryFragment: resolvedUnit.libraryFragment,
361359
enclosingNode: resolvedUnit.unit,
362360
offset: offset,
363361
unit: resolvedUnit.unit,
@@ -403,9 +401,6 @@ class DartCompletionRequest {
403401
return analysisSession.inheritanceManager;
404402
}
405403

406-
/// Getter for the [Element2] representation of [libraryElement].
407-
LibraryElement2 get libraryElement2 => libraryElement.asElement2;
408-
409404
/// Answer the [DartType] for Object in dart:core
410405
InterfaceType get objectType => libraryElement.typeProvider.objectType;
411406

pkg/analysis_server/lib/src/services/completion/dart/completion_state.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class CompletionState {
5858
}
5959

6060
/// The element of the library containing the completion location.
61-
LibraryElement2 get libraryElement => request.libraryElement2;
61+
LibraryElement2 get libraryElement => request.libraryElement;
6262

6363
/// The type of quotes preferred for [String]s as specified in [CodeStyleOptions].
6464
String get preferredQuoteForStrings =>

0 commit comments

Comments
 (0)