Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

☂️ New analyzer plugin system #53402

Open
11 of 28 tasks
srawlins opened this issue Aug 31, 2023 · 7 comments
Open
11 of 28 tasks

☂️ New analyzer plugin system #53402

srawlins opened this issue Aug 31, 2023 · 7 comments
Assignees
Labels
analyzer-plugin area-devexp Developer Experience related issues (DevTools, IDEs, Analysis Server, completions, refactoring, etc) P2 A bug or feature request we're likely to work on type-enhancement A request for a change that isn't a bug

Comments

@srawlins
Copy link
Member

srawlins commented Aug 31, 2023

Tasks needed to deliver a new analyzer plugin system:

Tech preview

General availability

Product excellence

  • Support writing Assists
  • Support providing Snippets
  • Support writing analysis rules for pubspec files and analysis options files.
  • Support writing quick fixes for pubspec files and analysis options files.
  • Support applying plugin-provided quick fixes with dart fix .
@srawlins srawlins added area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P2 A bug or feature request we're likely to work on type-enhancement A request for a change that isn't a bug analyzer-plugin labels Aug 31, 2023
@srawlins srawlins self-assigned this Aug 31, 2023
@matanlurey
Copy link
Contributor

This is really exciting Sam! If you could use any help trying out prototypes I'd volunteer some time!

@parlough
Copy link
Member

@srawlins Would you mind creating go links for your design docs on https://github.com/flutter/website/blob/main/firebase.json? Then you can add them to the top of your docs making them a bit easier to share and discuss publicly.

Community members often follow new go links on flutter.dev as well.

copybara-service bot pushed a commit that referenced this issue Jan 15, 2024
In order for CorrectionProducers to be used in analyzer plugins, we
need to access DartFixContributor which needs to compute fixes via
FixProcessor. So both DartFixContributor and FixProcessor need to be
moved into analyzer_plugin (eventually). For now, to support
prototyping, I am moving FixProcessor to its own library, and
separating all of the built in mappings (from diagnostic to producer
generators).

I think this separation actually stands on its own as being tidier,
simplifying fix_internal.dart, and separating code from data, as it
were.

Work towards #53402

Cq-Include-Trybots: luci.dart.try:flutter-analyze-try,analyzer-win-release-try
Change-Id: I3b4fadc7ed94c23597d72bef7dcd832380d34e9a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/345561
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
copybara-service bot pushed a commit that referenced this issue Mar 18, 2024
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 <athom@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
copybara-service bot pushed a commit that referenced this issue Mar 19, 2024
* Combine DartFixContext and DartFixContextImpl into one class;
  separation seems unnecessary.
* Change constructor (which was on DartFixContextImpl) to use all
  named parameters.
* Change `resolveResult` field to `resolvedResult`, since the type is
  called `ResolvedUnitResult`.
* Start doc comments with third person verbs [1].


[1]: https://dart.dev/effective-dart/documentation#prefer-starting-function-or-method-comments-with-third-person-verbs

Work towards #53402

Change-Id: Idb3c6776f899d5bc9b634c1d9c4b998de2603d04
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/358382
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
copybara-service bot pushed a commit that referenced this issue Apr 17, 2024
`_getInsertionLocationTop` and `addLibraryImports` are each moved to
extract_method.dart, as the only location where they were used.

We get to delete the `_InsertionLocation` class.

The tests are also moved, unchanged, and CorrectionUtilsTest is very
much simplified.

Bug: #53402
Change-Id: Ia410f04a837d85a0e06ec523d156c6c6c8bf6a3b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/363402
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
copybara-service bot pushed a commit that referenced this issue Apr 18, 2024
…sites

Cq-Include-Trybots: luci.dart.try:flutter-analyze-try,analyzer-win-release-try,pkg-win-release-try
Bug: #53402
Change-Id: Id62b06f3419820d4a74b34b51a6022792bcef7ab
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/363404
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
copybara-service bot pushed a commit that referenced this issue Apr 18, 2024
…nto extract_method

Bug: #53402
Change-Id: I4fca3482c27520328339d1d1f0b6b541399ed612
Cq-Include-Trybots: luci.dart.try:flutter-analyze-try,analyzer-win-release-try,pkg-win-release-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/363501
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
copybara-service bot pushed a commit that referenced this issue Apr 19, 2024
We have chosen a new name for this package. So before we write more
code inside, we need to move everything from 'server_plugin' to
'analysis_server_plugin'. There are some steps do doing so, to not
break various infra:

1. Land this change, introducing the new package in the SDK, but no
   dependencies on it.
2. Land this change independently in google3 (the package is not
   yet "unbundled.")
