Commit Graph

8878 Commits

Author SHA1 Message Date
Srujan Gaddam b0a34dbccb [linter/analyzer] Add lint for runtime type tests of JS types
Closes https://github.com/dart-lang/linter/issues/4841

Adds a lint to verify and report whether an is check or a cast
may result in platform-inconsistent behavior. In order to do so,
adds necessary additions to canBeSubtypeOf and extends the mock
SDK. Also adds this to the list of default rules.

Change-Id: I7f235ee698419d9f253cc96f08322bedca271825
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/361722
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2024-05-08 20:57:59 +00:00
Devon Carew 8d6ad53c7e [pkg/analysis_server] remove use of package:usage
Change-Id: I3a18670b6131f4e8c445217f1b302e64a74f591c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/365489
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Devon Carew <devoncarew@google.com>
2024-05-07 22:11:29 +00:00
Konstantin Shcheglov 7812dbde89 Augment. Report DECLARATION_NAMED_AUGMENTED_INSIDE_AUGMENTATION.
Change-Id: Id80d6c2e6c874327c26421349cc4776087e2296f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/365661
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2024-05-07 20:42:48 +00:00
Konstantin Shcheglov 0e63a0ca01 Augment. Support 'augmented' as fields references.
Change-Id: I22bb23c51a86e4453b7f89a5c55fc2c8faba75aa
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/365501
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2024-05-07 20:37:28 +00:00
Danny Tuppeny 953e4076be [analysis_server] Record execution/timing of "pub upgrade" for plugins in instrumentation log
This will help identify issues like https://github.com/dart-lang/sdk/issues/55621 in future from the logs without needing to repro. Before, there was just a gap in the logs that wasn't obvious.

A sample log looks like:

```
1715080652096:Req:{"jsonrpc"::"2.0","id"::2,"result"::null,"clientRequestTime"::1715080652091}
1715080652253:Info:Running "pub upgrade" in "C::\Users\danny\AppData\Local\.dartServer\.plugin_manager\723cb7b2bec3011e09cd16421250ff7a\analyzer_plugin"
1715080653311:Info:Running "pub upgrade" took 0::00::01.057950
1715080653393:Res:{"id"::3,"jsonrpc"::"2.0","method"::"window/workDoneProgress/create","params"::{"token"::"ANALYZING"}}
```

(This was the only instance of `Process.runSync` in the server)

Change-Id: I2ccc5a7c538ae7a236a76df020c59014982a2e19
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/365602
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2024-05-07 16:27:55 +00:00
Konstantin Shcheglov 8ef0e2a158 Augment. Resolve PrefixExpression.
Change-Id: I947b0fee1b4f060bfe168a0f9138a6df4889d1d8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/365544
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2024-05-06 23:57:19 +00:00
pq 126ca0fc8c fix pubspec analysis for multi-options contexts
Fixes: https://github.com/dart-lang/sdk/issues/55580


Change-Id: I34ef0c9bca50d333ed2b058ddeb2ffdc1a4eaba9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/365542
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Phil Quitslund <pquitslund@google.com>
2024-05-06 23:41:32 +00:00
Sam Rawlins 5f19f0edca analyzer: Move LinterContext.inTestDir to an extension getter on CompilationUnit
This has a few nice follow-on benefits:

* SnippetProducer no longer needs to rely on LinterContext.
* Many classes no longer need a PathContext passed around, or a
  `String content`.
* BestPracticesVerifier has _3 fewer parameters_, and 1 fewer field.
* `_InvalidAccessVerifier._isInTestDirectory` no longer needs to be
  `late`.

