Commit Graph

7393 Commits

Author SHA1 Message Date
Danny Tuppeny f300269d0c [analysis_server] Exclude NameWithTypeParameters from selection ranges
This makes things more consistent between class/mixin (that have different ASTs) but also avoids jumping to the name+type args which probably isn't what you'd expect.

Change-Id: Ibd5e2a9b332c4c214ccc753080a61b1222445485
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/490260
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2026-03-24 10:20:30 -07:00
Danny Tuppeny 88bbb2c09b [analysis_server] Add tests for empty bodies in LSP SelectionRanges
Change-Id: I0bbd45277e942bdfabcdc1e1737f2cef048a1269
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/489961
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2026-03-23 14:00:09 -07:00
Danny Tuppeny 0b5a913de8 [analysis_server] Add Document Symbol + Outline tests with empty bodies
Change-Id: I77e901475c802dc4649ec09097618f2e5787fb7d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/489940
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2026-03-23 07:32:44 -07:00
Ben Konyi 2a83a78213 [ DAS ] Add initial support for widget preview detection service
The Flutter Widget Preview feature is currently implemented within
Flutter Tools, which is responsible for detecting widget preview
annotations in the user's project. When previews are detected, the
Flutter Tool injects code generated based on the detected previews into an artificial widget_preview_scaffold project and performs a hot reload to render updates to the preview set in the scaffold application.

`package:analyzer` is currently being used to detect previews, but this comes with a significant amount of memory overhead. Since widget
previews are mostly being used from within IDEs which already have an
active analysis server, moving widget preview detection into the DAS
will remove the need for creating an additional analysis context in the Flutter Tool itself.

This change includes the initial work to move widget preview detection
into the DAS. It utilizes a pull-based mechanism, where the Flutter Tool listens for file system events and then queries the DAS using the `dart/textDocument/getFlutterWidgetPreviews` and `dart/workspace/getFlutterWidgetPreviews` LSP methods.

Each reported preview contains some generated code based on the annotation used to define the preview. This code has all constants from the original annotation evaluated to either primitive values or constant expressions with namespaces applied to each symbol, allowing for the Flutter Tool to inject this code directly when updating the generated code in the scaffold project.

Towards https://github.com/flutter/flutter/issues/179584

Change-Id: I043cb3235a66b25dda3f852ca7f147bff0e1e537
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/478100
Auto-Submit: Ben Konyi <bkonyi@google.com>
Commit-Queue: Ben Konyi <bkonyi@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2026-03-22 19:19:03 -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
D.ildo 7cad9ad43d #62878 quick fix incorrectly treats positional arguments
Closes https://github.com/dart-lang/sdk/pull/62921

GitOrigin-RevId: 5f21333b6fc53b56897ab2a83e9aa8638911a56a
Change-Id: Ie24702e8e7b1eda21b34f9972f02fd94387dc1f0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/488525
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2026-03-20 07:51:50 -07:00
Danny Tuppeny a5506417da [analysis_server] Fix a flaky diagnostics test
The test has become flaky for me recently. I believe the issue is that analysis is completing too quickly and `waitForAnalysisComplete()` starts waiting for a future analysis that never comes.

Change-Id: Ie76dffd3fbaef50eb27d5fc9692131d38553d4b8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/489180
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2026-03-19 17:58:11 -07:00
Danny Tuppeny 32379cbeae [analysis_server] Add tests for move-params-left refactor for Primary Constructors
Change-Id: I48ada3209032f40d1c9ca7de9b41699fae8ab8a1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/486382
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2026-03-19 14:18:30 -07:00
Danny Tuppeny a772b97058 [analysis_server] Support primary constructors and new/factory in Convert Parameters to Named refactor
Change-Id: Id78b372f9b345cb287214d008b43d8a20ce3cbcd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/485822
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2026-03-19 13:39:06 -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
pq 6cb842ed05 [analytics] process and propagate analytics ENV context
Fixes: https://github.com/dart-lang/sdk/issues/62875

