Commit Graph

6984 Commits

Author SHA1 Message Date
Keerti Parthasarathy c78b8a5cc2 [Code completion] Move suggesting field from SuggestionBuilder to DeclarationHelper.
Also deleted unused class MemberSuggestionBuilder.

Change-Id: Ibe64963e342e4b0be822fbd25826159276a3d41e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/382442
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Keerti Parthasarathy <keertip@google.com>
2024-08-28 21:11:16 +00:00
Danny Tuppeny 8ca61608d8 [analysis_server] Add an allow-list for LSP methods exposed over DTD
Before exposing existing LSP methods we need to provide a way for DTD clients to always get the same format responses regardless of the client capabilities provided by the original server. Until then, add an allow-list for LSP methods that we can use to selectively enable specific methods that are not affected by client capabilities.

Change-Id: Ia1c994a50c9b94a91f4085c09f9d9d94c0fad79e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/382401
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Keerti Parthasarathy <keertip@google.com>
Commit-Queue: Keerti Parthasarathy <keertip@google.com>
2024-08-27 16:50:15 +00:00
Fedor Shcheglov a5cfca1b48 Issue 56572. Fix suggesting extension methods on record types.
Bug: https://github.com/dart-lang/sdk/issues/56572
Change-Id: I47e4b07270843ffb53ab90963e04f01b3b105043
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/382261
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2024-08-26 21:18:56 +00:00
Danny Tuppeny da414c2957 [analysis_server] Allow passing a DTD URI to the analysis server so it can provide LSP functionality to DTD clients
This adds a new request `dart/connectToDtd` that lets a client pass a DTD URI to the server. The server will connect to DTD and provide a subset of LSP methods (those that are currently available over LSP-Over-Legacy, minus the `connectToDtd` method itself) to DTD clients.

This works for both LSP and Legacy servers, and the shared tests run against both (where for legacy, the `dart/connectToDtd` request uses the LSP-over-Legacy support).

This is not currently behind a flag, however it won't do much on its own because no clients will make this request. Once we're happy the functioanlity is good we can either agree an SDK version number for IDEs to gate calling this method on, or we can expose a flag in server capabilities (and some equiv for legacy) so the client knows the functionality is available.

Change-Id: I911d37745a1b2685249dd88e4b152c3196ba627c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/379303
Commit-Queue: Keerti Parthasarathy <keertip@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Keerti Parthasarathy <keertip@google.com>
2024-08-22 20:43:41 +00:00
Keerti Parthasarathy ffd9004314 [Code completion] Move checks to when suggestions are created for static fields.
Change-Id: Iaf11cd7cad225859d7731acd4eb0d3a94076eb4c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/381700
Commit-Queue: Keerti Parthasarathy <keertip@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2024-08-21 17:19:29 +00:00
Keerti Parthasarathy f1a0c38af5 [Code completion]Compute completion string for ConstructorSuggestion.
Change-Id: Ic061c0bc04a777c10447df03c70403442f4b9841
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/381310
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Keerti Parthasarathy <keertip@google.com>
2024-08-21 15:58:32 +00:00
Danny Tuppeny a76ff6b2cf [analysis_server] Add failing tests for analyzer plugin issue
This adds failing tests for https://github.com/dart-lang/sdk/issues/56475.

If this CL is applied to the 3.5 release and the `singleOptionContexts` flag set back to `true` (matching 3.4 behaviour), the tests will pass. Each package in both tests will get its own context root (because they have analysis_options to enable the plugins) and each one will read the correct plugins that are enabled.

However if `singleOptionContexts` is `false` (as shipped in 3.5) or this code is applied to bleeding-edge (where the flag is gone, but behaves the same as `false`) both tests fail as follows:

`test_sentToPlugins_inNestedPackages_withPackageConfigs` fails because we read the child analysis_options for the root and try to incorrectly load plugins from the root (and include duplicates and allow more than one plugin):

```
  Expected: {
              'package1': ['plugin1'],
              'package2': ['plugin2'],
              'package3': ['plugin1']
            }
    Actual: {
              'home': ['plugin1', 'plugin2', 'plugin1'],
              'package1': ['plugin1', 'plugin2', 'plugin1'],
              'package2': ['plugin1', 'plugin2', 'plugin1'],
              'package3': ['plugin1']
            }
```