Change-Id: I0c2059feae22a75f7c706676cc228fa404dd0cf7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/365300
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2024-05-02 20:25:48 +00:00
Konstantin Shcheglov 013d5d72b9 Completion. Issue 55614. Suggestions for types in WildcardPattern.
Bug: https://github.com/dart-lang/sdk/issues/55614
Change-Id: I2228ac24f7802865cecdf28757b65a6a9339495a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/365284
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2024-05-02 20:23:09 +00:00
Sam Rawlins 25a309a85c linter: Re-implement LinterContext.canBeConst and .canBeConstConstructor
Similar to `computeConstantValue`, an Expression or a
ConstructorDeclaration each have enough information on their fields
to calculate these values.

* This also lets us remove the now unused
  `CorrectionProducer.getLinterContext`.
* Also two functions in prefer_const_constructors_in_immutibles can be
  made static: `_hasConstConstructorInvocation` and
  `_hasImmutableAnnotation` (so they get resorted in this change).
* Several rules no longer need to pass around a LinterContext.

Change-Id: I584c62e2673658c5004283842a6525eea89f805b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/364964
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2024-05-01 23:17:28 +00:00
Konstantin Shcheglov 582e3037da Augment. Report when a class/mixin augmentation has extra/missing modifier.
Change-Id: I351f8edec54a2b7459756e7622c0f4e9d728584c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/365203
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2024-05-01 21:05:45 +00:00
pq cd6ad63805 mark skipped test as failing
See: https://github.com/dart-lang/sdk/issues/55580

Change-Id: Ia3dc798e0a56f7d6e2f5b159cb391e687efa2963
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/365182
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Phil Quitslund <pquitslund@google.com>
2024-05-01 17:05:24 +00:00
Sam Rawlins 26a7b68ee6 Migrate code off LinterContext.evaluateConstant
We don't need any more information than what is found on an Expression,
in order to attempt to compute a constant value. This simplifies some
lint rules, a quick fix, and BestPracticesVerifier.

Change-Id: Id02b7988be28e7d8846642b1ab890290a4279743
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/364821
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2024-05-01 16:13:04 +00:00
Sam Rawlins 60a0cd6e1c DAS: use camelCase for variables in domain_analysis_test
Change-Id: Id2d18e95a342ac96e6edaf51a491d53969ad9047
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/365121
Auto-Submit: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2024-04-30 23:06:03 +00:00
Sam Rawlins 293469ee22 linter: unn_lambdas: check assignability of constructor types
Basically, in `_visitInstanceCreation`, we make sure that, given an
expression like `(e) => C(e))`, that the function type of the outer
function expression is the same as the function type of `C(e)`.

And little cleanups:

* _extractElementsOfSimpleIdentifiers's returned Iterable is only used
  to check whether it contains something, so change it to a Set.
* In `isFinalNode`, use `unParenthesized` to unwrap parens, rather
  calling recursively.
* In `_Visitor`, we stored a `LinterContext`, but we only need the
  TypeSystem object, so just store that for more terse code later.
* In `_visitInstanceCreation`, remove the local function, `matches`,
  by checking whether all arguments are SimpleIdentifiers.
* Convert `isFinalElement` to an extension getter on `Expression`.
* Remove helper `isTearoffAssignable`. It is more concise and I think
  easier to read to just use TypeSystem.isSubtypeOf on its own.
* When looking at a VariableDeclaration, get the type from the
  declared element, which will include inference, rather than the
  literal type annotation on the declaration.

Fixes https://github.com/dart-lang/linter/issues/4914
Fixes https://github.com/dart-lang/linter/issues/3516

Change-Id: I3e89ee4dc011473511d375b0ad324988232c8c96
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/364628
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
2024-04-29 20:55:39 +00:00
Konstantin Shcheglov e8c1369746 Augment. Report AUGMENTATION_OF_DIFFERENT_DECLARATION_KIND.
Change-Id: Ic5716910944e61af0466b7ab1f2ab6c060134c1d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/364920
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2024-04-29 20:44:29 +00:00
Danny Tuppeny 6127f10c22 [analysis_server] Include lint documentation in completion results
It's a little annoying to get lint names in completion but not their docs and have to look them up. Turns out we already had the required docs where we produced completion, we just weren't passing them.

