Skip to content

Commit 41641e9

Browse files
bwilkersoncommit-bot@chromium.org
authored andcommitted
Migrate more completion support
Change-Id: I073972400bb79166a836e517e268452a03b64f52 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/195040 Reviewed-by: Konstantin Shcheglov <[email protected]> Commit-Queue: Brian Wilkerson <[email protected]>
1 parent 9bd43c3 commit 41641e9

File tree

6 files changed

+79
-121
lines changed

6 files changed

+79
-121
lines changed

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

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
// @dart = 2.9
6-
75
import 'package:analysis_server/src/protocol_server.dart';
86
import 'package:analysis_server/src/services/completion/completion_core.dart';
97
import 'package:analysis_server/src/services/completion/completion_performance.dart';
@@ -35,7 +33,7 @@ class CiderCompletionComputer {
3533
final OperationPerformanceImpl _performanceRoot =
3634
OperationPerformanceImpl('<root>');
3735

38-
DartCompletionRequestImpl _dartCompletionRequest;
36+
late DartCompletionRequestImpl _dartCompletionRequest;
3937

4038
/// Paths of imported libraries for which suggestions were (re)computed
4139
/// during processing of this request. Does not include libraries that were
@@ -53,10 +51,10 @@ class CiderCompletionComputer {
5351
///
5452
/// The [line] and [column] are zero based.
5553
Future<CiderCompletionResult> compute({
56-
@required String path,
57-
@required int line,
58-
@required int column,
59-
@visibleForTesting void Function(ResolvedUnitResult) testResolvedUnit,
54+
required String path,
55+
required int line,
56+
required int column,
57+
@visibleForTesting void Function(ResolvedUnitResult)? testResolvedUnit,
6058
}) async {
6159
return _performanceRoot.runAsync('completion', (performance) async {
6260
var resolvedUnit = performance.run('resolution', (performance) {
@@ -147,9 +145,9 @@ class CiderCompletionComputer {
147145
suggestions: suggestions,
148146
performance: CiderCompletionPerformance._(
149147
file: Duration.zero,
150-
imports: performance.getChild('imports').elapsed,
151-
resolution: performance.getChild('resolution').elapsed,
152-
suggestions: performance.getChild('suggestions').elapsed,
148+
imports: performance.getChild('imports')!.elapsed,
149+
resolution: performance.getChild('resolution')!.elapsed,
150+
suggestions: performance.getChild('suggestions')!.elapsed,
153151
operations: _performanceRoot.children.first,
154152
),
155153
prefixStart: CiderPosition(line, column - filter._pattern.length),
@@ -161,9 +159,9 @@ class CiderCompletionComputer {
161159

162160
@Deprecated('Use compute')
163161
Future<CiderCompletionResult> compute2({
164-
@required String path,
165-
@required int line,
166-
@required int column,
162+
required String path,
163+
required int line,
164+
required int column,
167165
}) async {
168166
return compute(path: path, line: line, column: column);
169167
}
@@ -184,8 +182,8 @@ class CiderCompletionComputer {
184182
/// TODO(scheglov) Implement show / hide combinators.
185183
/// TODO(scheglov) Implement prefixes.
186184
List<CompletionSuggestion> _importedLibrariesSuggestions({
187-
@required LibraryElement target,
188-
@required OperationPerformanceImpl performance,
185+
required LibraryElement target,
186+
required OperationPerformanceImpl performance,
189187
}) {
190188
var suggestions = <CompletionSuggestion>[];
191189
for (var importedLibrary in target.importedLibraries) {
@@ -202,8 +200,8 @@ class CiderCompletionComputer {
202200
/// Return cached, or compute unprefixed suggestions for all elements
203201
/// exported from the library.
204202
List<CompletionSuggestion> _importedLibrarySuggestions({
205-
@required LibraryElement element,
206-
@required OperationPerformanceImpl performance,
203+
required LibraryElement element,
204+
required OperationPerformanceImpl performance,
207205
}) {
208206
performance.getDataInt('libraryCount').increment();
209207

@@ -262,11 +260,11 @@ class CiderCompletionPerformance {
262260
final OperationPerformance operations;
263261

264262
CiderCompletionPerformance._({
265-
@required this.file,
266-
@required this.imports,
267-
@required this.resolution,
268-
@required this.suggestions,
269-
@required this.operations,
263+
required this.file,
264+
required this.imports,
265+
required this.resolution,
266+
required this.suggestions,
267+
required this.operations,
270268
});
271269
}
272270

@@ -281,9 +279,9 @@ class CiderCompletionResult {
281279
final CiderPosition prefixStart;
282280

283281
CiderCompletionResult._({
284-
@required this.suggestions,
285-
@required this.performance,
286-
@required this.prefixStart,
282+
required this.suggestions,
283+
required this.performance,
284+
required this.prefixStart,
287285
});
288286
}
289287

@@ -305,8 +303,8 @@ class _FilterSort {
305303
final DartCompletionRequestImpl _request;
306304
final List<CompletionSuggestion> _suggestions;
307305

308-
FuzzyMatcher _matcher;
309-
String _pattern;
306+
late FuzzyMatcher _matcher;
307+
late String _pattern;
310308

311309
_FilterSort(this._request, this._suggestions);
312310

pkg/analysis_server/lib/src/domains/execution/completion.dart

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,11 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
// @dart = 2.9
6-
75
import 'package:analysis_server/src/protocol_server.dart'
8-
show
9-
CompletionSuggestion,
10-
RuntimeCompletionExpression,
11-
RuntimeCompletionVariable,
12-
SourceEdit;
6+
show CompletionSuggestion, RuntimeCompletionExpression, SourceEdit;
137
import 'package:analysis_server/src/services/completion/completion_core.dart';
148
import 'package:analysis_server/src/services/completion/completion_performance.dart';
159
import 'package:analysis_server/src/services/completion/dart/completion_manager.dart';
16-
import 'package:analyzer/dart/analysis/results.dart';
1710
import 'package:analyzer/file_system/overlay_file_system.dart';
1811
import 'package:analyzer/src/dart/analysis/driver.dart';
1912
import 'package:analyzer_plugin/utilities/change_builder/change_builder_core.dart';
@@ -28,18 +21,8 @@ class RuntimeCompletionComputer {
2821
final String contextPath;
2922
final int contextOffset;
3023

31-
final List<RuntimeCompletionVariable> variables;
32-
final List<RuntimeCompletionExpression> expressions;
33-
34-
RuntimeCompletionComputer(
35-
this.resourceProvider,
36-
this.analysisDriver,
37-
this.code,
38-
this.offset,
39-
this.contextPath,
40-
this.contextOffset,
41-
this.variables,
42-
this.expressions);
24+
RuntimeCompletionComputer(this.resourceProvider, this.analysisDriver,
25+
this.code, this.offset, this.contextPath, this.contextOffset);
4326

4427
Future<RuntimeCompletionResult> compute() async {
4528
var contextResult = await analysisDriver.getResult(contextPath);
@@ -65,7 +48,7 @@ class RuntimeCompletionComputer {
6548

6649
// Compute the patched context file content.
6750
var targetCode = SourceEdit.applySequence(
68-
contextResult.content,
51+
contextResult.content!,
6952
changeBuilder.sourceChange.edits[0].edits,
7053
);
7154

@@ -75,9 +58,8 @@ class RuntimeCompletionComputer {
7558

7659
// Update the context file content to include the code being completed.
7760
// Then resolve it, and restore the file to its initial state.
78-
ResolvedUnitResult targetResult;
79-
await _withContextFileContent(targetCode, () async {
80-
targetResult = await analysisDriver.getResult(contextPath);
61+
var targetResult = await _withContextFileContent(targetCode, () async {
62+
return await analysisDriver.getResult(contextPath);
8163
});
8264

8365
var contributor = DartCompletionManager(
@@ -106,8 +88,8 @@ class RuntimeCompletionComputer {
10688
return RuntimeCompletionResult(expressions, suggestions);
10789
}
10890

109-
Future<void> _withContextFileContent(
110-
String newContent, Future<void> Function() f) async {
91+
Future<R> _withContextFileContent<R>(
92+
String newContent, Future<R> Function() f) async {
11193
if (resourceProvider.hasOverlay(contextPath)) {
11294
var contextFile = resourceProvider.getFile(contextPath);
11395
var prevOverlayContent = contextFile.readAsStringSync();
@@ -119,7 +101,7 @@ class RuntimeCompletionComputer {
119101
modificationStamp: 0,
120102
);
121103
analysisDriver.changeFile(contextPath);
122-
await f();
104+
return await f();
123105
} finally {
124106
resourceProvider.setOverlay(
125107
contextPath,
@@ -136,7 +118,7 @@ class RuntimeCompletionComputer {
136118
modificationStamp: 0,
137119
);
138120
analysisDriver.changeFile(contextPath);
139-
await f();
121+
return await f();
140122
} finally {
141123
resourceProvider.removeOverlay(contextPath);
142124
analysisDriver.changeFile(contextPath);

pkg/analysis_server/test/services/completion/postfix/test_all.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
// @dart = 2.9
6-
75
import 'package:test_reflective_loader/test_reflective_loader.dart';
86

97
import 'postfix_completion_test.dart' as postfix_completion_test;

0 commit comments

Comments
 (0)