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
1 of 8 tasks
srawlins opened this issue Aug 31, 2023 · 3 comments
Open
1 of 8 tasks

☂️ New analyzer plugin system #53402

srawlins opened this issue Aug 31, 2023 · 3 comments
Assignees
Labels
analyzer-plugin 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

Comments

@srawlins
Copy link
Member

srawlins commented Aug 31, 2023

Tasks needed to deliver a new analyzer plugin system:

@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).
  • 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).

correction producer APIs:

  • _AbstractCorrectionProducer:
    • Remove strictCasts (344220), invalidNodes, displayStringForType, mightBeImplicitConstructor, nameOfType, shouldWrapParenthesisBeforeAnd (367363).
  • CorrectionProducer:
    • Remove getLinterContext (364964).
    • Convert each of assistArguments, fixArguments, multiFixArguments to be List<String>? (364420).
    • Remove errorMessage (367363).
    • Make configure abstract (367363).
  • MultiCorrectionProducer: remove typeProvider, typeSystem (367363).
  • 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, node, token (364420).
    • Remove selectionEnd, unit, file, session, workspace, typeProvider; these can be accessed via
      getters (364420).
  • Make private AssistProcessor.generators, multiGenerators, .assistContext, .assists (364420).
  • FixProcessor:
    • Make private: FixProcessor.fixContext (364420).
  • 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).

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-plugin 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
Projects
None yet
Development

No branches or pull requests

3 participants