`test_sentToPlugins_inNestedPackages_withoutPackageConfigs` fails because we now only have a context root for the root which enables all plugins from the children:

```

  Expected: {
              'package1': ['plugin1'],
              'package2': ['plugin2'],
              'package3': ['plugin1']
            }
    Actual: {
              'home': ['plugin1', 'plugin2', 'plugin1']
            }
```
Change-Id: I12f45eeb5c1848352af26ac3fdb690e51833c22a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/381460
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2024-08-20 20:13:57 +00:00
pq 6413386f29 [wildcards] improve _ type param handling
See: https://github.com/dart-lang/sdk/issues/56361

Change-Id: Ic3be09014afc095490d9332bd124843b5a65e1cd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/381385
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Phil Quitslund <pquitslund@google.com>
2024-08-20 17:07:33 +00:00
Sam Rawlins 5ce0cc571c analyzer: correct wording of "always null" and "never null" warning
Fixes https://github.com/dart-lang/sdk/issues/53670

Cq-Include-Trybots: luci.dart.try:flutter-analyze-try,analyzer-win-release-try,pkg-win-release-try
Change-Id: I5e890e990d128754b8d9a89e8e940c756779a602
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/381100
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2024-08-19 16:14:28 +00:00
Paul Berry 7f5a698514 UNREACHABLE_SWITCH_CASE: Remove HintCode in favor of WarningCode.
Previously, `HintCode.UNREACHABLE_SWITCH_CASE` was marked as
deprecated, and `WarningCode.UNREACHABLE_SWITCH_CASE` was an alias to
it. This created a slightly confusing situation, because it meant that
all code referring to the diagnostic had to refer to it as
`WarningCode.UNREACHABLE_SWITCH_CASE` (to avoid a deprecation lint),
but the diagnostic still _behaved_ like it was a hint, and therefore
test runner expectations still had to treat it as a hint.

It turns out that it's not really necessary to go through the
deprecation dance when changing the kind of a diagnostic, since (a)
members of `HintCode` and `WarningCode` aren't exposed through the
analyzer public API, and (b) ignore comments don't have to specify
whether something is a hint or a warning.

So the easiest way to clear up the confusion is to just remove
`HintCode.UNREACHABLE_SWITCH_CASE` entirely, and move its implemention
into `WarningCode.UNREACHABLE_SWITCH_CASE` (so that the latter is no
longer an alias).

Change-Id: I9ff7901ad38a2c168c5e54cbe0c1c52bf7c50186
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/381103
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2024-08-19 16:09:14 +00:00
Keerti Parthasarathy 738e65bb98 [Code completion] Add a SetStateMethodSuggestion for completions of the setState method.
Change-Id: I86a0955d45a7d62b3063c9683c883c47fe5a88dd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/380964
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Keerti Parthasarathy <keertip@google.com>
2024-08-16 18:43:04 +00:00
Keerti Parthasarathy 334a131c0a [dart fix] Catch exception when parsing pubspecs.
Fixes https://github.com/dart-lang/sdk/issues/56473.

Change-Id: I4b69a74c4d0f129ff25a074104b80c6b75e96e9b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/380076
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Keerti Parthasarathy <keertip@google.com>
2024-08-16 18:17:10 +00:00
Paul Berry eb887c28bf Fix dead code removal when multiple cases share a body.
Fixes https://github.com/dart-lang/sdk/issues/56485.

Bug: https://github.com/dart-lang/sdk/issues/56485
Change-Id: Idea150d9b00bdf90ecff184da14ecbdbe5902a30
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/380901
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2024-08-16 14:19:28 +00:00
Sam Rawlins fbf62c12c2 DAS: Add assist to remove digit separators from number literal
Fixes https://github.com/dart-lang/sdk/issues/56467

Cq-Include-Trybots: luci.dart.try:flutter-analyze-try,analyzer-win-release-try,pkg-win-release-try
Change-Id: I711d0d483db0e61f907c884e33fb7511168dde2d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/380686
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2024-08-16 00:43:38 +00:00
Keerti Parthasarathy 3ae45511b5 [Code completion] Move info needed from SuggestionBuilder to ClosureCandidateSuggestion.
Change-Id: Id93b8d4780377de0980fb189172d0ad21261ab1f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/380603
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Keerti Parthasarathy <keertip@google.com>
2024-08-15 18:11:22 +00:00
Halil Durmus 840729a90a [analysis_server] Show library documentation when hovering over unnamed
library directives

