Commit Graph

2203 Commits

Author SHA1 Message Date
Danny Tuppeny 5d84439f5d [analyzer] Add support for "formatter" in analysis_options + use page_width in LSP
This adds support for validation + completion for `formatter/page_width` in analysis_options, and uses this value in preference to the client-supplied value in the LSP server.

It does not yet add support for the legacy protocol, and there are a few questions in https://github.com/dart-lang/sdk/issues/56864#issuecomment-2399289974.

See https://github.com/dart-lang/sdk/issues/56864

Change-Id: I7844e3abd1191beb9cc24197bbc8aa7c9e9ad4fa
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/388822
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2024-10-08 16:37:54 +00:00
Alexander Thomas d4aa30a3ba Revert "analyzer: Write out qualified extension names in error messages"
This reverts commit 10c1d883df.

Reason for revert: g/dart-sdk-rolls/MOLCzv4S-kQ

Original change's description:
> analyzer: Write out qualified extension names in error messages
>
> Fixes https://github.com/dart-lang/sdk/issues/56269
>
> Change-Id: I025966fd4aa3d7c5b71175321f21f95e8c41f086
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/388580
> Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
> Commit-Queue: Samuel Rawlins <srawlins@google.com>
> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>

Change-Id: I613695e90c96e5ffdb4dc56e729dc34be385f5fe
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/388823
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Auto-Submit: Alexander Thomas <athom@google.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Alexander Thomas <athom@google.com>
2024-10-08 15:07:38 +00:00
Sam Rawlins 10c1d883df analyzer: Write out qualified extension names in error messages
Fixes https://github.com/dart-lang/sdk/issues/56269

Change-Id: I025966fd4aa3d7c5b71175321f21f95e8c41f086
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/388580
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2024-10-07 18:01:54 +00:00
Sam Rawlins 1fbeaa0d19 DAS: offer to import extension on null-aware access and unary op
Fixes https://github.com/dart-lang/sdk/issues/56328

Change-Id: I144d9ca92a93bcc72c2cdd2016fcb2784f2858ee
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/388067
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2024-10-04 21:45:29 +00:00
FMorschel 79c0c75053 [DAS] Fix add type annotation assist for parameter types
R=srawlins@google.com

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

Change-Id: Iecf667e48cc42b06ea62c052c136b6f717657396
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/388281
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Phil Quitslund <pquitslund@google.com>
2024-10-04 20:55:48 +00:00
FMorschel 9a23a0cad6 [DAS] Fixing swap with single Widget on children
R=pquitslund@google.com

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

Change-Id: I5cad91a97dcd9fe7b550b3661e8a46a301cbb558
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/387862
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Auto-Submit: Felipe Morschel <fmorschel.dev@gmail.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2024-10-04 18:10:35 +00:00
Simon Binder f58e0ed8aa Don't suggest references to private enum fields
Some Dart code defines enums with private fields. This is useful to
indicate that the represented values might change in the future, and
should not considered to be exhaustive. Take this enum as an example:

```dart
enum ProtocolVersion {
  v1,
  v2,
  _upcoming,
}
```

When code in a different library is switching over that enum, it can't
use the private member:

```dart
import 'protocol_version.dart';

ProtocolImplementation findImplementation(ProtocolVersion version) {
  return switch (version) {
  	ProtocolVersion.v1 => LegacyProtocol(),
  	ProtocolVersion.v2 => NewProtocol(),
  	// Missing default case
  };
}
```

At the moment, the analysis server would suggest adding a reference to
`ProtocolVersion._upcoming` to fix the switch expression, which is
invalid. The only way to fix the switch is to add a default expression,
which this change introduces instead.

Change-Id: Id38dbf206a25c11dcc53af50e19ac5dd1287637e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/388005
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2024-10-03 23:45:06 +00:00
Parker Lougheed a409a1c07d [analyzer/linter] Use shared enumeration for lint names
This helps to avoid any accidental mispellings, enables find usages, and potentially makes future renames easier.

