Skip to content

This telescope displays callable names in workspace. After searching a callable name you want, if you press <enter>, it inserts a import statement to top of buffer.

License

Notifications You must be signed in to change notification settings

ok97465/telescope-py-importer.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

telescope-py-importer.nvim

DEMO

Overview

This telescope displays callable names in workspace. After searching a callable name you want, if you press <enter>, it inserts a import statement to top of buffer. If you press <tab>, it inserts a import statement to top of buffer, and type the callable name at cursor position.

  • It doesn't use treesitter, lsp.
  • It need ripgrep, telescope.nvim, vim-isort.
  • It supports only class, function.

Installation

Plug 'fisadev/vim-isort'
Plug 'nvim-telescope/telescope.nvim'
Plug 'ok97465/telescope-py-importer.nvim'

Configuration

require('telescope').load_extension('py_importer')
-- Optional: configure behavior
require('telescope').extensions.py_importer.setup({
  search = {
    globs_include = { "*.py" },
    globs_exclude = { ".venv/**", "venv/**", "__pycache__/**", "build/**", "dist/**" },
    include_async_functions = true,
    include_variables = true,
  },
  insert = {
    docstring_scan_lines = 30,
    import_scan_lines = 80,
    put_mode = 'c', -- characterwise put for symbol name
    isort_command = 'Isort',
    -- header_markers are auto-detected from isort config when available
    -- Supported files: pyproject.toml, .isort.cfg, setup.cfg, tox.ini
    -- If none found, defaults below are used. In all cases, "# %% Import" is enforced.
    header_markers = {
      "# %% Import",
      "# Standard library imports",
      "# Local imports",
      "# Third party imports",
    },
  },
  path = {
    collapse_dunder_init = true, -- map pkg/__init__.py -> pkg
  },
})

Usage

require 'telescope'.extensions.py_importer.workspace({layout_config={prompt_position="top"}, sorting_strategy="ascending"})

Troubleshooting

  • Errors are reported via vim.notify with the title telescope-py-importer.
    • Missing ripgrep: ensure rg is in your PATH.
    • Insert failures: buffer may be unmodifiable; check :set ma.
  • isort command errors: set insert.isort_command = nil to disable.
  • You can enable verbose notifications by checking :messages.
  • Header markers: When an isort config exists, import section headings (e.g., import_heading_stdlib) are read and matched as # <heading>. If no config is found, the defaults above are used. # %% Import는 항상 포함됩니다.

About

This telescope displays callable names in workspace. After searching a callable name you want, if you press <enter>, it inserts a import statement to top of buffer.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages