Commit Graph

138 Commits

Author SHA1 Message Date
FMorschel b5113c2c23 [DAS] Review create fixes for if-null expressions
Fixes: https://github.com/dart-lang/sdk/issues/61575
Change-Id: If5232574ebe9cb352628eac0f6c07c39c964a110
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/452240
Auto-Submit: Felipe Morschel <git@fmorschel.dev>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2025-10-17 09:15:48 -07:00
FMorschel fbd3cfe08d [DAS] Fixes "Add ignore comment" handling if existing has with unknown code at the end
Fixes: https://github.com/dart-lang/sdk/issues/61143
Change-Id: I8b4c08f1d00b46ee4975de192150fdafd552da9f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/454480
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Auto-Submit: Felipe Morschel <git@fmorschel.dev>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2025-10-17 09:04:01 -07:00
Konstantin Shcheglov 2afa2e89ac Deprecate PartDirective.configurations
Change-Id: I6e9757e531e2f9f46da5bb78ffef7cf694cf7467
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/454321
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2025-10-13 11:17:56 -07:00
FMorschel bf2fc7d8e5 [DAS] Fixes part file handling for some create fixes
Bug: https://github.com/dart-lang/sdk/issues/61192
Change-Id: I8aa765fca2d2948ab6fe1b47a6bff6bf58de3cd3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/447341
Auto-Submit: Felipe Morschel <git@fmorschel.dev>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2025-10-08 11:40:11 -07:00
FMorschel cc876c2345 [DAS] Fixes infering bool for guard in create fixes
Fixes: https://github.com/dart-lang/sdk/issues/61589
Change-Id: Iaf43927c9d3fcf43b2dfa23c91e17333baeed184
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/452181
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Auto-Submit: Felipe Morschel <git@fmorschel.dev>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2025-10-06 14:46:01 -07:00
Konstantin Shcheglov 1dc08ea5eb Make AnalysisDriver.discoverAvailableFiles() synchronous.
Change-Id: Ida5ed3a8e464070075de48c22b156babe975c122
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/452900
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2025-10-01 12:55:38 -07:00
Sam Rawlins efa1c497d6 DAS plugins: Fix "interesting files" glob
In testing, I saw that _added_ files were not being analyzed at all by
plugins. It turned out that `PluginManager.broadcastWatchEvent` uses
that glob to decide if watch events should be broadcast to a given
plugin isolate. It uses this Glob to determine that answer:

```dart
Glob(
  _resourceProvider.pathContext.separator,
  pattern,
).matches(filePath)
```

and using `'*.dart'` for that pattern, always answers "no, this file
does not match '*.dart'"; I believe `**.dart` is the correct glob
pattern we should use.

Change-Id: Id99d758151629c485884ba20e4d1f49f574f5889
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/452160
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2025-09-29 12:48:31 -07:00
Sam Rawlins 74ef6d1740 DAS plugins: Do not run lint rules or warnings unnecessarily
Work towards https://github.com/dart-lang/sdk/issues/61490

When a plugin re-resolves a library [1] via
`AnalysisSessionImpl.getResolvedLibrary`, which calls
`AnalysisDriver.getResolvedLibrary`, eventually we get down to
`LibraryAnalyzer.analyze`. This method contains the singular piece of
code that checks `AnalysisOptions.lint` and `AnalysisOptions.warning` [2].

A plugin re-resolves a library in order to parse the code, and ultimately resolve the library into a LibraryElement. It does _not_ use
any lint computed by `LibraryAnalyzer.analyze()`, nor any warnings, nor even any compile-time errors. So we should do our best to do the minimal amount of work that still gets us our LibraryElement.

Setting `AnalysisOptions.lint` and `AnalysisOptions.warning` reduces the
amount of work that `LibraryAnalyzer.analyze()` does.

[1]: https://github.com/dart-lang/sdk/blob/c11f9118692461f61570e1ee07b6f5fc43288bb0/pkg/analysis_server_plugin/lib/src/plugin_server.dart#L351
[2]: https://github.com/dart-lang/sdk/blob/c11f9118692461f61570e1ee07b6f5fc43288bb0/pkg/analyzer/lib/src/dart/analysis/library_analyzer.dart#L342-L359

Change-Id: I73413a6646b14ff3a01246470b00e0a3676c4b3a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/450365
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2025-09-22 14:36:22 -07:00
Sam Rawlins b8cf6ba3a1 DAS plugins: Wire up priority files
This is super awkward. I had "added support" in https://github.com/dart-lang/sdk/commit/f27e78af6b20 but it was really just internal wiring. I honestly do not remember what I was thinking or why I landed that CL incomplete.

Change-Id: Iad6800e11df189879acad4d189d6f8c68ee673f4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/449602
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2025-09-17 09:27:00 -07:00
Sam Rawlins 03d0629a69 DAS plugins: provide a WorkspacePackage to RuleContext
Fixes https://github.com/dart-lang/sdk/issues/61489

Change-Id: I50dc5a0649ef9f77e37efb27430cbb3736814313
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/449360
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2025-09-15 16:07:55 -07:00
Sam Rawlins a9feb25e30 DAS plugins: Make the fix offset a range over the diagnostic
Fixes https://github.com/dart-lang/sdk/issues/61491

Change-Id: I2616006b7ac1ba645e4bed3caeb0781f04864feb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/449362
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2025-09-15 13:26:39 -07:00
Sam Rawlins cbb3237f04 DAS plugins: fix bad parsing of unsupported requests
I noticed only recently that every time I create a new source file in
a package which is being analyzed with analyzer plugins, I get an
"exception," a toast popup in the IDE. It turns out I goofed in
https://github.com/dart-lang/sdk/commit/da1d59c4e6cdb65b48db8ff182cf77f377ca8d1b
and totally busted the switch statement. The request types above
ANALYSIS_REQUEST_HANDLE_WATCH_EVENTS still flow into it's body. Ouch.

Change-Id: I3ba9fecfb9c3a1e8585e472b09fa0b2f78ba18df
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/449145
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2025-09-11 17:21:45 -07:00
Konstantin Shcheglov 6752d3f109 Elements. Replace LibraryElementImpl.definingCompilationUnit with firstFragment.
Change-Id: Ia6775b8fcea166e772036aafa96d96da0f8ab70b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/449067
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2025-09-11 11:27:22 -07:00
Sam Rawlins 401c8bf75a DAS plugins: Fix the path at which part diagnostics are reported
I had not run the first fix through manual testing. Manual testing
revealed a second location (!!) where the file path is stored, for
diagnostics. This updates the code to send a notification for each file
path, including parts.

Change-Id: Iee60330c579563f31c8d9a2c65a22c9cde4b64d8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/448881
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2025-09-08 17:50:21 -07:00
Sam Rawlins c667238efd DAS plugins: analyze and report diagnostics in parts
Fixes https://github.com/dart-lang/sdk/issues/61449

The previous code, sure enough, only created a DiagnosticReporter for
the defining unit, and only visited the main unit.

The fix is to create a DiagnosticListener for each unit, set the
DiagnosticReporters correctly and the "current unit" as we go, and then
pull the reported diagnostics from each listener.

Change-Id: I6b645284c58e5e35ccc5b89f30f6ffe97f48296c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/448644
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2025-09-07 18:47:44 -07:00
Sam Rawlins 26102c5d52 DAS plugins: Wire up initial screen for new plugins.
This renames the old screen, "Legacy plugins" and adds a new screen,
"Plugins". On the new plugins screen, we ask the plugins isolate(s) for
their plugins details, and print the following, for eadh plugin:

* the plugin's name
* the names of the registered lint rules
* the names of the registered warning rules
* the IDs and "messages" of the registered assists
* the IDs and "messages" and associated diagnostic codes of the
  registered quick fixes

More to come in follow ups:

* The resolved versions of plugin packages (coming from package_config.json)

Change-Id: Ic3dc4c5bffa64fd4da4097c042a847cc064e41ce
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/447763
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2025-09-02 08:38:32 -07:00
Sam Rawlins 53d805ff63 analyzer: Move the PluginSource classes to be private; add to signature
This week we moved some other "plugin analysis options" code into the
private API. This continues that work, in order to add plugin source
options into the AnalysisOptionsImpl signature code.

The classes are deprecated as far as the public API is concerned,
encoded with a `@Deprecated` export. This is not reflected in api.txt.

Change-Id: Ie95851a7b0d54ef6abb8fb1e2b41294fbc5db836
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/447841
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2025-08-29 15:44:39 -07:00
FMorschel 7c754d325d [DAS] Adds typeParametersInScope for DartEditBuilder.writeType and related methods
This change adds a new parameter `typeParametersInScope` to `DartEditBuilder.writeType`, and related methods to deprecate the previous `methodBeingCopied` parameter, which limited our ability to pass in some type parameters that are in scope.

Also fixes a TODO about testing if the `Record` feature is enabled or not.

And as a bonus, we now always write down type parameters by looking for the closest public type or falling back to `Object?` or `dynamic`.

Bug: https://github.com/dart-lang/sdk/issues/61186

Change-Id: I7a7b1c62adb81aecfdf61ebbaa0d95f1d33bced8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/442282
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Auto-Submit: Felipe Morschel <git@fmorschel.dev>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2025-08-29 10:32:10 -07:00
Sam Rawlins cbfc0784de DAS plugins: Bump language version to 3.9
Change-Id: I880e53634c570cc25f4ff22dd01397b088b9bd07
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/447441
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2025-08-28 09:35:20 -07:00
Sam Rawlins da1d59c4e6 DAS plugins: handle added, modified, removed files
Change-Id: Idc8cd1378e5a7e8c8191dfad9a37edd990e88120
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/446920
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2025-08-26 11:41:18 -07:00
Sam Rawlins 438b560e44 analyzer: Dismantle legacy 'linter.dart' library
This library mostly exports _public_ API, and the to-be-deprecated
NodeLintRegistry class. So we just move private RuleContext classes
into a new library, and remove the exports.

The lint rules then are adjusted, mostly just renaming
NodeLintRegistry -> RuleVisitorRegistry. But also, this removes a lot
of implementation imports; most rules now have _no_ private imports!

Change-Id: I023f7efa979f94d208a6ae7421902145e8761c9a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/443364
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2025-08-11 13:59:53 -07:00
FMorschel 990d99161a [DAS] Removes "Add null check" fix false-positive and fixes num special-casing operators
Fixes: https://github.com/dart-lang/sdk/issues/61056
Change-Id: I28dab2908a9a2f384190a4705dd7383aec86860c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/442703
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-08-06 13:42:02 -07:00
Danny Tuppeny 784fdb4a1f [analysis_server] Move EOL from ChangeBuilder to FileEditBuilder
Because ChangeBuilder can be used to modify multiple files, the EOL should come from an individual files edit builder and not from the overall ChangeBuilder.

This change renames `eol` on ChangeBuilder to `defaultEol` (since it's still useful to supply a custom default, for example when moving a class from an existing file to a new file, we want to default to the same EOL as the source file), and adds an EOL to file edit builders which is computed from the file content (and falls back to the default from ChangeBuilder if there are none).

My intention here is to not introduce any breaking changes (yet) so the ChangeBuilder constructor interface still has the "eol" named parameter (marked as deprecated) as well as the new `defaultEol` parameter.

I added a new `StringExtension` for `endOfLine` to both analyzer_plugin and analysis_server_plugin as we need this in both places (but I expect one of those projects will ultimately be dropped). This slightly differs from `CorrectionUtils.endOfLine` because it can return `null` which is a signal to fall back to the ChangeBuilder default instead of forcing its own default. (CorrectionUtils.endOfLine now uses that extension, although because of the null/default, it's likely that some - if not all - uses of this should migrate to the new extension and fall back to a default from a ChangeBuilder).

Change-Id: Ie2e6eaba78c96a1cbd79eba881e12bbeef724aa8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/443122
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2025-08-04 14:56:40 -07:00
Sam Rawlins c1c62259e7 DAS plugins: Support configurable severity
This introduces a concept of a "configured severity," based on the
design at https://github.com/dart-lang/sdk/issues/57034, such that
an analysis rule can be configured in analysis options to be one of:
"disable," "enable," "info," "warning," or "error."

We actually don't have any validation of what is inside a plugin
section in analysis options; that should come next.

Closes https://github.com/dart-lang/sdk/issues/59644

Change-Id: I56f1f51ef01adee7e6c042d8df9a974e7e5a11a8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/443003
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2025-07-31 15:07:24 -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
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
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
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
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 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 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