Commit Graph

161 Commits

Author SHA1 Message Date
Sam Rawlins 38b60624d4 DAS plugins: Test how an unsupported request is handled.
Change-Id: If214c32f396867a5af0a3bfcc40946121c895aef
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/442285
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2025-07-28 09:44:52 -07:00
Paul Berry 6610e5cbfe [analyzer] Break dependency between analyzer message codegen and analyzer.
This fixes a bootstrapping problem: previously we could get into a
situation where the generated files for analyzer diagnostic messages
were out of date, but the code generator for those messages couldn't
be run, because it imported the analyzer itself, which contained
compiled errors due to the generated files being out of date.

There were two problematic dependencies:

- The `GeneratedContent.check` and `GeneratedContent.checkAll` methods
  relied on invoking the Dart formatter as a library (rather than
  invoking `dart format` as a subprocess); the Dart formatter library
  imports the analyzer. Fortunately, this functionality is not needed
  by the code generators themselves. It's only needed by the _tests_
  that verify that code generation has run. So I was able to break the
  dependency by moving this functionality into a new file,
  `package:analyzer_utilities/generated_content_check.dart`, which is
  imported only by the code generation tests. The new API is slightly
  different: `GeneratedContent.checkAll` has been replaced by an
  extension method `check` on `Iterable<GeneratedContent>`.

- The diagnostic message code generator used to have a post-processing
  step that made use of the scanner to find error messages used by the
  parser that needed to be translated, and issued a warning if it
  found any. This check was useful a long time ago, when we were
  unifying the analyzer and CFE parsers, and is no longer useful, so
  I've removed it.

Change-Id: I509b741faca3b9ae21c23936001105ded731b490
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/442241
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2025-07-25 13:18:00 -07:00
Fedor Shcheglov f47cc4487b Remove Xyz2 suffix getters from /analysis
Change-Id: I10221b86f63ee8a2d74938ef0438945b43e11f6b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/441990
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2025-07-24 05:54:30 -07:00
Danny Tuppeny c235fadc99 Fix some EOL bugs + remove useLineEndingsForPlatform=false from refactor tests
Some additional work towards https://github.com/dart-lang/sdk/issues/60234, along with a couple of small fixes for issues uncovered while getting the tests running with \r\n.

Change-Id: Iff3700fad017825f65d64195d844b1694163456a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/441840
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2025-07-23 09:12:53 -07:00
Sam Rawlins 6d6fdc1a52 DAS plugins: bump analysis_server_plugin to 0.2.0
Change-Id: I0022c19ffbb30066087abc1005923ef558c9fdfb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/441081
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2025-07-21 07:52:49 -07:00
Sam Rawlins 0c3de0815f DAS plugins: Add docs on testing rules
Change-Id: Ia3e771a2f0b8ce01c0a57d3c442492943089a23b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/439821
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2025-07-11 10:51:40 -07:00
Lasse R.H. Nielsen 1afbc51874 Add type support to data-fix replacedBy.
Still missing extension type support.

Change-Id: Ida582e6f5832d2ee0a648f0aecb9e8c50c0ee8e1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/432982
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Morgan :) <davidmorgan@google.com>
Commit-Queue: Lasse Nielsen <lrn@google.com>
2025-07-10 01:06:23 -07:00
Sam Rawlins 636f144fb6 DAS plugins: Change AnalysisRule type to AbstractAnalysisRule
Change-Id: I17f13d386872b21fdd4ff16601bb0e23c478e992
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/439341
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2025-07-08 13:34:13 -07:00
Sam Rawlins 1ce5b15166 DAS plugins: Update docs for new public names
This change highlights how all of the necessary imports are now public!

From here, forward, we are guarded by analyzer's public API rules.

Change-Id: I71a7f928fc5913df846aa6253cd880719b4cd726
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/439342
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2025-07-08 11:15:02 -07:00
FMorschel 2419e97604 [DAS] Fixes create method, create getter and create mixin fixes
Fixes: https://github.com/dart-lang/sdk/issues/60826
Change-Id: I16cb1db16bcb8d7e57cb92723f058302f347e40e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/432580
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Auto-Submit: Felipe Morschel <git@fmorschel.dev>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2025-07-08 09:14:41 -07:00
Paul Berry fb2d1171e5 Reference all genearted file paths to pkg directory.
Modifies `GeneratedDirectory.outputDirPath` and
`GeneratedFile.outputPath` to be relative to the SDK's `pkg` directory
rather than relative to the containing package. Accordingly, modifies
the `GeneratedContent` methods `check`, `checkAll`, `generate`,
`generateAll`, `output`, as well as the `DirectoryContentsComputer`
and `FileContentsComputer` callbacks, so that their first parameter is
the path to the `pkg` directory rather than the path to the containing
package.

