Two fixes here:
1. The code that tried to compute a relative path from the "package root" was using the "context root" which in a Pub Workspace is not the same. Now we instead first try to get the package via `workspace.packages.packageForPath()`.
2. We used underscores for italics in the package name, and in GH Markdown, underscores at what it considers word boundaries can mess things up, so `_package:_foo_` would be rendered incorrectly. Now, we use single asterisks for italics instead.
Fixes https://github.com/dart-lang/sdk/issues/62501
Fixes https://github.com/dart-lang/sdk/issues/62500
Change-Id: I72dc736aef32c85a9e4fce8a0aad552a5a4e3c14
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/491840
Reviewed-by: Keerti Parthasarathy <keertip@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Keerti Parthasarathy <keertip@google.com>
With this change, we collect elements for all supertypes for the element at the supplied position. Then when walking the AST, we check whether each items elements or any of its own supertype elements match against that set.
This should result in all of the items the user would consider "reachable" from the starting location. This does mean some results are not symmetric (see the `fromLeaf` and `fromRoot` tests), but I think they are the most logical. While VS Code currently has a bug related to asymmetric highlights, I believe this will be fixed (because TypeScript also behaves this way).
This does add a little more work, but when walking the AST, we do check the name first as a quick check before we look at any supertypes.
Fixes https://github.com/Dart-Code/Dart-Code/issues/4670
Change-Id: Id2bcdff04c6c7826f8a164ecf99752951f641b8a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/490960
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Add `ClassBody.members` and `EnumBody.constants`/`members` so callers
can access class and enum contents through the common body interfaces
instead of pattern matching on `BlockClassBody` and `BlockEnumBody`.
Implement empty node lists for empty class and enum bodies, update the
public API, and migrate analyzer, analysis_server, analyzer_plugin, and
linter code to use the new accessors directly. This removes the ad hoc
`members2` helper extensions and a large amount of repeated `tryCast`
and `switch` logic, making body traversal more uniform.
Change-Id: I51d75f2253c7e6f75efecae84bf0443ff5eb6788
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/488263
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
The previous set of tests missed two cases:
- a primary constructor with a private named parameter
- constructors introduced by `new`
The latter had some bugs, which are fixed in this CL.
Change-Id: I872a3948dd1b0f791dbea1354c8377e83048e618
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/484227
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
As a copy of Occurrences, this computer would previously build all of the groups for all elements (/loop nodes) in the document and then filter at the end.
With this change, we determine the target element(s) or node first, and then only collect the related tokens as we walk the AST.
This should reduce the amount of memory used and reduce the cost of doing something like https://github.com/Dart-Code/Dart-Code/issues/4670 which may add some additional computation for resolving members to their super-most element.
Change-Id: Id516dbdf26b0b6ac3b1bedc7bc092f1f79f94a95
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/479622
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
This moves the LSP handler off the legacy servers occurrences onto its own copy in `computer_document_highlights`, and then removes the LSP-specific parts from the original occurrences class.
The implementation of `DartDocumentHighlightsComputerVisitor` is an exact copy of the original `DartUnitOccurrencesComputerVisitor` with no changes yet (to simplify reviewing, and have a better git history for changes that are made in future CLs).
Change-Id: Iea884522f6cbd760b8443d8e4525558de699f87b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/479560
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
DartUnitOutlineComputer adds field outlines for primary constructor
parameters that declare implicit fields. Previously this relied on a
syntactic heuristic (`final`/`var` keyword checks) via
FormalParameterExtension.isDeclaringParameter, which duplicated analyzer
logic and could misclassify parameters.
Switch to the resolved element model instead:
- Read the declared fragment element for each primary constructor
parameter.
- Add a declared-field outline only when the element is a
FieldFormalParameterElement with isDeclaring set.
Remove the now-unused AST extension and its import.
Change-Id: Ic0780a0cb9af1519d9a1f39a116e935eda52ab8f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/478244
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
For consistency with other things, we're generally just using the declaration for all ranges/positions, but we do support invoking call hierarchy on the `this` keyword of the body for convenience too.
Change-Id: I52e7a02a33f36f69775fb1231cc06095d47ecda9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/477740
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
This isn't the right implementation, but it no longer crashes when
experimenting with the primary_constructor feature.
While I don't expect this to impact users, it makes it easier for us to
play with the feature while developing the tooling for it.
Change-Id: I317eb03bfd4057adb39dd4352e43e41fdd28bd7f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/469101
Auto-Submit: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
We previously just showed "<unnamed extension>" for extensions without names, but in some files I noticed we have a lot of these, and the outline/symbols list looks awful (just "<unnamed extension>" repeated many times).
This changes it to instead show "extension on FooClass" instead (if there is a valid type name). I added a new field to the protocol to support this because the LSP classes convert from those classes (something we've discussed changing, but might be easier later).
Screenshots of before/after are in https://github.com/Dart-Code/Dart-Code/issues/5818
Fixes https://github.com/Dart-Code/Dart-Code/issues/5818
Change-Id: I3885a722443291bfa2419514841469c862b74450
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/464560
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
No more flag, always parse into the new AST, always visit new AST nodes,
always return them as child entities, parent-child structure reflects
the new AST.
So, use `namePart` and `body` where possible. Deprecate previous
properties.
This is still de jure a breaking change, because `parent` of deprecated
properties changes. De facto this required very few changes in google3.
Once this CL lands, I will publish `analyzer 10.0.0`, migrate everything
to new properties, delete deprecated properties, and publish `analyzer
11.0.0`.
Maybe deprecate `NamedCompilationUnitMember.name` and migrate to
subclass specific `name` or `namePart` properties before publishing
`analyzer 10.0.0`. This part is not breaking per se.
* Deprecations in `ClassDeclaration`:
* Properties `leftBracket`, `members`, `rightBracket` are deprecated, use `body` instead.
* Properties `name`, `typeParameters` are deprecated, use `namePart` instead.
* Deprecations in `EnumDeclaration`:
* Properties `leftBracket`, `constants`, `members`, `rightBracket` are deprecated, use `body` instead.
* Properties `name`, `typeParameters` are deprecated, use `namePart` instead.
* Deprecations in `ExtensionDeclaration`:
* Properties `leftBracket`, `members`, `rightBracket` are deprecated, use `body` instead.
* Deprecations in `ExtensionTypeDeclaration`:
* Properties `leftBracket`, `constants`, `members`, `rightBracket` are deprecated, use `body` instead.
* Properties `constKeyword`, `name`, `representation`, `typeParameters` are deprecated,
use `primaryConstructor` instead.
* **Breaking Change:** While the deprecated members mentioned above still exist in the AST,
their parent nodes have changed. This means that code relying on specific parent-child
relationships for these nodes might break.
Bug: https://github.com/dart-lang/sdk/issues/61701
Change-Id: Ic48104da8b029c9b454bbd2336574b7823025565
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/461841
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This fixes `_findTargetNode` on function tear-offs. Previously it would take the parent node of many `SimpleIdentifiers` which in the case of a tear-off could be some random expression.
Now we only return something other than the `node` in some very specific cases where we're trying to handle constructors (so that the type name is not considered a call for named constructors, but is considered the constructor for unnamed constructors).
Fixes https://github.com/dart-lang/sdk/issues/61736
Change-Id: I815d4dc8e1f1eaadd5ee033abf9731666944e45e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/457061
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>