Skip to content

Commit 3a650f4

Browse files
srawlinsCommit Queue
authored and
Commit Queue
committed
analysis_server: Introduce analysis_server_shared package
With a simple move of two classes, Fix and FixContent. The class moves are not exactly no-ops. I moved each class into its own library and made the following changes: * Start doc comments with third person verbs [1]. * Make `Fix` class **final**. * Make `FixContext` class **interface**. [1]: https://dart.dev/effective-dart/documentation#prefer-starting-function-or-method-comments-with-third-person-verbs Work towards #53402 Cq-Include-Trybots: dart-internal/g3.dart-internal.try:g3-cbuild-try Change-Id: Ic046b236d634543832825db8746e0abdca5191fe Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/355889 Reviewed-by: Alexander Thomas <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Samuel Rawlins <[email protected]>
1 parent f82ab4c commit 3a650f4

File tree

23 files changed

+314
-39
lines changed

23 files changed

+314
-39
lines changed

pkg/analysis_server/lib/plugin/edit/fix/fix_dart.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
import 'package:analysis_server/plugin/edit/fix/fix_core.dart';
65
import 'package:analyzer/dart/analysis/results.dart';
76
import 'package:analyzer/dart/element/element.dart';
87
import 'package:analyzer/instrumentation/service.dart';
98
import 'package:analyzer_plugin/utilities/change_builder/change_workspace.dart';
9+
import 'package:server_plugin/edit/fix/fix_content.dart';
1010

1111
/// An object used to provide context information for Dart fix contributors.
1212
///

pkg/analysis_server/lib/src/cider/fixes.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
import 'package:analysis_server/plugin/edit/fix/fix_core.dart';
65
import 'package:analysis_server/src/services/correction/change_workspace.dart';
76
import 'package:analysis_server/src/services/correction/fix.dart';
87
import 'package:analysis_server/src/services/correction/fix_internal.dart';
@@ -16,6 +15,7 @@ import 'package:analyzer/src/dart/analysis/performance_logger.dart';
1615
import 'package:analyzer/src/dart/micro/resolve_file.dart';
1716
import 'package:analyzer/src/services/top_level_declarations.dart';
1817
import 'package:analyzer_plugin/utilities/change_builder/change_workspace.dart';
18+
import 'package:server_plugin/edit/fix/fix.dart';
1919

