Commit Graph

6341 Commits

Author SHA1 Message Date
Sigurd Meldgaard 86ecb7185e Support for # ignore: comments in pubspec.yaml
Contains quite a bit of refactoring. One big change is that `PubspecValidator.validate()` now also finds lints. Not sure we want this, but it seemed desirable to me. (Otherwise there was no central place to filter the lints through the ignores).

Change-Id: Ic8a463a9718fb29bec0d4f7e849b6da7799aebc6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/311980
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Sigurd Meldgaard <sigurdm@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2023-10-13 12:44:09 +00:00
Danny Tuppeny 2c0a33400e [analysis_server] Use existing file state for Dart files to get LineInfo
Make this change broke some tests because the Fix All code which uses temporary overlays would revert the overlays but not immediately apply those changes (so the file state was out of sync) to compute edits.

To fix this, the step to revert overlays also immediately applies those changes (rather than leaving them until the whole operation has completed).

+ improve a variable name

Change-Id: Ic76b1c25d808c07e1d9d7e304babf6c79556dc36
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/330100
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Keerti Parthasarathy <keertip@google.com>
Commit-Queue: Keerti Parthasarathy <keertip@google.com>
2023-10-12 19:58:22 +00:00
Danny Tuppeny 57e5e98ab4 [analysis_server] Allow LSP requests like willRenameFiles to be cancelled by legacy protocol cancellation requests
Previously the cancellation of Legacy and LSP requests were distinct. Sending a cancellation for a (legacy) "lsp.handle" request would not signal to the LSP handler to cancel.

This passes down the legacy requests cancellation token to be used by the LSP handler.

An alternative option would've been to support sending LSP cancellation methods through `lsp.handle` but so far our assumption has been that only _requests_ will be sent through `lsp.handle` and LSP's cancellation is a notification.

Change-Id: I74dc472011b86578d1b40b3034ac6a252d317f59
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/330300
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2023-10-12 19:42:50 +00:00
Danny Tuppeny 23e9681392 [analysis_server] Handle object patterns without explicit field names
+ merge overlapping occurrences groups in LSP.

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

Change-Id: I5a855f68963fc06e2e878a0a8f872f3f68ea1d34
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/326220
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2023-10-12 18:44:16 +00:00
Danny Tuppeny e44d114297 [analysis_server] Enable workspace/willRenameFiles for LSP-over-Legacy
Change-Id: Ib572663a247f7e5521b0a9c69f201c22cea29b16
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/330102
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2023-10-12 18:36:12 +00:00
Erik Ernst cdc16e7d3d Create lint PR 3578 as Gerrit CL
This CL transfers the changes made by
https://github.com/dart-lang/linter/pull/3578
to Gerrit.

Change-Id: Ib1eae56d2112e25bcf9916abf27b05bd3de15735
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/326342
Commit-Queue: Erik Ernst <eernst@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2023-10-12 10:09:10 +00:00
Danny Tuppeny 209483da72 [analysis_server] Don't disallow extracting local variables matching argument names
Fixes https://github.com/Dart-Code/Dart-Code/issues/4787

Change-Id: Idbd54e55599cf3cb34f504e4aad40018b70dfe78
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/330109
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2023-10-11 17:37:43 +00:00
Brian Wilkerson bbd8c88862 Move local variable generation to the in-scope completion pass
Change-Id: If43972bc58a52664d7c70d37d1a0b25a494dbec9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/330022
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2023-10-11 14:47:28 +00:00
Danny Tuppeny 09f3eb0c8b [analysis_server] Support renaming multiple files in a single operation
We already supported moving a single folder, which we expanded to each file inside it. This adds support for moving multiple distinct items at the same time (eg. dragging multiple files).