Example of how it looks in VS Code when we supply these: https://github.com/Dart-Code/Dart-Code/issues/5086#issuecomment-2082798310

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

Change-Id: Ic1aa9a4be3c64892f59d26c327004213c15ca37c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/364740
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2024-04-29 15:58:31 +00:00
Konstantin Shcheglov 15c3434efe Completion. Issue 55576. Support for completion in IndexExpression.
Bug: https://github.com/dart-lang/sdk/issues/55576
Change-Id: I30369fa9259e6852204acd8ad2d130617f2b8e12
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/364581
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
2024-04-26 20:08:41 +00:00
Sam Rawlins f6828ddd8d DAS: Simplify CorrectionProducer, et al.
Just a lot of tidying in preparation for this code being public API
in the `analysis_server_plugin` package.

A big change:
* Convert `CorrectionProducer.assistArguments`,
  `CorrectionProducer.fixArguments`, and
  `CorrectionProducer.multiFixArguments` each from a `List<Object>?`
  to a `List<String>?`. This should be a no-op.

Smaller changes:
* Make private: `AssistProcessor.generators`, `.multiGenerators`,
  `.assistContext`, `.assists`,
* Make private: `CorrectionProducerContext.selectionOffset`,
  `.selectionLength`, `.utils`, `.sessionHelper`, `.unitResult`,
  `.applyingBulkFixes`, `.diagnostic`, `.node`, `.token`.
* Make private: `FixProcessor.fixContext`.
* Remove `CorrectionProducerContext.selectionEnd`, `.unit`, `.file`,
  `.session`, `.workspace`, `.typeProvider`; these can be accessed via
  getters.
* Remove unused `FixProcessor.computeFix()`.
* Make doc comments more idiomatic.

Change-Id: I100fe81aad612967191568fe207ff0b807f131b3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/364420
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2024-04-25 18:02:42 +00:00
Daco Harkes 4b66657b98 [vm/ffi] address of operator for FFI leaf calls
During FFI leaf calls, the Dart GC will not run. This means that we
can pass pointers into `TypedData` to FFI calls that take `Pointer`
arguments.

After this CL, we have three types of arguments that can flow into
`Pointer` argument in an FFI call:
* `Pointer`.
* `TypedData`: Any typed data including views.
* `_Compound`: A TypedData/Pointer and an offset in bytes.

The is only possible for `@Native external` functions, `asFunction`
does not support passing in `TypedData`. (See related GitHub issues
for discussion. TLDR: FFIgen should generate bindings without config.)

`.address` expressions on `TypedData` and `Array` elements do _not_
introduce bounds checks, even though `TypedData` and `Array` have
bounds information. E.g. `ffiNative(Uint8List(10)[20].address)` does
not throw.

Implementation details:

The CFE analyzes call-sites to `@Native external` functions. If the
arguments are `.address` expressions, it transforms the call site to
pass the compound or `TypedData`. If an additional offset needs to be
applied, the CFE constructs a new `_Compound` with the correct offset
in bytes.

The CFE then also creates a new `@Native external` function which have
`TypedData`s and `_Compound`s parameters. To avoid name clashes, these
functions are postfixed with `#` and `P`, `T`, or `C` for each Pointer
parameter.

TEST=pkg/vm/testcases/transformations/ffi/address_of_*

In the VM, `TypedData` arguments are passed as tagged values, and the
address is loaded inside the `FfiCallInstr`. `_Compound` arguments
turn into two IL definitions, one for the `TypedDataBase` (tagged),
and one for the offset in bytes (unboxed). The address is then loaded
inside the `FfiCallInstr` and the offset in bytes is applied.

Adding the offset in bytes required an extra temp register for ia32.
Also, it uncovered that the temp register in arm32 was conflicting
with the argument registers. However, TMP should suffice instead.

TEST=tests/ffi/address_of_array_generated_test.dart
TEST=tests/ffi/address_of_struct_generated_test.dart
TEST=tests/ffi/address_of_typeddata_generated_test.dart

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

