Commit Graph

76 Commits

Author SHA1 Message Date
Konstantin Shcheglov 5273f91b95 CQ. Scan from strings and drop scanner reader shim.
Remove the analyzer-only `scanner/reader.dart` re-export and refactor
`Scanner` to accept source text directly.

* Delete `pkg/analyzer/src/dart/scanner/reader.dart`, which only re-exported
  `_fe_analyzer_shared` reader types.
* Replace the `Scanner(CharacterReader, ...)` factory with
  `Scanner(String contents, ...)`, aligning the API with the underlying
  `scanString` implementation.
* Update analyzer, analysis_server, analyzer_cli, analyzer_plugin, and scrape
  call sites to pass the source string directly instead of constructing
  `CharSequenceReader`.

This removes an unnecessary abstraction layer, reduces
imports/indirection, and makes scanner usage simpler and more uniform
across the repo.

Change-Id: I380b365676c8a62971a3700deadb695d1519d653
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/477600
Reviewed-by: Paul Berry <paulberry@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2026-02-02 11:20:31 -08:00
Paul Berry cf1d8b96db [messages] Make Scanner and Parser take a DiagnosticReporter.
Changes the signature of the following constructors:
- Scanner
- Scanner.fasta
- Parser

So that they accept a `DiagnosticReporter` object rather than a
`DiagnosticListener` object. This brings the scanner and the parser
into alignment with the majority of the rest of the analyzer (which
reports errors using `DiagnosticReporter` rather than by talking to
`DiagnosticListener` directly).

It also makes the `source` parameter of these constructors
unnecessary, because the `source` can be obtained from the
`DiagnosticReporter`.

Change-Id: I6a6a6964607ffb52a8332a6e618dc0c9a1e48c5c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/473442
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Bob Nystrom <rnystrom@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2026-01-16 13:34:50 -08:00
FMorschel 0e35d4ecf7 [DAS] Fixes create member inference for switch expressions
Fixes: https://github.com/dart-lang/sdk/issues/62108
Change-Id: Iefed0af48180deb75f185417ea88361290a85ebe
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/466122
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Auto-Submit: Felipe Morschel <git@fmorschel.dev>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2025-12-10 11:06:58 -08:00
FMorschel 2cbcc7f37c [DAS] Fixes Create (extension) method for unresolved closure return type
Fixes: https://github.com/dart-lang/sdk/issues/61898
Change-Id: I0b1e7ad208a54a04f0ff4147f27403845f9a379d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/459521
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Auto-Submit: Felipe Morschel <git@fmorschel.dev>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2025-12-10 10:40:00 -08:00
FMorschel 9f4c7e5d8b [DAS] Fixes Create setters, getters and fields for using type parameters
Bug: https://github.com/dart-lang/sdk/issues/61186
Change-Id: Ib70937ce8232ec087cf95d12d52a1bfdf59ad3ba
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/442240
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-12-05 10:32:55 -08:00
FMorschel eb1a814681 [DAS] Fixes create fixes type resolving in for-in loops.
This makes the create fixes correctly suggest `Iterable`, `Future<Iterable>`, or `Future<Stream>` when the awaited expression is used in a for-in loop. It also takes into account the type of the loop variable for the type argument of `Iterable` or `Stream`.

Fixes: https://github.com/dart-lang/sdk/issues/62092
Change-Id: I055af13ee12ceb141f5d75c340c607ae803d0b07
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/464782
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Auto-Submit: Felipe Morschel <git@fmorschel.dev>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2025-11-30 15:19:55 -08:00
Jens Johansen 6b4210d9ca [analysis server/analyzer] Improvements to completion
Observation 1: The legacy protocol answered completion requests via a
`server.resolveForCompletion` call, and the LSP protocol answered
completion requests via a `server.getResolvedUnit` call where the idea
is that resolving for completion requires less and is therefore faster.

Solution: Make the LSP protocol use `server.resolveForCompletion` too.

Observation 2: Completion requests often come right after change request
making timing important and the `await driver.applyPendingFileChanges()`
call done in the analysis server "pushed" the timing making the
`server.resolveForCompletion` actually finished after it had already
resolved the whole thing.

Solution: Don't do that - the driver adds it to the queue of work, the
work is done later in `performWork` called from
`AnalysisDriverScheduler._run` where `_applyPendingFileChanges` is
always called anyway (which is the call that completes the
`applyPendingFileChanges`call).

Observation 3: If there is no change yet to be processed, a
`resolveForCompletion` call is slower than a `getResolvedUnit` because
the resolved unit is cached (assuming it's a priority file) and the
`resolveForCompletion` call always parses the file again.

Solution: Respond to the `resolveForCompletion` call with the resolved
unit data if it's available in the cache. The cache is always cleared
when changes happen anyway.

Benchmarks on this stuff is a bit weird because it's timing related - so
while I'd say this is overall just better there are also runs where we
get "bad timing" and the runtimes are therefore not better. In an
attempt to clear it up I've run the benchmarks 25 times each, and
attempted to put the data in two different buckets as needed.

*lsp_type_in_big_file of size 16,000*

```
Fully done after last type (ms):
Difference at 95.0% confidence
        -1419.2 +/- 322.074
        -16.8866% +/- 3.83225%
        (Student's t, pooled s = 566.238)

Whole typing time (ms):
Difference at 95.0% confidence
        -1418.88 +/- 322.037
        -13.9661% +/- 3.16983%
        (Student's t, pooled s = 566.172)

Uncancelled completion response time (ms):
Difference at 95.0% confidence
        -1590.48 +/- 682.753
        -28.0194% +/- 12.028%
        (Student's t, pooled s = 1200.35)
```

The `Uncancelled completion response time` has a big "+/-" so attempting
to "good and bad bucketize" it I get:

good bucket:

```
Difference at 95.0% confidence
        -1929.8 +/- 347.712
        -35.9528% +/- 6.47797%
        (Student's t, pooled s = 543.261)
```

bad bucket (though truthfully there wasn't a clear cutoff before):

```
No difference proven at 95.0% confidence
```

which sort of makes sense: If the completion runs before a (new) change
starts processing we now `resolveForCompletion` instead which is faster,
but if completion runs after the change has started processing we
essentially - both before and after - do nothing (except wait for the
calculation to finish) because we just load the data from cache.

*lsp_type_in_big_file_ask_for_completion, 16,000*

```
Completion #1 (ms):
No difference proven at 95.0% confidence
```

Ehh. There's a clear cutoff in the now, so taking the 8 (how the cutoff
happens to be) fastest from each I get

```
Difference at 95.0% confidence
        -1034.12 +/- 75.3617
        -37.673% +/- 2.74542%
        (Student's t, pooled s = 70.2673)
```

Moving on.

```
Completion #2 (ms):
Difference at 95.0% confidence
        -1076.28 +/- 178.446
        -37.2601% +/- 6.17769%
        (Student's t, pooled s = 313.726)
```

here 2 in the "now" has bad timing, removing them from the statistics
gives

```
Difference at 95.0% confidence
        -1182.39 +/- 104.543
        -40.9334% +/- 3.6192%
        (Student's t, pooled s = 179.748)
```

Moving on.

```
Completion #3 (ms):
Difference at 95.0% confidence
        -735.6 +/- 292.553
        -25.6471% +/- 10.2%
        (Student's t, pooled s = 514.336)

and removing the 8 bad ones:

Difference at 95.0% confidence
        -1195.69 +/- 99.305
        -41.6884% +/- 3.46232%
        (Student's t, pooled s = 156.306)
```

Continuing like this:

```
Completion #4 (ms):
Difference at 95.0% confidence
        -948.4 +/- 265.704
        -32.9887% +/- 9.24214%
        (Student's t, pooled s = 467.134)

and removing the 5 bad ones:

Difference at 95.0% confidence
        -1252.87 +/- 86.5425
        -43.5793% +/- 3.01026%
        (Student's t, pooled s = 143.022)

Completion #5 (ms):

Difference at 95.0% confidence
        -1067.88 +/- 199.266
        -37.0011% +/- 6.90439%
        (Student's t, pooled s = 350.329)

and removing the 3 bad ones:

Difference at 95.0% confidence
        -1236.76 +/- 69.5776
        -42.8527% +/- 2.4108%
        (Student's t, pooled s = 118.18)
```

Moving on to the "Completion without change" I realize just now that the
benchmark for the first entry is broken - it doesn't wait until the
previous change has been processed, meaning that in the 3 cases where we
got bad timing in "Completion #5 (ms)" we see about the same result as
before, but in the 22 other cases we see bad results because it has to
wait until the previous change has been processed. For the remaining
(2-5) there is no virtually change which makes sense because both before
and now it just fetches the resolved unit from cache.

*legacy_type_in_big_file_ask_for_completion*

```
Completion #1 (ms):
Difference at 95.0% confidence
        -1817.08 +/- 60.6836
        -48.0638% +/- 1.60515%
        (Student's t, pooled s = 106.688)

Completion #2 (ms):
Difference at 95.0% confidence
        -2208.56 +/- 48.4844
        -55.4647% +/- 1.21761%
        (Student's t, pooled s = 85.2403)

Completion #3 (ms):
Difference at 95.0% confidence
        -2159.68 +/- 69.4145
        -53.0717% +/- 1.70578%
        (Student's t, pooled s = 122.037)

Completion #4 (ms):
Difference at 95.0% confidence
        -2264.44 +/- 73.2112
        -53.5455% +/- 1.73117%
        (Student's t, pooled s = 128.712)

Completion #5 (ms):
Difference at 95.0% confidence
        -2147.4 +/- 68.5023
        -50.9254% +/- 1.62453%
        (Student's t, pooled s = 120.434)
```

The first "Completion without change" suffers from the same as before
and I will skip it here.

```
Completion without change #2 (ms):
Difference at 95.0% confidence
        -416.28 +/- 28.2024
        -61.3512% +/- 4.15646%
        (Student's t, pooled s = 49.5826)

Completion without change #3 (ms):
Difference at 95.0% confidence
        -687.24 +/- 21.9848
        -92.6499% +/- 2.96387%
        (Student's t, pooled s = 38.6514)

Completion without change #4 (ms):
Difference at 95.0% confidence
        -637.32 +/- 26.482
        -95.2703% +/- 3.95868%
        (Student's t, pooled s = 46.5579)

Completion without change #5 (ms):
Difference at 95.0% confidence
        -702.32 +/- 18.7277
        -95.8301% +/- 2.55535%
        (Student's t, pooled s = 32.925)
```

I don't know why there doesn't appear to be any timing related issues
here (maybe sending and receiving the entire big file (in legacy vs in
lsp where a small 'diff' is send) taking more time pushes the timing,
but I'm guessing) - nor do I know why now "Completion without change #2"
is slower (~250 ms) than the subsequent ones (~30 ms).

Change-Id: I4c21d658efccbcf197eedb69f466b2942b78c4b9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/457364
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2025-10-28 05:28:09 -07:00
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 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
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
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
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
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 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 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 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
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 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
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
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 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
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
Sam Rawlins ffd08a344b DAS: Do not repeatedly compute a null value for coveringNode
The field may be set to `null`, so it's nullity is not a signal of whether it needs to be computed.

Change-Id: If19eb1f77ad601e744e41bde45a30d393ab8726f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/417327
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2025-03-25 13:57:39 -07:00
Konstantin Shcheglov b3ca203e8f Elements. Start deprecating V1 elements.
This updates `analyzer_use_new_elements` lint to stop reporting inside
deprecated declarations. So, we can deprecated and prepare for removal.

Apply deprecation dart/analysis/results.dart

Deprecate `ElementDeclarationResult`, add `FragmentDeclarationResult` instead.

Change `getFragmentDeclaration` (not yet published) return type to `FragmentDeclarationResult` to better correspond to the method name.

Rename `getElementDeclaration` from `AnalysisSessionHelper` to
`getFragmentDeclaration`, to better reflect on what it operates.

Change-Id: I2839c9a7e21ed2e5b34035fc8c3ec88fd23df1b5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/412840
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2025-02-28 08:19:21 -08:00
Brian Wilkerson a59bae3f37 Cleanup code in analysis_server_plugin
Change-Id: I596a5a516136b4bd024b8f72b11df6eb641075ee
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/412680
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2025-02-27 11:44:14 -08:00
Konstantin Shcheglov 2ad1b56534 Elements. Use TypeImpl in more places.
Change-Id: I68fd3ca29f4059d9772233978da9391245097207
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/412000
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2025-02-25 09:56:20 -08:00
Jake Macdonald f4cfbf9cdc Update create function fix to create an async function for await expressions
Bug: https://github.com/dart-lang/sdk/issues/59990
Change-Id: I9e89089ca5c60bea190060bc0c8e869c7e78e32e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/408361
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Auto-Submit: Jake Macdonald <jakemac@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2025-02-06 14:25:39 -08:00
Sam Rawlins f5d01eb734 DAS plugins: Remove direct dependency on _fe_analyzer_shared
Change-Id: If498173f3d37ab6798a1e05070274c197948ab0e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/406687
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2025-01-31 09:27:59 -08:00