Skip to content

Conversation

@milesziemer
Copy link
Contributor

@milesziemer milesziemer commented Feb 28, 2025

When I re-wrote the language feature implementations in #166, I
refactored documentSymbol. But it mostly just copied the previous
implementation, which produced a flat list of symbols. This meant that
member symbols would appear at the top-level, but documentSymbol is
meant to provide a tree-like view, where symbols can have children. So
this commit re-writes documentSymbol to produce a list of only the
top-level shapes' symbols (and the namespace statement's symbol), with
members' symbols being added as children to the top-level symbols, and
members of inline i/o are children of the inline i/o symbol.

I also changed up the Symbol kind a bit, so root shapes are of type
Class (except enum/intEnum, which are of type Enum), members are
of type Field (except enum/intEnum members, which are of type
EnumMember), and service/resource/operation members are of type
Property.

I explored having different symbol kinds for different types of shapes,
like making service-type shapes be of kind Interface, and primitive
types being of their corresponding kind (for example, an integer shape
would have kind Number), but I wasn't sure what some shape types
should be. For example, what should a blob shape be? So I decided to
just make all top-level shapes just be of kind Class.

I also fixed the range and selection range of symbols. Range now covers
everything from shape type -> end of block (if applicable), and
selection range is just the shape/member name.

I considered adding more children for service-type shape members,
like making the operations child symbol of a service shape have a
child for each of the operations in the list, but I think it would make
the tree view more noisy, plus I think the intent is to show symbol
definitions.

I also made a minor adjustment to the parsing of operations members,
making them always be inline or node member defs, instead of possibly a
regular member def for non-inline i/o. This is consistent with
resource/service members, which are always node members.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@milesziemer milesziemer force-pushed the improve-document-symbols branch 3 times, most recently from 4701a1b to 0abfdd1 Compare March 4, 2025 18:05
@milesziemer milesziemer changed the title Improve document/documentSymbol Properly implement document/documentSymbol Mar 4, 2025
When I re-wrote the language feature implementations in smithy-lang#166, I
refactored documentSymbol. But it mostly just copied the previous
implementation, which produced a flat list of symbols. This meant that
member symbols would appear at the top-level, but documentSymbol is
meant to provide a tree-like view, where symbols can have children. So
this commit re-writes documentSymbol to produce a list of only the
top-level shapes' symbols (and the namespace statement's symbol), with
members' symbols being added as children to the top-level symbols, and
members of inline i/o are children of the inline i/o symbol.

I also changed up the Symbol kind a bit, so root shapes are of type
`Class` (except enum/intEnum, which are of type `Enum`), members are
of type `Field` (except enum/intEnum members, which are of type
`EnumMember`), and service/resource/operation members are of type
`Property`.

I explored having different symbol kinds for different types of shapes,
like making service-type shapes be of kind `Interface`, and primitive
types being of their corresponding kind (for example, an integer shape
would have kind `Number`), but I wasn't sure what some shape types
should be. For example, what should a `blob` shape be? So I decided to
just make all top-level shapes just be of kind `Class`.

I also fixed the range and selection range of symbols. Range now covers
everything from shape type -> end of block (if applicable), and
selection range is just the shape/member name.

I considered adding more children for service-type shape members,
like making the `operations` child symbol of a service shape have a
child for each of the operations in the list, but I think it would make
the tree view more noisy, plus I think the intent is to show symbol
definitions.

I also made a minor adjustment to the parsing of operations members,
making them always be inline or node member defs, instead of possibly a
regular member def for non-inline i/o. This is consistent with
resource/service members, which are always node members.
Uses new Document methods for computing range and selectionRange.
@milesziemer milesziemer force-pushed the improve-document-symbols branch from 0abfdd1 to 538606f Compare March 27, 2025 20:49
@milesziemer milesziemer marked this pull request as ready for review March 27, 2025 20:50
@milesziemer milesziemer requested a review from a team as a code owner March 27, 2025 20:50
@milesziemer milesziemer requested review from haydenbaker and yefrig and removed request for haydenbaker March 27, 2025 20:50
List<Either<SymbolInformation, DocumentSymbol>> result = new ArrayList<>();
// Passing around the list would make the code super noisy, and we'd have
// to do Either.forRight everywhere, so use a consumer.
addSymbols((symbol) -> result.add(Either.forRight(symbol)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

neat!

@milesziemer milesziemer merged commit 77b522d into smithy-lang:main Mar 27, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants