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 component references experience #2130

Open
brunnerh opened this issue Aug 17, 2023 · 2 comments
Open

Improve component references experience #2130

brunnerh opened this issue Aug 17, 2023 · 2 comments
Labels
feature request New feature or request

Comments

@brunnerh
Copy link
Member

Description

There currently is no intuitive way to find references to a component from within the component.

  • One has to know about the special command Svelte: Find Component References
  • The regular commands do not work:
    • Go to References (would be equivalent to above command)
    • References: Find All References (has no equivalent, shows references in the side bar)

Proposed solution

  • Add a lens at the top of the component file that behaves like that in JS/TS files
    image
    • If the count cannot easily be determined dynamically it could just say "Go to references"
    • Essentially already implemented as Svelte: Find Component References
  • If there is a way to make the standard commands work, integrate them.
    Since those can be used on other symbols, I was thinking that maybe with the cursor on the <script> tag it could search for component references. Of course still not ideal, as components can just omit that entirely as well...
  • If standard commands can not be integrated, maybe add a separate Svelte: ... command that shows references in the side bar, not sure if that is possible either, though.

Alternatives

Stick with Svelte: Find Component References and global search, if a more persistent list is required (e.g. for checking every single usage site).

Additional Information, eg. Screenshots

No response

@dummdidumm dummdidumm added the feature request New feature or request label Aug 17, 2023
@jasonlyu123
Copy link
Member

jasonlyu123 commented Aug 18, 2023

We didn't use the normal command but created a "Svelte: Find Component References" because find-reference is triggered from a symbol. But there isn't a symbol to trigger. Using the script tag as the trigger could work; we already do that in "show call hierarchy". Does that feel more intuitive to you? Or do you want References: Find All References to work? If you always prefer a sidebar reference. You could use the "references.preferredLocation": "view" config to make "Svelte: Find Component References" shows up in the sidebar. We didn't make it always does that because of #1516.

And about code len, the typescript reference code len is disabled by default, probably due to performance concerns. If we add the support, we would probably disable it by default. That might not help with feature discovery.

@brunnerh
Copy link
Member Author

Ideally both types of reference view should work, I specifically did not set references.preferredLocation because depending on use case there are advantages to both. If I just want to go to one specific usage the "peek" view is more straightforward, if I need to check or adjust all usages, the view is better, as it persists after navigation.

If the two commands Go to References & References: Find All References would work on <script> that would be great, but having separate commands that can be triggered anywhere in the component would be nice too, especially since they would always work and you do not need to know that you have to put the cursor on <script>.

dummdidumm pushed a commit that referenced this issue Sep 19, 2023
#2130

This allows for finding current component references from the script tag. The advantage of this is that you can now use the "Find All References" command for component references. This will always open in the sidebar without setting the references.preferredLocation config.

While we're on this topic, I also map the reference for a component to "find component references". Currently, these are only the references for the file that was requested. The reason is that the name of the generated component is suffixed, so any import will be an aliased default import. Thus, TypeScript only searches within the same file.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants