mirror of
https://github.com/dart-lang/sdk
synced 2024-10-14 10:33:28 +00:00
[analysis_server] Include types in closure completions when always_specify_types is enabled
Fixes https://github.com/Dart-Code/Dart-Code/issues/5149 Change-Id: Ic212e13d9fe90b4c728f92ecdf8fd5ca519047ed Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/372426 Reviewed-by: Konstantin Shcheglov <scheglov@google.com> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
parent
793194e2b9
commit
a42ae0c906
|
@ -351,13 +351,16 @@ class SuggestionBuilder {
|
||||||
/// If [includeTrailingComma] is `true` then the completion text will include
|
/// If [includeTrailingComma] is `true` then the completion text will include
|
||||||
/// a trailing comma, such as when the closure is part of an argument list.
|
/// a trailing comma, such as when the closure is part of an argument list.
|
||||||
void suggestClosure(FunctionType type, {bool includeTrailingComma = false}) {
|
void suggestClosure(FunctionType type, {bool includeTrailingComma = false}) {
|
||||||
|
var includeTypes =
|
||||||
|
request.fileState.analysisOptions.codeStyleOptions.specifyTypes;
|
||||||
var indent = getRequestLineIndent(request);
|
var indent = getRequestLineIndent(request);
|
||||||
var parametersString = buildClosureParameters(type);
|
var parametersString = buildClosureParameters(type,
|
||||||
// Build a version of the parameter string without keywords for the
|
includeTypes: includeTypes, includeKeywords: true);
|
||||||
// completion label because `required` is less useful and may push the
|
// Build a short version of the parameter string without keywords or types
|
||||||
// end of the completion (`=>` vs `() {}`) off the end.
|
// for the completion label because they're less useful there and may push
|
||||||
var parametersDisplayString =
|
// the end of the completion (`=>` vs `() {}`) off the end.
|
||||||
buildClosureParameters(type, includeKeywords: false);
|
var parametersDisplayString = buildClosureParameters(type,
|
||||||
|
includeKeywords: false, includeTypes: false);
|
||||||
|
|
||||||
var blockBuffer = StringBuffer(parametersString);
|
var blockBuffer = StringBuffer(parametersString);
|
||||||
blockBuffer.writeln(' {');
|
blockBuffer.writeln(' {');
|
||||||
|
|
|
@ -31,8 +31,11 @@ Comparator<CompletionSuggestionBuilder> completionComparator = (a, b) {
|
||||||
return b.relevance.compareTo(a.relevance);
|
return b.relevance.compareTo(a.relevance);
|
||||||
};
|
};
|
||||||
|
|
||||||
String buildClosureParameters(FunctionType type,
|
String buildClosureParameters(
|
||||||
{bool includeKeywords = true}) {
|
FunctionType type, {
|
||||||
|
required bool includeTypes,
|
||||||
|
required bool includeKeywords,
|
||||||
|
}) {
|
||||||
var buffer = StringBuffer();
|
var buffer = StringBuffer();
|
||||||
buffer.write('(');
|
buffer.write('(');
|
||||||
|
|
||||||
|
@ -52,6 +55,10 @@ String buildClosureParameters(FunctionType type,
|
||||||
hasOptionalPositional = true;
|
hasOptionalPositional = true;
|
||||||
buffer.write('[');
|
buffer.write('[');
|
||||||
}
|
}
|
||||||
|
if (includeTypes) {
|
||||||
|
buffer.write(parameter.type);
|
||||||
|
buffer.write(' ');
|
||||||
|
}
|
||||||
var name = parameter.name;
|
var name = parameter.name;
|
||||||
if (name.isEmpty) {
|
if (name.isEmpty) {
|
||||||
name = 'p$i';
|
name = 'p$i';
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
|
import 'package:analysis_server/src/services/linter/lint_names.dart';
|
||||||
|
import 'package:linter/src/rules.dart';
|
||||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||||
|
|
||||||
|
import '../../../../analysis_server_base.dart';
|
||||||
import '../../../../client/completion_driver_test.dart';
|
import '../../../../client/completion_driver_test.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
|
@ -116,6 +119,29 @@ ${' ' * 4}
|
||||||
''');
|
''');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> test_lint_alwaysSpecifyTypes() async {
|
||||||
|
registerLintRules();
|
||||||
|
writeTestPackageAnalysisOptionsFile(
|
||||||
|
AnalysisOptionsFileConfig(lints: [LintNames.always_specify_types]),
|
||||||
|
);
|
||||||
|
|
||||||
|
await computeSuggestions('''
|
||||||
|
void Function(List<int> a, Object? b, [dynamic c]) v = ^;
|
||||||
|
''');
|
||||||
|
assertResponse('''
|
||||||
|
suggestions
|
||||||
|
|(List<int> a, Object? b, [dynamic c]) => |
|
||||||
|
kind: invocation
|
||||||
|
displayText: (a, b, [c]) =>
|
||||||
|
(List<int> a, Object? b, [dynamic c]) {
|
||||||
|
${' ' * 2}
|
||||||
|
}
|
||||||
|
kind: invocation
|
||||||
|
displayText: (a, b, [c]) {}
|
||||||
|
selection: 42
|
||||||
|
''');
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> test_parameters_optionalNamed() async {
|
Future<void> test_parameters_optionalNamed() async {
|
||||||
await computeSuggestions('''
|
await computeSuggestions('''
|
||||||
void f({void Function(int a, {int b, int c}) closure}) {}
|
void f({void Function(int a, {int b, int c}) closure}) {}
|
||||||
|
|
Loading…
Reference in a new issue