The primary goal is to make future work in https://github.com/dart-lang/sdk/issues/56835 easier.

Change-Id: I684630a4d6cb145031de0dabc221f247246ea00c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/388042
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Auto-Submit: Parker Lougheed <parlough@gmail.com>
Commit-Queue: Phil Quitslund <pquitslund@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
2024-10-03 21:36:49 +00:00
FMorschel 2fd313b62a fix renaming prefix
Fixes https://github.com/dart-lang/sdk/issues/56809

R=srawlins@google.com

Change-Id: I3df1f42923e7cb6382f7d6ad9875af6bb91a62a6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/387381
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Auto-Submit: Felipe Morschel <fmorschel.dev@gmail.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2024-10-02 20:58:13 +00:00
Fedor Shcheglov 4366f822b6 Issue 56558. Fixed encapsulate_field to work with dynamic and prefixed types.
Bug: https://github.com/dart-lang/sdk/issues/56558
Change-Id: I59cce649a2f7989804e4dfd580cf2041c89fbe3a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/385322
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2024-10-01 16:43:49 +00:00
FMorschel 480756dad3 [DAS] Test for aliased import add show
Fixes https://github.com/dart-lang/sdk/issues/45993

Since the recent change in this class the behaviour is working as intended. Simply added a test to make sure future changes don't break this by mistake.

R=srawlins@google.com

Change-Id: Ie978690ecad0731ace001d74c6ab2dd623681aa5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/387529
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Auto-Submit: Felipe Morschel <fmorschel.dev@gmail.com>
2024-10-01 00:34:43 +00:00
FMorschel 7b502b1e63 Fix extension type import library
Closes https://github.com/dart-lang/sdk/pull/56781

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

GitOrigin-RevId: b6d7b3dab49964bb0fc6e2a3abdc643df5023d97
Change-Id: I708da5d01ccae45cc7d143e4fac365fb2c84e31e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/386701
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2024-09-30 19:44:57 +00:00
FMorschel 6298d95a51 Invert conditional expression assist
Closes https://github.com/dart-lang/sdk/pull/56714

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

GitOrigin-RevId: 7afb370aee8cabaac337ffaaa08248df6d2e1570
Change-Id: I86730c45f2025653bca013f4a81d6ebab06bad3e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/384960
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2024-09-30 19:36:55 +00:00
FMorschel 83c26333a2 [DAS] Consider two lint rules when offering "add import" refactorings
Taking into consideration `prefer_relative_imports` and `always_use_package_imports` for adding import options to the assists list.

When neither is set, both will appear always showing package imports first. If both are set we will treat this as if only `always_use_package_imports` is and show only package imports.

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

R=scheglov@google.com

Change-Id: If2353479de91f50c6c44eb7a17487fb6d0d6f681
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/387500
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Auto-Submit: Felipe Morschel <fmorschel.dev@gmail.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2024-09-30 19:17:36 +00:00
Konstantin Shcheglov e3e0275e2c Elements. Migrate DataDriven.
Change-Id: I355e846224549ca2795fee9f9d2b8ae7a4be32e5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/387351
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2024-09-30 00:48:03 +00:00
Konstantin Shcheglov 4f1161e1d9 Elements. Migrate AddRequiredKeyword.
Change-Id: I82165c4afbade8430e97ef00c1b89181f6de3f6d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/386979
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2024-09-28 16:32:41 +00:00
Konstantin Shcheglov 7d6d5448dc Elements. Migrate AddExplicitCall.
Change-Id: Idccff2640ec19806cfd3231c5c618c5b84950ad8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/386972
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
2024-09-27 18:59:58 +00:00
FMorschel 30a57b2b47 Fix convert to cascade
Closes https://github.com/dart-lang/sdk/pull/56788

GitOrigin-RevId: 7e35273490dd1c99275251577f8a715957170806
Change-Id: I49af5c39267d6b91cfca40b4feb42e1d921a4eeb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/386860
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2024-09-27 16:16:09 +00:00
Konstantin Shcheglov 86c5a93832 Elements. Migrate AddAsync.
Change-Id: I46cc11d3db84b53d873cbf366ccd3db8cbc1f153
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/387143
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2024-09-26 20:24:52 +00:00
Sam Rawlins f84a81002c linter rules: tidy up test support
Just little things:

* Convert the class AnalysisOptionsFileConfig and it's `toContent`
  method into a single function.
* Convert the class PubspecYamlFileConfig and it's `toContent` method
  into a single function.
* Privatize ExpectedDiagnostic fields `diagnosticMatcher`, `offset`,
  `length`, `messageContains`,
  ExpectedError field `codes`,
  ExpectedLint field `lintName`,
  LintRuleTest field `collectionIncludedPaths`,
  _ContextResolutionTest field `sdkRoot`.
* Privatize `writeTestPackageAnalysisOptionsFile` and
  `writeTestPackagePubspecYamlFile`
* Start doc comments with a single-sentence summary (https://dart.dev/effective-dart/documentation#do-start-doc-comments-with-a-single-sentence-summary and https://dart.dev/effective-dart/documentation#do-separate-the-first-sentence-of-a-doc-comment-into-its-own-paragraph)
* Document with third-person verbs (https://dart.dev/effective-dart/documentation#prefer-starting-function-or-method-comments-with-third-person-verbs)

Change-Id: I7d584810cd339f8184fe14c3151b55988bf2cfff
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/386580
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2024-09-26 14:33:04 +00:00
FMorschel dbf87d8644 Improving string conversion
Closes https://github.com/dart-lang/sdk/pull/56723

GitOrigin-RevId: 802fda7efeace66f33a82fa939a3efac11064390
Change-Id: I6d4d3931e62b89265eb1d324856bed5b9febfe8e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/384962
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2024-09-25 21:11:17 +00:00
FMorschel a0374dd70c Fix create method/function inside conditional operator
Closes https://github.com/dart-lang/sdk/pull/56722

GitOrigin-RevId: 9a861d4078b326754b8855e833c52ede03f0e28d
Change-Id: Ia7535ff48c16836b0e7d3a32005051c7defc3766
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/384941
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2024-09-25 20:51:54 +00:00
Danny Tuppeny c8adf3da3f [analysis_server] Update color handling for recent Flutter Color class changes
In https://github.com/flutter/engine/pull/54714 the "int value" that was used for storing the color values for a Flutter color was removed and replaced with `double red, double green` etc.

The color computer used the `value` field so this stopped it from computing any colors for previews in LSP clients. No tests broke because the tests here use a mock version of the Color class that still had `value`.

This change updates the mock Color class to match the new Flutter implementation, and updates the computer to use the red/green/blue doubles instead of parsing from an int.

It also adds support for the new `Color.from()` constructor that was also recently added.

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

Change-Id: I3ff20bda0cc848e028822cfcb5a14e6a8f6934d5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/386802
Commit-Queue: Phil Quitslund <pquitslund@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
2024-09-25 16:27:51 +00:00
Parker Lougheed 46cd8b627c [linter] Move old lint details out of source
- Makes way for slowly replacing them with new "why" docs.
- Slightly reduces snapshot size of analysis server
- Colocates docs in the new linter/messages.yaml file.

Change-Id: I8708b8b55455a183ccfa5c9d8c21098ae0655b51
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/385304
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Auto-Submit: Parker Lougheed <parlough@gmail.com>
2024-09-24 23:06:34 +00:00
Fedor Shcheglov 9f4bb0d654 Issue 56559. Remove @override from private field, add to getter/setter.
Bug: https://github.com/dart-lang/sdk/issues/56559
Change-Id: I57e9c5e286af520499ddddeee5818f1c22a94ee8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/384921
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2024-09-23 18:13:45 +00:00
pq 2c73635d00 [wildcards] fix ConvertToWildcardVariable to convert variable references
Change-Id: Ie9b9d03adf11bf2e18d5a3da6e28be8abf4eb53d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/384943
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Phil Quitslund <pquitslund@google.com>
2024-09-23 16:53:11 +00:00
FMorschel 26a035d692 Fix remove-unnecesary-parentheses quick-fix false negative
Closes https://github.com/dart-lang/sdk/pull/56746

GitOrigin-RevId: 3e296b4b88b91d671e4e061ae8613f9b09d7f2f5
Change-Id: Ib174df2b3d825129c22eab71f2c7f38d88a66781
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/385382
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2024-09-23 15:04:44 +00:00
FMorschel 00a1608bd8 Add fix for use_colored_box
Closes https://github.com/dart-lang/sdk/pull/56702

GitOrigin-RevId: 1e043e03da0b43f7f7ab3365f16fe557689a712c
Change-Id: I7fff9c1d0f7c479890625b16b3beed449d504436
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/384662
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Phil Quitslund <pquitslund@google.com>
2024-09-17 18:37:54 +00:00
Parker Lougheed 4819bd09aa [analyzer/linter] Deprecate LintRule.details to avoid new usages
Change-Id: I3d03d5f06901e0a548020522387e8984507a7f4c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/384940
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
2024-09-13 18:13:26 +00:00
pq 86306b194e fix test expectation doc typo
Change-Id: I57aeac20269a2527e81822a550d483ab34064c6c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/385081
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Phil Quitslund <pquitslund@google.com>
Auto-Submit: Phil Quitslund <pquitslund@google.com>
2024-09-12 22:18:46 +00:00
Sam Rawlins b1416116b7 analyzer: rename most API references to 'plugins' to 'legacy plugins'
Change-Id: I56217045ff9d4da8a5a556cd709e0f63a507884f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/384964
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2024-09-12 21:25:56 +00:00
Danny Tuppeny 0ed690798d [analysis_server] Replace URI fields in tests with getters to avoid having to set all paths twice
This is a minor refactoring to swap some fields for URIs to getters so that any tests that modify them don't have to set both a path and URI (or risk them being out-of-sync).

Change-Id: Ic3776d250f4cfd9b0f16a7fc578ab5e7f19e52a9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/384762
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2024-09-11 20:14:23 +00:00
pq c386f13a83 [enhanced-parts] Code Folding tests
Fixes: https://github.com/dart-lang/sdk/issues/56696

Bug: https://github.com/dart-lang/sdk/issues/56696
Change-Id: I20011f1c60bab29d8ed6e78be70b6f807dce03f9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/384560
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Phil Quitslund <pquitslund@google.com>
2024-09-11 17:33:51 +00:00
Sam Rawlins 5ee4eb52e6 DAS plugins: Add plugin package generator
This generator will be used create shared plugin package entrypoints from
plugin configurations.

Work towards https://github.com/dart-lang/sdk/issues/53402

Change-Id: If5c6aeb7bc7845311975928fba1cb9c8d273423c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/384681
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2024-09-11 16:54:29 +00:00
Paul Berry cda2815bb1 Add UNREACHABLE_SWITCH_DEFAULT warning to the analyzer.
This warning is similar to the existing `UNREACHABLE_SWITCH_CASE`
warning, except that it warns if the `default` clause of a switch
statement is unreachable due to all the `case` clasuses fully
exhausting the switched type.

To make the implementation easier, I changed the API for the
`reportExhaustiveness` method in `_fe_analyzer_shared` (which is the
primary entry point to the shared exhaustiveness checker). Previously,
this method returned a list of `ExhaustivenessError`, where each list
element was either an `UnreachableCaseError` (indicating that a
certain case was unreachable) or a `NonExhaustiveError` (indicating
that the entire switch statement was not exhaustive). If the caller
passed in `false` for `computeUnreachable`, `UnreachableCaseError`s
would not be returned, so the returned list would either be empty or
contain a single `NonExhaustiveError`.

The new API renames the types for clarity:

- `NonExhaustiveError` becomes `NonExhaustiveness`, to highlight the
  fact that it's not necessarily an error for the switch's cases to be
  non-exhaustive; it's only an error if the scrutinee's static type is
  an "always exhaustive" type and there is no `default` clause.

- `UnreachableCaseError` becomes `CaseUnreachability`, to highlight
  the fact that it's not an error for a case to be unreachable; it's a
  warning.

Also, the new API adds instances of `CaseUnreachability` to an
optional user-provided list instead of returning a newly created list;
this allows callers to communicate that they don't need to see
`CaseUnreachability` information by passing `null`. This frees up the
return type to simply be an instance of `NonExhaustiveness` (if the
cases are not exhaustive) or `null` (if they are exhaustive). This
makes it easier for the analyzer to decide whether to issue the new
warning, because it doesn't have to dig around the list looking for an
instance of `NonExhaustiveness`.

The new warning has an associated quick fix (remove the unreachable
`default` clause). This quick fix uses the same `RemoveDeadCode` logic
in the analysis server that the existing `UNREACHABLE_SWITCH_CASE`
warning uses.

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

Bug: https://github.com/dart-lang/sdk/issues/54575
Change-Id: I18b6b7c5249d77d28ead7488b4aae4ea65c4b664
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/378960
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Erik Ernst <eernst@google.com>
2024-09-10 19:13:12 +00:00
pq 1bdb366d4d [enhanced-parts] test “Organize Imports”
Fixes: https://github.com/dart-lang/sdk/issues/56683

Change-Id: I6b6aae385d4313e551f7c110e1e2544cc418a5a8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/384308
Commit-Queue: Phil Quitslund <pquitslund@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Auto-Submit: Phil Quitslund <pquitslund@google.com>
2024-09-10 17:23:40 +00:00
Danny Tuppeny ffeadc947a [analysis_server] Fix sorting of different kinds of imports in DartFileEditBuilder.importLibrary
Previously any pending imports added by DartFileEditBuilder would just be sorted by their text ignoring the kind of import. If there were existing imports for dart, package, relative then they might be inserted in the right places, but if there were not (or not the right kind) of existing imports, they would be just be added in alphabetical order (rather than dart, then package, then relative).

This change extracts some of the rules for sorting directives from analysis_server's ImportOrganizer into analyzer_plugin/src so that they can be reused by the DartFileEditBuilder that lives there.

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

Change-Id: I6dc5476add2b7b1804080ffdc8270d0bb80597db
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/384284
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2024-09-10 14:43:58 +00:00
Fedor Shcheglov 4a7f9c87e2 Issue 56682. Add break for empty cases when converting if chain into switch.
Bug: https://github.com/dart-lang/sdk/issues/56682
Change-Id: Iafc1154801ec207152104b9b064f2b587a13ac4b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/384306
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2024-09-09 22:49:51 +00:00
Fedor Shcheglov bbc642e6c1 Issue 56371. Quick assist from switch to if statements chain without unnecessary break statements.
Bug: https://github.com/dart-lang/sdk/issues/56371
Change-Id: I826f6f8fa1e9b5123ff8aa1d637d5da1ff63a09a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/383931
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2024-09-09 15:58:39 +00:00
Fedor Shcheglov 4aaca0b4c0 Issue 56413. Consider prefer_int_literals in 'Wrap with Padding'.
Bug: https://github.com/dart-lang/sdk/issues/56413
Change-Id: I0e4aa2a53a2387caa4ad451e7033767c1b180436
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/384100
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2024-09-06 20:24:48 +00:00
Konstantin Shcheglov 4855fed15b Parts. Report UNNECESSARY_IMPORT using the new tracking.
Change-Id: Ide8f003bdfb1c80f1e342d3742b538edfda6ad8b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/382901
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2024-09-05 22:16:21 +00:00
Honza Bittner 18466983ac feat: make remove widget work for slivers
Closes https://github.com/dart-lang/sdk/pull/56638

GitOrigin-RevId: 835dd143a7b56a9249d4d48da5de4253c57bee21
Change-Id: If0fd507b51a224770cf724568925fa895bfa3e20
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/383201
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Phil Quitslund <pquitslund@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
2024-09-05 22:13:30 +00:00
Konstantin Shcheglov 67c21f7b67 Migrate from 'import augment' to 'part' in analysis_server/.
Change-Id: Iac57024ab48ed389b4578bc0fb2a2e620533812b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/383420
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Keerti Parthasarathy <keertip@google.com>
2024-09-03 19:45:55 +00:00
Konstantin Shcheglov 957699fba9 Revert "Parts. Track used imports while resolving library files. #v2"
This reverts commit b3cdad286f.

Reason for revert: https://github.com/flutter/flutter/issues/154413 - there is a test in Flutter that expects UNUSED_IMPORT that we don't report anymore.

Original change's description:
> Parts. Track used imports while resolving library files. #v2
>
> TGP looks green.
> https://fusion2.corp.google.com/presubmit/668751751/OCL:668751751:BASE:669923082:1725204615406:830df8a3/targets
>
> Previous: https://dart-review.googlesource.com/c/sdk/+/382680
> Revert: https://dart-review.googlesource.com/c/sdk/+/382903
> Change-Id: Idbca23a13cf5c7490aa8bc859e21609c6241951e
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/383022
> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>

Change-Id: I2825dae66db0b7eaef1b86511ce1eb9b958d8b20
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/383380
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2024-09-03 16:40:20 +00:00
Sam Rawlins 94eef72b7d Move lint rule category mappings to messages.yaml
Cq-Include-Trybots: luci.dart.try:flutter-analyze-try,analyzer-win-release-try,pkg-win-release-try
Change-Id: Ie15fbe4d442ced91540f7653888882691bbb4ec1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/382780
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2024-09-02 23:19:10 +00:00
Konstantin Shcheglov 8de1422a0e Parts. Deprecate Element.enclosingElement, use enclosingElement3.
Change-Id: Iadc4ed02d4bda3b882e65dc6f4d263a6a938e0fe
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/382920
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2024-09-01 18:50:29 +00:00
Konstantin Shcheglov b3cdad286f Parts. Track used imports while resolving library files. #v2
TGP looks green.
https://fusion2.corp.google.com/presubmit/668751751/OCL:668751751:BASE:669923082:1725204615406:830df8a3/targets

Previous: https://dart-review.googlesource.com/c/sdk/+/382680
Revert: https://dart-review.googlesource.com/c/sdk/+/382903
Change-Id: Idbca23a13cf5c7490aa8bc859e21609c6241951e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/383022
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2024-09-01 15:58:39 +00:00
Konstantin Shcheglov 70aed6a93c Revert "Parts. Track used imports while resolving library files."
This reverts commit 49c6679e4a.

Reason for revert: breaks google3

Original change's description:
> Parts. Track used imports while resolving library files.
>
> Change-Id: Ic23ec9ca49d93382449bfe2650089eb43099c3e4
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/382680
> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>

Change-Id: Ia954aea30c6ef61197ddaeca53a5179745c30908
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/382903
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
2024-08-30 13:56:36 +00:00
Danny Tuppeny a0411ae244 [analysis_server] Prevent duplicate completions for extensions for libraries that import them
Fixes https://github.com/dart-lang/sdk/issues/56320

Change-Id: I4645165857c082cb26ac09eb12df3106769fb25a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/382821
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2024-08-29 17:11:33 +00:00
Konstantin Shcheglov 49c6679e4a Parts. Track used imports while resolving library files.
Change-Id: Ic23ec9ca49d93382449bfe2650089eb43099c3e4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/382680
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2024-08-29 16:19:11 +00:00