Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 58b0668

Browse files
author
Dart CI
committed
Version 2.18.0-58.0.dev
Merge commit 'eabec1c6a554a3cc13dcd41a09675ec8cf79d3e2' into 'dev'
2 parents e89b629 + eabec1c commit 58b0668

File tree

8 files changed

+156
-53
lines changed

8 files changed

+156
-53
lines changed

pkg/analysis_server/lib/src/lsp/handlers/handler_completion.dart

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ class CompletionHandler extends MessageHandler<CompletionParams, CompletionList>
130130
offset,
131131
triggerCharacter,
132132
token,
133-
maxResults: maxResults,
134133
);
135134
},
136135
);
@@ -294,9 +293,8 @@ class CompletionHandler extends MessageHandler<CompletionParams, CompletionList>
294293
OperationPerformanceImpl performance,
295294
int offset,
296295
String? triggerCharacter,
297-
CancellationToken token, {
298-
required int maxResults,
299-
}) async {
296+
CancellationToken token,
297+
) async {
300298
final useSuggestionSets =
301299
suggestFromUnimportedLibraries && capabilities.applyEdit;
302300

pkg/analyzer/lib/src/dart/analysis/driver.dart

Lines changed: 90 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ class AnalysisDriver implements AnalysisDriverGeneric {
166166
final _requestedLibraries =
167167
<String, List<Completer<ResolvedLibraryResult>>>{};
168168

169+
/// The queue of requests for completion.
170+
final List<_ResolveForCompletionRequest> _resolveForCompletionRequests = [];
171+
169172
/// The task that discovers available files. If this field is not `null`,
170173
/// and the task is not completed, it should be performed and completed
171174
/// before any name searching task.
@@ -401,6 +404,9 @@ class AnalysisDriver implements AnalysisDriverGeneric {
401404

402405
@override
403406
AnalysisDriverPriority get workPriority {
407+
if (_resolveForCompletionRequests.isNotEmpty) {
408+
return AnalysisDriverPriority.completion;
409+
}
404410
if (_requestedFiles.isNotEmpty) {
405411
return AnalysisDriverPriority.interactive;
406412
}
@@ -1044,6 +1050,19 @@ class AnalysisDriver implements AnalysisDriverGeneric {
10441050
_discoverDartCore();
10451051
}
10461052

1053+
if (_resolveForCompletionRequests.isNotEmpty) {
1054+
final request = _resolveForCompletionRequests.removeLast();
1055+
try {
1056+
final result = _resolveForCompletion(request);
1057+
request.completer.complete(result);
1058+
} catch (exception, stackTrace) {
1059+
_reportException(request.path, exception, stackTrace);
1060+
request.completer.completeError(exception, stackTrace);
1061+
_clearLibraryContextAfterException();
1062+
}
1063+
return;
1064+
}
1065+
10471066
// Analyze a requested file.
10481067
if (_requestedFiles.isNotEmpty) {
10491068
String path = _requestedFiles.keys.first;
@@ -1311,54 +1330,14 @@ class AnalysisDriver implements AnalysisDriverGeneric {
13111330
required int offset,
13121331
required OperationPerformanceImpl performance,
13131332
}) async {
1314-
if (!_isAbsolutePath(path)) {
1315-
return null;
1316-
}
1317-
1318-
if (!_fsState.hasUri(path)) {
1319-
return null;
1320-
}
1321-
1322-
// Process pending changes.
1323-
while (_fileTracker.verifyChangedFilesIfNeeded()) {}
1324-
1325-
var file = _fsState.getFileForPath(path);
1326-
1327-
var library = file.isPart ? file.library : file;
1328-
if (library == null) {
1329-
return null;
1330-
}
1331-
1332-
await libraryContext.load(library);
1333-
var unitElement = libraryContext.computeUnitElement(library, file)
1334-
as CompilationUnitElementImpl;
1335-
1336-
var analysisResult = LibraryAnalyzer(
1337-
analysisOptions as AnalysisOptionsImpl,
1338-
declaredVariables,
1339-
sourceFactory,
1340-
libraryContext.elementFactory.libraryOfUri2(library.uriStr),
1341-
libraryContext.elementFactory.analysisSession.inheritanceManager,
1342-
library,
1343-
testingData: testingData,
1344-
).analyzeForCompletion(
1345-
file: file,
1333+
final request = _ResolveForCompletionRequest(
1334+
path: path,
13461335
offset: offset,
1347-
unitElement: unitElement,
13481336
performance: performance,
13491337
);
1350-
1351-
return ResolvedForCompletionResultImpl(
1352-
analysisSession: currentSession,
1353-
path: path,
1354-
uri: file.uri,
1355-
exists: file.exists,
1356-
content: file.content,
1357-
lineInfo: file.lineInfo,
1358-
parsedUnit: analysisResult.parsedUnit,
1359-
unitElement: unitElement,
1360-
resolvedNodes: analysisResult.resolvedNodes,
1361-
);
1338+
_resolveForCompletionRequests.add(request);
1339+
_scheduler.notify(this);
1340+
return request.completer.future;
13621341
}
13631342

13641343
void _addDeclaredVariablesToSignature(ApiSignature buffer) {
@@ -1869,6 +1848,57 @@ class AnalysisDriver implements AnalysisDriverGeneric {
18691848
);
18701849
}
18711850

1851+
Future<ResolvedForCompletionResultImpl?> _resolveForCompletion(
1852+
_ResolveForCompletionRequest request,
1853+
) async {
1854+
final path = request.path;
1855+
if (!_isAbsolutePath(path)) {
1856+
return null;
1857+
}
1858+
1859+
if (!_fsState.hasUri(path)) {
1860+
return null;
1861+
}
1862+
1863+
var file = _fsState.getFileForPath(path);
1864+
1865+
var library = file.isPart ? file.library : file;
1866+
if (library == null) {
1867+
return null;
1868+
}
1869+
1870+
await libraryContext.load(library);
1871+
var unitElement = libraryContext.computeUnitElement(library, file)
1872+
as CompilationUnitElementImpl;
1873+
1874+
var analysisResult = LibraryAnalyzer(
1875+
analysisOptions as AnalysisOptionsImpl,
1876+
declaredVariables,
1877+
sourceFactory,
1878+
libraryContext.elementFactory.libraryOfUri2(library.uriStr),
1879+
libraryContext.elementFactory.analysisSession.inheritanceManager,
1880+
library,
1881+
testingData: testingData,
1882+
).analyzeForCompletion(
1883+
file: file,
1884+
offset: request.offset,
1885+
unitElement: unitElement,
1886+
performance: request.performance,
1887+
);
1888+
1889+
return ResolvedForCompletionResultImpl(
1890+
analysisSession: currentSession,
1891+
path: path,
1892+
uri: file.uri,
1893+
exists: file.exists,
1894+
content: file.content,
1895+
lineInfo: file.lineInfo,
1896+
parsedUnit: analysisResult.parsedUnit,
1897+
unitElement: unitElement,
1898+
resolvedNodes: analysisResult.resolvedNodes,
1899+
);
1900+
}
1901+
18721902
/// Serialize the given [resolvedUnit] errors and index into bytes.
18731903
Uint8List _serializeResolvedUnit(
18741904
CompilationUnit resolvedUnit, List<AnalysisError> errors) {
@@ -2002,7 +2032,8 @@ enum AnalysisDriverPriority {
20022032
generalChanged,
20032033
changedFiles,
20042034
priority,
2005-
interactive
2035+
interactive,
2036+
completion
20062037
}
20072038

20082039
/// Instances of this class schedule work in multiple [AnalysisDriver]s so that
@@ -2618,3 +2649,16 @@ class _FilesReferencingNameTask {
26182649
return true;
26192650
}
26202651
}
2652+
2653+
class _ResolveForCompletionRequest {
2654+
final String path;
2655+
final int offset;
2656+
final OperationPerformanceImpl performance;
2657+
final Completer<ResolvedForCompletionResultImpl?> completer = Completer();
2658+
2659+
_ResolveForCompletionRequest({
2660+
required this.path,
2661+
required this.offset,
2662+
required this.performance,
2663+
});
2664+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
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.
4+
5+
import 'dart:async';
6+
7+
class _WhereTypeStreamSink<S, T> implements EventSink<S> {
8+
final EventSink<T> _sink;
9+
10+
_WhereTypeStreamSink(this._sink);
11+
12+
@override
13+
void add(S data) {
14+
if (data is T) {
15+
_sink.add(data);
16+
}
17+
}
18+
19+
@override
20+
void addError(e, [StackTrace? stackTrace]) => _sink.addError(e, stackTrace);
21+
22+
@override
23+
void close() => _sink.close();
24+
}
25+
26+
class _WhereTypeStreamTransformer<S, T> extends StreamTransformerBase<S, T> {
27+
@override
28+
Stream<T> bind(Stream<S> stream) => Stream.eventTransformed(
29+
stream, (sink) => _WhereTypeStreamSink<S, T>(sink));
30+
}
31+
32+
extension StreamExtension<T> on Stream<T> {
33+
Stream<S> whereType<S>() => transform(_WhereTypeStreamTransformer<T, S>());
34+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
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.
4+
5+
import 'package:analyzer/src/utilities/extensions/stream.dart';
6+
import 'package:test/test.dart';
7+
import 'package:test_reflective_loader/test_reflective_loader.dart';
8+
9+
main() {
10+
defineReflectiveSuite(() {
11+
defineReflectiveTests(StreamExtensionTest);
12+
});
13+
}
14+
15+
@reflectiveTest
16+
class StreamExtensionTest {
17+
test_whereType() async {
18+
var result = await Stream<Object?>.fromIterable([0, '1', 2])
19+
.whereType<int>()
20+
.toList();
21+
expect(result, [0, 2]);
22+
}
23+
}

pkg/analyzer/test/src/utilities/extensions/test_all.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
import 'package:test_reflective_loader/test_reflective_loader.dart';
66

77
import 'collection_test.dart' as collection;
8+
import 'stream_test.dart' as stream;
89
import 'string_test.dart' as string;
910

1011
main() {
1112
defineReflectiveSuite(() {
1213
collection.main();
14+
stream.main();
1315
string.main();
1416
}, name: 'extensions');
1517
}

runtime/vm/log_test.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "platform/globals.h"
66

77
#include "include/dart_tools_api.h"
8+
#include "platform/utils.h"
89
#include "vm/dart_api_impl.h"
910
#include "vm/dart_entry.h"
1011
#include "vm/debugger.h"
@@ -23,7 +24,7 @@ static void TestPrinter(const char* buffer) {
2324
free(const_cast<char*>(test_output_));
2425
test_output_ = NULL;
2526
}
26-
test_output_ = strdup(buffer);
27+
test_output_ = Utils::StrDup(buffer);
2728

2829
// Also print to stdout to see the overall result.
2930
OS::PrintErr("%s", test_output_);

runtime/vm/tags.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include "vm/tags.h"
66

7+
#include "platform/utils.h"
78
#include "vm/isolate.h"
89
#include "vm/json_stream.h"
910
#include "vm/native_entry.h"
@@ -159,7 +160,7 @@ void UserTags::AddStreamableTagName(const char* tag) {
159160
return;
160161
}
161162
}
162-
subscribed_tags_.Add(strdup(tag));
163+
subscribed_tags_.Add(Utils::StrDup(tag));
163164
}
164165

165166
void UserTags::RemoveStreamableTagName(const char* tag) {

tools/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ CHANNEL dev
2727
MAJOR 2
2828
MINOR 18
2929
PATCH 0
30-
PRERELEASE 57
30+
PRERELEASE 58
3131
PRERELEASE_PATCH 0

0 commit comments

Comments
 (0)