3. Mark the package as "unbundled" in google3.
4. Move all code from server_plugin to analysis_server_plugin; update
   imports; and delete server_plugin.
5. Remove server_plugin as an "unbundled" package; and remove
   server_plugin from google3.

Bug: #53402
Change-Id: I70197fdf61dd5862c2220d8ed5dd0880a1593ead
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/363600
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Alexander Thomas <athom@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
copybara-service bot pushed a commit that referenced this issue May 28, 2024
Work towards #53402

None of the classes which were moved are changed in any way.

Cq-Include-Trybots: luci.dart.try:flutter-analyze-try,analyzer-win-release-try,pkg-win-release-try
Change-Id: If81098971de044e2f69c1039ec23eff07b108af6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/368066
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
@srawlins
Copy link
Member Author

srawlins commented May 30, 2024

I'm not good about referencing this issue in my CLs, as all the work is sort of just preparation and grooming the code. So I'll write down some of the under-the-hood changes I've been making. They are largely to support two areas: lint rule APIs and correction producer (mostly quick fix) APIs:

lint rule APIs:

  • LinterContext:
    • Deprecate resolveNameInScope (replaced with resolveNameInScope2) (334082) and inTestDir (replaced with extension getter) (365300).
    • Remove analysisOptions, declaredVariables, canBeConst, canBeConstConstructor, inTestDir (replaced with extension getters) (365521), isEnabled (368524).
    • Rename currentUnit to definingUnit (368524).
    • Add isInLibDir, libraryElement (368524).
  • LinterContextImpl: remove strictCasts field (344200).
  • Mark LintDriver and DartLinter as "only used for linter tools and tests" (334645).
  • Remove CamelCaseString and SourceLinter (334645).
  • Mark DartLinter.lintPubspecSource as @visibleForTesting (334645).
  • LinterOptions: mark enabledLints and analysisOptions final, and remove
    resourceProvider (334645).
  • Move analyzer's top-level function lintFiles, classes ErrorWatchingSink and FileGlobFilter to linter's tool/ directory (334645).
  • NodeLintRegistry: remove deprecated addOnClause (366404).
  • Remove NodeLintRuleWithContext (366504), Linter, getVisitor, linterVersion (366840), LinterAnalysis.linterUnit, LinterContextUnit2 (366405).
  • Simplify LibraryAnalyzer._computeLints (366222).
  • Add LinterContextUnit.errorReporter (366405).
  • Add LinterVisitor.afterLibrary (368524).
  • Move DartLinter out of analyzer package (369562).
  • Mark Group.builtin and Group.custom as visible-for-testing (369562).
  • Remove all fields from Group (369782).
  • Allow each LintRule multiple categories (369861).
  • Require each LintRule to either override lintCode or lintCodes (372183).
  • Rename LinterContextUnit -> LintRuleUnitContext, LinterContextImpl -> LinterContextWithResolvedResults, LinterContextParsedImpl -> LinterContextWithParsedResults (374861).
  • Make LintCode public API (375060).
  • Rename Category to LintRuleCategory (377269).
  • Move LintRule category declarations to a messages.yaml file (382780).
  • Convert the classes AnalysisOptionsFileConfig and PubspecYamlFileConfig each to a single method ().
  • Privatize: ExpectedDiagnostic fields diagnosticMatcher, offset, length, and messageContains, ExpectedError field codes, ExpectedLint field lintName, LintRuleTest field collectionIncludedPaths, _ContextResolutionTest field sdkRoot (386580).
  • Privatize writeTestPackageAnalysisOptionsFile and writeTestPackagePubspecYamlFile functions (386580).
  • Simplify LintConfig and RuleConfig to not have an unnecessary impl class (388960).
  • Make many functions on _LintConfig like addAsListOrString both static and private (388960).
  • Make all of RuleConfig's fields final and pass them all as parameters into the constructor (388960).
  • Simplify FormatterOptions code (389020).
  • Remove most use cases of LintFilter and move it to the linter package (389403).
  • Use StringSinks more in linter code, simplifying some tools (390665).
  • Always propagate exceptions in lint rule tests (391202).
  • Move LintDriver into the linter package (391321).

correction producer APIs:

  • _AbstractCorrectionProducer:
    • Remove strictCasts (344220), invalidNodes, displayStringForType, mightBeImplicitConstructor, nameOfType, shouldWrapParenthesisBeforeAnd (367363), coveredNode (367761).
    • Make sealed (367761)
  • CorrectionProducer:
    • Remove getLinterContext (364964).
    • Convert each of assistArguments, fixArguments, multiFixArguments to be List<String>? (364420).
    • Remove errorMessage (367363).
    • Make configure abstract (367363).
    • Add coveringNode (367761).
    • Make sealed (367761).
    • Remove configure (368760).
    • Add context as a named parameter to the constructor (368760).
  • MultiCorrectionProducer: remove typeProvider, typeSystem (367363).
  • MultiCorrectionProducer: add context (368760).
  • ResolvedCorrectionProducer: remove coreTypeBool (367363).
  • CorrectionUtils:
    • Remove patternOfBoolCondition (347781).
    • Remove findPossibleLocalVariableConflicts (358641).
    • Remove getTypeSource, targetClassElement, and
      targetExecutableElement (358663).
    • Remove prepareNewStatementLocation (360080).
    • Move prepareNewFieldLocation and
      prepareNewGetterLocation to DartFileEditBuilder, as
      addFieldInsertion and addGetterInsertion (360302).
    • Move addMethodInsert and addCaseClauseAtEndInsert to DartEditBuilder (360980).
    • Remove getDefaultValueCode (361132).
    • Move last constructor APIs to DartFileEditBuilder (362063).
    • Remove prepareNewClassMemberLocation (362303).
    • Remove addLibraryImports (363402).
    • Remove indentLeft, indentRight (363404).
    • Remove selectionIncludesNonWhitespaceOutsideNode (363501).
  • DartFileEditBuilder:
    • Add addConstructorInsertion, a replacement for both CorrectionUtils.prepareEnumNewConstructorLocation and
      CorrectionUtils.prepareNewConstructorLocation (361624).
    • Rename add___Insertion APIs to insert___ (362001).
    • Add insertIntoUnitMember (362183).
    • Add a parameter to writeOverride called setSelection which controls whether selection should be set (362183).
  • CorrectionProducerContext:
    • Make private: selectionOffset, selectionLength, utils, sessionHelper, unitResult, applyingBulkFixes, diagnostic, token (364420).
    • Remove selectionEnd, unit, file, session, workspace, typeProvider; these can be accessed via
      getters (364420).
    • Make final (367761).
    • Make non-generic (368760).
  • Make private AssistProcessor.generators, multiGenerators, .assistContext, .assists (364420).
  • FixProcessor:
    • Make private: FixProcessor.fixContext (364420).
    • Add registration of "ignore" producer generators (376126).
    • Registered producer generators use LintCodes over Strings (377267).
  • Remove hasFix top-level function(345347), classes TransformOverride (347641), ExpressionCasePattern (347781), CorrectionUtils_InsertDesc (347780), CancelCorrectionException (348083), Baseprocessor (364360).
  • Separate FixProcessor and built-in fix producer mappings into two files (345561).
  • Combine DartFixContext and DartFixContextImpl and change constructor to use all named parameters (358382).
  • Remove static class Flutter. Most methods are refactored as extension methods. Some unused ones are deleted.
    Some are inlined into their call sites (362300).
  • Remove unused class TransformOverrideSet (340280).
  • Use an enum to express how widely a CorrectionProducer can be applied (366740).
  • Remove unused ParsedCorrectionProducer (368760).
  • Re-introduce ParsedCorrectionProducer, and use in 7 producers (369561).
  • Make DartFixKindPriority public, use lower-cased values (374742).
  • BulkFixProcessor:
    • Privatize BulkFixProcessor.syntacticLintCodes (377267).
    • Privatize four more fields and one method (377622).
    • Mark two fields @visibleForTesting (377622).
    • Privatize 6 fields and 1 getter on IterativeBulkFixProcessor (377622).
  • Separate fix generators into their own file (377563).

Plugin server API:

  • Introduce the PluginServer (382480).
  • Run PluginServer zoned (384140).
  • Support overlay changes (384305).
  • Add the plugin package generator (384681).

Analysis Options

  • Rename most references, in the analyzer and analysis server, of 'plugins' to be 'legacy plugins' (384964).
  • Simplify fields in AnalysisOptionsImpl (389040).
  • Simplify parseConfig function to take a non-nullable parameter (389022).
  • In CodeStyleOptions, privatize options field (389023) and improve doc comments (390266).
  • Remove dead code in AnalysisOptionsImpl (390420).
  • Remove unused LinterOptions.analysisOptions (390563).
  • Remove unused DriverOptions.strongMode (390666).
  • Convert the applyOptions extension method into a builder class (390660).
  • Make the 'strict' modes part of the public API (391020).

I'll update this comment as I make more preparatory changes.

copybara-service bot pushed a commit that referenced this issue Jul 18, 2024
FixProcessor has to be part of the analysis_server_plugin package, so it
cannot have any dependencies on the analysis_server package. This removes one.

Work towards #53402