Bug: https://github.com/dart-lang/sdk/issues/62875
Change-Id: I864c2fb401dd2eb9859b1277ea971db758ace618
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/488583
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Phil Quitslund <pquitslund@google.com>
2026-03-18 14:30:09 -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
Danny Tuppeny 811849dd1e [analysis_server] Fix LineInfo used in Type Hierarchy
This fixes the LineInfo used for type hierarchy, no longer assuming that the Element is in the same file where Type Hierarchy was invoked.

It also removes some of the fetching of LineInfos for files and caching them, since we can now access the LineInfo from a LibraryFragment much more easily.

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

Change-Id: I3dd3527cf4afb9ae3171b90def02452d04ffa9c2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/488481
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2026-03-17 08:49:50 -07:00
Konstantin Shcheglov e655e9fd6c DeCo. Add ClassBody.members, EnumBody.constants, EnumBody.members
Add `ClassBody.members` and `EnumBody.constants`/`members` so callers
can access class and enum contents through the common body interfaces
instead of pattern matching on `BlockClassBody` and `BlockEnumBody`.

Implement empty node lists for empty class and enum bodies, update the
public API, and migrate analyzer, analysis_server, analyzer_plugin, and
linter code to use the new accessors directly. This removes the ad hoc
`members2` helper extensions and a large amount of repeated `tryCast`
and `switch` logic, making body traversal more uniform.

Change-Id: I51d75f2253c7e6f75efecae84bf0443ff5eb6788
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/488263
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2026-03-16 19:29:20 -07:00
Brian Wilkerson c457ab141d Update addSuperConstructorInvocation for primary constructors
We need to think about utilities we can add to `ChangeBuilder` to make
this kind of edit easier. I thought about an `addInitializer` utility,
but wasn't sure it would have other uses. I also thought about an
`addMember`, which would probably be good, but not for this use case.
More thinking is probably needed.

Change-Id: Ie30d9f4a47007b03b22a290e2ba6c72f3c5423bf
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/488361
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2026-03-16 16:12:35 -07:00
Sam Rawlins 7d0a17196c DAS plugins: Add print-debugging support in Insights pages.
Work towards https://github.com/dart-lang/sdk/issues/61868

This adds a new notification type, 'PluginPrint'. There are several
fields and variables then named 'pluginPrint' or 'print', and I am
definitely open to changing these names, but this is the best one that
I thought of.

PluginPrint has three fields: The name of the plugin that printed, the
message that was printed, and the timestamp.

We wrap each plugin's AnalysisRule invocations with a zone, so that
the `print` handler can know the name of the plugin. The prints are
caught and sent to the server isolate as Notifications. The
PluginIsolate then stores the collected prints. The Plugins Insights
page can then retrieve them and display them.

Manual testing, with 1000 libraries that get new lint reported once per
file, I did not observe a negative performance impact.

Change-Id: Id800ae41781c15ce89d06b563878c2b0edae43d3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/486827
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2026-03-16 14:56:59 -07:00
Brian Wilkerson aa77bd2d21 Update the addMissingParameterNamed fix for primary constructors
This required updating some utility methods used by the fix. I'm not
sure what other code that effects.

Change-Id: If0c1df36847d4a319624252f63901af18c7fafe4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/487640
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2026-03-16 11:28:00 -07:00
Konstantin Shcheglov e9d8109258 DeCo. Support empty bodies in membered declarations
Allow enums, extensions, and mixins to use `;` as their body and
represent that form explicitly in the AST. The parser now produces
`EmptyEnumBody` or `EmptyClassBody` for the empty form.

Also replace `LibraryIdentifier` with token-based `DottedName` and store
the full token sequence for dotted names. This preserves periods and
source offsets directly in the AST, which keeps printing, selection, and
directive name handling working with the new shape. See
https://github.com/dart-lang/sdk/issues/62819

See https://github.com/dart-lang/language/issues/4645

Google3 presubmit looks green:
https://fusion2.corp.google.com/presubmit/884063020/OCL:884063020:BASE:884079610:1773618867493:b2110d76

Change-Id: I2d023cd03b6423da634c3e14742e02a61dc3b403
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/486080
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2026-03-16 08:56:11 -07:00
Danny Tuppeny 87e0fea473 [analysis_server] Don't let format errors fail change building
Some refactors try to format their code, but formatting can fail if there is a parse error anywhere in the file (including in completely unrelated code). This change catches formatting errors and ignores them, so the refactors will continue to work in that case (albeit without formatting).

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

Change-Id: Ia3c3769640314557191244393ab8c1bd38dc2fdb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/487841
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2026-03-14 07:27:50 -07:00
Paul Berry 07b214eef5 Bump analysis server to language version 3.12.
Also start using the "private named parameters" feature.

Change-Id: I1c6da5f8ae2985e12313d405a2eb419c6a6a6964
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/487521
Auto-Submit: Paul Berry <paulberry@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2026-03-12 14:18:11 -07:00
Brian Wilkerson b54f4b718e Support primary constructors for the addKeyToConstructors fix
Change-Id: I74a07d76c4e874dd1cc2ecaffe0f6a5a994a746e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/487221
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2026-03-12 08:57:25 -07:00
Brian Wilkerson 282f109ddf Add another fix for invalidCovariantModifierInPrimaryConstructor
This adds a fix to replace the `final` with `var` in cases where the
defined field needs to be covariant because it overrides an inherited
member.

Change-Id: I2dc57253beedb89ce942ba38e7d0855a43bb3308
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/486700
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2026-03-10 08:26:01 -07:00
Brian Wilkerson a547559f3c Add a fix for the representationFieldModifier diagnostic
In addition to wiring up the fix for this one diagnostic I also changed
the naming convention for the constructors so that they will be
consistent as we add support for keywords that can't be used as a name.

Change-Id: Icf83bc7d3f33fea14165acd755889233ac8797b7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/486480
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2026-03-09 09:11:07 -07:00
Brian Wilkerson 6015fddb43 [CQ] Use removeKeyword in place of removeAwait
This replaces the removeAwait correction producer with the awaitKeyword
producer.

The tests were moved to their new location. The test methods were not
changed, but the classes were renamed to be more appropriate.

In the process I noticed a performance improvement I could make to the
replaceKeyword producer, so I included that change here.

Change-Id: Ibff1e61762fa6d4d750d39f130d23681fee766ea
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/486400
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2026-03-08 07:37:05 -07:00
Brian Wilkerson fde3828514 Add a fix for invalidCovariantModifierInPrimaryConstructor
This adds a fix for a newly added diagnostic.

I wrote another correction producer that removes a single keyword, but
the intent is for this one to be general enough that it can replace all
of the previous ones. I decided, however, not to try to replace all of
them in a single CL.

Change-Id: I1191021a81f3c1532235316aab6e47cf0b7c9957
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/486320
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2026-03-06 14:33:29 -08:00
FMorschel 82c13315c0 [DAS] Adds quick-fix to unnecessary_null_aware_operator_on_extension_on_nullable
This changes `unnecessary_null_aware_operator_on_extension_on_nullable` to stop also triggering for non-null nodes because we already report `invalid_null_aware_operator` in that case, and having two diagnostics for the same problem is not useful and would make the fix run twice.

This also `exports 'package:linter/src/lint_names.dart'`, where we declare `FixProcessorLintTest`. This way, we don't need many existing `imports` for it, and this also removes those unnecessary imports.

Fixes: https://github.com/dart-lang/sdk/issues/62766
Change-Id: Iadb460e8db8eb8e020f413f371df424d768fa768
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/485500
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Auto-Submit: Felipe Morschel <git@fmorschel.dev>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2026-03-06 14:12:15 -08:00
Brian Wilkerson 901c94b18f Add tests for the add-required-keyword fix
In the process, I renamed the file so that it would correspond more
closely to the name of the class and the implementation file.

