Skip to content

Neoconf plugin to automatically set project's virtual-environment python runtime.

Notifications You must be signed in to change notification settings

rafi/neoconf-venom.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 

Repository files navigation

Venom: Neoconf Plugin

Discover project's virtual-environment and automatically set LSP servers.

Overview

Automatically find project's virtual-environment using various strategies:

  • Searches for venv, .venv, .python-version
    • If directory, use as virtual-environment. Great for in-project environments.
    • If a file, read the first line as path. Good for pyenv/virtualenvwrapper
  • Otherwise, use 3rd-party tools to find one:
    • poetry env info -p
    • pipenv --venv

Once found, register with LSP servers:

  • pyright
  • pylsp

Once installed and set-up, you can use :Neoconf lsp to view the applied changes.

Install

Requirements:

Use your favorite package-manager:

With lazy.nvim
{
  'rafi/neoconf-venom.nvim',
  dependencies = { 'nvim-lua/plenary.nvim' },
  version = false,
},
With packer.nvim
use {
  'rafi/neoconf-venom.nvim',
  requires = { 'nvim-lua/plenary.nvim' }
}

Setup

It's important that you set up venom AFTER neoconf.nvim and BEFORE nvim-lspconfig.

For example, using lazy.nvim:

{
  'neovim/nvim-lspconfig',
  event = { 'BufReadPre', 'BufNewFile' },
  dependencies = {
    { 'folke/neoconf.nvim', cmd = 'Neoconf', config = true },
    'rafi/neoconf-venom.nvim',
  },
  config = function(_, opts)
    --

    require('venom').setup()

    -- continue to setup lsp servers…
  end,
},

{
  'rafi/neoconf-venom.nvim',
  dependencies = { 'nvim-lua/plenary.nvim', 'folke/neoconf.nvim' },
},

Usage

Plugin will automatically run once editing a file. You can also select a runtime path using :Telescope venom virtualenvs

Use :Neoconf lsp to view settings. For example:

# Lsp Settings

## pyright

{
  python = {
    analysis = {
      …
    },
    pythonPath = "/Users/bob/.local/share/pyenv/versions/foo/bin/python"
  }
}

Config

These are the default settings:

require('venom').setup({
  echo = true,
  symbol = '🐍',
  venv_patterns = { 'venv', '.venv', '.python-version' },
  use_tools = true,
  tools = {
    pipenv = { 'pipenv', '--venv' },
    poetry = { 'poetry', 'env', 'info', '-p' },
  },
  plugins = {
    pyright = function(venv_path)
      return {
        python = {
          pythonPath = table.concat({ venv_path, 'bin', 'python' }, '/')
        },
      }
    end,
    pylsp = function(venv_path)
      return {
        pylsp = {
          plugins = { jedi = { environment = venv_path } }
        },
      }
    end,
  },
})

Telescope Extension

A Telescope extension is also included that you can select a python runtime you'd like to use.

Open: :Telescope venom virtualenvs

See More

neoconf.nvim, nvim-lspconfig

About

Neoconf plugin to automatically set project's virtual-environment python runtime.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages