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

feat: go-to-def and find-references on control-flow keywords #17542

Merged
merged 11 commits into from
Jul 22, 2024

Conversation

roife
Copy link
Member

@roife roife commented Jul 4, 2024

fix #17517.

This PR implements go-to-definition and find-references functionalities for control flow keywords, which is similar to the behaviors in the highlight-related module. Besides, this PR also fixes some incorrect behaviors in highlight-related.

Changes

  1. Support for go-to-definition on control flow keywords:
    This PR introduces functionality allowing users to navigate on the definition of control flow keywords (return, break, continue).
    Commit: 2a3244e..7391e7a.

  2. Bug fixes and refactoring in highlight-related:

    • Handling return/break/continue within try_blocks:
      This PR adjusted the behavior of these keywords when they occur within try_blocks. When encounter these keywords, the program should exit the outer function or loop which containing the try_blocks, rather than the try_blocks itself; while the ? will cause the program to exit try_blocks.
      Commit: 59d697e.
    • Support highlighting keywords in macro expansion for highlight-related:
      Commit: 88df24f.
    • Detailed description for the bug fixes
      • The previous implementation of preorder_expr incorrectly treated try_blocks as new contexts, thereby r-a will not continue to traverse inner return and break/continue statements. To resolve this, a new function preorder_expr_with_ctx_checker has been added, allowing users to specify which expressions to skip.
        • For example, when searching for the ? in the context, r-a should skip try_blocks where the ? insides just works for try_blocks. But when search for the return keyword, r-a should collect both the return keywords inside and outside the try_blocks
      • Thus, this PR added WalkExpandedExprCtx (builder pattern). It offers the following improvements: customizable context skipping, maintenance of loop depth (for break/continue), and handling macro expansion during traversal.
  3. Support for find-references on control flow keywords:
    This PR enables users to find all references to control flow keywords.
    Commit: 9202a33.

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 4, 2024
crates/ide/src/goto_definition.rs Outdated Show resolved Hide resolved
crates/ide/src/goto_definition.rs Outdated Show resolved Hide resolved
crates/ide/src/goto_definition.rs Outdated Show resolved Hide resolved
crates/ide/src/navigation_target.rs Outdated Show resolved Hide resolved
Copy link
Member

@Veykril Veykril left a comment

Choose a reason for hiding this comment

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

One thing to look out for is the turning FileRange into TextRange after upmapping. All of those need to verify that the file id of the FileRange is in fact the same as the file we are doing the feature stuff in, as include! has its input in a different file than where the call is. Generally speaking, dropping the file id of a FileRange yielded from upmapping without checks can easily cause issues

crates/ide/src/goto_definition.rs Outdated Show resolved Hide resolved
crates/ide/src/highlight_related.rs Outdated Show resolved Hide resolved
@Veykril Veykril added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 8, 2024
roife added a commit to roife/rust-analyzer that referenced this pull request Jul 10, 2024
@roife roife force-pushed the fix-issue-17517 branch 2 times, most recently from 5e66fbd to 4ffe9e5 Compare July 10, 2024 15:01
roife added a commit to roife/rust-analyzer that referenced this pull request Jul 10, 2024
roife added a commit to roife/rust-analyzer that referenced this pull request Jul 10, 2024
@roife roife force-pushed the fix-issue-17517 branch 3 times, most recently from f3db243 to 7d171bf Compare July 16, 2024 08:49
@roife
Copy link
Member Author

roife commented Jul 16, 2024

I squashed some commits related to goto-def and updated the PR description for simplicity.

@rustbot label -S-waiting-on-author +S-waiting-on-review

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 16, 2024
@roife roife requested a review from Veykril July 16, 2024 09:02
@bors
Copy link
Contributor

bors commented Jul 19, 2024

☔ The latest upstream changes (presumably #17620) made this pull request unmergeable. Please resolve the merge conflicts.

@Veykril
Copy link
Member

Veykril commented Jul 22, 2024

@bors r+

@bors
Copy link
Contributor

bors commented Jul 22, 2024

📌 Commit f027a46 has been approved by Veykril

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Jul 22, 2024

⌛ Testing commit f027a46 with merge d092f7d...

@bors
Copy link
Contributor

bors commented Jul 22, 2024

☀️ Test successful - checks-actions
Approved by: Veykril
Pushing d092f7d to master...

@bors bors merged commit d092f7d into rust-lang:master Jul 22, 2024
11 checks passed
Veykril pushed a commit to Veykril/rust-analyzer that referenced this pull request Jul 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

More IDE features for control flow keywords
4 participants