Cq-Include-Trybots: luci.dart.try:flutter-analyze-try,analyzer-win-release-try,pkg-win-release-try
Change-Id: I935712bf75837ba95438ac9ed5f7ba5d8f941a7a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/376126
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
copybara-service bot pushed a commit that referenced this issue Jul 29, 2024
Work towards #53402

I move them all out of static fields on FixProcessor to be instance
fields on a singleton class in a new file, fix_generators.dart. For
each one that ended in the word 'Map', I removed that.

I also move `_bulkFixableErrorCodes` and `canBulkFix` to
BulkFixProcessor, as it is the only caller, and holds onto the data.

I also correct some outdated doc comments.

I also make `_isFixableError` static.

Cq-Include-Trybots: luci.dart.try:flutter-analyze-try,analyzer-win-release-try,pkg-win-release-try
Change-Id: I01beccac4969f832941c75eb6d7b49b54a0b085c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/377563
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
copybara-service bot pushed a commit that referenced this issue Jul 30, 2024
These two are needed in the shared package so that plugins can run
CorrectionProducers. They go in 'src' because plugin developers do not
need to see this code.

Work towards #53402

Cq-Include-Trybots: luci.dart.try:flutter-analyze-try,analyzer-win-release-try,pkg-win-release-try
Change-Id: Iee5b5dd063d5b0a9b00c58b91a3e50328c8b5fc2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/377860
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
copybara-service bot pushed a commit that referenced this issue Jul 31, 2024
Also move the top-level `computeFixes` convenience function.

The `computeFixes` function is the main entrypoint that various code
uses to, well, compute all fixes with a FixProcessor and a
FixInFileProcessor. In order for plugin code to call `computeFixes`,
we need that function and FixInFileProcessor in the
analysis_server_plugin package.

Work towards #53402

Cq-Include-Trybots: luci.dart.try:flutter-analyze-try,analyzer-win-release-try,pkg-win-release-try
Change-Id: Id5f02864762eeefb92055a3534e91b60b76dfeb2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/378220
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
copybara-service bot pushed a commit that referenced this issue Sep 9, 2024
This adds and tests support for adding file overlays, changing them, and
removing them.

Work towards #53402

Change-Id: I7939f8199639f7e336cd97515c2f7d48b1d777a0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/384305
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
copybara-service bot pushed a commit that referenced this issue Sep 11, 2024
This generator will be used create shared plugin package entrypoints from
plugin configurations.

Work towards #53402

Change-Id: If5c6aeb7bc7845311975928fba1cb9c8d273423c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/384681
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
@rrousselGit
Copy link

👋
Is this likely to land within 6months or so?

This seems to be actively worked on ; which is cool! But it also makes me re-evaluate how much effort I should spend working on custom_lint.
If this takes a while to land >= 6month, I'll likely keep working on custom_lint in the meantime (such as supporting newer analyzer versions whenever they land).
But if it's <=6 months, I'd consider stopping support for custom_lint, to use that time on things more valuable in the long term.

@srawlins
Copy link
Member Author

Yes, actively working on it, and hope to send out something in the next month or so. Definitely < 6 months 😁 stay tuned.

copybara-service bot pushed a commit that referenced this issue Dec 10, 2024
This change is the final piece in enabling plugins in the new style to
be launched from a specification in analysis options.

Work towards #53402

* We support both one legacy analyzer plugin (the current max), and
  a set of new analyzer plugins, which are combined and launched in one
  shared plugin isolate.
* Make PluginLocator.pluginMap private.
* Add a parameter to PluginManager.addPluginToContextRoot:
  isLegacyPlugin. This method is used for both legacy and new plugins,
  but has slightly different behavior, finding where the plugin files
  are.

Change-Id: I6644aecd4283eea22586ffd051a01b0ec8987fc5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/395360
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
@rrousselGit
Copy link

Product excellence

  • Support writing Assists

I missed the fact that assists were part of the "In the future".

Assists are key IMO. I'd say they are critical.
Assists are one of the main way to improve developer experience. The few assists I wrote for Riverpod are quite the time savers ; and I'd be quite sad to see them go.

@srawlins
Copy link
Member Author

I'm very open to bumping the pirority on Assists. They "should" be easy to add, as we already have quick fixes. I'll sync with the team on this for MVP.

@bwilkerson bwilkerson added area-devexp Developer Experience related issues (DevTools, IDEs, Analysis Server, completions, refactoring, etc) and removed area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. labels Feb 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-plugin area-devexp Developer Experience related issues (DevTools, IDEs, Analysis Server, completions, refactoring, etc) P2 A bug or feature request we're likely to work on type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

5 participants