Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve document symbol hierarchy to match rust-analyzer layout #6678

Merged
merged 24 commits into from
Nov 29, 2024

Conversation

JoshuaBatty
Copy link
Member

@JoshuaBatty JoshuaBatty commented Oct 30, 2024

Description

Changes document symbols to provide a richer code outline view with nested hierarchies and type information, similar to rust-analyzer's implementation. This improves code navigation by showing relationships between elements (e.g., structs with their fields, functions with their variables) and includes type annotations for better understanding.

Key improvements:

  • Nested symbol hierarchy instead of flat list
  • Type information in symbol details
  • Function signatures with parameter/return types
  • Proper parent-child relationships for all code elements
  • Better outline view organization
Screenshot 2024-11-26 at 2 25 17 PM

Note: the performance impact is due to the get_range_from_span function which can't avoid calling. 19ms is still reasonable.

closes #6100

Checklist

  • I have linked to any relevant issues.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have updated the documentation where relevant (API docs, the reference, and the Sway book).
  • I have added tests that prove my fix is effective or that my feature works.
  • I have added (or requested a maintainer to add) the necessary Breaking* or New Feature labels where relevant.
  • I have done my best to ensure that my PR adheres to the Fuel Labs Code Review Standards.
  • I have requested a review from the relevant team or maintainers.

@JoshuaBatty JoshuaBatty requested a review from a team as a code owner October 30, 2024 04:47
@JoshuaBatty JoshuaBatty self-assigned this Oct 30, 2024
@JoshuaBatty JoshuaBatty added enhancement New feature or request language server LSP server labels Oct 30, 2024
@JoshuaBatty JoshuaBatty marked this pull request as draft October 30, 2024 04:48
alfiedotwtf
alfiedotwtf previously approved these changes Oct 30, 2024
@alfiedotwtf
Copy link
Contributor

Just curious why both range and selection_range are needed if they're the same values?

@JoshuaBatty
Copy link
Member Author

Just curious why both range and selection_range are needed if they're the same values?

I just put that there as a placeholder for now, still need to sort that and quite a bit more out. Probably at least a few more days of work left to get this PR ready. I'd expect this part to change before i'm ready to open up the PR for review.

@maxtalantsev
Copy link

cool

Copy link

codspeed-hq bot commented Nov 26, 2024

CodSpeed Performance Report

Merging #6678 will degrade performances by 71.22%

Comparing josh/nested_outline (df451fa) with master (33d3674)

Summary

❌ 1 regressions
✅ 21 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark master josh/nested_outline Change
document_symbol 5.5 ms 19.1 ms -71.22%

@JoshuaBatty JoshuaBatty marked this pull request as ready for review November 26, 2024 23:53
@JoshuaBatty JoshuaBatty requested review from a team and alfiedotwtf November 26, 2024 23:53
Copy link
Contributor

@alfiedotwtf alfiedotwtf left a comment

Choose a reason for hiding this comment

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

Apart from my questions and comments, looks good!

@JoshuaBatty
Copy link
Member Author

Apart from my questions and comments, looks good!

Thanks for the review. Should be good now.

@JoshuaBatty JoshuaBatty requested review from a team and alfiedotwtf November 27, 2024 23:47
Copy link
Member

@sdankel sdankel left a comment

Choose a reason for hiding this comment

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

This looks great!

I manually tested it on a bunch of different sway files and the only issue I found is that the outline doesn't show the types for enum variants the way it does for struct fields. For example, in sway-lsp/tests/fixtures/benchmark/src/main.sw I'd expect to see u8 next to Enum11's Variant1, and so on.

image

@JoshuaBatty
Copy link
Member Author

Good catch, adding type information in for enum fields is a great idea! I'll add that now. Thanks :)

@JoshuaBatty
Copy link
Member Author

Thanks for the suggestion @sdankel , added in 552fafc

@JoshuaBatty JoshuaBatty requested review from sdankel and a team November 28, 2024 04:57
Copy link
Member

@sdankel sdankel left a comment

Choose a reason for hiding this comment

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

:shipit:

@JoshuaBatty JoshuaBatty requested a review from a team November 28, 2024 09:07
@JoshuaBatty JoshuaBatty merged commit 2bc469a into master Nov 29, 2024
41 checks passed
@JoshuaBatty JoshuaBatty deleted the josh/nested_outline branch November 29, 2024 21:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request language server LSP server
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Nested outline of file for LSP
4 participants