Skip to content

Commit

Permalink
DAS: Move away from LintNames, now that LintRules have LintCodes
Browse files Browse the repository at this point in the history
Cq-Include-Trybots: luci.dart.try:flutter-analyze-try,analyzer-win-release-try,pkg-win-release-try
Change-Id: Id52cbf9fe95f9f2aaff80baaa10b2abbdba85f9e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/376560
Commit-Queue: Samuel Rawlins <[email protected]>
Reviewed-by: Brian Wilkerson <[email protected]>
Reviewed-by: Phil Quitslund <[email protected]>
  • Loading branch information
srawlins authored and Commit Queue committed Jul 22, 2024
1 parent d04394c commit beee864
Show file tree
Hide file tree
Showing 14 changed files with 358 additions and 169 deletions.
3 changes: 2 additions & 1 deletion pkg/analysis_server/lib/plugin/edit/assist/assist_dart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import 'package:analysis_server/src/services/correction/fix_processor.dart';
import 'package:analysis_server_plugin/src/correction/change_workspace.dart';
import 'package:analyzer/dart/analysis/results.dart';
import 'package:analyzer/error/error.dart';
import 'package:analyzer/instrumentation/service.dart';

/// An object used to provide context information for Dart assist contributors.
Expand All @@ -17,7 +18,7 @@ abstract class DartAssistContext {

/// A mapping of [ProducerGenerator]s to the set of lint names with which they
/// are associated (can fix).
Map<ProducerGenerator, Set<String>> get producerGeneratorsForLintRules;
Map<ProducerGenerator, Set<LintCode>> get producerGeneratorsForLintRules;

/// The resolution result in which assist operates.
ResolvedUnitResult get resolveResult;
Expand Down
3 changes: 2 additions & 1 deletion pkg/analysis_server/lib/src/analysis_server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import 'package:analyzer/dart/analysis/results.dart';
import 'package:analyzer/dart/analysis/session.dart';
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/error/error.dart';
import 'package:analyzer/exception/exception.dart';
import 'package:analyzer/file_system/file_system.dart';
import 'package:analyzer/file_system/overlay_file_system.dart';
Expand Down Expand Up @@ -236,7 +237,7 @@ abstract class AnalysisServer {

/// A mapping of [ProducerGenerator]s to the set of lint names with which they
/// are associated (can fix).
final Map<ProducerGenerator, Set<String>> producerGeneratorsForLintRules;
final Map<ProducerGenerator, Set<LintCode>> producerGeneratorsForLintRules;

AnalysisServer(
this.options,
Expand Down
3 changes: 2 additions & 1 deletion pkg/analysis_server/lib/src/cider/assists.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:analysis_server/src/services/correction/assist_internal.dart';
import 'package:analysis_server/src/services/correction/fix_processor.dart';
import 'package:analysis_server_plugin/src/correction/dart_change_workspace.dart';
import 'package:analyzer/dart/analysis/session.dart';
import 'package:analyzer/error/error.dart';
import 'package:analyzer/instrumentation/service.dart';
import 'package:analyzer/src/dart/analysis/performance_logger.dart';
import 'package:analyzer/src/dart/micro/resolve_file.dart';
Expand All @@ -18,7 +19,7 @@ class CiderAssistsComputer {

/// A mapping of [ProducerGenerator]s to the set of lint names with which they
/// are associated (can fix).
final Map<ProducerGenerator, Set<String>> _producerGeneratorsForLintRules;
final Map<ProducerGenerator, Set<LintCode>> _producerGeneratorsForLintRules;

CiderAssistsComputer(
this._logger, this._fileResolver, this._producerGeneratorsForLintRules);
Expand Down
3 changes: 2 additions & 1 deletion pkg/analysis_server/lib/src/services/correction/assist.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:analysis_server/plugin/edit/assist/assist_dart.dart';
import 'package:analysis_server/src/services/correction/fix_processor.dart';
import 'package:analysis_server_plugin/src/correction/change_workspace.dart';
import 'package:analyzer/dart/analysis/results.dart';
import 'package:analyzer/error/error.dart';
import 'package:analyzer/instrumentation/service.dart';
import 'package:analyzer_plugin/utilities/assist/assist.dart';

Expand All @@ -21,7 +22,7 @@ class DartAssistContextImpl implements DartAssistContext {
final ResolvedUnitResult resolveResult;

@override
final Map<ProducerGenerator, Set<String>> producerGeneratorsForLintRules;
final Map<ProducerGenerator, Set<LintCode>> producerGeneratorsForLintRules;

@override
final int selectionOffset;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ import 'package:analysis_server/src/services/correction/dart/surround_with.dart'
import 'package:analysis_server/src/services/correction/dart/use_curly_braces.dart';
import 'package:analysis_server/src/services/correction/fix_processor.dart';
import 'package:analysis_server_plugin/edit/dart/correction_producer.dart';
import 'package:analyzer/error/error.dart';
import 'package:analyzer/src/dart/ast/utilities.dart';
import 'package:analyzer/src/generated/java_core.dart';
import 'package:analyzer/src/util/file_paths.dart';
Expand Down Expand Up @@ -213,7 +214,8 @@ class AssistProcessor {
for (var generator in _generators) {
if (!_generatorAppliesToAnyLintRule(
generator,
_assistContext.producerGeneratorsForLintRules[generator] ?? {},
_assistContext.producerGeneratorsForLintRules[generator] ??
<LintCode>{},
)) {
var producer = generator(context: context);
await compute(producer);
Expand All @@ -231,7 +233,7 @@ class AssistProcessor {
/// [errorCodes].
bool _generatorAppliesToAnyLintRule(
ProducerGenerator generator,
Set<String> errorCodes,
Set<LintCode> errorCodes,
) {
var selectionEnd =
_assistContext.selectionOffset + _assistContext.selectionLength;
Expand All @@ -247,7 +249,7 @@ class AssistProcessor {
if (_assistContext.resolveResult.path == errorSource.fullName) {
if (fileOffset >= error.offset &&
fileOffset <= error.offset + error.length) {
if (errorCodes.contains(error.errorCode.name)) {
if (errorCodes.contains(error.errorCode)) {
return true;
}
}
Expand All @@ -256,7 +258,7 @@ class AssistProcessor {
return false;
}

static Map<ProducerGenerator, Set<String>> computeLintRuleMap() => {
static Map<ProducerGenerator, Set<LintCode>> computeLintRuleMap() => {
for (var generator in _generators)
generator: {
for (var MapEntry(key: lintName, value: generators)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ class BulkFixProcessor {
var codeName = errorCode.name;
try {
if (errorCode is LintCode) {
var generators = FixProcessor.lintProducerMap[codeName] ?? [];
var generators = FixProcessor.lintProducerMap[errorCode] ?? [];
await _bulkApply(generators, codeName, context);
if (isCancelled) {
return;
Expand Down
Loading

0 comments on commit beee864

Please sign in to comment.