All Projects → HallerPatrick → py_lsp.nvim

HallerPatrick / py_lsp.nvim

Licence: other
Lsp Plugin for working with Python virtual environments

Programming Languages

lua
6591 projects
Vim Script
2826 projects

Projects that are alternatives of or similar to py lsp.nvim

nvim-config
My neovim config
Stars: ✭ 63 (+8.62%)
Mutual labels:  nvim, lsp
lsp spinner.nvim
neovim plugin to retrieve the name of the running LSP client(s) and display a spinner when there are wip job
Stars: ✭ 23 (-60.34%)
Mutual labels:  nvim, lsp
vim-lamp
💡Language Server Protocol client for Vim.
Stars: ✭ 34 (-41.38%)
Mutual labels:  nvim, lsp
lsp-command
Command interface for neovim LSP
Stars: ✭ 48 (-17.24%)
Mutual labels:  nvim, lsp
Thinkvim
Vim configuration in the 21st century
Stars: ✭ 832 (+1334.48%)
Mutual labels:  nvim, lsp
coc-java-debug
An extension for coc.nvim to enable Java debugging via jdt.ls
Stars: ✭ 92 (+58.62%)
Mutual labels:  nvim, lsp
fzf-lsp.nvim
Enable the power of fzf fuzzy search for the neovim built in lsp
Stars: ✭ 143 (+146.55%)
Mutual labels:  nvim, lsp
neovimfiles
My Neovim configuration written in Lua
Stars: ✭ 52 (-10.34%)
Mutual labels:  nvim, lsp
nvim-fennel-lsp-conjure-as-clojure-ide
Basic config to transform your NVIM in a powerful Clojure IDE using fennel, clojure-lsp and conjure.
Stars: ✭ 144 (+148.28%)
Mutual labels:  nvim, lsp
vimrc
My neovim config
Stars: ✭ 43 (-25.86%)
Mutual labels:  nvim, lsp
nvim-metals
A Metals plugin for Neovim
Stars: ✭ 265 (+356.9%)
Mutual labels:  nvim, lsp
Lsp Status.nvim
Utility functions for getting diagnostic status and progress messages from LSP servers, for use in the Neovim statusline
Stars: ✭ 201 (+246.55%)
Mutual labels:  nvim, lsp
aerial.nvim
Neovim plugin for a code outline window
Stars: ✭ 485 (+736.21%)
Mutual labels:  nvim, lsp
lspactions
handlers for required lsp actions
Stars: ✭ 44 (-24.14%)
Mutual labels:  nvim, lsp
Nvim Lspconfig
Quickstart configurations for the Nvim LSP client
Stars: ✭ 3,410 (+5779.31%)
Mutual labels:  nvim, lsp
Coc.nvim
Nodejs extension host for vim & neovim, load extensions like VSCode and host language servers.
Stars: ✭ 18,268 (+31396.55%)
Mutual labels:  nvim, lsp
wdl-ide
Rich IDE support for Workflow Description Language
Stars: ✭ 36 (-37.93%)
Mutual labels:  lsp
tds-vscode
Totvs Developer Studio for vscode
Stars: ✭ 135 (+132.76%)
Mutual labels:  lsp
qf helper.nvim
A collection of improvements for the quickfix buffer
Stars: ✭ 70 (+20.69%)
Mutual labels:  nvim
taskrunner.nvim
🏃 Runs Gulp/Gruntfiles in terminal splits
Stars: ✭ 13 (-77.59%)
Mutual labels:  nvim

py_lsp.nvim

What is py_lsp?

py_lsp.nvim is a neovim plugin that helps with using the lsp feature for python development.

It tackles the problem about the activation and usage of python virtual environments and conda environments for the nvim lsp.

Installation

Using vim-plug:

Plug 'HallerPatrick/py_lsp.nvim'

Using packer.nvim:

use {
    'HallerPatrick/py_lsp.nvim',
    -- Support for versioning
    -- tag = "v0.0.1" 
}

