Skip to content

Commit

Permalink
Version 3.6.0-103.0.dev
Browse files Browse the repository at this point in the history
Merge 93054a6 into dev
  • Loading branch information
Dart CI committed Aug 1, 2024
2 parents 0b09d93 + 93054a6 commit b56fcd8
Show file tree
Hide file tree
Showing 21 changed files with 282 additions and 1,042 deletions.
2 changes: 1 addition & 1 deletion pkg/analysis_server/lib/src/cider/fixes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
// 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:analysis_server/src/services/correction/fix_internal.dart';
import 'package:analysis_server_plugin/edit/fix/dart_fix_context.dart';
import 'package:analysis_server_plugin/edit/fix/fix.dart';
import 'package:analysis_server_plugin/src/correction/dart_change_workspace.dart';
import 'package:analysis_server_plugin/src/correction/fix_processor.dart';
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/error/error.dart';
import 'package:analyzer/instrumentation/service.dart';
Expand Down
2 changes: 1 addition & 1 deletion pkg/analysis_server/lib/src/g3/fixes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

import 'package:analysis_server/src/protocol_server.dart' show SourceEdit;
import 'package:analysis_server/src/services/correction/fix.dart';
import 'package:analysis_server/src/services/correction/fix_internal.dart';
import 'package:analysis_server_plugin/edit/fix/dart_fix_context.dart';
import 'package:analysis_server_plugin/edit/fix/fix.dart';
import 'package:analysis_server_plugin/src/correction/dart_change_workspace.dart';
import 'package:analysis_server_plugin/src/correction/fix_in_file_processor.dart';
import 'package:analysis_server_plugin/src/correction/fix_processor.dart';
import 'package:analyzer/dart/analysis/results.dart';
import 'package:analyzer/error/error.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import 'package:analysis_server/src/protocol_server.dart';
import 'package:analysis_server/src/request_handler_mixin.dart';
import 'package:analysis_server/src/services/correction/fix/analysis_options/fix_generator.dart';
import 'package:analysis_server/src/services/correction/fix/pubspec/fix_generator.dart';
import 'package:analysis_server/src/services/correction/fix_internal.dart';
import 'package:analysis_server_plugin/edit/fix/dart_fix_context.dart';
import 'package:analysis_server_plugin/edit/fix/fix.dart';
import 'package:analysis_server_plugin/src/correction/dart_change_workspace.dart';
import 'package:analysis_server_plugin/src/correction/fix_processor.dart';
import 'package:analyzer/dart/analysis/results.dart';
import 'package:analyzer/dart/analysis/session.dart';
import 'package:analyzer/file_system/file_system.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import 'package:analysis_server/src/protocol_server.dart'
hide AnalysisOptions, Position;
import 'package:analysis_server/src/services/correction/assist.dart';
import 'package:analysis_server/src/services/correction/assist_internal.dart';
import 'package:analysis_server/src/services/correction/fix_internal.dart';
import 'package:analysis_server/src/services/refactoring/framework/refactoring_context.dart';
import 'package:analysis_server/src/services/refactoring/framework/refactoring_processor.dart';
import 'package:analysis_server/src/services/refactoring/legacy/refactoring.dart';
import 'package:analysis_server_plugin/edit/fix/dart_fix_context.dart';
import 'package:analysis_server_plugin/src/correction/dart_change_workspace.dart';
import 'package:analysis_server_plugin/src/correction/fix_processor.dart';
import 'package:analyzer/dart/analysis/results.dart';
import 'package:analyzer/dart/analysis/session.dart'
show InconsistentAnalysisException;
Expand Down
7 changes: 5 additions & 2 deletions pkg/analysis_server/lib/src/lsp/mapping.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ final sortTextMaxValue = int.parse('9' * maximumRelevance.toString().length);

/// A regex used for splitting the display text in a completion so that
/// filterText only includes the symbol name and not any additional text (such
/// as parens, ` => `).
final _completionFilterTextSplitPattern = RegExp(r'[=\(]');
/// as parens, ` => `). Match `=>` but not `==` (which may appear in overrides).
final _completionFilterTextSplitPattern = RegExp(r'=>|[\(]');

/// A regex to extract the type name from the parameter string of a setter
/// completion item.
Expand Down Expand Up @@ -1018,6 +1018,9 @@ lsp.CompletionItem toCompletionItem(
// Only do this if label doesn't start with the pattern, because if it does
// (for example for a closure `(a, b) {}`) we'll end up with an empty string
// but we should instead use the whole label.

// TODO(dantup): Consider including more of these raw fields in the original
// suggestion to avoid needing to manipulate them in this way here.
var filterText = !label.startsWith(_completionFilterTextSplitPattern)
? label.split(_completionFilterTextSplitPattern).first.trim()
: label;
Expand Down
173 changes: 0 additions & 173 deletions pkg/analysis_server/lib/src/services/correction/fix_internal.dart
Original file line number Diff line number Diff line change
Expand Up @@ -239,19 +239,12 @@ import 'package:analysis_server/src/services/correction/dart/use_not_eq_null.dar
import 'package:analysis_server/src/services/correction/dart/use_rethrow.dart';
import 'package:analysis_server/src/services/correction/dart/wrap_in_text.dart';
import 'package:analysis_server/src/services/correction/dart/wrap_in_unawaited.dart';
import 'package:analysis_server_plugin/edit/dart/correction_producer.dart';
import 'package:analysis_server_plugin/edit/fix/dart_fix_context.dart';
import 'package:analysis_server_plugin/edit/fix/fix.dart';
import 'package:analysis_server_plugin/src/correction/fix_generators.dart';
import 'package:analysis_server_plugin/src/correction/fix_processor.dart';
import 'package:analyzer/error/error.dart';
import 'package:analyzer/src/dart/error/ffi_code.g.dart';
import 'package:analyzer/src/error/codes.dart';
import 'package:analyzer/src/generated/parser.dart';
import 'package:analyzer_plugin/src/utilities/change_builder/change_builder_core.dart';
import 'package:analyzer_plugin/utilities/change_builder/change_builder_core.dart';
import 'package:analyzer_plugin/utilities/change_builder/conflicting_edit_exception.dart';
import 'package:analyzer_plugin/utilities/fixes/fixes.dart';
import 'package:linter/src/rules/always_declare_return_types.dart';
import 'package:linter/src/rules/always_put_control_body_on_new_line.dart';
import 'package:linter/src/rules/always_put_required_named_parameters_first.dart';
Expand Down Expand Up @@ -2001,13 +1994,6 @@ final _builtInParseLintProducers = <LintCode, List<ProducerGenerator>>{
],
};

Future<List<Fix>> computeFixes(DartFixContext context) async {
return [
...await FixProcessor(context).compute(),
...await FixInFileProcessor(context).compute(),
];
}

/// Registers each mapping of diagnostic -> list-of-producers with
/// [FixProcessor].
void registerBuiltInProducers() {
Expand All @@ -2026,162 +2012,3 @@ void registerBuiltInProducers() {
IgnoreDiagnosticInAnalysisOptionsFile.new,
]);
}

/// Computer for Dart "fix all in file" fixes.
class FixInFileProcessor {
final DartFixContext context;

FixInFileProcessor(this.context);

Future<List<Fix>> compute() async {
var error = context.error;
var errors = context.resolvedResult.errors
.where((e) => error.errorCode.name == e.errorCode.name);
if (errors.length < 2) {
return const <Fix>[];
}

var instrumentationService = context.instrumentationService;
var workspace = context.workspace;
var resolvedResult = context.resolvedResult;

/// Helper to create a [DartFixContextImpl] for a given error.
DartFixContext createFixContext(AnalysisError error) {
return DartFixContext(
instrumentationService: instrumentationService,
workspace: workspace,
resolvedResult: resolvedResult,
error: error,
);
}

var generators = _getGenerators(error.errorCode);

var fixes = <Fix>[];
for (var generator in generators) {
if (generator(context: StubCorrectionProducerContext.instance)
.canBeAppliedAcrossSingleFile) {
_FixState fixState = _EmptyFixState(
ChangeBuilder(workspace: workspace),
);

// First try to fix the specific error we started from. We should only
// include fix-all-in-file when we produce an individual fix at this
// location.
fixState = await _fixError(
createFixContext(error), fixState, generator, error);

// The original error was not fixable, don't continue.
if (!(fixState.builder as ChangeBuilderImpl).hasEdits) {
continue;
}

// Compute fixes for the rest of the errors.
for (var error in errors.where((item) => item != error)) {
var fixContext = createFixContext(error);
fixState = await _fixError(fixContext, fixState, generator, error);
}
if (fixState is _NotEmptyFixState) {
var sourceChange = fixState.builder.sourceChange;
if (sourceChange.edits.isNotEmpty && fixState.fixCount > 1) {
var fixKind = fixState.fixKind;
sourceChange.id = fixKind.id;
sourceChange.message = fixKind.message;
fixes.add(Fix(kind: fixKind, change: sourceChange));
}
}
}
}
return fixes;
}

Future<_FixState> _fixError(
DartFixContext fixContext,
_FixState fixState,
ProducerGenerator generator,
AnalysisError diagnostic,
) async {
var context = CorrectionProducerContext.createResolved(
applyingBulkFixes: true,
dartFixContext: fixContext,
diagnostic: diagnostic,
resolvedResult: fixContext.resolvedResult,
selectionOffset: diagnostic.offset,
selectionLength: diagnostic.length,
);

var producer = generator(context: context);

try {
var localBuilder = fixState.builder.copy();
var fixKind = producer.fixKind;
await producer.compute(localBuilder);
assert(
!producer.canBeAppliedAcrossSingleFile || producer.fixKind == fixKind,
'Producers used in bulk fixes must not modify the FixKind during '
'computation. $producer changed from $fixKind to ${producer.fixKind}.',
);

var multiFixKind = producer.multiFixKind;
if (multiFixKind == null) {
return fixState;
}

// TODO(pq): consider discarding the change if the producer's fixKind
// doesn't match a previously cached one.
return _NotEmptyFixState(
builder: localBuilder,
fixKind: multiFixKind,
fixCount: fixState.fixCount + 1,
);
} on ConflictingEditException {
// If a conflicting edit was added in [compute], then the [localBuilder]
// is discarded and we revert to the previous state of the builder.
return fixState;
}
}

List<ProducerGenerator> _getGenerators(ErrorCode errorCode) {
if (errorCode is LintCode) {
return registeredFixGenerators.lintProducers[errorCode] ?? [];
} else {
// TODO(pq): consider support for multi-generators.
return registeredFixGenerators.nonLintProducers[errorCode] ?? [];
}
}
}