2020
class CiderErrorFixes {
2121
final AnalysisError error;

pkg/analysis_server/lib/src/g3/fixes.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
import 'package:analysis_server/plugin/edit/fix/fix_core.dart';
65
import 'package:analysis_server/src/protocol_server.dart' show SourceEdit;
76
import 'package:analysis_server/src/services/correction/change_workspace.dart';
87
import 'package:analysis_server/src/services/correction/fix.dart';
@@ -16,6 +15,7 @@ import 'package:analyzer/instrumentation/service.dart';
1615
import 'package:analyzer/src/dart/analysis/analysis_context_collection.dart';
1716
import 'package:analyzer/src/dart/error/lint_codes.dart';
1817
import 'package:collection/collection.dart';
18+
import 'package:server_plugin/edit/fix/fix.dart';
1919

2020
/// The root of a set of classes that support testing for lint fixes.
2121
///

pkg/analysis_server/lib/src/handler/legacy/edit_get_fixes.dart

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

55
import 'dart:async';
66

7-
import 'package:analysis_server/plugin/edit/fix/fix_core.dart';
87
import 'package:analysis_server/src/handler/legacy/legacy_handler.dart';
98
import 'package:analysis_server/src/legacy_analysis_server.dart';
109
import 'package:analysis_server/src/plugin/result_converter.dart';
@@ -30,6 +29,7 @@ import 'package:analyzer/src/util/file_paths.dart' as file_paths;
3029
import 'package:analyzer/src/util/file_paths.dart';
3130
import 'package:analyzer/src/workspace/pub.dart';
3231
import 'package:analyzer_plugin/protocol/protocol_generated.dart' as plugin;
32+
import 'package:server_plugin/edit/fix/fix.dart';
3333
import 'package:yaml/yaml.dart';
3434

3535
/// The handler for the `edit.getFixes` request.

pkg/analysis_server/lib/src/services/correction/bulk_fix_processor.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
import 'package:_fe_analyzer_shared/src/scanner/errors.dart';
6-
import 'package:analysis_server/plugin/edit/fix/fix_core.dart';
76
import 'package:analysis_server/plugin/edit/fix/fix_dart.dart';
87
import 'package:analysis_server/protocol/protocol_generated.dart'
98
hide AnalysisOptions;
@@ -49,6 +48,7 @@ import 'package:analyzer_plugin/protocol/protocol_common.dart'
4948
import 'package:analyzer_plugin/src/utilities/change_builder/change_builder_core.dart';
5049
import 'package:analyzer_plugin/utilities/change_builder/change_builder_core.dart';
5150
import 'package:analyzer_plugin/utilities/change_builder/conflicting_edit_exception.dart';
51+
import 'package:server_plugin/edit/fix/fix.dart';
5252
import 'package:yaml/yaml.dart';
5353

5454
import 'fix/pubspec/fix_generator.dart';

pkg/analysis_server/lib/src/services/correction/fix/analysis_options/fix_generator.dart

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

55
import 'dart:math' as math;
66

7-
import 'package:analysis_server/plugin/edit/fix/fix_core.dart';
87
import 'package:analysis_server/src/services/correction/fix.dart';
98
import 'package:analysis_server/src/utilities/strings.dart';
109
import 'package:analysis_server/src/utilities/yaml_node_locator.dart';
@@ -20,6 +19,7 @@ import 'package:analyzer_plugin/utilities/change_builder/change_builder_yaml.dar
2019
import 'package:analyzer_plugin/utilities/change_builder/change_workspace.dart';
2120
import 'package:analyzer_plugin/utilities/fixes/fixes.dart';
2221
import 'package:collection/collection.dart';
22+
import 'package:server_plugin/edit/fix/fix.dart';
2323
import 'package:yaml/yaml.dart';
2424
import 'package:yaml_edit/yaml_edit.dart';
2525

@@ -182,7 +182,7 @@ class AnalysisOptionsFixGenerator {
182182
}
183183
change.id = kind.id;
184184
change.message = formatList(kind.message, args);
185-
fixes.add(Fix(kind, change));
185+
fixes.add(Fix(kind: kind, change: change));
186186
}
187187

188188
Future<ChangeBuilder?> _createScalarDeletionBuilder(

pkg/analysis_server/lib/src/services/correction/fix/pubspec/fix_generator.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
import 'package:_fe_analyzer_shared/src/scanner/characters.dart';
6-
import 'package:analysis_server/plugin/edit/fix/fix_core.dart';
76
import 'package:analysis_server/src/services/correction/fix/pubspec/fix_kind.dart';
87
import 'package:analysis_server/src/utilities/yaml_node_locator.dart';
98
import 'package:analyzer/dart/analysis/session.dart';
@@ -18,6 +17,7 @@ import 'package:analyzer/src/util/yaml.dart';
1817
import 'package:analyzer_plugin/utilities/change_builder/change_builder_core.dart';
1918
import 'package:analyzer_plugin/utilities/change_builder/change_workspace.dart';
2019
import 'package:analyzer_plugin/utilities/fixes/fixes.dart';
20+
import 'package:server_plugin/edit/fix/fix.dart';
2121
import 'package:yaml/yaml.dart';
2222

2323
/// The generator used to generate fixes in pubspec.yaml files.
@@ -147,7 +147,7 @@ class PubspecFixGenerator {
147147
}
148148
change.id = kind.id;
149149
change.message = formatList(kind.message, null);
150-
fixes.add(Fix(kind, change));
150+
fixes.add(Fix(kind: kind, change: change));
151151
}
152152

153153
Future<void> _addMissingDependency(ErrorCode errorCode) async {

pkg/analysis_server/lib/src/services/correction/fix_internal.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
import 'package:analysis_server/plugin/edit/fix/fix_core.dart';
65
import 'package:analysis_server/plugin/edit/fix/fix_dart.dart';
76
import 'package:analysis_server/src/services/correction/dart/abstract_producer.dart';
87
import 'package:analysis_server/src/services/correction/dart/add_async.dart';
@@ -239,6 +238,7 @@ import 'package:analyzer_plugin/src/utilities/change_builder/change_builder_core
239238
import 'package:analyzer_plugin/utilities/change_builder/change_builder_core.dart';
240239
import 'package:analyzer_plugin/utilities/change_builder/conflicting_edit_exception.dart';
241240
import 'package:analyzer_plugin/utilities/fixes/fixes.dart';
241+
import 'package:server_plugin/edit/fix/fix.dart';
242242

243243
final _builtInLintMultiProducers = {
244244
LintNames.deprecated_member_use_from_same_package: [
@@ -1667,7 +1667,7 @@ class FixInFileProcessor {
16671667
var fixKind = fixState.fixKind;
16681668
sourceChange.id = fixKind.id;
16691669
sourceChange.message = fixKind.message;
1670-
fixes.add(Fix(fixKind, sourceChange));
1670+
fixes.add(Fix(kind: fixKind, change: sourceChange));
16711671
}
16721672
}
16731673
}

pkg/analysis_server/lib/src/services/correction/fix_processor.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
import 'package:analysis_server/plugin/edit/fix/fix_core.dart';
65
import 'package:analysis_server/plugin/edit/fix/fix_dart.dart';
76
import 'package:analysis_server/src/services/correction/base_processor.dart';
87
import 'package:analysis_server/src/services/correction/bulk_fix_processor.dart';
@@ -15,6 +14,7 @@ import 'package:analyzer/src/generated/java_core.dart';
1514
import 'package:analyzer/src/util/file_paths.dart';
1615
import 'package:analyzer_plugin/utilities/change_builder/change_builder_core.dart';
1716
import 'package:analyzer_plugin/utilities/change_builder/conflicting_edit_exception.dart';
17+
import 'package:server_plugin/edit/fix/fix.dart';
1818

1919
/// A function that can be executed to create a multi-correction producer.
2020
typedef MultiProducerGenerator = MultiCorrectionProducer Function();
@@ -97,7 +97,7 @@ class FixProcessor extends BaseProcessor {
9797

9898
change.id = kind.id;
9999
change.message = formatList(kind.message, producer.fixArguments);
100-
fixes.add(Fix(kind, change));
100+
fixes.add(Fix(kind: kind, change: change));
101101
}
102102

103103
Future<void> _addFromProducers() async {

pkg/analysis_server/pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ dependencies:
2121
memory_usage: any
2222
meta: any
2323
path: any
24+
server_plugin: any
2425
stream_channel: any
2526
telemetry: any
2627
test: any

pkg/analysis_server/test/src/cider/fixes_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
import 'package:analysis_server/plugin/edit/fix/fix_core.dart';
65
import 'package:analysis_server/src/cider/fixes.dart';
76
import 'package:analysis_server/src/services/correction/fix.dart';
87
import 'package:analyzer/source/line_info.dart';
98
import 'package:analyzer_plugin/protocol/protocol_common.dart' show SourceEdit;
109
import 'package:analyzer_plugin/utilities/fixes/fixes.dart';
10+
import 'package:server_plugin/edit/fix/fix.dart';
1111
import 'package:test/test.dart';
1212
import 'package:test_reflective_loader/test_reflective_loader.dart';
1313

pkg/analysis_server/test/src/services/correction/fix/analysis_options/test_support.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
import 'package:analysis_server/plugin/edit/fix/fix_core.dart';
65
import 'package:analysis_server/src/services/correction/fix/analysis_options/fix_generator.dart';
76
import 'package:analyzer/error/error.dart';
87
import 'package:analyzer/src/generated/source.dart';
@@ -11,6 +10,7 @@ import 'package:analyzer/src/task/options.dart';
1110
import 'package:analyzer/src/test_utilities/resource_provider_mixin.dart';
1211
import 'package:analyzer_plugin/protocol/protocol_common.dart'
1312
hide AnalysisError;
13+
import 'package:server_plugin/edit/fix/fix.dart';
1414
import 'package:test/test.dart';
1515
import 'package:yaml/yaml.dart';
1616

pkg/analysis_server/test/src/services/correction/fix/fix_processor.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
import 'package:analysis_server/plugin/edit/fix/fix_core.dart';
65
import 'package:analysis_server/src/services/correction/bulk_fix_processor.dart';
76
import 'package:analysis_server/src/services/correction/change_workspace.dart';
87
import 'package:analysis_server/src/services/correction/fix.dart';
@@ -16,6 +15,7 @@ import 'package:analyzer_plugin/protocol/protocol_common.dart'
1615
import 'package:analyzer_plugin/utilities/change_builder/change_workspace.dart';
1716
import 'package:analyzer_plugin/utilities/fixes/fixes.dart';
1817
import 'package:meta/meta.dart';
18+
import 'package:server_plugin/edit/fix/fix.dart';
1919
import 'package:test/test.dart';
2020

2121
import '../../../../abstract_context.dart';

pkg/analysis_server/test/src/services/correction/fix/pubspec/test_support.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
import 'package:analysis_server/plugin/edit/fix/fix_core.dart';
65
import 'package:analysis_server/src/protocol_server.dart' show SourceEdit;
76
import 'package:analysis_server/src/services/correction/fix/pubspec/fix_generator.dart';
87
import 'package:analyzer/error/error.dart';
98
import 'package:analyzer/src/pubspec/pubspec_validator.dart'
109
as pubspec_validator;
1110
import 'package:analyzer/src/test_utilities/resource_provider_mixin.dart';
1211
import 'package:analyzer_plugin/utilities/fixes/fixes.dart';
12+
import 'package:server_plugin/edit/fix/fix.dart';
1313
import 'package:test/test.dart';
1414
import 'package:yaml/yaml.dart';
1515

pkg/server_plugin/CONTRIBUTING.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
## Contributing
2+
3+
Contributions welcome! Please follow the guide in [Contributing][contributing].
4+
5+
## Building
6+
7+
If you want to build Dart yourself, here is a guide to [getting the source,
8+
preparing your machine to build the SDK, and building][building].
9+
10+
There are more documents on our [wiki][]. Once set up to build the SDK, run:
11+
12+
```none
13+
./tools/build.py -mrelease create_sdk
14+
```
15+
16+
## Coding style
17+
18+
The analyzer packages are coded with a styled specified in our [coding style
19+
document][coding style].
20+
21+
[building]: https://github.com/dart-lang/sdk/wiki/Building
22+
[coding style]: https://github.com/dart-lang/sdk/blob/main/pkg/analyzer/doc/implementation/coding_style.md
23+
[contributing]: https://github.com/dart-lang/sdk/wiki/Contributing
24+
[wiki]: https://github.com/dart-lang/sdk/wiki

pkg/server_plugin/LICENSE

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Copyright 2012, the Dart project authors.
2+
3+
Redistribution and use in source and binary forms, with or without
4+
modification, are permitted provided that the following conditions are
5+
met:
6+
* Redistributions of source code must retain the above copyright
7+
notice, this list of conditions and the following disclaimer.
8+
* Redistributions in binary form must reproduce the above
9+
copyright notice, this list of conditions and the following
10+
disclaimer in the documentation and/or other materials provided
11+
with the distribution.
12+
* Neither the name of Google LLC nor the names of its
13+
contributors may be used to endorse or promote products derived
14+
from this software without specific prior written permission.
15+
16+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

pkg/server_plugin/OWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
file:/tools/OWNERS_ANALYZER

pkg/server_plugin/README.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# server\_plugin package
2+
3+
This package is being developed for the second incarnation of Dart Analyzer
4+
plugins. It is in an intermediate state, and a few things must be kept in mind
5+
during this phase of development:
6+
7+
1. **This package is not to be published on pub.** Yet. We may decide to go
8+
forward with this package as a full replacement of the `analyzer_plugin`
9+
package, in which case we _would_ ultimately publish it. But we may choose a
10+
different plan. Until we finalize, this package is not to be published.
11+
2. **In order to support the above point, no pub-publishable code can depend on
12+
this package.** At no point can we introduce a dependency from a package
13+
like `analyzer` or `analyzer_plugin` to this package. If we did so, then at
14+
the next time we published _that_ package to pub, we would need to publish
15+
_this_ package to pub. No. In short, I think what this means is that only
16+
the `analsis_server` package can depend on this package (until we decide the
17+
final path to publishing the next Dart Analyzer plugins story.
18+
19+
## Migration of code between packages
20+
21+
As part of the design of the new Dart Analyzer plugins, much code will shift
22+
around, in a few directions.
23+
24+
* **`analysis_server` package to `server_plugin` package:** The API of the new
25+
Dart Analyzer plugins focuses around two primary concepts: lint rules and
26+
quick fixes. Quick assists may be chosen as a third important concept. Lint
27+
rule code has typically lived in the `analyzer` package, and does not need to
28+
move. (It's presense in the `analyzer` package could be deprecated in favor
29+
of this package, but it is not important for the implementation.)
30+
31+
Quick fixes, however, have only existed in concept, and interface, and API,
32+
in the `analysis_server` package. That code needs to move to this package in
33+
order to be used in a Dart Analyzer plugin.
34+
35+
**A move from the `analysis_server` package to this package is not a breaking
36+
change.**
37+
38+
* **`analyzer_plugin` package to `server_plugin` package:** Care is being taken
39+
to decide where Dart Analyzer plugin code will live and how it will be
40+
published. It is not decided yet what the ultimate package API will be. Some
41+
code from **analyzer_plugin** may move to this package.
42+
43+
**A move from the `analyzer_plugin` package is a breaking change. Extreme
44+
care must be taken.**
45+
46+
* **`analyzer_plugin` package to `analysis_server` package:** There will be
47+
many components of the analysis server that currently live in
48+
`analyzer_plugin`, because they were necessary for the first version of Dart
49+
Analyzer plugins), but are not part of the new Dart Analyzer plugins. These
50+
components can be moved safely back into the `analysis_server` package.
51+
52+
In terms of priority, it is not crucial for such code to be moved out of the
53+
`analyzer_plugin` package. It can live there indefinitely, and the
54+
`analysis_server` package can continue to depend on code from the
55+
`analyzer_plugin` package, as shipped in the SDK.
56+
57+
**A move from the `analyzer_plugin` package is a breaking change. Extreme
58+
care must be taken.**
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
include: package:lints/recommended.yaml
2+
3+
analyzer:
4+
language:
5+
strict-casts: true
6+
strict-inference: true
7+
strict-raw-types: true
8+
errors:
9+
# This package imports much of the implementation libraries of the
10+
# 'analyzer' (and sometimes the '_fe_analyzer_shared' package), because it
11+
# is tightly integrated. This will not likely change any time soon.
12+
implementation_imports: ignore
13+
14+
linter:
15+
rules:
16+
- always_use_package_imports
17+
- avoid_dynamic_calls
18+
- avoid_redundant_argument_values
19+
- avoid_unused_constructor_parameters
20+
- flutter_style_todos
21+
- library_annotations
22+
- prefer_single_quotes
23+
- unawaited_futures
24+
- unnecessary_breaks
25+
- unnecessary_library_directive
26+
- unnecessary_parenthesis
27+
- unreachable_from_main
28+

0 commit comments

Comments
 (0)