piersolenski / telescope-import.nvim

Import modules with ease
169 stars 8 forks source link

Useful plugin, but it is not working (tried with different, but doesn't work) #26

Closed daUnknownCoder closed 1 week ago

daUnknownCoder commented 4 months ago

image ⬇️ presses fi [Telescope import] ⬇️ image

config:

    require("telescope").setup({
        ...
        extensions = {
          ...
          import = {
            insert_at_top = true,
            custom_languages = {
              {
                regex = [[^(?:import(?:[\"'\s]*([\w*{}\n, ]+)from\s*)?[\"'\s](.*?)[\"'\s].*)]],
                filetypes = {
                  "typescript",
                  "typescriptreact",
                  "javascript",
                  "react",
                  "python",
                  "lua",
                  "c",
                  "cpp",
                  "zsh",
                  "java",
                  "bash",
                },
                extensions = {
                  "js",
                  "ts",
                  "typescript",
                  "typescriptreact",
                  "javascript",
                  "react",
                  "python",
                  "c",
                  "cpp",
                  "lua",
                  "zsh",
                  "java",
                  "bash",
                },
              },
            },
          },
        },
      })
      ...
      telescope.load_extension("import")

other config, where extensions table does not have python ⬇️ image

    require("telescope").setup({
        ...
        extensions = {
          ...
          import = {
            insert_at_top = true,
            custom_languages = {
              {
                regex = [[^(?:import(?:[\"'\s]*([\w*{}\n, ]+)from\s*)?[\"'\s](.*?)[\"'\s].*)]],
                filetypes = {
                  "typescript",
                  "typescriptreact",
                  "javascript",
                  "react",
                  "python",
                  "lua",
                  "c",
                  "cpp",
                  "zsh",
                  "java",
                  "bash",
                },
                extensions = {
                  "js",
                  "ts",
                },
              },
            },
          },
        },
      })
      ...
      telescope.load_extension("import")

other config, where extensions table does not have python, filetypes table also does not have python ⬇️ image ⬇️ [Note that typing from <some module> ... and import <some module> does not give me results] ⬇️ image

    require("telescope").setup({
        ...
        extensions = {
          ...
          import = {
            insert_at_top = true,
            custom_languages = {
              {
                regex = [[^(?:import(?:[\"'\s]*([\w*{}\n, ]+)from\s*)?[\"'\s](.*?)[\"'\s].*)]],
                filetypes = {
                  "typescript",
                  "typescriptreact",
                  "javascript",
                  "react",
                },
                extensions = {
                  "js",
                  "ts",
                },
              },
            },
          },
        },
      })
      ...
      telescope.load_extension("import")

[Same for lua with same config]

piersolenski commented 4 months ago

Hey there!

Python and many of the other languages you're trying to add are already supported by default..

When adding custom languages, it's important that you add a separate table for each language, each with its own regex, filetypes, and extensions, rather than put it all in one single table.

Currently it looks like you're trying to use a single catch all regex, for all the different potential filetypes.

Just follow the format of the built in supported languages, or search GitHub to see how others have used the the custom languages option.

daUnknownCoder commented 4 months ago

cool, adding the custom table proved unnecessary ig

daUnknownCoder commented 4 months ago

ok so this doesnt work for python, tested for js, ts, lua but it doesnt work for python idk why my config:

      {
        "piersolenski/telescope-import.nvim",
        lazy = true,
        keys = { { "fi", "<cmd>Telescope import<CR>", desc = "Import Modules [Telescope]" } },
        cmd = "Telescope import",
      },
          import = {
            insert_at_top = true,
          },
      telescope.load_extension("import")
piersolenski commented 4 months ago

From your example it looks like you're not using standard Python, and you have some form of type annotations. Can you share what your import statements look like in the project you're trying to use it in? What happens when you run <cmd>Telescope import<cr>?

daUnknownCoder commented 4 months ago

i just do nvim <some-file>.py this is the code in the file:

from abc import ABC, abstractmethod

class Shapes(ABC):
    @abstractmethod
    def area(self):
        pass

class Circle(Shapes):
    def __init__(self, radius):
        self.radius = radius

    def area(self):
        return (22 / 7) * self.radius * self.radius

class Rectangle(Shapes):
    def __init__(self, width, length):
        self.width = width
        self.length = length

    # def area(self):
    #     return (22 / 7) * self.length * self.width

rectangleobj = Rectangle(500, 100)
print(f"Rectangle Area: {rectangleobj.area()}")

circleobj = Circle(5)
print(f"Circle Area: {circleobj.area()}")

<cmd>Telescope import<cr> looks like this

image

for a random lua code, it looks like this: image for a random js code, it looks like this: image

piersolenski commented 1 week ago

Fixed in https://github.com/piersolenski/telescope-import.nvim/pull/28