To support this, we need to track a full mapping of source/destination paths (because files might be moved from different levels into the same level - we can't compute destination paths from a single `newFile` variable), and also build a unique set of references that need updating (rather than building edits as we go - where we might try to edit the same reference from both ends).

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

This is currently only supported for LSP.

Change-Id: I3a8ab8b2dcb13451111d38d2ec0e2f69d6084e28
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/329320
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2023-10-11 03:56:29 +00:00
Danny Tuppeny 800421bc60 [analysis_server] Refactor servers to allow producing edits for LSP over Legacy
This is a no-op refactor extracted from an upcoming change to enable the onWillRenameFiles request to work for LSP over the Legacy protocol.

It's mostly lifting some API from the LSP server to the base server and some into a new mixin (`LspVerifyEditHelpersMixin`) to provide the required methods for verifying edits without the usual LSP base test classes.

Change-Id: Id6084a80e3afb9c6af1a84d9e8a18d460b5f4cce
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/329980
Commit-Queue: Keerti Parthasarathy <keertip@google.com>
Reviewed-by: Keerti Parthasarathy <keertip@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2023-10-10 21:30:25 +00:00
Danny Tuppeny 9b1be91249 [analysis_server] Tolerate added/removed commas when computing minimal diffs for formatting
Fixes https://github.com/dart-lang/sdk/issues/53561

Change-Id: Iaa93c1fd3565bd079676a146592279d42863b018
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/329602
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Bob Nystrom <rnystrom@google.com>
2023-10-10 15:36:20 +00:00
Alexander Thomas 49f4c5f94a [analysis_server] Move language server protocol to third_party
Bug: b/286184681
Change-Id: Iabb9070e354f85d29bb94dee4bdd52a0cf664c94
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/326643
Commit-Queue: Alexander Thomas <athom@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Devon Carew <devoncarew@google.com>
2023-10-10 07:48:30 +00:00
Danny Tuppeny 260b9b18f5 [analysis_server] Fix location of ignore comments on getters with dartdocs
Fixes https://github.com/Dart-Code/Dart-Code/issues/4775

Change-Id: I7fd049f2f58ed677c5c4a8e5ab7450e54ae61c9c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/329740
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2023-10-09 18:58:40 +00:00
Keerti Parthasarathy feb486fdd4 Update CASE_EXPRESSION_TYPE_IMPLEMENTS_EQUALS to needsFix.
Change-Id: Id2616570f7b282561d1975537fd6e59470733c0c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/329783
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Keerti Parthasarathy <keertip@google.com>
2023-10-09 18:29:59 +00:00
Danny Tuppeny 20d598c7ce [analysis_server] Change LSP server to truncate using Fuzzy Score before Relevance
Previously the fuzzy score was only used for filtering, then we truncated using the relevance score. This change uses the fuzzy score for sorting prior to truncation (calling back to relevance if it's the same) too.

Currently, VS Code in non-web contexts does not truncate (it's set to 100,000 items) so this change will only impact web contexts (currently set to 1,000 items to reduce payload sizes). From my testing, the difference in the first 30 items that will be seen is negligible (there are some differences between the servers fuzzy score and VS Codes, but they tend to be when there are typos).

Change-Id: Ia10d1991085054cec9c0c1071a516c8aa286156c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/329323
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2023-10-09 17:05:08 +00:00
Danny Tuppeny cf78037c5b [analysis_server] Change default leading/trailing behaviour for replaceSourceIndent
Makes behaviour of changing leading indent or trailing newlines opt-in.

There are only slightly more uses of this method that don't want this (now opt-in) behaviour, although I think this is slightly less surprising (for example the trailing newline behaviour was to "add a trailing newline only if it didn't already exist" which I don't think was obvious).

Mostly this was just changing the defaults and all of the call sites. However, some call sites were getting the old behaviour (inc leading/trailing whitespace), but then calling `.trim()`, so I didn't add the opt-in there because it would then be removed (they won't show up in the diff because they didn't actually get any changes).

Change-Id: I2f05b3a6266aaad5ee510ce2a8bf269b26d42d5d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/329540
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
2023-10-06 23:32:22 +00:00
Danny Tuppeny 2d0985340b [analysis_server] Add explicit test for generating minimal edits
This is a minor refactor that adds an explicit test for generating minimal edits without going through the formatter.

There's no change in behaviour - this is just to reduce the noise in a future CL for inserted/deleted commas to be supported in computing minimal diffs.

Change-Id: I3d254bd7a90ccc7b11700b54110ece040e837363
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/329601
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2023-10-06 18:46:25 +00:00
Brian Wilkerson 420bfe3bf5 Cleanup overlap between suggestions for statements and expressions
Fixes some cases where the same keyword was being suggested twice
because we were completing at the beginning of a statement which can
also be the beginning of an expression.

Change-Id: I7c12da8caed14438f9f1a16fa7121d1cbd96b891
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/328769
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2023-10-03 13:23:46 +00:00
Keerti Parthasarathy c452dfcdc0 Fix data driven fix bug when the element in question is not resolved.
Fixes https://github.com/Dart-Code/Dart-Code/issues/4757.

Change-Id: Ifd160dbafa468db6a703209a6ee6ea1566da5223
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/328742
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Keerti Parthasarathy <keertip@google.com>
2023-09-29 15:56:52 +00:00
Keerti Parthasarathy 3263977c48 Add a validator for missing dependencies in pubspec file.
Change-Id: Ief1986d4eb5a8095ea6a21d81239e6dd08b9a0b2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/326260
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Keerti Parthasarathy <keertip@google.com>
2023-09-29 15:01:05 +00:00
Brian Wilkerson 6dd50ba9b0 Convert LabelContributor
Change-Id: I8d68a037496e2c54db9878426fd098bc3ae0f875
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/328682
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2023-09-29 00:21:29 +00:00
Konstantin Shcheglov 6aea7a0247 Issue 53628. Implement AugmentationFileKind.asLibrary, report error, tests.
Add more data to FileKind(s) to see why augmentations are not correct.

Bug: https://github.com/dart-lang/sdk/issues/53628
Change-Id: If4ac400efa48f40baf99feb53d9b0456baa8a15b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/328320
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
2023-09-28 21:25:26 +00:00
Brian Wilkerson a23b48ff43 Capture performance information about the new completion pass
Change-Id: I675146a3c7292585c450fe607025d4bce7e3c8f0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/328700
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2023-09-28 20:18:28 +00:00
Konstantin Shcheglov fc43c8a363 Extension type. Issue 53625. Report REPRESENTATION_FIELD_TRAILING_COMMA.
Bug: https://github.com/dart-lang/sdk/issues/53625
Change-Id: I89d34b35b3e8b5977d1f99d550f91ce58e1c2150
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/328340
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
2023-09-28 20:01:36 +00:00
Brian Wilkerson b580b1c08e Minor cleanup in code completion
Change-Id: Ie9a6effe069ca327b6fc42a7a4b4198427d19627
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/328184
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2023-09-28 03:47:58 +00:00
pq 5deb63b791 add fix for ParserErrorCode.PATTERN_ASSIGNMENT_DECLARES_VARIABLE
Fixes: https://github.com/dart-lang/sdk/issues/49960

Change-Id: I3e49203a73739eacff8e05ad2ede25816212a718
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/328403
Commit-Queue: Phil Quitslund <pquitslund@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2023-09-28 00:40:08 +00:00
Danny Tuppeny 7dfd97ba99 [analysis_server] Improve re-indenting of fixes/assists + add additional switch expression fix for Wrap
The original goal of this change was to add the `switchExpression` test in `flutter_wrap_center_test.dart`, but it failed on Windows and exposed a bug that affected a number of assists/fixes.

The issue was that indentation was being rewritten using a regex:

src.replaceAll(RegExp('^$indentOld', multiLine: true), indentNew)

On Windows, when `indentOld` is an empty string, both `\r` and `\n` are matched individually, resulting in indentation being inserted between them:

foo\r    \n    bar

To fix this, I changed all places using a regex for replacement like this to call the existing `CorrectionUtils.replaceSourceIndent` method which did not have this problem. However, it made two different assumptions:

1. Indentation should always be updated on the first line (which if `indentOld` is an empty string, results in extra unwanted indentation being prepended to the string)
2. A new EOL should always be added at the end of the new code

To handle this, I added two new parameters and kept the original behaviour the same (although, I'm not sure if defaulting to adding a newline makes a lot of sense).

Change-Id: Ifa714da62c2541ba54a5376aa67149c90396dec2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/328220
Reviewed-by: Keerti Parthasarathy <keertip@google.com>
Commit-Queue: Keerti Parthasarathy <keertip@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2023-09-27 22:25:52 +00:00
Danny Tuppeny 2d0bebfb22 [analysis_server] Identify Flutter widgets in switch expressions
Fixes https://github.com/Dart-Code/Dart-Code/issues/4758

Change-Id: Id43a772a59db580e68897b84b782516857d68417
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/327883
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Keerti Parthasarathy <keertip@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2023-09-27 17:32:32 +00:00
Sam Rawlins 8042d092fd analyzer: Support tool doc directive
Fixes https://github.com/dart-lang/sdk/issues/52705

Change-Id: I15f8f4d9b989df75600ae589366126ed0c2fcb33
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/327284
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2023-09-25 22:44:29 +00:00
Brian Wilkerson 4963955276 Finish converting the KeywordContributor
Change-Id: Ifa5100c6458f1a91f492223b261bcd53f23e847f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/327560
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2023-09-25 22:07:56 +00:00
Konstantin Shcheglov aa76c0c7af Highlight 'augment' and 'macro' keywords.
Change-Id: I236969f9f66da7d1a0765593db28dd0beee2b0e3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/327801
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2023-09-25 21:33:56 +00:00
Sam Rawlins 7178fb9000 analyzer: Validate doc directive argument formats
Work towards https://github.com/dart-lang/sdk/issues/52705

Change-Id: Ieea17365397eaf9936ea9eaede2d472bd91abbc6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/327300
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2023-09-25 21:00:58 +00:00
Danny Tuppeny c08aeec581 [analysis_server] Explicitly check for switch expression instead of parens in inline_local
A tweak to the fix made for https://github.com/Dart-Code/Dart-Code/issues/4732.

Change-Id: I5f0d8f97ec693cb538df94a42128e0325b6ef929
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/327200
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2023-09-22 17:31:48 +00:00
Kallen Tu 742ba5c20d [analyzer] Change the const evaluation result of variables to be Constant.
We rely on the result of the `ConstantVisitor` to indicate whether we have an error or a valid constant value.

This CL changes `evaluationResult` to be a `Constant` and changes error reporting to occur at a POE for evaluating a constant.

Last few chunks of cleaning up the constant evaluator, woo!

Change-Id: Icd41a4fcbab0626df36c6a83cd60ecbb59c2dcf0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/324573
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Lasse Nielsen <lrn@google.com>
Commit-Queue: Kallen Tu <kallentu@google.com>
2023-09-22 16:13:10 +00:00
Brian Wilkerson 4c73e0ab49 Convert one more KeywordContributor method
Change-Id: Ic58d7a4cd2878981f77221b85b0566a7a0f5b732
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/327240
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2023-09-21 19:21:39 +00:00
Sam Rawlins b09ecc45bf analyzer: Block doc directives
In this CL, we shake things up a bit to separate the idea of a "doc
directive" and a "doc directive tag". The doc comments have been
updated to reflect the change. We have to recognize and support end-
tags, and recover when an end-tag is missing, a start-tag is missing,
or end-tags are out-of-order.

I also introduce a notion of doc directive nesting, in a way that
should not be computationally expensive, nor memory expensive.

Take this text as an example:

/// {@template foo}
/// Text.
/// {@inject-html}
/// <p>Some HTML.</p>
/// {@end-inject-html}
/// {@youtube ... }
/// {@endtemplate}

Notice the doc directives nested in the following way:

* template directive:
  * text: "Text."
  * inject-html directive:
    * text: "<p>Some HTML.</p>"
    * youtube directive

I want to avoid storing any blocks of text on the DocDirective nodes,
to avoid what could be very excessive memory usage. And if I want to
avoid storing the text, I think there is little benefit in storing the
data for these directives in a tree structure. In this CL, the data
is stored in one List, `docDirectives` on the CommentImpl:

* [0] - template directive, with data about its opening tag and
        closing tag.
* [1] - inject-html directive, with data about its opening tag and
        closing tag.
* [2] - youtube tag, with data about its singular tag.

For syntax highlighting purposes, there is no benefit to understanding
the nesting. And dartdoc currently gets all of the comment text from
the AST (or maybe from offsets in the actual text???) so I think there
is currently no downside to not capturing the nesting structure in
the CommentImpl instance.

But I can see in the future it might be better for dartdoc to consume
an API with the nesting structure, and that nesting structure does not
necessarily need to contain a copy of any text; it could contain some
sort of 'Text' data, with offsets of text contained in block doc
directives.

Change-Id: Ib58ab68fe80eea76ee7fa912d00fc69cc74f72d3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/326883
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2023-09-20 21:56:50 +00:00
Jens Johansen 807d1cf47b [analyzer] Don't cache completion data
TL;DR: This CL is shown to reduce memory usage by ~660MB when asking
for many completions.

Before this CL the analyzer cached `_ElementCompletionData` for every
element that have ever had it calculated. This itself contains new
strings, lists etc.

This was likely (although I'm guessing) done because it was asked for
it a lot: In my benchmarks, asking for at most 250 completions for each
of the first 200 files (twice) it was asked more than 113 million times.
Likely (extrapolating) it would take ~26 minutes creating these if not
cached.

In practise we don't need to ask for >113 million of them though.
Each request only wants at most, say, 100 results and likely fewer.
In the benchmark the `build` command was only run ~31% more times than
the number of caches. Building 100 results (again just using the
average) would take ~1.4 ms so hardly matters.

This CL removes the caching (including the field on many `Element`s),
and only calculates it when needed (i.e. on `build` as it's about to be
sent to the users IDE).

When asking for at most 250 completions in the first 1000 files in flutter/flutter (80+ contexts) we save ~669MB of heap usage, making
the heap usage decrease from ~8.34GB to ~7.69GB.

Details:

```
ExtensionElementImpl (package:analyzer/src/dart/element/element.dart) (bytes):
Difference at 95.0% confidence
   -1185728.00 +/- 413.05
   -8.36% +/- 0.00%

SimpleIdentifierImpl (package:analyzer/src/dart/ast/ast.dart) (bytes):
Difference at 95.0% confidence
   -1187104.00 +/- 133935.98
   -1.14% +/- 0.13%

_List (dart:core) (instances):
Difference at 95.0% confidence
   -1204916.00 +/- 5571.96
   -10.08% +/- 0.05%

ConstTopLevelVariableElementImpl (package:analyzer/src/dart/element/element.dart) (bytes):
Difference at 95.0% confidence
   -1301800.00 +/- 12081.85
   -7.93% +/- 0.07%

_OneByteString (dart:core) (instances):
Difference at 95.0% confidence
   -1825992.50 +/- 186205.44
   -28.49% +/- 2.91%

ConstructorElementImpl (package:analyzer/src/dart/element/element.dart) (bytes):
Difference at 95.0% confidence
   -5518400.00 +/- 135361.21
   -6.29% +/- 0.15%

ClassElementImpl (package:analyzer/src/dart/element/element.dart) (bytes):
Difference at 95.0% confidence
   -6820704.00 +/- 21606.00
   -6.34% +/- 0.02%

CompletionDefaultArgumentList (package:analysis_server/src/services/completion/dart/utilities.dart) (bytes):
Difference at 95.0% confidence
   -9054304.00 +/- 6195.82
   -100.00% +/- 0.07%

InterfaceTypeImpl (package:analyzer/src/dart/element/type.dart) (bytes):
Difference at 95.0% confidence
   -9941600.00 +/- 776821.86
   -2.32% +/- 0.18%

ElementLocationImpl (package:analyzer/src/dart/element/element.dart) (bytes):
Difference at 95.0% confidence
   -10401472.00 +/- 111022.97
   -46.19% +/- 0.49%

_TwoByteString (dart:core) (bytes):
Difference at 95.0% confidence
   -11262480.00 +/- 227076.11
   -11.77% +/- 0.24%

MethodElementImpl (package:analyzer/src/dart/element/element.dart) (bytes):
Difference at 95.0% confidence
   -13877752.00 +/- 351565.94
   -7.70% +/- 0.20%

_ElementDocumentation (package:analysis_server/src/services/completion/dart/suggestion_builder.dart) (bytes):
Difference at 95.0% confidence
   -18954304.00 +/- 202259.10
   -100.00% +/- 1.07%

_GrowableList (dart:core) (bytes):
Difference at 95.0% confidence
   -23003968.00 +/- 3135.17
   -25.12% +/- 0.00%

Location (package:analyzer_plugin/protocol/protocol_common.dart) (bytes):
Difference at 95.0% confidence
   -63403200.00 +/- 444171.45
   -99.68% +/- 0.70%

_List (dart:core) (bytes):
Difference at 95.0% confidence
   -71587648.00 +/- 2062003.75
   -5.54% +/- 0.16%

Element (package:analyzer_plugin/protocol/protocol_common.dart) (bytes):
Difference at 95.0% confidence
   -79254080.00 +/- 555214.31
   -100.00% +/- 0.70%

_ElementCompletionData (package:analysis_server/src/services/completion/dart/suggestion_builder.dart) (bytes):
Difference at 95.0% confidence
   -110955712.00 +/- 777300.03
   -100.00% +/- 0.70%

_OneByteString (dart:core) (bytes):
Difference at 95.0% confidence
   -258932360.00 +/- 9586397.08
   -35.00% +/- 1.30%

maxRSS:
Difference at 95.0% confidence
   -327434240.00 +/- 121326188.82
   -3.05% +/- 1.13%

currentRSS:
Difference at 95.0% confidence
   -551153664.00 +/- 121286389.20
   -5.34% +/- 1.18%

heapCapacity:
Difference at 95.0% confidence
   -555710464.00 +/- 164879781.95
   -5.75% +/- 1.71%

heapUsage:
Difference at 95.0% confidence
   -701868280.00 +/- 8054728.47
   -7.84% +/- 0.09%
```

Change-Id: I3b3631520d56ab36dabaee913e802aa1b7ebacfe
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/326822
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2023-09-19 18:40:30 +00:00
Danny Tuppeny cc7dd80d51 [analysis_server] Don't include unnecessary parens when inlining locals
Fixes https://github.com/Dart-Code/Dart-Code/issues/4732

Change-Id: I5d0da808bea37b533a42b7aaf5443433826393f5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/326821
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2023-09-19 17:04:40 +00:00
Brian Wilkerson cc399708d3 Move more keyword completions
Change-Id: Ibdd1175731317acc91bff3e08ac57f706775bf56
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/326540
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2023-09-18 18:02:25 +00:00
pq d1b6ea9f4d +annotate_redeclares
Fixes: https://github.com/dart-lang/linter/issues/4747

Change-Id: I7bf3e83dbe279f5b1a03dc5e5806c7c0fe3e3486
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/326263
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Phil Quitslund <pquitslund@google.com>
2023-09-18 02:41:29 +00:00
Sam Rawlins a46738c378 analysis_server: enforce prefer_void_to_null
Change-Id: I9dbb5d28ef92ac1af3a505e2790e42a136e3a417
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/325801
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2023-09-15 19:35:21 +00:00
Sam Rawlins 339d9f2dc5 analyzer: add doc directive support for example and macro
Work towards https://github.com/dart-lang/sdk/issues/52705

Change-Id: I9c3dc18546345905f179eef01c94bac2277e6bfb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/325581
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2023-09-13 18:03:42 +00:00
Sam Rawlins 283dad4ddc analysis_server: Enforce single quotes preference
Change-Id: I553befc2c45e66bfc569004d810b4e0a958d4baa
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/325544
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2023-09-13 17:48:22 +00:00
Sam Rawlins cdf016c6ab analyzer: Support animation doc directive; refactor classes
Work towards https://github.com/dart-lang/sdk/issues/52705

Change-Id: Idc77bf866beace85b40b30d464ff4c7c62e19735
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/325360
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2023-09-12 19:40:38 +00:00
Sam Rawlins 252bfcb27a Move UNIGNORABLE_IGNORE from HintCode to WarningCode
Work towards https://github.com/dart-lang/sdk/issues/50796

Change-Id: Idb8d04eb07beeb4f201ca69d0543d85305d62ea8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/325127
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Auto-Submit: Samuel Rawlins <srawlins@google.com>
2023-09-12 17:26:29 +00:00
Keerti Parthasarathy 4a04ec3201 Wire up use of deprecated export.
Bug:48997
Change-Id: I440fb8ebfe63ae785571f7927c5cdab625eee0cb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/325363
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Keerti Parthasarathy <keertip@google.com>
2023-09-11 23:24:19 +00:00
Danny Tuppeny f2eee8bf71 [analysis_server] Don't flush diagnostics for deleted files that have overlays
Fixes https://github.com/dart-lang/sdk/issues/53475

Change-Id: I5eaba2192e8d9d141cbee02f4c9bbe941db026f2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/325262
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2023-09-11 18:16:38 +00:00
Danny Tuppeny 3bf8a233a5 [analysis_server] Add a preview flag for surveys
Change-Id: Iaacdeb24a222df3cf6d730641c7c4cf7355f0f2f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/325263
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2023-09-11 18:08:06 +00:00
Konstantin Shcheglov 2a758931aa Extension type. Fixes for activating rename refactoring.
Change-Id: Ie275fbb94789878ca96302635677823f24242284
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/325080
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
2023-09-08 18:13:51 +00:00
Brian Wilkerson b8a89b66a6 Initial support for code completion in extension type declarations
Change-Id: I6acb71d0ac282135b6527431b162fad9a0dee8f7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/324900
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2023-09-08 14:30:20 +00:00