zed icon indicating copy to clipboard operation
zed copied to clipboard

Find references of files and directories

Open oleasteo opened this issue 1 year ago • 2 comments

Check for existing issues

  • [X] Completed

Describe the feature

Similar to find all references for variables, etc. it should be possible to find references to files and directories.

This would probably be a first step towards

  • #4895

If applicable, add mockups / screenshots to help present your vision of the feature

No response

oleasteo avatar Oct 09 '24 15:10 oleasteo

Can you describe a bit further what you're envisioning here? Like what's the use case / what does it look like / what gets included, etc. I'm having trouble imagining this being useful as a standalone feature and not just as a requirement for implementing #4895.

notpeter avatar Oct 09 '24 18:10 notpeter

What's the use case?

I'm used to those features in IntelliJ. Some common use-cases, for me, are:

  • Check if a file / module (directory) is fully unused (and hence can be dropped from the repository).
  • Have a quick & easy "lay man's dependency analysis" to see which other modules use some directory / file.
  • Find references of a whole file, to check all related places after a major change in that file. Easier than checking all exports one by one.
  • Find invalid references after deleting some stuff from a file.
  • Find file references in documentation files as well (e.g. hierarchical markdown files)

What does it look like

I imagine it similar to the current "find all references" feature. In my opinion, the references' editor view in combination with the outline panel is perfect. It provides a good overview of surrounding excerpts as well as a hierarchical directory tree.

Personally, I'd change the overview panel for the references view a little to only show relevant keywords or the lines that match the searched symbol. But I would change that for the current "find all references" alike.

What gets included?

Well, I'm not an expert in editor development, so I'm not sure if I'm the right person to ask at this point. For file references, all imports of said file for sure, but also links to that file within markdown files, etc. I could imagine a classification of search results into "language server related" and a more loose "filename grep" (within all project files not belonging to the language server).

For the latter, it's better to show false positives than to have false negatives (missing out on matches). In a more sophisticated manner, one could first grep for /my-dir-or-file and then filter those results to omit cases where a wrong path is found. E. g. if I search for src/path/to/dir:

  1. grep -R '/dir'
  2. omit results like /wrong/dir, but not to/dir or ../dir
  3. for relative path matches (everything that begins with explicit ./ or ../), check if that reference would actually point to the directory / file in question.

For the omitted results of steps 2 and 3, one could also add a button to the editor view to show them as well ("weak references").

oleasteo avatar Oct 09 '24 19:10 oleasteo