Commit Graph

2256 Commits

Author SHA1 Message Date
Brian Wilkerson 916afe3219 Suggest fields from declaring parameters in completions
This was preventing suggesting fields from declaring parameters
everywhere.

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

Change-Id: I552f85275c6a1aebaa4a50af88d661bc7e3d6492
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/511040
Reviewed-by: Keerti Parthasarathy <keertip@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2026-06-11 11:09:54 -07:00
Danny Tuppeny ff0cd5e0d6 [analysis_server] Don't warn on renames of private named parameters
Fixes https://github.com/dart-lang/sdk/issues/63433

Change-Id: I6e39d3b8c9379df07a677cabfcd9028a7bca79db
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/510840
Reviewed-by: Bob Nystrom <rnystrom@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2026-06-10 11:57:21 -07:00
Varad Raj Agrawal 6a678d1f49 Quick fixes that create constructors use new-style syntax when primary_constructors is enabled
Closes https://github.com/dart-lang/sdk/pull/63534

GitOrigin-RevId: 345471bc33c002bbca9cea9c6626a05f481f70e3
Change-Id: If8d533ab0bbb4e6dff51a4256101fb8cb0490fb4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/509680
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2026-06-09 10:57:01 -07:00
Brian Wilkerson e13ffe9aff Fix a bug in the member sorter
Because of the reversed condition, the priority for primary constructor
bodies wasn't being added when the lint was disabled, causing it to not
be moved, resulting in seemingly inconsistent results.

Change-Id: I5110e39e066414e04bb69f61b3aa7189875469f9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/507460
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2026-05-29 12:57:43 -07:00
Paul Berry afcfbbeba8 Migrate developer experience packages to new constructor decl syntax.
(Part of https://github.com/dart-lang/sdk/issues/63288)

This change migrates the packages owned by the developer experience
team to use the new constructor declaration syntax, described in
https://github.com/dart-lang/language/blob/main/accepted/future-releases/primary-constructors/feature-specification.md#abbreviations-of-in-body-constructor-declarations.

This change was performed in an automated fashion, by (a) bumping the
packages' SDK constraints to `3.13.0-0`, (b) enabling the lints
`unnecessary_type_name_in_constructor` and
`unnecessary_const_in_enum_constructor`, (c) fixing the resulting lint
failures using `dart fix`, and then (d) reformatting the affected
files.

To ease code review, I've reverted unrelated formatting changes.

Since this change requires bumping SDK constaints to `3.13.0-0`, it
was only performed on packages that are *not* published on
pub. (Packages that *are* published on pub should remain on lower
language versions until at least after the stable version of 3.13 is
released, so that we don't block users on the stable channel from
receiving updates to those packages.)

Change-Id: Ibb4daebafd239da58251e838ea6a3f336a6a6964
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/505046
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
SLSA-Policy-Verified: SLSA Policy Verification Service <devtools-gerritcodereview-exitgate@google.com>
2026-05-27 14:52:58 -07:00
Brian Wilkerson 1e1ecd8b41 Fix code completion before keyword in constructor
This fixes an exeception when code completing before the `new` or
`factory` keyword in a constructor and the type name is not explicitly
used. The exception prevents any suggestions from being returned, so
it's fairly serious.

Change-Id: I2f5028812ee1945ac9635f55953fb800b19a48c5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/505620
Auto-Submit: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2026-05-22 10:25:06 -07:00
Konstantin Shcheglov fb2962c045 Issue 63382. Use WorkspacePackage.isInTestDirectory() instead of CompilationUnitExtension.
Bug: https://github.com/dart-lang/sdk/issues/63382
Change-Id: I3c1d2495f9cb6804c73d1f36314556186f825a67
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/505064
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2026-05-20 14:39:04 -07:00
Keerti Parthasarathy 98c3699f32 Add test for inlining a getter.
This test confirms that https://github.com/dart-lang/sdk/issues/45997 is fixed.

Change-Id: Iafdd8be922a770d2bc11260a94237845df336d4b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/503660
Commit-Queue: Keerti Parthasarathy <keertip@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2026-05-15 09:28:17 -07:00
Danny Tuppeny 8b29e93bea [analysis_server] Include count of additional errors in "Rename anyway?" prompt
Follow up from https://dart-review.googlesource.com/c/sdk/+/499600

+ fix typo
+ fix bug that inline_method treated required named arguments as optional instead of required

Change-Id: I1c088138d990a27ed74ff51993bbe4032b245693
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/500780
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Keerti Parthasarathy <keertip@google.com>
2026-05-06 07:30:09 -07:00
Danny Tuppeny ac8b7adbaf [analysis_server] Add refactors for Add/Remove import prefixes
Fixes https://github.com/Dart-Code/Dart-Code/issues/4289

Change-Id: I875cbab9f36111cbbdd2b9723c1da80a0de72034
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/498700
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2026-05-05 12:53:41 -07:00
Konstantin Shcheglov aa1ebb4eae CQ. Stop using mock Source in LinterRuleOptionsValidatorTest.
Change-Id: I89bd2665963b44dae971bab593df956766ca9919
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/499781
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2026-04-30 22:31:29 -07:00
Brian Wilkerson 7d3b23b84e Update extract_method to use the ChangeBuilder
This impacted the placement of the imports, but I think the new results
are better. If nothing else, it's more consistent.

I thought it might be easier to review as two separate changes.

- The first patchset includes the basic transformation.

- The second patchset removes the old code to add the imports.

Change-Id: Ia0a3745152a14ce32fb757e797d0848b9f8d47cb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/499320
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2026-04-30 07:37:12 -07:00
Danny Tuppeny c5fb640747 [analysis_server] Handle request cancellation when a request is waiting for an outbound user prompt
This updates the `showUserPrompt` method to accept a cancellation token so that if requests are cancelled (by the client, or something like a second refactor cancelling the first), the prompt is also cancelled (and when the response arrives, it can be ignored).

Note: Unfortunately the protocol (and VS Code) don't actually allow for the prompt to be cancelled/hidden from the user, this is mainly to avoid us keeping the request "alive" on the server if the user ignores a prompt and we know the parent request was cancelled anyway.

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

Change-Id: Ia77880a749b284a2ff31c8cf560307ad908d2175
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/499360
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2026-04-29 13:57:38 -07:00
Konstantin Shcheglov e20704c3b0 CQ. Move PackageConfigFileBuilder to analyzer_testing.
Move PackageConfigFileBuilder into the analyzer_testing public API and
deprecate the copy exposed from package:analyzer. The builder is only
used by test infrastructure, so keeping it in analyzer_testing makes the
ownership clearer and avoids exposing test-only utilities from analyzer.

Update the builder API to accept a rootFolder instead of a rootPath.
This lets callers pass the resource-provider folder directly, so the
generated rootUri is derived from the same file-system abstraction that
created the test files. This avoids accidentally passing POSIX paths
where resource provider paths are required, such as on Windows.

Update existing test utilities and callers to import the new library and
pass Folder objects. Remove the production analysis server dependency on
the builder by emitting the temporary plugin package config JSON
directly.

Change-Id: I46b14710626e0d6d5884afcdc5a05b23077acfc9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/499081
Reviewed-by: Paul Berry <paulberry@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2026-04-29 13:18:35 -07:00
Brian Wilkerson 18c3034f20 Convert two more refactors to use ChangeBuilder
This continues the effort to move all of the legacy refactors over to
using the ChangeBuilder rather than creating legacy edit objects
directly. This should make it easier to atomically convert all of the
refactors to produce a protocol-agnostic representation as part of the
move to remove the legacy protocol.

Change-Id: I659c14966b543f21ecc94248a2c0dda5692473fb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/499045
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2026-04-29 13:15:21 -07:00
Konstantin Shcheglov ba666c8082 CQ. Refactor references by role.
Replace the generic mutable reference tree with typed reference classes
for roots, libraries, top-level declarations, member containers,
members, and built-in elements.

The previous API was shallow. It offered a small primitive,
`getChild(String)`, but pushed too much knowledge to every caller: which
sentinel names exist, which paths are valid for each declaration kind,
which references may contain members, and which references are not real
declarations at all. That kept the reference implementation simple by
spreading its complexity across the analyzer.

Make the reference model deeper instead. Callers now ask for the
semantic role they need, such as a library, constructor, method, field,
or top-level declaration. The reference layer owns the representation,
lookup, creation, and serialization details. This concentrates the
complexity behind a narrower interface, makes the common cases clearer,
and makes invalid reference shapes harder to construct.

This is a strategic cleanup rather than a local simplification. The
reference graph is used by element construction, summary reading and
writing, scopes, exports, and fine-grained dependency manifests. Giving
it explicit concepts reduces the amount of convention each subsystem
must remember and preserves a simpler mental model at the call sites.

Update summary serialization to write semantic reference rows with a
tag, enclosing reference, kind, key, and URI payload. Bump the analyzer
data version because this changes the linked summary format.

Represent exported declarations as export entries that carry the
exported name, reference, and export locations. Use those entries when
building scopes, filtering deprecated exports, and updating fine-grained
library manifests.

Keep import prefixes out of the declaration reference tree. Bind prefix
fragments through fragment-local ids so prefixes can be restored and
merged without fabricating declaration references.

Bug: https://github.com/dart-lang/sdk/issues/63227
Change-Id: If28f8b779faa78bdf023bc69b714555fae57ccb3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/497621
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2026-04-27 10:07:25 -07:00
Konstantin Shcheglov 6cd3938741 Breaking changes for analyzer 13.0.0
https://github.com/dart-lang/sdk/issues/62799
https://github.com/dart-lang/sdk/issues/62944
https://github.com/dart-lang/sdk/issues/63002
https://github.com/dart-lang/sdk/issues/62970

Looks mostly green in google3: https://fusion2.corp.google.com/presubmit/901021300/OCL:901021300:BASE:901308428:1776439417713:37cd1695

Change-Id: I44754a48f66a0b58851d7c20fcfa61f7fb1b555a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/488624
Reviewed-by: Paul Berry <paulberry@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2026-04-17 23:06:25 -07:00
Konstantin Shcheglov e7c6654312 Augment. Allow abstract top-level variables.
Permit `abstract` on top-level variable declarations when the
augmentations feature is enabled. Previously the parser always reported
`abstract` as extraneous at the top level, which rejected valid syntax
and dropped the modifier before later stages could see it.

Thread the abstract token through top-level field parsing, record it on
`TopLevelVariableDeclaration`, and pass it through the front-end
builders. Reorder the field callback arguments so `augment` precedes
`abstract`, matching the augmentation grammar for incomplete top-level
variables and keeping the parser, listener, and outline plumbing
consistent.

Change-Id: I680414a746b707d483e485702685c95f28a9c9ac
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/494564
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2026-04-14 16:12:24 -07:00
Sam Rawlins 2ee3239969 DAS: use options cache in analysis options provider
Fixes https://github.com/dart-lang/sdk/issues/62539

I'm calling this one fixed after this change; we started with ~1850
analysis option reads for the `dependency_resolution` repository in the
issue. The previous changes cached reads, knocking the number of reads
down to ~1000. This change knocks it down to ~300.

Change-Id: Ia8be5880e63cb299e73f72403c3943d115da8e1d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/493201
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2026-04-08 02:37:49 -07:00
Danny Tuppeny 931a3ff671 [analysis_server] Fix type name for constructors from type aliases in completion
We were adding constructors to completion for type aliases, but not using the type alias in the completion, which mean a lot of duplicates against the target class (see https://github.com/Dart-Code/Dart-Code/issues/6003).

I don't know if this got lost in one of the completion refactors, as there didn't seem to be support in `ConstructorSuggestion` for this, so I've added an `alias` field to it to override the name.

Fixes https://github.com/Dart-Code/Dart-Code/issues/6003

Change-Id: I06c073b1a9cae012c5bdf0fb8a3aa22f8fed728c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/491880
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Keerti Parthasarathy <keertip@google.com>
2026-04-02 13:27:09 -07:00
Lasse R.H. Nielsen 56505e0575 Stop using Match.group.
The `Match.operator[]` does the same thing and is
generally recommended (and shorter).
(I want to deprecate `group` and `groups`)

Tested: Refactoring.
CoreLibraryReviewExempt: Calling equivalent function.
Change-Id: I4c758968ae622fe16b7322be1b29b05b91e7fcd9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/489021
Reviewed-by: Paul Berry <paulberry@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Lasse Nielsen <lrn@google.com>
2026-03-20 09:09:46 -07:00
Brian Wilkerson 8d15d9ffaf Update rename to work for primary constructors
We don't appear to have any end-to-end tests of the rename refactor (and
maybe not of other legacy refactors). We need to fix that, but that's a
bigger task than I want to include in this CL. For now I've locally built
and tested the rename on a primary constructor and verified that it
works as expected.

Change-Id: Icec20f3204c58fa219ff7df117511ed47629bd1f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/489120
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2026-03-19 10:17:01 -07:00
Brian Wilkerson daa9b8e31b Refactor RenameConstructor to use a ChangeBuilder
In order to support primary constructors we need to have two new
refactors that will add and remove a constructor name. Rather than
duplicate the logic in the RenameConstructor class, I want to reuse it.
In order to do that, I need to be able to pass in a ChangeBuilder.

This CL accomplishes that goal by making it possible to pass in a
ChangeBuilder to any refactoring, even though in most cases the
ChangeBuilder will be ignored. In the future I intend that all of the
refactors will be updated to use the passed in ChangeBuilder, but that
would have been too big for a single CL.

Beyond that, I did make one other change, which is that the refactor
now supports classes with an empty body (`;`). I added a test for the
new functionality, but I believe that the existing tests should be
adequate to ensure that there was no loss of functionality.

This does not add support to RenameConstructor to deal with primary
constructors. That will also happen in a follow-on CL.

Change-Id: I51749e9cd1d775744dc6e64c1dc67967ef492d45
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/488527
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2026-03-17 14:26:21 -07:00
FMorschel 72c417c133 [DAS] Fixes dot shorthand completions when feature is disabled
Fixes: https://github.com/dart-lang/sdk/issues/61983
Change-Id: Id5901b1094e2d9b18bc2ab3c279ddc94f6063eb3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/472020
Commit-Queue: 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>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2026-03-04 10:51:41 -08:00
FMorschel 7b782cb298 [DAS] Fixes closure suggestions in returns
Fixes: https://github.com/dart-lang/sdk/issues/62791
Change-Id: Ie8cbdd28e52ca9d7199198b4f3396d31ec503baf
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/485340
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Auto-Submit: Felipe Morschel <git@fmorschel.dev>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2026-03-04 10:30:51 -08:00
Danny Tuppeny b1355a46e5 [analysis_server] Add tests for primary constructors in inline/extract refactors
Change-Id: I884588e0b0d8ae5ab65af7b582d110d179a74f4a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/485523
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2026-03-04 10:22:47 -08:00
Danny Tuppeny b26f951011 [analysis_server] Fix renames for constructors declared with new/factory keywords and no type name
Change-Id: Ifc19ad892695726d4a40bc69acffa7d7b27df6df
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/484940
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2026-03-03 08:39:43 -08:00
Brian Wilkerson 7080a8bcef Update test of sort members to include use of new
The previous pass, which added a primary constructor, did not include a
test of a constructor introduced by `new`. This remedies that oversight.

Change-Id: I8fb91fad0a929b81d6af2900c3a6093db62f5315
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/484022
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Auto-Submit: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2026-02-27 11:51:19 -08:00
Brian Wilkerson 2be889b59f Update completion to suggest new in class-like bodies
Primary constructors introduces the ability to use `new` in place of
a class name in a constructor. The previous changes to code completion
missed this, but this CL causes `new` to be suggested at the beginning
of a member.

Change-Id: I56ac6d3d8649e55de264f6e4f91b4c5db2e37c92
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/483322
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2026-02-24 11:45:39 -08:00
Robert Nystrom bb13a0e609 Handle private named parameters in "Extract Widget".
When creating the constructor parameters for the widget, if the field
is private, prefer to use a private named parameter unless it collides
with another public field.

Bug: https://github.com/dart-lang/sdk/issues/61644
Change-Id: I2776e4a350f5034e33bd80f4686e4164e8b0bda8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/479740
Auto-Submit: Bob Nystrom <rnystrom@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2026-02-11 07:19:00 -08:00
FMorschel eee4dfa5e7 [DAS] Fixes rename class member adding this. in qualified accesses
Fixes: https://github.com/dart-lang/sdk/issues/62629
Change-Id: Id3fcdd5676ad2d2fa1a81f4908c47309a2d964f0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/479660
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Auto-Submit: Felipe Morschel <git@fmorschel.dev>
2026-02-10 16:58:30 -08:00
Sam Rawlins d3ecc0f8a7 anlyzer: Simplify AnalysisOptionsProvider exception-logic, non-nullable _sourceFactory
Change-Id: I8eb2484340a939107abfad88bbf7a919c1461a75
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/475785
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2026-01-27 08:59:11 -08:00
Konstantin Shcheglov f576c2d8e9 SR. Add a warning in 'Convert Getter to Method' for places where the getter is used for pattern matching.
When a getter is referenced from a pattern field (e.g. `A(test: ...)` or
`A(:var test)`), converting the getter to a method changes the meaning
of the pattern: it will match the method tear-off rather than the
getter’s evaluated result. This can silently break code that relies on
pattern matching behavior.

Update the refactoring to detect these references and report a warning
during final condition checks, including a precise source location for
the affected pattern field.

Also refactor the implementation to:
- Collect all relevant getter elements up front (top-level getter or the
  corresponding hierarchy getters for a field) and reuse that list for
  both condition checking and change creation.
- Skip inserting `()` for references in pattern fields, as before.

Bug: https://github.com/dart-lang/sdk/issues/62139
Change-Id: I81170b7c39ae77148b7bc0a0979c390b5f5afe7d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/475704
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2026-01-26 11:51:17 -08:00
Sam Rawlins f0c737d6c2 analyzer_testing: Widget is @immutable
This requires some changes to tests, where fields should be final. In
tests where it seemed like the mutability of a field was important, I
just ignored the warning. Otherwise, I made fields final.

I do like keeping this stub in-line with the real Widget class. If
anything, it keeps in mind that flutter Widgets should generally no
have mutable fields.

Change-Id: Ib7dc1fbd6aa013dc72925404c4be8186ddcddaa4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/475400
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2026-01-23 12:25:21 -08:00
Konstantin Shcheglov f18e8c0d1b DeCo. Stop using final / var, or opt-out from primary constructors.
Primary constructors repurpose `var`/`final` in formal parameter lists
as declaring parameters, which makes many older snippets erroneous.

Update tests to avoid these keywords unless they are the subject under
test:

- Remove redundant `var` from untyped formal parameters across analyzer,
  analysis_server, and linter tests (e.g., `f(var x)` -> `f(x)`), and rename affected tests from “...Var” to “...Untyped” where appropriate.
- Add `// @dart = 3.10` to test snippets and documentation examples that
  intentionally use legacy `final`/`var` constructor parameters so they remain parsed and analyzed under the pre-DeCo language version.
- Adjust expected diagnostic offsets and resolved-node expectations where code changed due to keyword removal or inserted language-version markers.
- Update mock SDK declarations to avoid `var` in parameter positions.

Change-Id: Ic0a2b129cda75d542f8229bc65b44bf6ad26ae22
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/475180
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2026-01-23 09:22:59 -08:00
FMorschel c1b38fd690 [DAS] Makes the defined parameters not show as suggestions on constructors
Fixes: https://github.com/dart-lang/sdk/issues/62326
Change-Id: Id5436cf281eb596bf673da717a21d8e0df96ddf5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/474680
Auto-Submit: Felipe Morschel <git@fmorschel.dev>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2026-01-21 12:33:59 -08:00
FMorschel 44cb72e0bb [DAS] Fixes some completions in argument lists for required keyword and related
Bug: https://github.com/dart-lang/sdk/issues/62326
Change-Id: If3174c62cc9ba0889c139fe773bc782f12275a7c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/474240
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Auto-Submit: Felipe Morschel <git@fmorschel.dev>
2026-01-20 11:33:19 -08:00
Robert Nystrom df5d728e08 Test that BindToField and BindAllToFields handle private named parameters.
They already do the right thing, but this pins it down.

Also added a little functionality in AbstractSingleUnit to allow ignoring expected diagnostics in the input code. I did that instead of adding another diagnostic to the blanket ignores because diag.privateNamedNonFieldParameter felt like an error we wouldn't want to always ignore. I also like tests generally being specific in what they permit. Let me know what you think of this approach.

BUG: https://github.com/dart-lang/sdk/issues/62434

Change-Id: I344aa665aeed0b766d6c2d97608dc4eedf14b2f9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/473925
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Auto-Submit: Bob Nystrom <rnystrom@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2026-01-20 08:05:17 -08:00
FMorschel 0a421ad409 [DAS] Fixes dot-shorthand completions for private types
Fixes: https://github.com/dart-lang/sdk/issues/62416
Change-Id: Ie8a4080866e0b95cde4f2267604f115350230e29
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/473300
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>
2026-01-16 11:03:54 -08:00
FMorschel 44fbfa987f [DAS] Fixes dot-shorthand completion for ParenthesizedPattern
Fixes: https://github.com/dart-lang/sdk/issues/62408
Change-Id: Idcf437a7af46d6ee804becd968446005b18df7fc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/473060
Commit-Queue: Keerti Parthasarathy <keertip@google.com>
Auto-Submit: Felipe Morschel <git@fmorschel.dev>
Reviewed-by: Keerti Parthasarathy <keertip@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2026-01-15 09:51:33 -08:00
FMorschel b58ce6cba1 [DAS] Fixes completion between nullable cascade dots
Fixes: https://github.com/dart-lang/sdk/issues/62397
Change-Id: I3ce51142e5e81196107d295fc7123c93086ac7cc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/472920
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Keerti Parthasarathy <keertip@google.com>
Auto-Submit: Felipe Morschel <git@fmorschel.dev>
Commit-Queue: Keerti Parthasarathy <keertip@google.com>
2026-01-14 08:51:12 -08:00
Robert Nystrom b6c19cbe13 [private named parameters] Handle rename refactoring.
Remove the special case handling that would add a public parameter and
a separate initializer in the initializer list since you can now use the
private name as a parameter directly.

Handle updating references at constructor callsites where we need to
rename the argument to the corresponding public name.

Bug: https://github.com/dart-lang/sdk/issues/61644
Change-Id: I76160f2a702073f57a45b9ea0425e4a7567ba466
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/466960
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Bob Nystrom <rnystrom@google.com>
Auto-Submit: Bob Nystrom <rnystrom@google.com>
2026-01-12 14:37:52 -08:00
FMorschel fb419269bc [DAS] Fixes dot shorthand completion for if case and &&/|| operators
Fixes: https://github.com/dart-lang/sdk/issues/62381
Change-Id: If8e161d37caf9e8c561cb28e42ae2cbe4ac7fada
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/471780
Commit-Queue: Keerti Parthasarathy <keertip@google.com>
Reviewed-by: Keerti Parthasarathy <keertip@google.com>
Auto-Submit: Felipe Morschel <git@fmorschel.dev>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2026-01-12 11:29:02 -08:00
FMorschel 6d28e46ead [analyzer] Fixes class references for const invocation of named constructor
Fixes: https://github.com/dart-lang/sdk/issues/55348
Change-Id: Ib57f1c4bf9db84bb0e940fea02b480bbcd5706ce
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/472360
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Auto-Submit: Felipe Morschel <git@fmorschel.dev>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2026-01-12 10:54:27 -08:00
Brian Wilkerson c4ed22e204 Update the member sorter to handle primary constructor bodies
With these changes, primary constructor bodies will sort with
constructors (based on whether `sort_members_first` is enabled), but
will always be before other constructors.

Change-Id: If6719dedd5178c384712a5d08b4e74a38aaf54a1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/471280
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2026-01-07 09:29:04 -08:00
Fedor Shcheglov 884817d52d Fix case and default not appearing as suggestions inside a switch statement that contains elements
Change-Id: Ib9a2f6ec583efee33566e17cc54ce1484cf87dbf
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/470080
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2025-12-30 13:01:50 -08:00
Fedor Shcheglov c854455f62 Fix a bug where renaming a field formal parameter would not rename the field formal parameter in subclasses or superclasses.
Change-Id: I43a11195e08b66b561e7bb163a62d00bb5c3dc03
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/469520
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Jaime Wren <jwren@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2025-12-22 14:58:19 -08:00
Konstantin Shcheglov 23a903e9ae DeCo. Build extension type primary constructors like regular ones.
Previously, the AST builder enforced strict constraints on extension
type primary constructors during parsing, often discarding or
transforming invalid parameters (e.g., multiple, optional, or named
parameters) to force a valid representation field structure. This
limited recovery and resulted in inaccurate element models for invalid
code.

This change updates the AST builder to parse and build elements for the
primary constructor's formal parameters exactly as written. The
validation logic ensuring a single, positional representation field has
been moved to `ErrorVerifier`.

To maintain the invariant that an extension type has a representation, a
synthetic "recovery" representation field is now added to the element
model if the parsed parameters do not provide a valid one.

Bug: https://github.com/dart-lang/sdk/issues/61701
Change-Id: I37b7eaf2c085db6317b2c2b0bf35ff31423f9738
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/465180
Reviewed-by: Paul Berry <paulberry@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2025-12-19 07:38:31 -08:00
FMorschel 850a760078 [DAS] Fixes dot-shorthand completion for annotations
Fixes: https://github.com/dart-lang/sdk/issues/62260
Change-Id: I3439237fd02c66600908190caeb07e1b0c4bfa7e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/468701
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Auto-Submit: Felipe Morschel <git@fmorschel.dev>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2025-12-17 08:59:27 -08:00
FMorschel 275581bca1 [DAS] Fixes completion for switch expression pattern after when
Fixes: https://github.com/dart-lang/sdk/issues/62210
Change-Id: I42a3d6f3f93a8ecc8f4b866d89119a6cc49bd3e8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/467160
Commit-Queue: Keerti Parthasarathy <keertip@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Auto-Submit: Felipe Morschel <git@fmorschel.dev>
Reviewed-by: Keerti Parthasarathy <keertip@google.com>
2025-12-16 09:07:37 -08:00