telescope.nvim
telescope.nvim copied to clipboard
Feature: related files
Is your feature request related to a problem? Please describe. I am an Ember JS developer. Because Ember has very strong conventions about file system organisation, it is possible to define directories where a file related to the currently open file exists.
For example, I may be working on a component backing JS file and I would want to quickly switch to the template or test file for currently open file.
Being able to define some schema for file "types" in a project and quickly list all files which match this schema in a project would be a great productivity enhancement. In fact I used this vscode addon before my very recent switch to nvim.
I found this old vim plugin which does something similar, but something like this feature in telescope would be very nice for consistency and also because of the previewers.
I think it would be a requirement of this feature that a user can define arbitrary "file layout schemas" and each "type" of file can define multiple paths to check in. nextfile.vim handles it like this:
let g:relatedFiles = {
\ "Ruby On Rails" : {
\ "Controller" : { "expression" : "app/controllers/(.*)_controller.rb$", "transform" : "pluralize" },
\ "Funtional Test" : { "expression" : "test/functional/(.*)_controller_test.rb$", "transform" : "pluralize" },
\ "View" : { "expression" : "app/view/(.*)/", "transform" : "pluralize" },
\ "Model" : { "expression" : "app/models/(.*).rb$", "transform" : "singularize" },
\ "Unit Test" : { "expression" : "test/unit/(.*)_test.rb$", "transform" : "singularize" }
\ }
\ }
Okay this will be a weird analysis of how to realize that feature request in the most generic way. Hear me out.
I suggested some time ago to introduce a only similar to file_ignore_patterns see https://github.com/nvim-telescope/telescope.nvim/issues/408#issuecomment-757118731. We could use something like this and the already existing work in telescope-project to make it possible that we can define a "expression" which files are included in which project / subproject. I just don't get the transform part right now :)
CC @cjjlaidler wanna hear your thoughts
@Conni2461 @lougreenwood this would be a really nice feature. It's just difficult to think how to best implement it. Initially I imagine it as a separate 'telescope related files' plugin. You hit 'r' for instance, whilst working on a file and telescope opens a list of related files (set by the user). I don't imagine it fitting in telescope project, unless it was to search for specific types of files within a project - i.e. show me all test files in a project, or all styling related files.... which would be a great feature that I'll put on the roadmap (after workspaces - something I'm planning to look into in about month or so when I'm not quite so busy!)
But yeah @Conni2461 we could re-use parts of telescope project for this, mainly for storing the file matching patterns. Sounds sensible
@claidler @Conni2461
Thanks for engaging on this! 😄
I can see some functionality (the config of such a feature) crossing over with the projects addon, or rather classes of projects, simply because the related files are dependent on the architecture of a specific project - my "related files map" for an EmberJS project would be useless when working on the backend in Rails or whatever.
But maybe that's over thinking it, and seeing this as a simple addon which doesn't care about the architecture of a project and is simply concerned with what matching files exist on disk is the best way to think about it?
Hi @lougreenwood, I'll put this on the roadmap for the telescope project extension. I can see what you're saying. It is done on a per project basis, so should be part of the extension. Please let me know if you have any specific ideas towards implementation.
So.... I left neovim world for a while and have been using VSCode for most of the year, but I'm back and I made some progress on this - I discovered the vim-projectionist plugin which manages defining and switching between related files for a given file (e.g jumping between a test and a template for a component-type file)
One interesting feature that could be used as a basis for implementing this as a telescope extension (telescope-projectionist) is that for the defined types in a given projection, a command (with autocomplete) is available to switch to that related file.
For example, if I define a unit-test type of related file (and define the paths to find the related unit test, on the vim command line, if I type :EI will get a list of the available types, including:Eunittest` - listing these autocompletions could be an initial version of the extension discussed above.
I think this can be closed, there's now the telescope-alternate plugin which addresses this issue:
https://github.com/otavioschwanck/telescope-alternate.nvim