Change-Id: Ic878782a16e5bde34443157e22a14f9b16862ce0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/486001
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2026-03-06 08:13:50 -08:00
Brian Wilkerson d4447b770b Update add_field_formal_parameters fix for primary constructors
The fix was failing to fire for primary constructors, but this CL fixes
that. It also adds tests for primary constructors.

Along the way I was able to clean up some repeated subexpressions.

Change-Id: I1870ad7c83478b141ab2099c26b9a719f1de7468
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/485602
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2026-03-05 07:48:56 -08: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
Brian Wilkerson df48c55595 Fix the remove-unused-parameter fix when applied to a field formal parameter
The assist used to change the semantics by removing the assignment of
the default value to the field. This fixes that by adding an explicit
assignment in the initializer list.

Fixes: https://github.com/dart-lang/sdk/issues/61810
Fixes: https://github.com/dart-lang/sdk/issues/62809
Change-Id: I8fdb9169e8499e5a99c7b954f3dad7ddab289bb6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/485280
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2026-03-03 16:30:09 -08:00
Brian Wilkerson 28b1ea93af Do not convert super parameters to field formal parameters
This ensures that the lint that suggests the converion to a field formal
parameter doesn't fire for super parameters, and also that the assist
isn't offered in those cases.

We can consider allowing both if we find a good way to perform the
conversion, but at the moment the tools can create invalid code.

Fixes: https://github.com/dart-lang/sdk/issues/62807
Change-Id: I7b4b2011059afc8ae0fc9649d012c51a37c64472
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/485121
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2026-03-03 10:27:19 -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
Danny Tuppeny c3cc1d53a3 [analysis_server] Add test for hover with factory()
This was recently updated for `new()` but didn't handle `factory()`.

Change-Id: I8a75dcbfa7d5454e0758f0ff8f2ca1bb7bd5ddfa
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/484740
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2026-03-02 08:44:08 -08:00
Brian Wilkerson 6225aade99 Add tests for hover and primary constructors
The previous set of tests missed two cases:
- a primary constructor with a private named parameter
- constructors introduced by `new`

The latter had some bugs, which are fixed in this CL.

Change-Id: I872a3948dd1b0f791dbea1354c8377e83048e618
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/484227
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2026-02-27 21:18:20 -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 999d6a45df Improve diagnostic when a private name is used in invocation
This introduces a specialized message when an invocation of a
constructor with a private named parameter uses the private name in the
argument list.

It also removes the '_test' suffix from a couple of import prefixes in
the `test_all.dart` file as the use of the suffix is not the convention.

Fixes https://github.com/dart-lang/sdk/issues/62749
Change-Id: I0d2d586c2131df6d7bfe45a3e6bdf9c14c33470c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/483866
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2026-02-27 11:43:08 -08:00
Paul Berry 8034e84ed1 [analysis_server] Improve how ConvertToInitializingFormal modifies parameters.
Previously, changing an ordinary formal parameter like `required int
x`, to an initializing formal parameter like `required this.x`, was
done using a single edit that replaced the entire AST node with a
newly constructed one.

This had the unfortunate disadvantage that if the formal parameter had
any annotations, (like `@visibleForTesting`), they would be removed.

The new technique is to make 3 edits:

- Insert `this.` before the name.

- If the field name is different, replace the parameter name with the
  field name (this handles migration to the "private named parameters"
  feature).

- If the parameter has an explicit type, and that type is the same as
  the field's type, delete it.

Since I was in the neighborhood, I also generalized the code so that
it handles old-style function-typed parameters. Even though those have
fallen out of favor, the generalization was pretty easy: I just
changed the code to handle `NormalFormalParameter` rather than
`SimpleFormalParameter`, and in the case where the parameter is a
`FunctionTypedFormalParameter`, make sure to delete the parameters as
well.

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

Change-Id: I6a6a69642291c5c4cc639725f6a36cb884f6d9bd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/483841
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2026-02-26 12:23:59 -08:00
Brian Wilkerson e13253c676 Handle doc comments in the convert to initializing formal assist
When the field is private and the parameter is named, the assist will
change the name of the parameter, but this requires a change to all
references to the parameter. Most were being handled, but the comment
references were not. This CL fixes that.

Change-Id: I9607eb8aa01a100e1c0015019c862838bd2eccb7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/483842
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2026-02-26 09:46:08 -08:00
Danny Tuppeny 8d983debe0 [analysis_server] Update call hierarchy for factory keyword
+ fix some typos

Change-Id: Ic4f05cc57130657445f3c2f5312998d018f56a8e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/483540
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2026-02-25 08:59:41 -08:00
Danny Tuppeny 0b2961da1f [analysis_server] Update Go-to-Definition for factory keyword
Change-Id: I76b23e549d20a0716df6b43b091976e54774f922
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/483541
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2026-02-25 07:53:36 -08:00
Danny Tuppeny 329c861be8 [analysis_server] Fix document highlights for factory + tests for references
Change-Id: I63551ea9ac9faf114d5b07e6ed86b673651ef92a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/483520
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2026-02-25 07:47:42 -08:00
Robert Nystrom 207e8f6f3c Change the ConvertToInitializingFormal availability to allow it in dart fix.
Change-Id: I9dc2a579f5c7a832bc3ba2adc4ea0ad965845397
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/483361
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Auto-Submit: Bob Nystrom <rnystrom@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2026-02-24 17:13:50 -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 ea1bc24fdc ConvertToInitializingFormal: Don't discard initializers when deleting the constructor body.
ConvertToInitializingFormal can convert an initializer to an initializing formal, or an assignment statement in the body:

```dart
class C {
  int x;
  C(int x) {
    this.x = x;
  }
}
```

When converting from an assignment statement, if there are no statements left in the block, it deletes the entire function body.

Prior to this CL, it would also erroneously delete any initializers that happened to be on the constructor:

```dart
// Before:
class C {
  int? x;
  int? y;

  C(int? x) : y = 1 {
    this.x = x;
  }
}

// Result of applying fix:
class C {
  int? x;
  int? y;

  C(this.x); // Oops! Where did ": y = 1" go?
}
```

Change-Id: I5bd27e925509adc82056b71f4c96432c819bc954
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/482966
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Auto-Submit: Bob Nystrom <rnystrom@google.com>
2026-02-23 18:12:59 -08:00
Kallen Tu 62fc64513c [analysis_server] Primary constructors - Add fix for var_with_no_type_annotation.
The fix for `var_with_no_type_annotation` is to remove the `var` keyword. We'll use the `RemoveLexeme` fix to accomplish this.

Bug: https://github.com/dart-lang/sdk/issues/61704
Change-Id: I0cd3951bdb78975c059ad2beaee4c77c68fabfda
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/482521
Commit-Queue: Kallen Tu <kallentu@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2026-02-23 16:44:11 -08:00
FMorschel 1f8861f4f9 [analyzer_plugin] Fixes recursive type writing on DartEditBuilder.writeType
Fixes: https://github.com/dart-lang/sdk/issues/62549
Change-Id: Ia5f8b7cf7f923d63a73a9b155d1590052a61eaa5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/476800
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-02-23 09:06:48 -08:00
Danny Tuppeny 2a375317f4 [analysis_server] Deprecate HighlightRegionType.BUILT_IN and always use KEYWORD
Change-Id: I86ff7edc2b4de5910b19f6bdb0d4422b7546897a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/482820
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2026-02-23 07:44:32 -08:00
Brian Wilkerson cdd8ca2dcc Add an assist to convert a non-declaring parameter into a declaring parameter
This handles the most of the cases I could think of. Please review with
an eye toward catching holes. I also left a couple of questions in the
tests as there are a couple of cases I wasn't sure we wanted to support.

This doesn't handle fields with an initializer, though I think we could.
If you think we ought to handle it before shipping the feature I can either
update this CL or do it in a follow-on.

Change-Id: Ia9ac5d86853bc907fdce10e31f03714eeb89f1af
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/481621
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2026-02-20 17:13:49 -08:00