piersolenski / telescope-import.nvim

Import modules with ease
189 stars 7 forks source link

FR: add files that haven't been imported yet #23

Closed chrisgrieser closed 7 months ago

chrisgrieser commented 9 months ago

Currently, the plugin uses rg look for imports already done in other files. That works well, except for the case if you haven't imported a file yet.

Adding new files to the list of potential import statements would fill that gap. (One could use vim.fs.find() to look for files, so there is no extra dependency on fd.) If the cwd is correctly set to be the project root, the import statements can be derived, e.g. require("import.utils") for a file located at ./lua/import/utils.lua. Though those are, of course, language specific. The imported var name could simply default to the filename:

local utils = require("import.utils")

piersolenski commented 7 months ago

This would be cool, but as you said, incredibly language specific given the simplicity of how the plugin works currently.

Even within the Javascript language alone, there are so many different variables to consider if it is looking at other files such as your node_modules for import statements, such as the package manager used, import vs require syntax, relative vs non-relative paths, the formatting of the import (spacing, quotation style etc)...

My original philosophy behind the plugin, asides creating a simple catch all approach, was to also look for existing recurring import "patterns" of imports you're currently using on your project. This also immediately encapsulates all of the potential pain points listed above. So for now I think it's easiest to stick with that rather than attempt to support all the languages the plugin can easily support given the existing approach.