Commit Graph

694 Commits

Author SHA1 Message Date
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
Konstantin Shcheglov b2bf4d33fe CQ. Mark NamespaceCombinator sealed.
Change-Id: I6a31db055276863435fc4e5c2e8811046de2378b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/379679
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2024-08-09 19:49:08 +00:00
Sam Rawlins 5e8ee77772 Support digit separators
Work towards https://github.com/dart-lang/language/issues/2

The feature is well-specified at the issue, but I will also follow
up with a specification to check into the language repo.

This change implements the feature more-or-less from front to back
(because the back is very close to the front in this case :P; no
"backend" work in the VM, etc). Digit separators are made available
via a new experiment, `digit-separators`.

Care is taken to report a single error when an underscore appears in
an unexpected position (see new `separators_error_test.dart`).

Three test files are added:

* `separators_test.dart` is run with the experiment enabled, and has
  no compile-time errors.
* `separators_error_test.dart` is run with the experiment enabled, and
  has many compile-time errors.
* `separators_error_no_experiment_test.dart` is run with the
  experiment _disabled_.

Change-Id: I7f1b1305d28b708b5ddf83f26188cd6e9ce3dd58
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/365181
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Lasse Nielsen <lrn@google.com>
Reviewed-by: Kevin Moore <kevmoo@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
2024-07-09 14:50:59 +00:00
Danny Tuppeny 916272331b [analysis_server] Remove the singleton uriConverter and pass explicitly to all toJson/fromJson methods
This avoids accidentally using the converter when talking to plugins, (at least for now) URIs are never expected, and file paths should always be used regardless of which mode the server is in.

This unfortunately touches a _lot_ of code, so I've pushed in many separate patch sets to Gerrit.

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

Change-Id: I312c3e2cbc35a05a078aaa0138aec7288b3c7dd6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/373745
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2024-07-02 14:15:11 +00:00
Sam Rawlins 1e84b64a0e DAS: Move DartChangeWorkspace to the analysis_server_plugin package
Cq-Include-Trybots: luci.dart.try:flutter-analyze-try,analyzer-win-release-try,pkg-win-release-try
Change-Id: I79f43d06b48149b1d9dec30c5f5a77fdfd57ce4e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/373143
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Sam Rawlins <srawlins@google.com>
2024-06-26 02:17:59 +00:00
Sam Rawlins 88e62a23cf Expose CommentToken as analyzer public API
CommentToken is the static type of `Token.precedingComments`:
https://pub.dev/documentation/analyzer/5.13.0/dart_ast_token/Token/precedingComments.html
and so should be exposed as public API.

Cq-Include-Trybots: luci.dart.try:flutter-analyze-try,analyzer-win-release-try,pkg-win-release-try
Change-Id: I06e3e897bf310b9bc0e5067ab0f44db3a3e459c4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/371946
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Sam Rawlins <srawlins@google.com>
2024-06-18 17:34:27 +00:00
Konstantin Shcheglov 78a0c7a5e1 DevX. Issue 54567. Support for joined cases in 'Convert to switch expression'.
Bug: https://github.com/dart-lang/sdk/issues/54567
Change-Id: Idb6cc7ecd88e1e9e3b14c6a54176c958bac36afa
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/371201
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2024-06-12 22:10:47 +00:00
Konstantin Shcheglov 73cd7c6439 CQ. Deprecate exports from package:analyzer/src/source/source.dart
Change-Id: I6256ad2a8472636fd39a9db7e0360f8d7104da0e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/369560
Reviewed-by: Sam Rawlins <srawlins@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2024-06-11 22:49:51 +00:00
Konstantin Shcheglov 1f3d1b6c81 QuickFix. Issue 55773. Flatten FutureOr() when convert to async.
Bug: https://github.com/dart-lang/sdk/issues/55773
Change-Id: I09653a5bce4c590fc95cbfb25eb3fbde1ffeb7c0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/369502
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2024-06-03 23:10:09 +00:00
Devenik7 c37ccccae4 Fixed _writeSuperMemberInvocation in DartEditBuilderImpl to properly suggest completions when super member has named parameters
Closes https://github.com/dart-lang/sdk/pull/55697

GitOrigin-RevId: 8a43d8595921a271eb54e7c8aa9966fe559e1fd4
Change-Id: I393b17fc26eda821615f2d2d29cb386ab5f98406
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/366081
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2024-05-14 16:01:33 +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
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
Sam Rawlins dd1fc29b73 DAS: Support "Create field" and "Create missing overrides" fixes for enums.
Fixes https://github.com/dart-lang/sdk/issues/55264

Fields added to enums are final.

Also:

* Fix a bug in CreateField - fields created from function-typed field
  formal parameters now have the right type.
* Fix a "bug" in CreateField - fields created from a field formal
  parameter in a const constructor are now final.
* Add more tests for CreateField.

Change-Id: I7d1344f6214c89e6351d3b5ed18b71ac97b9a310
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/362420
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2024-04-12 17:28:40 +00:00
Sam Rawlins 7735d94706 Remove last uses of CorrectionUtils.prepare*
In the *Builder APIs, this is what has changed:

* Add a parameter to `writeOverride` called `setSelection` which
  controls whether selection should be set.
* `_addCompilationUnitMemberInsertion` is made public as
  `insertIntoUnitMember`. Callers can insert multiple things into a
  unit member, so it's a pretty generic name.
* Improved handling of synthetic brackets for all existing add*
  APIs, like `class A extends B`. Many fixes and refactorings will
  now write brackets if necessary.

Change-Id: I7ed79793c8625ec922ab8de2cb9e6fc33d022b76
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/362183
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2024-04-11 16:58:15 +00:00
Sam Rawlins b397642220 DAS: Move last CorrectionUtils constructor APIs to DartFileEditBuilder
Change-Id: I8a4579d751ce3d663ca53abf56ce7d8ac38ada04
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/362063
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2024-04-10 18:42:20 +00:00
Sam Rawlins cb1ec02a0c DAS: Prefer platform-specific EOL sequence when given a string with no EOL sequences
Change-Id: I3a863434d58ac5b9c72359c34fd0225832864375
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/362061
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2024-04-09 20:49:57 +00:00
Sam Rawlins c2f3418251 DAS: Rename 'add___Insertion' to 'insert___' APIs
Change-Id: I57693591999e0845e6a3560a19de770eef4968b2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/362001
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2024-04-09 18:51:48 +00:00
Sam Rawlins 07c17fbb9f DAS: Move most CorrectionUtils.prepareConstructor code to use DartEditBuilder
Add `DartFileEditBuilder.addConstructorInsertion`, a replacement for
both `CorrectionUtils.prepareEnumNewConstructorLocation` and
`CorrectionUtils.prepareNewConstructorLocation`. Combining the two
APIs is made possible by adding enum support to _InsertionPreparer.
For example, constructors can be inserted after an enum value-list's
semicolon (if there is one), or after the last value (if there isn't).

Also:

* Refactor _InsertionPreparer a bit to be cleaner; in the constructor,
  we determine whether we can grab the `NamedCompilationUnitMember`
  members.
* Instead of storing a `_targetMember` as a field, which is only null-
  checked, store a Boolean value for whether a target member was
  found.
* Remove pre-nnbd support in `DartFileEditBuilder.writeParameter`.

Change-Id: I3e98ed906cf5ac82e464c502db5986d3761c3611
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/361624
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2024-04-09 16:43:30 +00:00
Sam Rawlins df707ac85e DAS: Refactor the logic determining the location of a new ignore-comment
I renamed a few classes, then sorted them, so the diff is big.

Broadly, here is a summary of the code before: two "ignore diagnostic"
correction producers were in place, and the one that inserts a
"ignore_for_file" comment (IgnoreDiagnosticInFile) uses a
`CorrectionUtils.getInsertionLocationIgnoreForFile` function to get an
InsertionLocation object, then passes that to `_computeEdit()`, a
method defined in a parent class. `_computeEdit()` takes that
InsertionLocation object, and uses LineInfo, to determine whether we
need to _append_ to an existing ignore-comment (in which case all
other InsertionLocation information is discarded), or write a full
comment, and use the InsertionLocation prefix and suffix.

To me this was a pretty complicated set-up: IgnoreDiagnosticInFile
calls out to a function defined in a separate library to do "the first
half" of the location calculation. Then the `_computeEdit()` function
has to finish the job, which might involve ignoring computations done
in the first half.

I've changed it to instead be the following design: Each class,
IgnoreDiagnosticInFile and IgnoreDiagnosticOnLine, wholly implements
`compute()` (removing the parent `_computeEdit()` method). The former
class has the much bigger task of finding an appropriate position near
the top of the file in which it can insert a comment. Instead of
tracking a lot of variables along the way, this code quickly calls out
to `insertAt()` as soon as it knows where it is inserting, whether it is
appending, and whether we need a newline before the comment, or after.
So everything about the offset, possible prefix, suffix, and decision
to-append is done in one place. The latter class,
IgnoreDiagnosticOnLine, has a much simpler `compute()`, the most
complex part is determining whether to append to an existing comment.
There is not much duplicated. The `insertAt()` method is defined in
the parent class; it is nice to have a method that is agnostic to the
ignore comment being inserted; it just calculates an indent, and
writes the comment.

Summary of changes:

* AbstractIgnoreDiagnostic, the parent of the two mentioned classes,
  and IgnoreDiagnosticInAnalysisOptionsFile, is actually a base class,
  shouldn't be public, and it's `_computeEdit()` was not relevant for
  the 3rd subclass. So I rename it to _BaseIgnoreDiagnostic, and add a
  new small class in between: _DartIgnoreDiagnostic. The new class
  defines `insertAt()` (only relevant for Dart files), and requires
  that subclasses define their `ignorePrefix`.
* `_isCodeUnignorable` is changed from a method to a getter.
* `DartEditBuilderImpl._linePrefix` is moved to an extension on ResolvedUnitResult, along with some helpers. It is moved to `src/` so
  not technically part of public API. It should be moved to
  server_plugin soon.
* `getInsertionLocationIgnoreForFile` and `getLinePrefix` are removed.

Change-Id: I4757ea2d8a3b43eeec0c8895c5c1fb3edc3ca8a3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/361006
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2024-04-05 00:17:58 +00:00
Sam Rawlins 51d7b8477d DAS: Move two CorrectionUtils methods to DartEditBuilder
`addMethodInsert` and `addCaseClauseAtEndInsert` are only used by code
which combines them with DartEditBuilder, so the change is pretty
simple. A few utilities are needed in DartEditBuilder, which are also
not complicated, such as a utility for getting the existing indentation
string on a line. Using this utility in the shared code should improve
someo of the existing fixes and assists, which didn't use it before.
The same goes for looking at whether left and right brackets are
synthetic. So this change comes with a few minor improvements.

Change-Id: I5b235021ac234b4a50b09dca6d14a28b3f163e5e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/360980
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2024-04-03 20:57:51 +00:00
Konstantin Shcheglov 5543d88289 AE. Deprecate OnClause, use MixinOnClause instead.
Change-Id: I938a1ff4046851c46c6ae4cebdff25e05e88300f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/360741
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2024-04-02 23:02:22 +00:00
Sam Rawlins e1a5b44144 DAS: Move some CorrectionUtils.prepare methods to DartFileEditBuilder.
Primarily this moves `prepareNewFieldLocation` and
`prepareNewGetterLocation` to DartFileEditBuilder, as
`addFieldInsertion` and `addGetterInsertion`. Where
`prepareNewFieldLocation` was previously used in conjunction with
`addInsertion`, a correction producer now just needs to call
`addFieldInsertion`. This new method determines the insertion offset,
and and prefix String and suffix String (just newlines and indents),
and handles the prefix and suffix, surrounding use of the `buildEdit`
callback.

These form a nice new API for correction producers like create_field,
create_getter, and create_setter.

The implementation is a little hairy; the DartFileEditBuilder does not
have access to things like `eol` and `getIndent`; those are made
available in DartEditBuilder, so it does that work in
`addCompilationUnitMemberInsertion`, _inside_ the call to
`addInsertion`, where that builder is available.

Though the implementation is a bit hairy, I think it is a much tidier
API for correction producers. The prior API was a little awkward in
that a correction producer would have to ask CorrectionUtils for this
odd data object that contained an offset, and a prefix and suffix
String. Rather than using these objects in any meaningful way, the
correction producer just gave it back to one or another builder. It
felt opaque to me.

The rest of the `CorrectionUtils.prepare*` methods will follow.

Change-Id: I32f23336c873cee4158a4ac6797961a40d86c25a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/360302
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2024-04-02 20:47:32 +00:00
Konstantin Shcheglov c5f876b7aa Augment. Use ExtensionOnClause in ExtensionDeclaration, make it optional.
Change-Id: I696ffd0b8e8f3bf9017b583d480313ec7c7753f7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/360561
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2024-04-02 16:12:00 +00:00
Danny Tuppeny 046f3117b6 [analysis_server] Fix navigation on augmentation directives
Change-Id: I0972d6c9aa93f1bac180504da96e63ed9f04e63e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/360260
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2024-04-02 16:09:26 +00:00
Konstantin Shcheglov aced0523a4 Augment. Fixes for navigation for constructor annotations.
...and for import prefixes in augmentations.

Change-Id: I4c2f358d5bd1819c8691990a0b86a37d04449213
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/360505
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2024-04-01 23:06:19 +00:00
Sam Rawlins 80d16cf9e5 DAS: Inline prepareNewStatementLocation into add_call_super
This was the only caller, and it always passed in `true` for `first`.

Inlining the function is the same number of lines as calling the function and using it's output.

Change-Id: Ifee204e68f2b7d168fe6078ac7f8ec66261ff76b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/360080
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2024-03-28 16:27:51 +00:00
Konstantin Shcheglov f353f03240 Completion. Print (sometimes) the location. Fixes for ObjectPattern_type.
As proposed in https://dart-review.googlesource.com/c/sdk/+/356641

Change-Id: If196709976b0fa06492f360d77172866892b4148
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/356921
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2024-03-12 00:47:38 +00:00
Konstantin Shcheglov c0a42ac077 Completion. Issue 52129. Suggest types for ObjectPattern.
Bug: https://github.com/dart-lang/sdk/issues/52129
Change-Id: I34dcb53a73099f1ac993aa01db0cee3d15afdc4c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/356641
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2024-03-11 19:33:50 +00:00
Danny Tuppeny 28e926f0fb [analyzer]/[analyzer_plugin] Support change descriptions on SourceEdit
Previously, we only had descriptions of changes on a SourceChange. In order to support annotated edits over LSP for "Fix All in Workspace" we need to be able to track descriptions on each change within a file so that if we're fixing multiple different lints with a single SourceFileEdit they can be annotated/grouped in the UI.

In order to avoid every fix providing a description, ChangeBuilder has a field that allows recording the current change description and all builders created from it will use that description when creating their changes. This allows the BulkFixProcessor to set the description on behalf of each fix producer ensuring they all get descriptions (which is done in a follow-up CL along with Fix All in Workspace functionality).

Change-Id: Ie1c508056898bd4000a5505cf59a1e6d35d28da0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/356160
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2024-03-08 18:54:05 +00:00
Konstantin Shcheglov 323a15b6e4 Completion. Issue 54746. Don't suggest extension members in the body of class-like declarations.
Bug: https://github.com/dart-lang/sdk/issues/54746
Change-Id: Ia8e6a3a864caf75bebd13fe28e3419962b6f7a63
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/355510
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Keerti Parthasarathy <keertip@google.com>
2024-03-05 17:10:36 +00:00
Danny Tuppeny c6f9141dd2 [analysis_server]/[analyzer_plugin] Use specific Dart/YAML edit builders
+ add asserts to prevent using generic builders for Dart + YAML files.

When edits are mixed from multiple sources (such as multiple fixes via "dart fix") they must use the same kind of builders. The only way to ensure this is to force the specific kinds to be used.

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

Change-Id: Ia41b9cadd2b79ed9eabdc4f976c8071021d2e060
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/355441
Reviewed-by: Keerti Parthasarathy <keertip@google.com>
Commit-Queue: Keerti Parthasarathy <keertip@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2024-03-04 22:39:13 +00:00
Konstantin Shcheglov ebb5c7d666 Augment. Use nullable PropertyAccessorElement.variable2
As much as I don't like the scale of changes, there is no valid variable in these cases. So, we express this explicitly, without trying to pretend that there is on. Or crashing as we did without this CL.

Change-Id: I74cef1d3d9d3cba6985d83b98be361cca09170f9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/355300
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2024-03-04 19:28:28 +00:00
Konstantin Shcheglov 8968e5500a CQ. Enable avoid_redundant_argument_values in analysis_server/
Change-Id: If9c09f81bdbac890553573a8491ca27cb4f22dd7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/353805
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2024-02-26 19:51:41 +00:00
Konstantin Shcheglov 14a1045f16 Legacy. Deprecate 'withNullability' in getDisplayString() methods.
Change-Id: I688f230f4189cd1fc600e4d34f07f339111c382d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/350645
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2024-02-07 01:25:38 +00:00
Konstantin Shcheglov fe0e0775c2 Legacy. Deprecate LibraryElement.isNonNullableByDefault
Change-Id: I1b15c59960aa7eb4d27c221febc857a974bae738
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/350404
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2024-02-06 01:19:09 +00:00
Danny Tuppeny c3d80286fe [analysis_server] Add a supportsUris client capability for legacy server to switch into URI mode
This adds support for the legacy server to switch to URIs using a client capability. In this mode, all "FilePaths" will be URI strings over the protocol (in both directions).

It also allows the server to send LSP notifications (wrapped inside an "lsp.notification" notification, matching how requests/responses work). Notifications are automatically enabled if the client uses any LSP methods or sends the new "supportsUris" capability.

Change-Id: I5d2b76e396862129c61de70d57397603c958a02d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/349120
Reviewed-by: Jaime Wren <jwren@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2024-02-01 22:19:00 +00:00
Danny Tuppeny 8d936d38fc [analysis_server]/[analyzer_plugin] Make all toJson/fromJson methods go through a central converstion for Path<->URI Strings
This change shouldn't change any current behaviour, but means all "FilePath" types in the legacy protocol spec will go through a (currently no-op) conversion. The server will be able to replace this conversion based on client capabilities in a future CL.

Because a lot of the generated classes are in analyzer_plugin, this also moves the ClientUriConverter class there.

`pkg\analysis_server\test\src\utilities\json_test.dart` contains tests that the toJson/fromJson methods go through the converter recursively (inc. map keys/values/etc.).

Change-Id: If5aec884070128eea594540fd25a9017ada86079
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/349060
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2024-01-30 16:58:25 +00:00
pq bc34c295ae final -> var for package:analyzer_plugin
Change-Id: I0e7cd26dcb0c7de1b4f7e19b66719d5a73670ce7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/345824
Commit-Queue: Phil Quitslund <pquitslund@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2024-01-12 22:37:40 +00:00
Greg Spencer e49f1ccbbe Fix the way that DartFileEditBuilder handles imports
It also handles imports a little better than it used to: it will replace an import that has the same URI and prefix with an updated one with appropriate show and hide combinators.

Bug: https://github.com/dart-lang/sdk/issues/54496
Change-Id: Ib53275f2d58c19085fe02cb83267c8dc0c23838b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/344940
Commit-Queue: Greg Spencer <gspencer@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Auto-Submit: Greg Spencer <gspencer@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2024-01-12 19:30:12 +00:00
Sam Rawlins 5ddb91860b analyzer: Close the ReceiverPort in PluginIsolateChannel.close
Change-Id: I7442da58ba9e6810bacc6380999097a3d9674658
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/344623
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2024-01-04 18:38:36 +00:00
Sam Rawlins 73ab31b98a analyzer: Move the Source class to be public API.
Deprecate accessing LineInfo, Source, or SourceRange via the
old library (pkg/analyzer/lib/src/generated/source.dart).
Migrate all SDK code to the new library.

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

Change-Id: Ic7c98a5820415c92a457f9fa2756351b05520cd1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/335382
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2023-11-14 17:10:37 +00:00
pq f962700302 + flutter_style_todos
Enabled `flutter_style_todos` in analyzer packages:

* `analyzer_cli`
* `analyzer_plugin`
* `analyzer_utilities`
* `meta`


Change-Id: I5fcd76bfa5a3bdeb14d6a81b8193129c6d83d0e8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/335405
Commit-Queue: Phil Quitslund <pquitslund@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2023-11-13 00:14:09 +00:00
pq 9e6c856c27 migrate to getAnalysisOptionsForFile(file)
This migrates the bulk of the calls to `.analysisOptions`. I'll tackle the remainder in a few follow-ups.

Change-Id: I0f4c78d88938feecaba7202e0dc299dc17e2bb35
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/334647
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Phil Quitslund <pquitslund@google.com>
2023-11-08 21:48:38 +00:00
Danny Tuppeny 4d9c40860f [analysis_server] Add support for LSP Document Links for example/api links
This extracts the code that finds "examples/api" paths in code from the navigation code so that it can be re-used by LSP's DocumentLink request.

This allows the links to be more visible in the editor (they are underlined and clearly clickable like hyperlinks, whereas definition required you to hover and hold Ctrl before you'd seen an underline in VS Code).

Example: https://github.com/Dart-Code/Dart-Code/assets/1078012/be9db467-dbc9-4206-9dd5-f8ca72d95596

There may be an argument for making this more general (so that links other than example/api could be detected) but for now the goal was to make these existing links more obvious.

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

Change-Id: Id00425175b24394e565e13406ea4bac5691d2c72
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/333082
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2023-11-02 15:51:49 +00:00
Brian Wilkerson 7da4e0b9e8 Complete in the representation field
Change-Id: I6906296b57c2cdd516ecc045ee78d74b4493e217
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/331096
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2023-10-19 21:08:32 +00:00
Brian Wilkerson 67e888113b Code complete inside an extension type
Change-Id: I293d1379561abdce3816dccaa6dfde867e0ed9ef
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/330998
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2023-10-19 14:04:51 +00:00
Devon Carew 3b0b1bd863 Bump package:lints to the latest; address instances of new lints.
Changes:
```
> git log --format="%C(auto) %h %s" 8d5f750..b044aca
 https://dart.googlesource.com/lints.git/+/b044aca add several rules to core and recommended (150)
 https://dart.googlesource.com/lints.git/+/81100a2 fix a dangling table link (146)
```

Diff: https://dart.googlesource.com/lints.git/+/8d5f7500024320654adb1e799e49fc10c5304ae7..b044acab9f6669b3d8e781923a8ff86877801177/
Change-Id: I031333ade99af700a7009b14a36d3aadba12fc94
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/327321
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Commit-Queue: Devon Carew <devoncarew@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
2023-09-25 21:15:15 +00:00
Danny Tuppeny bf13d89902 [analysis_server] Ensure variables declared in patterns are recorded in navigation data
Previously the pattern would only be recorded as a reference to the getter. If there was a reference to the declared variable elsewhere in the visited code, it would then record the variable declaration (via the reference).

In LSP, we locate declarations by only looking at the node at the cursor, so we can't rely on the declaration being recorded by some other reference (if one even exists) so this ensure it is recorded explicitly.

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

Change-Id: I8983d0637f2d89a427fb1fa11293eec8e06fede8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/326700
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2023-09-19 19:39:31 +00:00
Konstantin Shcheglov db212846ed Extension type. Create navigation regions for primary constructor and representation field.
Change-Id: I491780daa376941d031bba6dd7da60655ec3e76e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/324765
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2023-09-07 18:20:50 +00:00
Konstantin Shcheglov bbc3dcbe30 Extension type. Tests for type hierarchy.
Change-Id: Ic0e31bb13efd68a3413429d1ff9110bb9b268e2e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/323432
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2023-08-30 21:18:25 +00:00