CoreLibraryReviewExempt: VM only, unsupported in dart2wasm
Change-Id: I01fb428cfd6f9096a34689c2819c124a8003cb6b
Cq-Include-Trybots: dart/try:vm-aot-android-release-arm64c-try,vm-aot-android-release-arm_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-obfuscate-linux-release-x64-try,vm-aot-optimization-level-linux-release-x64-try,vm-aot-win-debug-arm64-try,vm-aot-win-debug-x64c-try,vm-aot-win-release-x64-try,vm-appjit-linux-debug-x64-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-arm64c-try,vm-ffi-qemu-linux-release-arm-try,vm-ffi-qemu-linux-release-riscv64-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-x64-try,vm-reload-linux-debug-x64-try,vm-reload-rollback-linux-debug-x64-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/+/360882
Reviewed-by: Jens Johansen <jensj@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Tess Strickland <sstrickl@google.com>
Reviewed-by: Lasse Nielsen <lrn@google.com>
2024-04-25 10:06:16 +00:00
Danny Tuppeny 1d8a9280da [analysis_server] Fix AddDiagnosticPropertyReference when in augmentations
Fixes https://github.com/dart-lang/sdk/issues/55312

Change-Id: I219e529a247814d8680babd07c30bf7a7a82747d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/360043
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2024-04-24 19:49:33 +00:00
Sam Rawlins e06e82d8c8 DAS: Remove unnecessary BaseProcessor
It turns out the superclass of FixProcessor and AssistProcessor does
not buy us much:

* It has 1 method, which has one call site. The method is just two
  statements, so that can be inlined.
* It has 10 public final fields:
  * 5 of these were simply unused. Never referenced. 🤷
  * The other 5 were referenced, but only directly in the direct
    subclasses. These were set in the constructor, all coming from an
    "assist context" or a "fix context", which is ultimately a more
    direct way to reference them later in AssistProcessor and
    FixProcessor.

Change-Id: I2b1d20f2f79206d744ad4edeedc3463d4523cf0f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/364360
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2024-04-24 17:32:41 +00:00
Danny Tuppeny 8d5794aa70 [analysis_server] Fix missing types on factory constructor arguments in LSP completion
There are two fixes here, either of which solve the problem but it seemed like both should exist:

1. Always set "element" on an argument suggestion, not only if it's a field formal
2. In LSP mapping, use the "parameterType" from a suggestion in addition to other fields to find the type

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

Change-Id: Iba21c94a157bfca4d53daad203d518d9fa765a59
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/363380
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2024-04-24 15:12:10 +00:00
Sam Rawlins 1b400ed68d DAS plugins: Move CorrectionUtils to analysis_server_plugin
* Move the only 3 files from server_plugin to analysis_server_plugin.
* Copy some test infra into analysis_server_plugin. This is temporary,
  as we need some shared test infra location.

Change-Id: If2b41d436c9d3051e590f60ae2eb7ab31e529321
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/364161
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2024-04-24 14:12:24 +00:00
Kallen Tu 26652c6d31 [analyzer] Const: Add assert message for assert errors.
The current const assertion error code is okay for errors without messages, but for ones with a message included, it would be preferable to add that for additional context.

This CL adds another error code named `CONST_EVAL_ASSERTION_FAILURE_WITH_MESSAGE` to add the assert message onto the constant error.

Bug: https://github.com/dart-lang/sdk/issues/55485
Change-Id: Ie3c9019aab3ce0eb8e595b5c41394c89af32eed1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/363942
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Kallen Tu <kallentu@google.com>
2024-04-23 23:05:01 +00:00
Sam Rawlins 79faded296 analyzer: Touch up docs and impl of CorrectionUtils and EditBuilders
In this CL, I do not change the signature of any EditBuilder code, as
it is public analyzer_plugin API. I only change doc comments and a few
impl nits here and there, to make more modern or idiomatic.

