Skip to content

Commit

Permalink
Version 3.5.0-251.0.dev
Browse files Browse the repository at this point in the history
Merge cf9623f into dev
  • Loading branch information
Dart CI committed Jun 11, 2024
2 parents ab4d5a0 + cf9623f commit 269125c
Show file tree
Hide file tree
Showing 37 changed files with 403 additions and 104 deletions.
2 changes: 1 addition & 1 deletion DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ vars = {
"characters_rev": "7633a16a22c626e19ca750223237396315268a06",
"cli_util_rev": "c37d5e14f50e72a268c1ad86149cecfa4b58c494",
"clock_rev": "7cbf08e36a92f14f22132d255846610c1b065324",
"collection_rev": "141d83af3d7586ae9d27de610fd426071c98e5d3",
"collection_rev": "c90b19f07b48391f3b1b4c39dd06ef0177f8e07c",
"convert_rev": "70940e3728f34d897ad92f44f98db2d47286b090",
"crypto_rev": "7a9428a78962783f6081dc42465ed580cff225ca",
"csslib_rev": "23c314bb6b247a71348cfb0987ba0eb29574abb6",
Expand Down
1 change: 1 addition & 0 deletions pkg/analysis_server/lib/src/cider/completion.dart
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ class CiderCompletionComputer {
performance,
enableOverrideContributor: false,
enableUriContributor: false,
maxSuggestions: -1,
useFilter: true,
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class RuntimeCompletionComputer {
).computeSuggestions(
dartRequest,
OperationPerformanceImpl('<root>'),
maxSuggestions: -1,
useFilter: false,
);
var suggestions = serverSuggestions.map((e) => e.build()).toList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class CompletionGetSuggestions2Handler extends CompletionHandler
required CompletionBudget budget,
required OperationPerformanceImpl performance,
required DartCompletionRequest request,
required int maxSuggestions,
NotImportedSuggestions? notImportedSuggestions,
required bool useFilter,
}) async {
Expand All @@ -66,6 +67,7 @@ class CompletionGetSuggestions2Handler extends CompletionHandler
await manager.computeSuggestions(
request,
performance,
maxSuggestions: maxSuggestions,
useFilter: useFilter,
),
);
Expand Down Expand Up @@ -205,6 +207,7 @@ class CompletionGetSuggestions2Handler extends CompletionHandler
budget: budget,
performance: performance,
request: completionRequest,
maxSuggestions: params.maxResults,
notImportedSuggestions: notImportedSuggestions,
useFilter: true,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ class CompletionHandler
offset,
triggerCharacter,
token,
maxResults,
);
},
);
Expand Down Expand Up @@ -360,6 +361,7 @@ class CompletionHandler
int offset,
String? triggerCharacter,
CancellationToken token,
int maxSuggestions,
) async {
var useNotImportedCompletions =
suggestFromUnimportedLibraries && capabilities.applyEdit;
Expand Down Expand Up @@ -397,6 +399,7 @@ class CompletionHandler
var suggestions = await contributor.computeSuggestions(
completionRequest,
performance,
maxSuggestions: maxSuggestions,
useFilter: true,
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class DartCompletionManager {
OperationPerformanceImpl performance, {
bool enableOverrideContributor = true,
bool enableUriContributor = true,
required int maxSuggestions,
required bool useFilter,
}) async {
request.checkAborted();
Expand All @@ -108,15 +109,15 @@ class DartCompletionManager {

var notImportedSuggestions = this.notImportedSuggestions;

var collector = SuggestionCollector();
var collector = SuggestionCollector(maxSuggestions: maxSuggestions);
try {
var selection = request.unit.select(offset: request.offset, length: 0);
if (selection == null) {
throw AbortCompletion();
}
var matcher = request.targetPrefix.isEmpty
? NoPrefixMatcher()
: FuzzyMatcher(request.targetPrefix);
var targetPrefix = request.targetPrefix;
var matcher =
targetPrefix.isEmpty ? NoPrefixMatcher() : FuzzyMatcher(targetPrefix);
var state = CompletionState(request, selection, budget, matcher);
var operations = performance.run(
'InScopeCompletionPass',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import 'package:analysis_server/src/services/completion/dart/candidate_suggestio

/// An object that collects the candidate suggestions produced by the steps.
class SuggestionCollector {
/// The maximum number of suggestions that will be returned.
final int maxSuggestions;

/// The list of candidate suggestions that have been collected.
final List<CandidateSuggestion> suggestions = [];

Expand All @@ -20,15 +23,56 @@ class SuggestionCollector {
/// exception being thrown.
bool isIncomplete = false;

/// Return `true` if the context prefers a constant expression. This is used
/// to compute relevance.
/// Whether the context prefers a constant expression. This is used to compute
/// relevance.
bool preferConstants = false;

/// Initializes a newly created collector to collect candidate suggestions.
SuggestionCollector();
///
/// The [maxSuggestions] is the maximum number of suggestions that will be
/// returned to the client, or `-1` if all of the suggestions should be
/// returned. This is used to truncate the list of suggestions early, which
/// - reduces the amount of memory used during completion
/// - reduces the number of suggestions that need to have relevance scores and
/// that need to be converted to the form used by the protocol
SuggestionCollector({required this.maxSuggestions});

/// Adds the candidate [suggestion] to the list of suggestions.
void addSuggestion(CandidateSuggestion suggestion) {
suggestions.add(suggestion);
// Insert the suggestion into the list in sorted order.
if (suggestions.isEmpty) {
suggestions.add(suggestion);
return;
}
var score = suggestion.matcherScore;
var added = false;
for (var i = suggestions.length - 1; i >= 0; i--) {
var currentSuggestion = suggestions[i];
if (currentSuggestion.matcherScore >= score) {
suggestions.insert(i + 1, suggestion);
added = true;
break;
}
}
if (!added) {
suggestions.insert(0, suggestion);
}
// If there are suggestions whose matcher score is too low, remove them.
//
// Note that this will allow the list of suggestions to be longer than the
// maximum number of suggestions as long as at least one suggestion with the
// lowest score would be kept. Suggestions with the same score will later be
// sorted by the relevance score and then the lowest bucket will be
// truncated.
if (maxSuggestions >= 0 && suggestions.length > maxSuggestions) {
var minScoreToKeep = suggestions[maxSuggestions].matcherScore;
while (suggestions.length > maxSuggestions) {
if (suggestions.last.matcherScore < minScoreToKeep) {
suggestions.removeLast();
} else {
break;
}
}
}
}
}
2 changes: 1 addition & 1 deletion pkg/analysis_server/test/lsp/code_actions_abstract.dart
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ abstract class AbstractCodeActionsTest extends AbstractLspAnalysisServerTest {
}
return action;
})
.whereNotNull()
.nonNulls
.toList();
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/analysis_server/test/lsp/server_abstract.dart
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ abstract class AbstractLspAnalysisServerTest
(textDocEdit) => textDocEdit,
),
)
.whereNotNull()
.nonNulls
.toList();

@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ class CompletionRunner {
var suggestions = await contributor.computeSuggestions(
dartRequest,
OperationPerformanceImpl('<root>'),
maxSuggestions: -1,
useFilter: true,
);
timer.stop();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ Future<void> _runForever({
).computeSuggestions(
dartRequest,
OperationPerformanceImpl('<root>'),
maxSuggestions: -1,
useFilter: false,
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1410,6 +1410,7 @@ class CompletionQualityMetricsComputer extends CompletionMetricsComputer {
).computeSuggestions(
dartRequest,
performance,
maxSuggestions: -1,
useFilter: true,
);

Expand Down
5 changes: 2 additions & 3 deletions pkg/analyzer/tool/summary/mini_ast.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import 'package:_fe_analyzer_shared/src/parser/parser.dart';
import 'package:_fe_analyzer_shared/src/parser/stack_listener.dart';
import 'package:_fe_analyzer_shared/src/scanner/token.dart';
import 'package:analyzer/src/dart/analysis/experiments.dart';
import 'package:collection/collection.dart';
import 'package:pub_semver/pub_semver.dart';

/// "Mini AST" representation of a declaration which can accept annotations.
Expand Down Expand Up @@ -433,8 +432,8 @@ class MiniAstBuilder extends StackListener {
var name = pop() as String;
var metadata = popTypedList<Annotation>();
var comment = pop() as Comment?;
compilationUnit.declarations.add(EnumDeclaration(
comment, metadata, name, constants.whereNotNull().toList()));
compilationUnit.declarations.add(
EnumDeclaration(comment, metadata, name, constants.nonNulls.toList()));
}

@override
Expand Down
53 changes: 32 additions & 21 deletions pkg/dartdev/lib/src/dds_runner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,17 @@ class DDSRunner {
],
mode: ProcessStartMode.detachedWithStdio,
);
final completer = Completer<void>();

// NOTE: update pkg/dartdev/lib/src/commands/run.dart if this message
// is changed to ensure consistency.
const devToolsMessagePrefix =
'The Dart DevTools debugger and profiler is available at:';
if (debugDds) {
late final StreamSubscription stdoutSub;
stdoutSub = process.stdout.transform(utf8.decoder).listen((event) {
stdoutSub = process.stdout
.transform(utf8.decoder)
.transform(const LineSplitter())
.listen((event) {
if (event.startsWith(devToolsMessagePrefix)) {
final ddsDebuggingUri = event.split(' ').last;
print(
Expand All @@ -61,37 +66,43 @@ class DDSRunner {
}
});
}
late final StreamSubscription stderrSub;
stderrSub = process.stderr.transform(utf8.decoder).listen((event) {
final result = json.decode(event) as Map<String, dynamic>;
final state = result['state'];
if (state == 'started') {
if (result.containsKey('devToolsUri')) {
final devToolsUri = result['devToolsUri'];

// DDS will close stderr once it's finished launching.
final launchResult = await process.stderr.transform(utf8.decoder).join();

void printError(String details) => stderr.writeln(
'Could not start the VM service:\n$details',
);

try {
final result = json.decode(launchResult);
if (result
case {
'state': 'started',
'ddsUri': final String ddsUriStr,
}) {
ddsUri = Uri.parse(ddsUriStr);
if (result case {'devToolsUri': String devToolsUri}) {
print('$devToolsMessagePrefix $devToolsUri');
}
ddsUri = Uri.parse(result['ddsUri']);
stderrSub.cancel();
completer.complete();
} else {
stderrSub.cancel();
final error = result['error'] ?? event;
final error = result['error'] ?? result;
final stacktrace = result['stacktrace'] ?? '';
String message = 'Could not start the VM service: ';
if (error.contains('Failed to create server socket')) {
message += '$ddsHost:$ddsPort is already in use.\n';
} else {
message += '$error\n$stacktrace\n';
}
completer.completeError(message);
printError(message);
return false;
}
});
try {
await completer.future;
return true;
} catch (e) {
stderr.write(e);
} catch (_) {
// Malformed JSON was likely encountered, so output the entirety of
// stderr in the error message.
printError(launchResult);
return false;
}
return true;
}
}
2 changes: 2 additions & 0 deletions pkg/dds/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# 4.2.4
- Added missing type to `Event` in `postEvent`.
- [DAP] Instaces with both fields and getters of the same name will no longer show duplicates in `variables` responses.
- `bin/dds.dart` now closes the `stderr` pipe after writing its JSON to the stream.

# 4.2.3
- Added missing await of `WebSocketChannel.ready` in `startDartDevelopmentService`.
Expand Down
5 changes: 5 additions & 0 deletions pkg/dds/bin/dds.dart
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,13 @@ ${argParser.usage}
'uri': dtdInfo.uri,
},
}));
stderr.close();
} catch (e, st) {
writeErrorResponse(e, st);
} finally {
// Always close stderr to notify tooling that DDS has finished writing
// launch details.
await stderr.close();
}
}

Expand Down
10 changes: 9 additions & 1 deletion pkg/dds/lib/src/dap/protocol_converter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -296,10 +296,18 @@ class ProtocolConverter {
}
}

// Collect getter names for this instances class and its supers.
// Collect getter names for this instances class and its supers, but
// remove any names that have already showed up as fields because
// otherwise they will show up duplicated.
final getterNames =
await _getterNamesForClassHierarchy(thread, instance.classRef);

// Remove any existing field variables where there are getters, because
// otherwise we'll have dupes, and the user will generally expected to
// see the getters value (if not the same).
variables
.removeWhere((variable) => getterNames.contains(variable.name));

final getterVariables = getterNames.mapIndexed(createVariable);
variables.addAll(await Future.wait(getterVariables));
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/dds/test/dap/integration/dart_test_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'package:collection/collection.dart';
import 'package:dap/dap.dart';
import 'package:test/test.dart';

Expand Down Expand Up @@ -114,7 +113,7 @@ main() {
// Collect paths from any OutputEvents that had them.
final stackFramePaths = outputEvents.output
.map((event) => event.source?.path)
.whereNotNull()
.nonNulls
.toList();
// Ensure we had a frame with the absolute path of the test script.
expect(stackFramePaths, contains(testFile.path));
Expand Down
Loading

0 comments on commit 269125c

Please sign in to comment.