Also modifies the `readApi` functions in `pkg/analysis_server` and
`pkg/analyzer_plugin` to accept a path to the `pkg` directory rather
than a path to the containing package, since these functions are
called by code generation callbacks.

These changes should make code generation logic easier to reason
about. They also will make it easier to move the outputs of code
generation from one package to another, which will pave the way for
some follow-up work in which I intend to start sharing error message
representations belonging to `pkg/analyzer`, `pkg/front_end`, and
`pkg/_fe_analyzer_shared`.

Change-Id: Ia9b369b16f2df931c8a472f91400f2c5a0b8be9d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/438480
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2025-07-04 05:04:50 -07:00
Paul Berry 5c091e010f Separate allTargets variables for api.txt code generators.
This change removes the top level variable `allTargets` from
`pkg/analyzer_utilities/lib/tool/api.dart` and replaces it with a
method `allTargetsForPackage`, parameterized by the name of the
package for which an `api.txt` file is generated. The individual code
generators that make use of this function now all have their own top
level variable `allTargets`.

In addition to being conceptually clearer (since we no longer have a
single `allTargets` variable with different meanings depending on
where it's used), this paves the way for a CL I am working on that
will change the `GeneratedContent` based code generators so that they
use paths relative to the `pkg` directory. That in turn should make it
simpler to move some of the code generated files that have to do with
error messages from `pkg/analyzer` to `pkg/_fe_analyzer_shared`.

Change-Id: Id636ddbca27c46ae4242bbf8e4b6f7b8dae4d4e9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/438481
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Auto-Submit: Paul Berry <paulberry@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2025-07-02 14:31:33 -07:00
Konstantin Shcheglov a1955aa8e7 Elements. Switch FunctionTypeImpl to typeParameters, remove typeFormals.
Change-Id: I6f190d53c6b13cab7d921b2bb895f1038c3f1cc8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/438401
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2025-07-02 07:24:41 -07:00
Paul Berry 814c61d88d [analyzer] Don't import generated error code files more than needed.
This change adds a `@Deprecated` annotation to each of the analyzer's
generated error code files, with a deprecation message that says the
corresponding non-code-generated file should be imported instead. For
example, `package:analyzer/src/error/codes.g.dart` now has a
deprecation message saying that
`package:analyzer/src/error/codes.dart` should be used instead.

All existing imports of these libraries are switched to the
corresponding non-code-generated file, where possible. (The only
circumstance in which it's not possible is when the corresponding
non-code-generated file imports the code-generated file---e.g., when
`package:analyzer/src/error/codes.dart` imports
`package:analyzer/src/error/codes.g.dart`. In these cases, the
deprecation warning is suppressed with an "ignore" comment.)

This change is part of a long term effort to unify the analyzer and
CFE representations of error messages. It paves the way for a
follow-up CL in which I intend to move some of the generated code from
`package:analyzer` to `package:_fe_analyzer_shared`, to allow it to be
shared with the CFE.

Change-Id: Ie91dc8fc9357defa8974cbe6836d582979d87d81
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/437840
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2025-07-01 06:00:30 -07:00
Jens Johansen 90fb141aa2 [analyzer] Speedup assist calls when file has non-Windows line-endings
Before an assist call on a file with non-windows lineendings would first
search through the entire file for Windows line endings, then search for
the non-Windows line endings. As such Windows line endings was faster.

This CL changes the semantics slightly from "Windows line endings if
any Windows line endings exist" to "whatever line endings are first
used" which should be good.

It speeds up assist calls with non-Windows line endings:

Statistics on 5 runs each:

```
Windows / 2000: No change.
Windows / 4000: No change.
Windows / 8000: No change.

Unix / 2000: 1000 assist calls: -46.9900% +/- 6.1715% (-0.88 +/- 0.12) (1.86 -> 0.99)
Unix / 4000: 1000 assist calls: -59.1561% +/- 6.3982% (-1.79 +/- 0.19) (3.03 -> 1.24)
Unix / 8000: 1000 assist calls: -63.8429% +/- 4.3083% (-3.68 +/- 0.25)(5.76 -> 2.08)
```

Change-Id: I61278ed4ad31b891e87951da0a6162fe37376888
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/437224
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2025-06-26 23:26:20 -07:00
Sam Rawlins 1091aed650 DAS: only attempt to compute fixes for fix-supporting producers
The diff makes this change look bigger than it is.

Here's how the code worked before: `compute()` called `_addFromProducers()`. `_addFromProducers()` had a local function, also
called `compute()`, which is called per CorrectionProducer. The local
`compute()` function would unconditionally create a ChangeBuilder and
call each CorrectionProducer's `compute()` method, then call back out
to an instance method called `_addFixFromBuilder()`, which would drop
the computed change on the floor if `fixKind` was `null`.

This CL contains the following changes to the above system:

* The local `compute()` function and the instance method,
  `_addFixFromBuilder()` are combined together, into one instance
  method, `_addFromProducer()`.
* Then, the `fixKind` check is moved to the very top of that
  method, bailing out _before_ computing changes if `fixKind == null`.

Change-Id: I6c61059fc36ec1587b15ca01b43830a5b179da9a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/417326
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2025-06-26 10:51:44 -07:00
Sam Rawlins ee69f45a1f analyzer: rework AnalysisErrorListener deprecation
Work towards #60635

In this change, we rework the AnalysisErrorListener deprecation to
better support users who have their own class that implements
AnalysisErrorListener. This change introduces a sealed supertype,
DiagnosticOrErrorListener, with the old implementation,
AnalysisErrorListener, and the new implementation, DiagnosticListener,
as its sole direct subclasses. Users who have implemented
AnalysisErrorListener should be able to instead implement
DiagnosticListener, and their class is an acceptable instance of
DiagnosticOrErrorListener, wherever that is needed.

In a breaking change we can drop AnalysisErrorListener and deprecate
DiagnosticOrErrorListener, and in the next breaking change, we can drop
DiagnosticOrErrorListener.

For reference, see the first API difference when deprecating AnalysisErrorListener and introducing DiagnosticListener: https://github.com/dart-lang/sdk/commit/903d77cc8229972a424941dcb7b7b79741e833eb#diff-dec15868961d7eadcd009f49d129bebcdb747aaa8dbfde5f5a08884e0cf11e32

Change-Id: I3ccf11d54b41fbca98d020d89978d250c16b4c04
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/436480
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2025-06-25 06:54:20 -07:00
Fedor Shcheglov 318aeb322b Deprecate DartType.element3, use element instead.
Change-Id: Idef9da09c565a05fa84869f7433df3c24c6fbb5f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/435521
Reviewed-by: Paul Berry <paulberry@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2025-06-24 07:23:11 -07:00
FMorschel 2175df077f [DAS] Adds new create operator fix
Fixes: https://github.com/dart-lang/sdk/issues/60954
Change-Id: I933e45ddd950b798e87595f4de8a5cadabddf898
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/435660
Auto-Submit: Felipe Morschel <git@fmorschel.dev>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2025-06-18 15:24:03 -07:00
Danny Tuppeny 7466f6e1ff [analysis_server] Fix preservation of strings when indenting code
When code indentation is replaced, strings should not be updated. This loop had inverted logic which meant that after processing a string before the current line, we would then exit early and not look at the subsequent string ranges (which we might be a match for).

Fixes https://github.com/dart-lang/sdk/issues/60951

Change-Id: I1a94ca05e968bb7f2193544779b2634b784f8aee
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/435580
Commit-Queue: Keerti Parthasarathy <keertip@google.com>
Reviewed-by: Keerti Parthasarathy <keertip@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2025-06-18 12:21:32 -07:00
Sam Rawlins a2218abe7c analyzer: Document release policies
Change-Id: I98c1d9265f80fff8e3d23e895b0b6b2339bea11a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/435261
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2025-06-17 15:57:33 -07:00
Sam Rawlins 1029af6229 DAS plugins: Rename FixContext.error to .diagnostic
Work towards https://github.com/dart-lang/sdk/issues/60635

Change-Id: I2a789749393efa3688ad0cf6b0d0e93e97136492
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/434540
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2025-06-16 10:28:53 -07:00
Sam Rawlins ff19bdba8a Rename AnalysisOptionsimpl.unignorableNames to .unignorableDiagnosticCodeNames
'unignorableNames' is ambiguous.

Change-Id: Ieb42d7cb612c27eb285f1eabdaa7a7584b63e96b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/434521
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2025-06-12 20:20:10 -07:00
Sam Rawlins dadef9bfab DAS: Rename CorrectionProducer.errorLength and errorOffset to diagnostic names
Change-Id: I7578da7f1be1f996474b22621885e45ab3e86428
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/434100
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2025-06-11 11:06:31 -07:00
Sam Rawlins f51d37e9b1 analyzer: Rename ErrorReporter to DiagnosticReporter
Work towards https://github.com/dart-lang/sdk/issues/60635

Change-Id: I84b095199773040fc0444364964654c4373a9d77
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/433740
Reviewed-by: Paul Berry <paulberry@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2025-06-10 12:24:34 -07:00
Sam Rawlins 7b42aae99f analyzer: Deprecate AnalysisResultWithErrors.errors in favor of .diagnostics
Also rename UnitAnalysisResult.errors (package-private API) to .diagnostics

Work towards https://github.com/dart-lang/sdk/issues/60635

Change-Id: I0bdd7c9c19cff3bff9ee61fe4689564a7b5b727b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/433581
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2025-06-09 15:51:01 -07:00
Sam Rawlins c219974ecf analyzer: Deprecate Diagnostic.errorCode in favor of diagnosticCode
Work towards https://github.com/dart-lang/sdk/issues/60635

Change-Id: I2c7d64a81bc214e64fbc3ac95cf1fe2363a6ebd0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/433242
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2025-06-09 09:22:22 -07:00
Sam Rawlins bddcddfe6b analysis_server: use new Diagnostic name over AnalysisError
Work towards https://github.com/dart-lang/sdk/issues/60635

Change-Id: I5cc0cc66afd3531271eb8dc337556505cb21c074
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/425962
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2025-06-06 16:00:25 -07:00
Sam Rawlins 903d77cc82 analyzer: Rename ErrorListener classes to DiagnosticListener
Work towards https://github.com/dart-lang/sdk/issues/60635

I tried to keep this minimal but still sensible:

* Rename AnalysisErrorListener and all subtypes to use 'Diagnostic'.
* Rename all instantiations of such classes if they previously
  contained the word 'error'.
* Rename `RecordingDiagnosticListener.errors` to `.diagnostics`.
* Rename some _testing_ instance members that had the word 'error'
  to instead use 'diagnostic'.

Change-Id: I3948e27ba28ac2494092e04f4e1d201a20cc1135
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/433004
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2025-06-05 14:05:40 -07:00
Sam Rawlins cb61cfa8fe linter: Use RuleContext over the deprecated alias, LinterContext
Change-Id: I3df38b96a0cb7756a9dbfbffc80d50c4c73337ba
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/432723
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2025-06-03 14:11:02 -07:00
Sam Rawlins 31f8f4b522 analyzer: Make various AnalysisRule classes and their dependencies public
This is a big CL; no code is really "changed." We basically move 3
components into the public API, which can all be reviewed concisely
in the `api.txt` file.

* The AnalysisRule classes: `AbstractAnalysisRule` (which is good to
  make public as a lot of the public API is specified and documented
  here), `AnalysisRule`, `MultiAnalysisRule`.
* The Pubspec classes, available for linting pubspec files:
  `PubspecDependency`, `PubspecDependencyList`, `PubspecEntry`,
  `PubspecEnvironment`, `PubspecGitRepo`, `PubspecHost`, `PubspecNode`,
  `PubspecNodeList`, `PubspecVisitor`.
* The `RuleVisitorRegistry` class. This class is needed by analysis
  rule authors, and is part of the public API of AnalysisRule.

Change-Id: Ib1803180de9469f4ff39cf1778f96787f5f74b14
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/432363
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2025-06-03 11:09:32 -07:00
Sam Rawlins 28fc6346eb analyzer: Move RuleContext and RuleContextUnit to public API
Change-Id: I9cca5ee27e623bfa5b878bb0277f5e12e84a745b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/431982
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2025-05-30 15:42:10 -07:00
Sam Rawlins 41ac971d8a analyzer: rename Lint*Context classes
For the analyzer plugin APIs, these classes should not have the word
'Lint' in them, as they are used for all analysis rules, whether they
report lints or warnings.

* LinterContext                    -> RuleContext
* LinterContextWithParsedResults   -> RuleContextWithParsedResults
* LinterContextWithResolvedResults -> RuleContextWithResolvedResults
* LintRuleUnitContext              -> RuleUnitContext

I'm open to better names for these. Some of these suffer from a
chain-of-nouns name (a "RuleUnitContext" is a Context for a Unit for
a Rule). So we could go with "UnitContextForRule" and "ContextForRule"
or other ideas like that.

Only RuleContext and RuleUnitContext will be public API.

Change-Id: I5550736beaba7e39b36e7b5584ca6d023aa4d02b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/431703
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2025-05-29 11:49:29 -07:00
Brian Wilkerson b5e12ecaff Replace use of NodeLocator2 in CorrectionProducer
This is the last use of NodeLocator2 outside of the analyzer package
itself that I'm aware of (at least in our code base).

Change-Id: I57ba74571d60e820c60e2ca3d8d17e9374597073
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/431440
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2025-05-27 21:03:43 -07:00
Sam Rawlins ef300f558c analyzer: allow LintCode instances to set their own severity
Work towards https://github.com/dart-lang/sdk/issues/53402

Letting plugin authors set the default severity of a lint code is a
top request. Users can still customize severities with analysis
options.

Change-Id: Id0a360f4a96ca9627f00d63d3487bfde554b74e8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/430260
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2025-05-22 12:51:30 -07:00
Sam Rawlins 87f5185577 analyzer: Rename NodeLintRegistry to RuleVisitorRegistry, provide alias
Work towards https://github.com/dart-lang/sdk/issues/50986

Change-Id: Id0053b4721ca0517e315d5118ae48839dfaa3027
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/429465
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2025-05-22 10:03:19 -07:00
Sam Rawlins f16cd980ce DAS: Deprecate CorrectionProducer.inheritanceManager
Change-Id: Id1772d47617a98ffc15d700a9bd7de58a04d745e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/430020
Reviewed-by: Keerti Parthasarathy <keertip@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2025-05-21 14:42:21 -07:00
Sam Rawlins 1e92be4f2c DAS plugins: update docs for new diagnosticCode field and MultiAnalysisRule
Change-Id: If52b7557251fbe022ec873f003fafecf035a370a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/429700
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2025-05-20 13:10:11 -07:00
Sam Rawlins 78c2181b3c analysis_server_plugin: Check-in the current api.txt file
Change-Id: Ia88f755e6b92559ad15aa53ec612d92597fb0dc3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/428928
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2025-05-19 12:24:39 -07:00
Sam Rawlins b40b806bee DAS: enforce unnecessary_async lint rule
Change-Id: I05c6fbcc5ea7dea37bb7a01a3492e5cd842d11ca
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/428923
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2025-05-16 13:37:53 -07:00
Sam Rawlins 22453ba77f linter: deprecate AnalysisRule.lintCode
Work towards https://github.com/dart-lang/sdk/issues/50986

Change-Id: Iedf1127b9f04aec910647c7f35597f38c6bfe1d2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/428846
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2025-05-15 16:20:11 -07:00
Sam Rawlins a3b1b4f172 analyzer: Deprecate AbstractAnalysisRule.lintCodes
Work towards https://github.com/dart-lang/sdk/issues/50986

Change-Id: I4c86dbf806964c98f4a1c5854eb53c6c8cfe002b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/428624
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2025-05-15 11:04:43 -07:00
Brian Wilkerson 5f75bb8ba2 Replace change builder copying with a transactional model
Copying change builders in order to enable reverting changes from a
single correction producer when there's an exception is expensive.

This CL replaces that implementation with a transactional model.
Clients are not required to start a transaction (that happens
automatically), but are required to signal the end of a transaction by
invoking either `commit` or `revert`. (Actually, `commit` is assumed
if neither method is invoked before computing the `SourceChange`.)

There is some information in the Dart file edit builder related to
imports that isn't correctly handled. The reason for this is that too
much of the import computation is done up-front. I don't think this
will be a problem in practice (or at least not often), but we should
come back at some point to change the implementation so that we retain
abstract data longer and perform more processing at the very end (where
we'll have complete information and probably be able to do a better
job anyway).

This CL improved the performance of the benchmark that adds and applies
fixes for 10,000 lint violations.

  Before it took an average of 11216.0 ms.
  After it took an average of 4200.2 ms.

Which is about a 62% improvement.

Change-Id: I12710606455a04e34a82308ede5d9fba1c68b972
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/428060
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2025-05-15 10:12:20 -07:00
Sam Rawlins 0d1fe0fc3a analyzer: Remove unnecessary InheritanceManager3 from LinterContext
Work towards https://github.com/dart-lang/sdk/issues/50986

At the same time, migrate `redeclare_verifier` from InheritanceManager3,
so that the impl is the same as the `annotate_redeclares` lint rule.

Change-Id: I9c5c77dcf50aa54820473874327bc3a7b93fd987
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/428380
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2025-05-13 15:21:52 -07:00
Sam Rawlins c4c9854b9b analyzer_testing: Move ResourceProviderMixin to analyzer_testing
Work towards https://github.com/dart-lang/sdk/issues/55660

Change-Id: I31932409e495369793dd16c017385c98b86cf44c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/427480
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2025-05-09 16:56:29 -07:00
Sam Rawlins abd4e7754c Introduce two subclasses of 'LintRule' for handling multiple lint codes
Before this change, we had an enforcement that either 'get lintCode' or
'get lintCodes' is implemented, but it was a runtime enforcement. And it
was a little roundabout.

The new system is simpler and more typical:
* `AbstractLintRule` is the parent type, and it's sealed. It provides
  `get lintCodes` as an interface. Code outside of the lint rules
  requires this getter, in registering codes, etc.
* `LintRule` is the new subclass which is the "90% case." It declares
  a `get lintRule`, and offers simpler reporting methods for reporting
  a single code everywhere.
* `MultiLintRule` is the new subclass which represents that last
  "10% case." It only declares the reporting methods which all require
  a LintCode parameter, since there is no concept of a "default lint
  code among all my lint codes."

Work towards https://github.com/dart-lang/sdk/issues/50986

Change-Id: I63cbbfc1d936bb4428aa0b8f5fb0638c9b61b3dc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/426284
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2025-05-08 16:10:57 -07:00
Jens Johansen ad3e20a2be [analyzer] Skip repeated equal yaml edit calculations
For `lsp_many_prefer_single_quotes_violations_benchmark.dart --sizes=3200`:

Before:
Initial analysis: 0.115672
First code action call: 2.577159
Subsequent action call 1: 2.154116
Subsequent action call 2: 2.321183
Select all code action call: 6.890875

After:
Initial analysis: 0.114040
First code action call: 2.585689
Subsequent action call 1: 2.099005
Subsequent action call 2: 2.229051
Select all code action call: 4.695931

Change-Id: I3f20b9fe7c0a5cf6d9f4e5ca74193fc1f0668af2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/427221
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2025-05-07 22:21:20 -07:00
Brian Wilkerson 5d6dc673dc Make nodeCovering a method on CompilationUnitImpl rather than an extension method
This allows us to traverse the children without needing to create lists.
It also allows us to iterate over lists of nodes more efficiently.

Tested against the script that computes fixes for 10,000 diagnostics,
I'm seeing the following result.

  Before this CL the average time was 10692.4 ms.
  After this CL the average time was 1900.0 ms.

That's just over an 82% improvement.

Change-Id: Ideff745288c8990e9948b22c5204d176af3cac6e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/426904
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2025-05-07 09:05:52 -07:00
Jens Johansen a01d47d5e2 [analyzer] Cache/reuse CorrectionUtils
For `lsp_many_prefer_single_quotes_violations_benchmark.dart --sizes=3200`:

Before:
Initial analysis: 0.119093
First code action call: 2.632948
Subsequent action call 1: 2.176926
Subsequent action call 2: 2.316560
Select all code action call: 8.269120

Now:
Initial analysis: 0.105622
First code action call: 2.629498
Subsequent action call 1: 2.240760
Subsequent action call 2: 2.354467
Select all code action call: 6.873468

Change-Id: Ic967e54592d96057e20a8d70355e47d5232653a7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/426180
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2025-05-06 23:14:28 -07:00
Sam Rawlins c6658d01c7 analysis_server_plugin: Use Diagnostic instead of deprecated AnalysisError
Work towards https://github.com/dart-lang/sdk/issues/60635

Change-Id: Icf4186098ed04f15395aaf06c18772f8fd6ec4b7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/426560
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2025-05-05 13:55:28 -07:00