Closes: https://github.com/dart-lang/sdk/issues/53476
Change-Id: I33a8e0ebd3ed7999eba71985fabb90c17444bde6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/380520
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2024-08-14 21:53:52 +00:00
Sam Rawlins 5a7b16ba4c DAS: introduce some assists that add digit separators to number literals
Work towards https://github.com/dart-lang/sdk/issues/56467

Thw two assists do the following:

* Add a digit separators every 3 digits in a decimal int, a decimal
  double, and a scientific notation double.
* Add a digit separators every 2 digits in a hexadecimal int.

No assists are introduced which remove digit separators.

Cq-Include-Trybots: luci.dart.try:flutter-analyze-try,analyzer-win-release-try,pkg-win-release-try
Change-Id: I0920fb279285963c33a78d9288317213739ae83b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/380601
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2024-08-14 20:22:47 +00:00
Erik Ernst 5b7c600d8b Implement the lint 'specify_nonobvious_local_variable_types'
This lint is the complement of 'omit_obvious_local_variable_types'
in that it flags every declaration that does _not_ specify the type
of a local variable, when it has an initializing expression whose type
is not obvious (defined as in 'omit_obvious_local_variable_types').

Change-Id: If80a961e47fed0412d0ea0bac5ac010e26fea7bc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/379160
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Erik Ernst <eernst@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
2024-08-13 09:43:49 +00:00
Konstantin Shcheglov 4cea10fbf0 Parts. Report PART_OF_NAME when Feature.enhanced_parts is enabled.
Change-Id: I85925218b37a7cb65a7b50da6cc968155fd4789e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/380043
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2024-08-12 20:11:06 +00:00
Konstantin Shcheglov 0d634d9bac CQ. Remove unnecessary 'default' cases.
Change-Id: I891c469a3580e2886c64b64dd4240729970758c8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/379677
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
2024-08-09 15:57:20 +00:00
Parker Lougheed 1f4f0d386a [linter] Generate lint codes from messages file
Change-Id: Id4f7ee5843a4063d1e527c1566847d88b355c614
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/373725
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Phil Quitslund <pquitslund@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2024-08-08 19:24:30 +00:00
Danny Tuppeny 6411c07255 [analysis_server] Refactor initialization of LSP in both servers in preperation for DTD support
This change is just some refactoring and additional flags on handlers to reduce the size of a future CL that adds DTD support.

It:

- Slightly changes the meaning of `lspInitialized` in the server (to now mean the server is in the "initialized" state where it can handle the set of requests LSP allows after a server is initialized)
- Adds an additional future for `lspUninitialized` to track when the server moves _out_ of that state
- Removes an expando in LspOverLegacyHandler that tracked handlers against a server, because they're now available in the `lspInitialized` future (for DTD support, we need access to them without the LSP-over-Legacy handler, because we need to initialize DTD at startup regardless of whether a legacy client triggers LSP initialization)
- Adds a flag `requiresTrustedCaller` to handlers to indicate whether they can only be called by the native protocol clients. Tthis must be explicitly provided for shared handlers to ensure each choice is deliberate. The flag is unused in this CL but included here to reduce noise in the next (it touches many files)
- Changes the type of `toJson()` on generated enum clases to have the native type of the value that is returned

Change-Id: I0615cf4671b84887bf56c236d82d0fa3c26e6d87
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/379304
Commit-Queue: Keerti Parthasarathy <keertip@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Keerti Parthasarathy <keertip@google.com>
2024-08-07 21:51:15 +00:00
Daco Harkes 965234ccbe [vm/ffi] Variable length inline arrays
Adds a new `@Array.variable()` to specify that the last element of
structs is a variable length inline array.

This CL does not add any checks for passing structs with variable
length inline arrays by value or directly calling them with
`AllocatorAlloc.call`. Instead, the implementation defaults to what
C does, allocate as if there are 0 elements in the variable length
inline array.

TEST=tests/ffi/*

CoreLibraryReviewExempt: VM only
Closes: https://github.com/dart-lang/sdk/issues/55964
Change-Id: I524d8a1d710b1a744b392e05fa884908c3ff1f12
Cq-Include-Trybots: dart/try:vm-aot-android-release-arm64c-try,vm-aot-android-release-arm_x64-try,vm-aot-asan-linux-release-x64-try,vm-aot-linux-debug-x64-try,vm-aot-linux-debug-x64c-try,vm-aot-mac-release-arm64-try,vm-aot-mac-release-x64-try,vm-aot-msan-linux-release-x64-try,vm-aot-obfuscate-linux-release-x64-try,vm-aot-optimization-level-linux-release-x64-try,vm-aot-tsan-linux-release-x64-try,vm-aot-ubsan-linux-release-x64-try,vm-aot-win-debug-arm64-try,vm-aot-win-debug-x64-try,vm-aot-win-debug-x64c-try,vm-appjit-linux-debug-x64-try,vm-asan-linux-release-arm64-try,vm-asan-linux-release-x64-try,vm-checked-mac-release-arm64-try,vm-eager-optimization-linux-release-ia32-try,vm-eager-optimization-linux-release-x64-try,vm-ffi-android-debug-arm-try,vm-ffi-android-debug-arm64c-try,vm-ffi-qemu-linux-release-arm-try,vm-ffi-qemu-linux-release-riscv64-try,vm-fuchsia-release-arm64-try,vm-fuchsia-release-x64-try,vm-linux-debug-ia32-try,vm-linux-debug-x64-try,vm-linux-debug-x64c-try,vm-mac-debug-arm64-try,vm-mac-debug-x64-try,vm-msan-linux-release-arm64-try,vm-msan-linux-release-x64-try,vm-reload-linux-debug-x64-try,vm-reload-rollback-linux-debug-x64-try,vm-tsan-linux-release-arm64-try,vm-tsan-linux-release-x64-try,vm-ubsan-linux-release-arm64-try,vm-ubsan-linux-release-x64-try,vm-win-debug-arm64-try,vm-win-debug-x64-try,vm-win-debug-x64c-try,vm-win-release-ia32-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/371960
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Lasse Nielsen <lrn@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2024-08-06 07:50:49 +00:00
Sam Rawlins 093d867a0c analyzer: Remove DIVISION_OPTIMIZATION hint
This is replaced by the use_truncating_division lint rule.

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

Cq-Include-Trybots: luci.dart.try:flutter-analyze-try,analyzer-win-release-try,pkg-win-release-try
Change-Id: Ied034267f4f8e5ea70ed0b4a21c39e88c88240ec
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/378574
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2024-08-03 02:47:41 +00:00
Sam Rawlins b946c47ec9 new lint rule: use_truncating_division
Fixes https://github.com/dart-lang/linter/issues/3930

This allows us to remove (softly) the DIVISION_OPTIMIZATION HintCode,
which was not deemed a good candidate for a Warning.

Cq-Include-Trybots: luci.dart.try:flutter-analyze-try,analyzer-win-release-try,pkg-win-release-try
Change-Id: Iac48c94687d0b6b32c971e9f366ccb96adf34429
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/378543
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2024-08-02 22:31:19 +00:00
pq 3b09a49ce5 [wildcards] ensure bound __ underscores are suggested in completions
See: https://github.com/dart-lang/sdk/issues/56361

Change-Id: Ia1b1a0fef17fb68f476d2ade96a0b5761152336b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/378720
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Phil Quitslund <pquitslund@google.com>
2024-08-02 17:17:59 +00:00
pq 6b16fab819 [wildcards] completion suggestion support
See: https://github.com/dart-lang/sdk/issues/56361

To follow, a bunch of tests to make sure `__`, `___`, etc are not incorrectly getting special cased.

Change-Id: I3d35a5344e09011460c074fdd43eccdac452a8ad
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/378623
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Phil Quitslund <pquitslund@google.com>
2024-08-02 14:51:14 +00:00
Sam Rawlins ed622c5300 DAS: Move FixInFileProcessor to analysis_server_plugin
Also move the top-level `computeFixes` convenience function.

The `computeFixes` function is the main entrypoint that various code
uses to, well, compute all fixes with a FixProcessor and a
FixInFileProcessor. In order for plugin code to call `computeFixes`,
we need that function and FixInFileProcessor in the
analysis_server_plugin package.

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

Cq-Include-Trybots: luci.dart.try:flutter-analyze-try,analyzer-win-release-try,pkg-win-release-try
Change-Id: Id5f02864762eeefb92055a3534e91b60b76dfeb2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/378220
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2024-07-31 19:16:27 +00:00
Danny Tuppeny 1e64108971 [analysis_server] Fix == overrides being truncated in LSP
The LSP completion mapping currently does some manipulation of values to fit better into the different fields LSP supports (to improve formatting and filtering). The code that splits the label on `=>` was also matching `==` in overrides but should not.

This is a simple fix to the regex to solve the issue, although longer-term (or at least if we see other issues as a result of this manipulation) this logic should be pushed up to the source so we have reliable fields and don't need to split things this way.

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

Change-Id: I056489df5aba417cab9162e027eb97579f71756b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/378200
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Phil Quitslund <pquitslund@google.com>
2024-07-31 17:37:10 +00:00
Danny Tuppeny 5c064b125a [analysis_server] Handle token differences like GT_GT_GT vs GT,GT,GT when minimizing edits from the formatter
This generalizes the code that was handling `[`+`]` being replaced with a single token for `[]` to support arbitrary substitutions (and in both directions) to handle where GTs can be moved by the formatted (usually because of differences in wrapping of type parameters).

Change-Id: Ia7d75637fa5506a33db1e91111ab3b7fc060f3ce
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/377647
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2024-07-31 14:26:49 +00:00
Danny Tuppeny f657b8b344 [analysis_server] Support "Go to type definition" for identifiers declared in "for in" loops
Fixes https://github.com/Dart-Code/Dart-Code/issues/5205

Change-Id: I9d28708c2df87771ab4d25786827fcd9dc91819d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/378040
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Phil Quitslund <pquitslund@google.com>
2024-07-30 22:59:29 +00:00
Sam Rawlins 34ad8e075e Move FixProcessors and registeredFixGenerators to analysis_server_plugin
These two are needed in the shared package so that plugins can run
CorrectionProducers. They go in 'src' because plugin developers do not
need to see this code.

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

Cq-Include-Trybots: luci.dart.try:flutter-analyze-try,analyzer-win-release-try,pkg-win-release-try
Change-Id: Iee5b5dd063d5b0a9b00c58b91a3e50328c8b5fc2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/377860
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2024-07-30 21:17:13 +00:00
Danny Tuppeny c18b84d6d2 [analysis_server] Fix handling of "Do not show again" on Dart fix prompt
A recent change to support in-editor "dart fix" changed the switch expression here in a way that the handling of "Do not show again" no longer matched and apparently this case had no test 😔

This fixes the check and adds the missing test.

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

Change-Id: I4fe182824a103d77b88e3a84d941f722f071f117
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/377940
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2024-07-30 19:58:57 +00:00
Danny Tuppeny 50673638de [analysis_server] Refactor computing minimal edits from formatting changes
This is a refactor with no functional changes.

The function to compute minimal edits for formatting changes has grown a lot over time and was very long with many nested functions making it difficult to maintain. Additional fixes I'm working on (to handle token changes between consecutive GT tokens and GT_GT or GT_GT_GT) add more to it, so this is an attempt to simplify it by moving it into a class and extracting the nested helper functions to make the logic easier to follow.

I'm pushing this to Gerrit in multiple patch sets in case it's easier to review:

1. Move the function (unchanged) into a class
2. Tidy up the logic slightly to use class variables (so helpers that were using local variables can be extracted later)
3. Move the nested functions (and some private top-level functions) to the class level

Change-Id: I277b458c8e4780ea02629f8cba80db683057ae90
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/377646
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2024-07-30 19:38:08 +00:00
Sam Rawlins f4423e61ec Remove 4 old HintCodes, all replaced with WarningCodes
* UNNECESSARY_CAST
* UNUSED_ELEMENT
* UNUSED_ELEMENT_PARAMETER
* UNUSED_LOCAL_VARIABLE

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

Cq-Include-Trybots: luci.dart.try:flutter-analyze-try,analyzer-win-release-try,pkg-win-release-try
Change-Id: I15c74e5ebc626f7e513c04013aa2f81b36ca39a8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/377762
Reviewed-by: Nate Bosch <nbosch@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2024-07-29 18:55:49 +00:00
Sam Rawlins 3e58529caa DAS: Separate out registered fix generators into their own file
Work towards https://github.com/dart-lang/sdk/issues/53402

I move them all out of static fields on FixProcessor to be instance
fields on a singleton class in a new file, fix_generators.dart. For
each one that ended in the word 'Map', I removed that.

I also move `_bulkFixableErrorCodes` and `canBulkFix` to
BulkFixProcessor, as it is the only caller, and holds onto the data.

I also correct some outdated doc comments.

I also make `_isFixableError` static.

Cq-Include-Trybots: luci.dart.try:flutter-analyze-try,analyzer-win-release-try,pkg-win-release-try
Change-Id: I01beccac4969f832941c75eb6d7b49b54a0b085c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/377563
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2024-07-29 13:59:59 +00:00
Danny Tuppeny fc4caff49b [analysis_server] Allow formatter changes to remove semicolons (and consecutive allowed tokens)
As well as commas, the formatter can remove semicolons from enums. Additionally, it can remove adjacent commas and semicolons! This adds support for both, by simplifying the check to have a set of allowed tokens, and looping to check again after it advances over any tokens.

Change-Id: I17a1172c803d579f01c801a372a69226d1dc3277
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/377643
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2024-07-26 16:23:48 +00:00
Sam Rawlins 77bf16396e DAS: Simplify and modernize BulkFixProcessor
* Re-implement `PubspecFixRequestResult` as a Record.
  This was a class with two final fields, and the class is always
  immediately deconstructed, so it seems like a fine case for a
  Record. That being said, if this is "surprising", we can go back to
  a full class. I don't think there is a performance change; just API.
* 4 fields and 1 method on BulkFixProcessor can be private. Making one
  of these private enables promotion, removing the need for local
  shadowing variables.
* 2 fields on BulkFixProcessor can be visibleForTesting.
* 6 fields and 1 getter on IterativeBulkFixProcessor can be made
  private.
* Update doc comments to be more idiomatic.

Cq-Include-Trybots: luci.dart.try:flutter-analyze-try,analyzer-win-release-try,pkg-win-release-try
Change-Id: I45ba8cbd428e281727cfc4dfba712be72d3325f7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/377622
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2024-07-25 19:20:47 +00:00
Danny Tuppeny b8c5f81367 [analysis_server] Handle minimizing formatting edits that remove trailing spaces from comments
When formatting over LSP, we run the formatter (which produces an entire new set of formatted code) and compare the unformatted/formatted code to try and produce minimal edits for the format. This allows things like breakpoints to remain stable in the editor (whereas replacing the entire content might cause them to be lost).

The algorithm we use to do this is a very simple diff on the token stream that assumes only whitespace (and commas) will change. If we find another difference, we fall back to just sending the entire document edit.

Another place this happens is when the formatter changes whitespace within comments (removing trailing spaces). That whitespace is not between tokens, but part of the comments. This change handles that by allowing entire comments to be replaced when the contents is different (stripped of any matching prefix/suffix).

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

Change-Id: I675f2b00aaa5ea07088d653ec746524f4166598b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/377424
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2024-07-25 17:08:40 +00:00
Danny Tuppeny 867611b4f1 [analysis_server] Prevent the InlayHints handler from locking requests when obtaining a resolved unit
Instead, obtain a resolved unit and then verify the versions still match (and if not, reject the request as stale).

This doesn't eliminate the possibility of a deadlock because the completion handler still does the same - however it's much less likely that completion is running during server initialization (whereas inlay hints for an open file can happen early) and rejecting requests during typing may have more of an impact there (where the user is often typing, and the editor may be compensating for their changes, so a "stale" response may be better than constantly restarting).

If we make changes to scheduling on the server, the ability to pause incoming _requests_ without also pausing incoming _responses_ may provide the best of both worlds here.

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

Change-Id: I34412356da444e8c57f38ebe0d821c805179b0b2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/377642
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2024-07-25 14:41:58 +00:00
Sam Rawlins fff7b0589c DAS: Re-map other LintNames-based maps
These maps can now just be oriented around the LintCodes.

Cq-Include-Trybots: luci.dart.try:flutter-analyze-try,analyzer-win-release-try,pkg-win-release-try
Change-Id: Ie4e88c61a4d55dbd6d184541cc80aa4893d2ef69
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/377267
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2024-07-25 02:33:19 +00:00
Danny Tuppeny 3fffa7139d [analysis_server] Handle callable classes and function expressions for LSP Signature Help
Fixes https://github.com/Dart-Code/Dart-Code/issues/5153.

Change-Id: I4335c2378c4e863a38d2f802ff1618b23917ba7d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/377460
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2024-07-24 22:59:32 +00:00
Danny Tuppeny b1f0b08c9b [analysis_server] When formatting, handle differences in token streams where an empty collection was unwrapped
When formatting over LSP, we run the formatter (which produces an entire new set of formatted code) and compare the unformatted/formatted code to try and produce minimal edits for the format. This allows things like breakpoints to remain stable in the editor (whereas replacing the entire content might cause them to be lost).

The algorithm we use to do this is a very simple diff on the token stream that assumes only whitespace (and commas) will change. If we find another difference, we fall back to just sending the entire document edit.

One case where this currently happens is when an empty collection contains whitespace and is collapsed (eg. `[\n]` becomes `[]`). It goes from being two tokens to a single token. This change adds support for that by stepping over the two tokens on the left and one token on the right so that we produce the right result.

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

Change-Id: Ice61ad92a372844445924cece009d31c98b38d60
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/377443
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2024-07-24 16:49:42 +00:00
Danny Tuppeny 822b1f2444 [analysis_server] Don't use full-document-format as a fallback when failing to produce minimal edits for range formatting
When formatting over LSP, we run the formatter (which produces an entire new set of formatted code) and compare the unformatted/formatted code to try and produce minimal edits for the format. This allows things like breakpoints to remain stable in the editor (whereas replacing the entire content might cause them to be lost).

The algorithm we use to do this is a very simple diff on the token stream that assumes only whitespace (and commas) will change. If we find another difference, we fall back to just sending the entire document edit.

In the case where the request was to format a _range_ sending back an entire formatted document is never correct, so this changes the handling to return no edits at all if the request was to format a range.

Fixes https://github.com/Dart-Code/Dart-Code/issues/5169 (to not format the entire document) but does not fix the issue that formatting empty collections produces unexpected differences in token streams - that will be fixed in another CL.

Change-Id: Ibaef49a2800d300606f5132e912c9d30b33cb18a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/377422
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2024-07-24 16:29:14 +00:00
Konstantin Shcheglov 4475e6ca7a CQ. Use shared ByteStore for ContextResolutionTest (legacy).
Specifically this speeds up code completion tests.
Before: 4m40.792s
After:  3m16.520s

So, 84 seconds faster :-)

Change-Id: I75194ecf9a622c108ddb8913337b9137fd9edee2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/377320
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2024-07-23 23:34:11 +00:00
Danny Tuppeny bdca2e7e20 [analysis_server] Fix duplicated fix producers in tests causing slow test performance
The `registerBuiltInProducers` function is called many times during a test run so adding producers to a `List` results in the collection getting larger and larger over time, resulting in tests taking much longer to run.

Change-Id: I7195a156e53223bc0ed9a41eb0138cff30b15aa3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/377220
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2024-07-23 19:32:35 +00:00
Sam Rawlins beee864196 DAS: Move away from LintNames, now that LintRules have LintCodes
Cq-Include-Trybots: luci.dart.try:flutter-analyze-try,analyzer-win-release-try,pkg-win-release-try
Change-Id: Id52cbf9fe95f9f2aaff80baaa10b2abbdba85f9e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/376560
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
2024-07-22 06:43:58 +00:00
Sam Rawlins 4099544ec1 DAS: fix convert_to_int edge case with capital E
Cq-Include-Trybots: luci.dart.try:flutter-analyze-try,analyzer-win-release-try,pkg-win-release-try
Change-Id: I156faa542cc77f9de55e0997840cc864047415f3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/375746
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2024-07-20 00:31:58 +00:00
Sam Rawlins 11827c81b3 DAS: Add support to import a library for an extension type
Also tests for some other types.

Cq-Include-Trybots: luci.dart.try:flutter-analyze-try,analyzer-win-release-try,pkg-win-release-try
Change-Id: I7fd41292f5c49bfb2d48ffae413cd51da781d081
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/376464
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2024-07-19 14:38:08 +00:00
Sam Rawlins 4e6d8115cd DAS: Move DartFixKindPriority, and rename values as lowerCamelCase.
FixProcessor has to be part of the analysis_server_plugin package, so
it cannot have any dependencies on the analysis_server package. This moves one.

The word 'default' is reserved, so I changed to 'standard'.

Cq-Include-Trybots: luci.dart.try:flutter-analyze-try,analyzer-win-release-try,pkg-win-release-try
Change-Id: I1ee21c800203fac758f10a6fde0ea7d07eee5e7f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/374742
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2024-07-18 21:23:14 +00:00