Commit Graph

114 Commits

Author SHA1 Message Date
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
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 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 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
Jens Johansen cddee72854 [analyzer] Don't find the same "fixes for all" multiple times
Before this CL, if one has a file like

```
Map<String, String> foo = {
  "1": "1",
  "2": "2",
  "3": "3",
[...]
```

with many violations of the prefer_single_quotes lint, using VSCode and
selecting all would lock up the analysis server, e.g. in
https://dart-review.googlesource.com/c/sdk/+/425503 I showed 400 such
lines taking ~36 seconds on my machine (and 800 such lines taking ~247
seconds).

This is because for each error (lint) in range (i.e. all of them) it
calculates fixes for all of them. Once it's done with that it
deduplicates and throws most of the data away again.

This CL instead only calculates the "fixes for all" for each
combination of error-type and generator, skipping lots of work,
making the whole thing be much faster.

In the data send to the client (VSCode in this instance) the
"diagnostics" for
"Convert to single quoted strings everywhere in file"
contains fewer elements (only 1, vs all before), but it's unclear when
(or if) this is used. Note that the "edit"s does contain all, and
applying it still changes all instances.

I now get these runtimes for the select all case (via the benchmark)
(with cpu governor "performance" which likely wasn't the case for
the ~36 seconds and ~247 seconds above, although it doesn't matter
much with these differences):

400: 0.736783
800: 1.502978
1600: 3.704314
3200: 10.701988

Change-Id: I2b69a77525c0e1ed720c2b3d1de70ccc1fc5e94c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/425861
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2025-05-05 01:50:25 -07:00
Sam Rawlins 992cfb13bc analyzer: Deprecate AnalysisError.correction; simplify other final fields
Work towards https://github.com/dart-lang/sdk/issues/60635

* `AnalysisError._contextMessages` unnecessarily backed the public
  `contextMessages` getter; the field is final so it can be public
  itself.
* `AnalysisError._correctionMessage` unnecessarily backed the public
  `correctionMessage` getter; the field is final so it can be public
  itself.

Change-Id: If269d4ed590ef7df81d9b9e3be03766601526d7f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/425620
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2025-04-30 16:06:19 -07:00
Sam Rawlins 508ad1359b analysis_server_plugin: Use new DiagnosticCode name
Work towards https://github.com/dart-lang/sdk/issues/60635

Change-Id: Ia021bc5a80f1e53407393454ab058f6b7c8a633a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/425460
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2025-04-30 09:35:02 -07:00
FMorschel dbd0be6b7e [DAS] Fixes Create getter and Create mixin quick-fixes trigger
Fixes: https://github.com/dart-lang/sdk/issues/60613
Change-Id: Ie8661ae57f4fb3d8e9702fb67fc900530ba10632
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/424560
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Auto-Submit: Felipe Morschel <git@fmorschel.dev>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2025-04-29 11:31:19 -07:00
Konstantin Shcheglov b2fdd8a345 Elements. Rename XyzElement2 into XyzElement.
The CL was done with rename + adding typedef for each class.

Change-Id: Ia25cc581d2e42cf7d12a85a3579af952d5c232ee
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/424687
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2025-04-25 13:27:18 -07:00
Konstantin Shcheglov 49599e06cc Elements. Deprecated element2.dart library.
Change-Id: I2be38df49e6f242d9fe59f34164549da4a0f41b5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/424683
Reviewed-by: Paul Berry <paulberry@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2025-04-25 11:23:18 -07:00
FMorschel ae6bdae111 [DAS] Fixes create method for enums and extension types
Fixes: https://github.com/dart-lang/sdk/issues/60562
Change-Id: I8bbc92205f5900c025e9dc31110f3e1cb2343643
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/423240
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Auto-Submit: Felipe Morschel <git@fmorschel.dev>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2025-04-18 16:52:11 -07:00
Sam Rawlins 91e682940c analyzer: Move coveringNode to public API
NodeLocator and NodeLocator2 are being deprecated in favor of this
extension method. We move it to the public API here and start using it
in the analysis_server_plugin package.

Change-Id: I4783bb1f511b798e52b3383dd600b154dccc6d5b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/420420
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2025-04-17 09:41:40 -07:00
Jens Johansen a9d2363f08 [analyzer] Don't collect analytics if not using it; cache getTopLevelDeclarations results in DartFixContext
Sometimes - on responding to `edit.getFixes` requests, the method
`getTopLevelDeclarations` is called several times with the same
parameter and caching has then sometimes sped things up.

I then also noticed that it caused `reportAnalysisAnalytics` to be
called many times (e.g. 73 times for one `edit.getFixes` request)
each time spending time collecting data which - on passing to
`analyticsManager.analysisComplete` - was just thrown away because it
only saves the first one.

Combined these changes have been observed to reduce the response time
on `edit.getFixes` by up (down?) to ~20% (e.g. from 5 seconds
to 1 second).

In response to http://b/407797012 where more data is also available.

Unfortunately I haven't been able to reproduce this is a benchmark
(yet anyway). I don't know if it needs slower slower reads, an extreme
amount of files, several contexts or something else entirely.

Change-Id: Id214b0e1b7d8bbef7f6d956408f17fab45618b78
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/420323
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2025-04-07 05:36:53 -07:00
Sam Rawlins 6838dabc15 DAS: make add_null_check fixKind final
A few statements around the package read:

> Producers used in bulk fixes must not modify the FixKind during
> computation.

In fact, this `add_null_check` correction producer seems to be the
_only_ remaining producer that violates this statement. In order to
fix it, such that `fixKind` is set during constructor initialization,
we must do some poking around the AST.

So we convert `_computeTarget` to be static (and change it to also
compute and return any possible null-aware token, renaming it to
`_computeTargetAndNullAwareToken`). We also convert `_isNullAware` to
be static. Then the two public constructors are converted into
factory constructors that determine the fix kind, and store the
`_target` and `_nullAwareToken` in fields, so as to avoid re-computing
them during `compute()`.

Change-Id: Ic66319ef764dd9bd69f0e1059347acf174debb25
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/419420
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2025-04-03 23:51:44 -07:00
Sam Rawlins 6253555a2c DAS: Only yield libraries that provide an extension member with a given name
The `DartFixContext.librariesWithExtensions` utility function accepts
a `memberName` parameter but never did anything with it. This change
adds filtering in that function based on the member name.

This code depends on the set of exported extensions, which is provided
in an extension (`LibraryElementExtensions.exportedExtensions`) in the
analysis_server package, which must be moved to the analyzer package.

Change-Id: I06c8a9a0e11ceb70e75517b30c0b048321d6b024
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/418641
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2025-04-02 08:06:25 -07:00
Sam Rawlins 4a96dd122c DAS plugins: Respond to real assist requests
Change-Id: I1f1afca0dc746948410a56e29cf13bebef234ed7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/419760
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2025-04-01 16:43:54 -07:00
Sam Rawlins b0c3f4ef1f DAS plugins: Move two files to be in the public API
Change-Id: I7230dead69b8c82ea758e48a0a3fbc56902cb05d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/417945
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2025-03-28 13:09:21 -07:00
Sam Rawlins 7f5485d23a DAS plugins: report early when a fix or assist does not have a fixKind or assistKind
Change-Id: I83a147adc4740d1a8891faa06d35c4901cf568b2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/417943
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2025-03-28 12:12:49 -07:00
FMorschel 90c0aa6aaa [DAS] Fixes create method/function return type
Fixes: https://github.com/dart-lang/sdk/issues/60306
Change-Id: Iba6222bbb5d0b63ca94920cad6d6abfd571ed830
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/417780
Auto-Submit: Felipe Morschel <git@fmorschel.dev>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2025-03-25 15:30:23 -07:00