/// [_FixState] that is still empty.
class _EmptyFixState implements _FixState {
@override
final ChangeBuilder builder;

_EmptyFixState(this.builder);

@override
int get fixCount => 0;
}

/// State associated with producing fix-all-in-file fixes.
abstract class _FixState {
ChangeBuilder get builder;

int get fixCount;
}

/// [_FixState] that has a fix, so knows its kind.
class _NotEmptyFixState implements _FixState {
@override
final ChangeBuilder builder;

final FixKind fixKind;

@override
final int fixCount;

_NotEmptyFixState({
required this.builder,
required this.fixKind,
required this.fixCount,
});
}
19 changes: 19 additions & 0 deletions pkg/analysis_server/test/analysis/get_signature_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,25 @@ void f() {
ParameterInfo(ParameterKind.REQUIRED_POSITIONAL, 'length', 'int')));
}

Future<void> test_function_wildcardParams() async {
newFile(testFilePath, '''
void g(int _, [String _]) {}
void f() {
g(/*^*/);
}
''');
var result = await prepareSignature('/*^*/');
expect(result.name, equals('g'));
expect(result.parameters, hasLength(2));
// Ensure wildcard params have their types.
expect(result.parameters[0],
equals(ParameterInfo(ParameterKind.REQUIRED_POSITIONAL, '_', 'int')));
expect(
result.parameters[1],
equals(
ParameterInfo(ParameterKind.OPTIONAL_POSITIONAL, '_', 'String')));
}

Future<void> test_function_zero_arguments() async {
newFile(testFilePath, '''
/// one doc
Expand Down
21 changes: 19 additions & 2 deletions pkg/analysis_server/test/lsp/completion_dart_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,24 @@ void f() {
detail: 'String');
}

Future<void> test_local_override_annotation() async {
Future<void> test_local_override_annotation_equals() async {
var content = '''
class Base {
}
class Derived extends Base {
@over^
}
''';
await expectLabels(content,
label: 'override ==',
labelDetail: '(…) → bool',
labelDescription: null,
filterText: null,
detail: '(Object other) → bool');
}

Future<void> test_local_override_annotation_method() async {
var content = '''
class Base {
String aa(String a) => '';
Expand Down Expand Up @@ -1901,7 +1918,7 @@ void f() {
/// the correct narrowed type in the `detail` field.
///
/// https://github.com/Dart-Code/Dart-Code/issues/4499
Future<void> test_getter_barrowedBySubclass() async {
Future<void> test_getter_narrowedBySubclass() async {
var content = '''
void f(MyItem item) {
item.na^
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
// BSD-style license that can be found in the LICENSE file.

import 'package:analysis_server/src/services/correction/bulk_fix_processor.dart';
import 'package:analysis_server/src/services/correction/fix_internal.dart';
import 'package:analysis_server_plugin/edit/dart/dart_fix_kind_priority.dart';
import 'package:analysis_server_plugin/edit/fix/dart_fix_context.dart';
import 'package:analysis_server_plugin/edit/fix/fix.dart';
import 'package:analysis_server_plugin/src/correction/change_workspace.dart';
import 'package:analysis_server_plugin/src/correction/dart_change_workspace.dart';
import 'package:analysis_server_plugin/src/correction/fix_in_file_processor.dart';
import 'package:analysis_server_plugin/src/correction/fix_processor.dart';
import 'package:analyzer/error/error.dart';
import 'package:analyzer/file_system/file_system.dart';
import 'package:analyzer/src/dart/analysis/byte_store.dart';
Expand Down
Loading

0 comments on commit b56fcd8

Please sign in to comment.