Usage

Instead of initializing the server on your own, like in nvim-lspconfig, py_lsp is doing that for you.

Put this in your init.lua (or wrap in lua call for your init.vim)

require'py_lsp'.setup {
  -- This is optional, but allows to create virtual envs from nvim
  host_python = "/path/to/python/bin",
  default_venv_name = ".venv" -- For local venv
}

This minimal setup will automatically pass a python virtual environment path to the LSP client for completion/linting.

WARNING: py_lsp is currently not agnostic against other python lsp servers that are starting or attaching. Please be aware of other plugins, autostarting lsp servers.

Features

py_lsp exposes several commands that help with a virtual env workflow.

Command Parameter Usage
:PyLspCurrentVenv No Prints the currently used python venv
:PyLspDeactiveVenv No Shuts down the current LSP client
:PyLspReload No Reload LSP client with current python venv
:PyLspActivateVenv venv name Activates a virtual env with given name (default: 'venv'). This venv should lie in project root
:PyLspActivateCondaEnv env name Activates a conda env with given name (default: 'base'). Requires conda to be installed on the system
:PyLspCreateVenv venv name Creates a virtual env with given name (default: 'venv'). Requires host_python to be set and have virtualenv installed
:PyRun Optional Run files and modules from current virtuale env. If no arguments specified, will run current buffer
:PyFindVenvs No List all found Virtualenvs found by different strategies. Select and reload LSP

Most of these commands can be also run over a popup menu with :PyLspPopup.

PyRun

The :PyRun command uses the currently activated virtuale environment to either execute the current buffer on or the arguments passed to pather. If toggleterm is an available plugin the command is executed through a toggleterm terminal.

Extras

The virtual environment path and name can be retrieved with client.config.settings.python.pythonPath and client.config.settings.python.venv_name. This can for example be used in your statuslines.

Example provider for feline:

local function lsp_provider(component)

    local clients = {}
    local icon = component.icon or ''

    for _, client in pairs(vim.lsp.buf_get_clients()) do
        if client.name == "pyright" then
          -- Check if lsp was initialized with py_lsp
          if client.config.settings.python["pythonPath"] ~= nil then
            local venv_name = client.config.settings.python.venv_name
            clients[#clients+1] = icon .. client.name .. '('.. venv_name .. ')'
          end
        else
          clients[#clients+1] = icon .. client.name
        end
    end

    return table.concat(clients, ' ')
end

This will give you a VSCode like status:

Statusline with LSP server and venv name

Configuration

The configurations are not sensible yet, and are suiting my setup. This will change.

Default:

Default Values:
    auto_source = true,
    language_server = "pyright",
    source_strategies = {"default", "poetry", "conda", "system"},
    capabilities = nil,
    host_python = nil,
    on_attach = nil,
    on_server_ready = nil
    default_venv_name = nil,
    venvs = {}

Other Language servers

I am using pyright and therefore works well with pyright. When using a not registered language server like jedi-language-server you can register it like following:

local nvim_lsp_configs = require "lspconfig.configs"

nvim_lsp_configs["jedi_language_server"] = {
    default_config = {
        cmd = {"jedi-language-server"},

        -- Depending on your environment
        root_dir = nvim_lsp.util.root_pattern(".git", "setup.py",
                                              "pyproject.toml"),
        filetypes = {"python"}
    }
}

local capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp
                                                                     .protocol
                                                                     .make_client_capabilities())

require("py_lsp").setup({
    language_server = "jedi_language_server",
    capabilities = capabilities
})

Todo

  • Support for different environment systems:
    • virtualenvwrapper
    • Pipenv
  • Agnostic against other python lsp server

Limitations

  • All features are currently only available with pyright and jedi-language-server. pylsp is weird. It will still be started, but all features are run with a 'pyright' server or not at all.
  • py_lsp expects to find virtualenv in the cwd, please check for that
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].