This CL is isolated this way so that when I do a copy to the
analysis_server_plugin package, the moves will be smaller, readable
diffs (almost zero diff, just imports and things like that).

Change-Id: Ibc8a5ddb9a679278dd7223a3e2d868fe21c4acef
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/363881
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2024-04-22 21:44:49 +00:00
Brian Wilkerson 326cf873d1 Rename the invalid_use_of_do_not_submit_member error code constant
Change-Id: I817c4764b40f100ca26ed911594dd388dc61166b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/363941
Reviewed-by: Matan Lurey <matanl@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2024-04-22 21:35:49 +00:00
Brian Wilkerson 9068f83a19 Minor cleanup in code completion
Change-Id: I9fa3da9de5d5d99f83e8875c33cc5d95b55bb309
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/363980
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2024-04-22 17:19:37 +00:00
Sam Rawlins 0895727c59 analyzer: allow trailing whitespace in ignore comments
Fixes https://github.com/dart-lang/sdk/issues/54247

The main piece of this CL is a rewrite of the `ignoredElements`
extension on CommentToken. This was a private extension getter, but
is made public now for two reasons: first is to reference it in tests,
and second is to make it available for a new lint rule in an upcoming
CL.

The new implementation drops all use of RegExp in order to more
precisely track when we may be at the end of a list of diagnostic
names and/or types. So the functional change here is that a diagnostic
name or type followed by whitespace instead of a comma marks the end
of the list. Any characters following that whitespace are not parsed,
as they are considered freeform comment text. While the new
implementation parses a comment code-unit-by-code-unit, it is still
a rather concise impl.

* Rename DiagnosticName and DiagnosticType to IgnoredDiagnosticName
  and IgnoredDiagnosticType; these names make more sense to me,
  specifically when they are used outside of the ignore_info.dart
  file.
* I introduce a new test file, ignore_info_test, to capture these
  various parsing particulars, that aren't specifically concerned with
  matching an ignore comment with a diagnostic. A few test cases from
  ErrorSuppressionTest are moved over here.
* A number of String (well, int, technically) helper functions are
  moved to analyzer, along with their tests.

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

Change-Id: Ife08d448a4e03b8a55b183d88a3ea8d07812fbdc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/363820
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2024-04-22 16:53:42 +00:00
Konstantin Shcheglov b65887829e Augment. Report enums without constants after parsing.
Change-Id: I5af7fbc398bfa4ad2463fb9f37cef3757dd42151
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/363741
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2024-04-22 15:22:32 +00:00
Sam Rawlins 9d04850beb analyzer: do not report variable declaration pattern variables for consistency
Fixes https://github.com/dart-lang/sdk/issues/54854

This change implements the new design: if every variable declared is
unused, report them. Otherwise, report none of them. This allows one to
specify pattern matches in a consistent format, and allows for names,
for documentation purposes.

Change-Id: I0c36a4eeec6dae2a65c8279f3198a718e893edd9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/363720
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2024-04-20 16:22:38 +00:00
Brian Wilkerson 0a1cad1947 Add a pass for suggesting elements that are not yet imported
This CL makes 3 different changes. I'm happy to split them out into
smaller CLs if you'd like me to.

The first is to add the class `NotImportedCompletionPass`, which is the
proposed replacement for the `NotImportedContributor`. I believe that
the pass is complete, but it currently doesn't contribute any
suggestions because the methods invoked by the two "operations" aren't
yet implemented.

That said, it does do real work in terms of searching through the
libraries that aren't imported. That work is currently duplicated by
the contributor, which would likely cause a performance degredation.
As a result, I've commented out the invocation of the pass (but have
verified that every test passes when it's not commented out).

The second is to start suggesting extension members from local
extensions. I'm not sure why, but prior to this CL they appear to have
only been suggested by the `NotImportedContributor`, which isn't
always run. I'm not sure where members from imported extensions are
currently being imported, but I'll figure that out before I remove
the `NotImportedContributor`.

The third is to change the element being compared against when
computing the inheritance distance. We were previously using the
container of the element being suggested, which caused the inheritance
distance to always be the same, no matter what the type hierarchy
looks like. We need better tests for relevance, but I didn't add any
in this CL.

Change-Id: Ic82a15cab5d022f89da234a8b31bc6bca34ccb5c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/363760
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2024-04-19 21:38:56 +00:00
Konstantin Shcheglov cc9de33052 Augment. Merge enum values.
Change-Id: I4bac24389449de6403a0c54d897b396650f7b94a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/363721
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2024-04-19 17:32:30 +00:00
Konstantin Shcheglov e12b3d0ee5 Completion. Issue 55505. Fix for completion in property access target in assignment begin.
Bug: https://github.com/dart-lang/sdk/issues/55505
Change-Id: I26bde2ab84d7216218ba9aed75b7561ed30c9c30
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/363620
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2024-04-18 23:13:16 +00:00
Sam Rawlins 33b97140fb DAS: Move CorrectionUtils.selectionIncludesNonWhitespaceOutsideNode into extract_method
Bug: https://github.com/dart-lang/sdk/issues/53402
Change-Id: I4fca3482c27520328339d1d1f0b6b541399ed612
Cq-Include-Trybots: luci.dart.try:flutter-analyze-try,analyzer-win-release-try,pkg-win-release-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/363501
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2024-04-18 17:32:21 +00:00
Sam Rawlins a862d9d745 analyzer: Correct message about const addition operator
Fixes https://github.com/dart-lang/sdk/issues/54578

Cq-Include-Trybots: luci.dart.try:flutter-analyze-try,analyzer-win-release-try,pkg-win-release-try
Fixed: 54578
Change-Id: Iebc9e04539a172e58024758e33ffd93e48cb1a81
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/363482
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Nate Bosch <nbosch@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2024-04-18 17:21:29 +00:00
Sam Rawlins a5fb950f97 DAS: Move CorrectionUtils.indentLeft and indentRight near their call sites
Cq-Include-Trybots: luci.dart.try:flutter-analyze-try,analyzer-win-release-try,pkg-win-release-try
Bug: https://github.com/dart-lang/sdk/issues/53402
Change-Id: Id62b06f3419820d4a74b34b51a6022792bcef7ab
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/363404
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2024-04-18 16:01:00 +00:00
Konstantin Shcheglov ad8f4b0f3d Issue 55495. Fix renaming extension types when and the end of the name.
Bug: https://github.com/dart-lang/sdk/issues/55495
Change-Id: I4db31e8a97a201fa00372f3d033d50ef79ca0941
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/363481
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2024-04-17 22:26:49 +00:00
Sam Rawlins 5c79627e08 Move CorrectionUtils addLibraryImports to ExtractMethod
`_getInsertionLocationTop` and `addLibraryImports` are each moved to
extract_method.dart, as the only location where they were used.

We get to delete the `_InsertionLocation` class.

The tests are also moved, unchanged, and CorrectionUtilsTest is very
much simplified.

Bug: https://github.com/dart-lang/sdk/issues/53402
Change-Id: Ia410f04a837d85a0e06ec523d156c6c6c8bf6a3b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/363402
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2024-04-17 22:12:28 +00:00
Konstantin Shcheglov 9a385638cd Augment. Basic support for enum elements..
Change-Id: I42e7b58f7edaa979740a8e5b6787665c7a79c54d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/363500
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2024-04-17 21:53:31 +00:00
Danny Tuppeny 0b170c759e [analysis_server] Don't expand variable declarations to their lists if multiple variables in LSP definitions
VS Code uses the definition range to show a preview of the hovered item (when holding `ctrl`). We usually expand a variable declaration to the parent list so that this preview includes "var", "final" and/or any type.

However, if the list contains multiple variables, this resulted in us showing other variables in the preview too which is confusing/misleading.

This change keeps the original behaviour for VariableDeclarationLists with only a single variable, and otherwise keeps the specific variables range.

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

Change-Id: I9e3cfd672f51040b60f9791ba89a937d5733c628
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/363280
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2024-04-17 17:24:29 +00:00
Konstantin Shcheglov 4bb644ce3e Augment. Parse enum constant augmentations, allow just ';' before methods.
I was unable to update the parser to avoid requirement for ';' at all.
Ideally we should be able to parse:
```
enum E {
  void foo()
}
```

Change-Id: I7edba99454b965407c3fb402642933b3d8d6bb7c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/363106
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2024-04-17 15:26:31 +00:00
Brian Wilkerson dee6feee1a Some minor clean-up separated to make the next CL shorter
Change-Id: I6bbfe3903c19dd9fe792647c725b0488eddb52d4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/363181
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2024-04-16 22:07:08 +00:00
Konstantin Shcheglov 5c07c89a35 Enable 'unnecessary_final' in analysis_server/.
Change-Id: I71ee934b915d4aff924cf5925f87bcc9adc6c015
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/362901
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2024-04-16 20:04:15 +00:00
Sam Rawlins b9f81e8b2c analyzer: Fix windows bot failure
Cq-Include-Trybots: luci.dart.try:flutter-analyze-try,analyzer-win-release-try,pkg-win-release-try
Change-Id: I6b47827575cf926e6701b2fa5890e4d4bbb3c121
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/363102
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2024-04-16 17:46:21 +00:00
Sam Rawlins 8e159373ee analyzer: verify const record fields
Fixes https://github.com/dart-lang/sdk/issues/55008, as specified by
new spec text introduced in https://github.com/dart-lang/language/pull/3630:

> Let _R_ be a record expression that occurs in a constant context,
> or a record expression whose first token is `const`. In this case,
> each record field in _R_ occurs in a constant context.

Change-Id: Idbc70529ddd9be408c53482cc0367367ac1ee0fd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/362720
Reviewed-by: Kallen Tu <kallentu@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2024-04-16 13:18:10 +00:00
Keerti Parthasarathy 6174b78b0d Add a score to CandidateSuggestion and use this to filter suggestions during computation.
Change-Id: I190349c03577cbb72d5dae2ebc2ecafe9fc88c95
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/362824
Commit-Queue: Keerti Parthasarathy <keertip@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2024-04-16 04:50:49 +00:00
Sam Rawlins 3ce721772c analyzer: Fix Windows tests
Cq-Include-Trybots: luci.dart.try:flutter-analyze-try,analyzer-win-release-try
Change-Id: I6c993ffac41343d07fa718f4a7f2c0e446f4ce5d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/362841
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Auto-Submit: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2024-04-15 20:43:38 +00:00
Keerti Parthasarathy 0199e9d2d0 Fix for pubspec edits when removing a line between entries.
Change-Id: Ie4a74e70f836b8f20631d2cd1cac8c962554d3d3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/362840
Commit-Queue: Keerti Parthasarathy <keertip@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2024-04-15 17:40:01 +00:00
Danny Tuppeny e067bf7815 [analysis_server] Improve handling of const keywords for color picker
There were some inconsistencies with insertion of "const" keywords when selecting colors from the color picker (eg. https://github.com/Dart-Code/Dart-Code/issues/5068).

Some of this was because some tests were testing different their own ranges that didn't match the ones the server would have provided (which meant the replacements were different).

This updates the tests to ensure all tests are using ranges that the server would have produced, changes to ensure any existing const keywords are included in the color expression (so if in future we allowed selecting named colours, existing const constructor keywords would be correctly removed) and fixes up some places where we didn't actually produce Colors (assigning top-level color variables in an initializer and constant patterns) but had tests assuming we did (which failed with the new checks).

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

Change-Id: Id8814a426df4cbc350febabd11c963447c4b0e73
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/362801
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2024-04-15 17:36:20 +00:00