Update install script to be more useful and README to match, move venv for pynvim to standard location and use pipx for installing LSP+formatters

This commit is contained in:
Evie Litherland-Smith 2023-01-09 15:24:30 +00:00
parent 7b8e64a8c3
commit d761086c49
5 changed files with 50 additions and 44 deletions

2
.gitignore vendored
View file

@ -3,3 +3,5 @@
.python-version
.DS_Store
plugin/
venv

View file

@ -5,19 +5,21 @@ Personal configuration and plugins for Vim
```bash
curl -LO https://github.com/neovim/neovim/releases/latest/download/nvim.appimage
chmod u+x nvim.appimage
mv nvim.appimage "$HOME/bin/."
ln -s "$HOME/bin/nvim.appimage" "$HOME/bin/nvim" # Optional to avoid extension in commands
# ./nvim.appimage
mv nvim.appimage "$HOME/bin/nvim"
```
## Installing configuration
```bash
git clone git@github.com:elitherl/vim-config.git $XDG_CONFIG_HOME/nvim
git clone git@github.com:elitherl/vim-config.git ${XDG_CONFIG_HOME:-$HOME/.config}/nvim
# or using symlink
git clone git@github.com:elitherl/vim-config.git /path/to/directory
ln -s /path/to/directory $XDG_CONFIG_HOME/nvim
ln -s /path/to/directory ${XDG_CONFIG_HOME:-$HOME/.config}/nvim
```
### Install script
`install.sh` currently handles installing `Packer`, `pynvim`, `pipx` and currently configured language servers with formatters.
Will also update existing installs if already present.
### Installing `Packer` plugin manager
```bash
git clone --depth 1 https://github.com/wbthomason/packer.nvim\
@ -26,15 +28,31 @@ git clone --depth 1 https://github.com/wbthomason/packer.nvim\
Plugin definitions are in `plugins.lua`, inside `vim` run `:PackerSync` to install plugins
## Enabling python support
Set up neovim specific virtual environment to install `pynvim` package:
```bash
pyenv virtualenv neovim3 # Assumes working pyenv
pyenv activate neovim3
pip install -U pip setuptools wheel
pip install -U pynvim pyright fortl # If pyright not available, fallback to: "python-lsp-server[all]" pylsp-mypy
pyenv deactivate
python3 -m venv "${XDG_CONFIG_HOME:-$HOME/.config}/nvim/venv"
source "${XDG_CONFIG_HOME:-$HOME/.config}/nvim/venv/bin/activate"
pip install -U pip setuptools wheel && pip install -U pynvim
source deactivate
```
From [vim documentation](https://neovim.io/doc/user/nvim.html#nvim-from-vim)
### Installing language servers using `pipx`
Install [pipx](https://pypa.github.io/pipx/) in chosen manner, e.g. as given in documentation:
```bash
python3 -m pip install --user pipx
python3 -m pipx ensurepath
```
For currently configured language servers and formatters run:
```bash
pipx install pyright
pipx install fortls
pipx install black
pipx install isort
pipx install zimports
```
## Add LUA language server
Follow instructions from [sumneko/lua-language-server GitHub](https://github.com/sumneko/lua-language-server/wiki/Getting-Started#command-line).

View file

@ -5,3 +5,16 @@ PACKER_DIR="$HOME/.local/share/nvim/site/pack/packer/start/packer.nvim"
if [ ! -d $PACKER_DIR ]; then
git clone --depth 1 https://github.com/wbthomason/packer.nvim $PACKER_DIR
fi
NVIM_DIR=$(dirname $(readlink -f $0))
python3 -m venv "$NVIM_DIR/venv"
$NVIM_DIR/venv/bin/python -m pip install -U pip setuptools wheel || exit 1
$NVIM_DIR/venv/bin/python -m pip install -U pynvim
python3 -m pip install -U --user pipx || exit 1
python3 -m pipx ensurepath || exit 1
python3 -m pipx install pyright
python3 -m pipx install fortls
python3 -m pipx install black
python3 -m pipx install isort
python3 -m pipx install zimports

View file

@ -121,37 +121,11 @@ cmp.setup.cmdline(':', {
-- Setup lspconfig.
local capabilities = require('cmp_nvim_lsp').default_capabilities(vim.lsp.protocol.make_client_capabilities())
local function file_exists(name)
local f = io.open(name, "r")
if f ~= nil then io.close(f) return true else return false end
end
local pyright_file = os.getenv("HOME") .. "/.pyenv/versions/neovim3/bin/pyright-langserver"
local pylsp_file = os.getenv("HOME") .. "/.pyenv/versions/neovim3/bin/pylsp"
if file_exists(pyright_file) then
require('lspconfig')['pyright'].setup {
cmd = { pyright_file, "--stdio" },
on_attach = on_attach,
flags = lsp_flags,
capabilities = capabilities,
}
elseif file_exists(pylsp_file) then
require('lspconfig')['pylsp'].setup {
cmd = { pylsp_file },
on_attach = on_attach,
flags = lsp_flags,
settings = {
pylsp = {
plugins = {
pycodestyle = { maxLineLength = 88 },
flake8 = { maxLineLength = 88 }
}
}
},
capabilities = capabilities
}
end
require('lspconfig')['pyright'].setup {
on_attach = on_attach,
flags = lsp_flags,
capabilities = capabilities,
}
require('lspconfig')['efm'].setup {
init_options = { documentFormatting = true },
@ -171,7 +145,6 @@ require('lspconfig')['efm'].setup {
}
require('lspconfig')['fortls'].setup {
cmd = { os.getenv("HOME") .. "/.pyenv/versions/neovim3/bin/fortls" },
on_attach = on_attach,
flags = lsp_flags,
capabilities = capabilities

View file

@ -1,4 +1,4 @@
vim.g.python3_host_prog = '~/.pyenv/versions/neovim3/bin/python'
vim.g.python3_host_prog = '~/.config/nvim/venv/bin/python'
vim.g.python_indent = {
open_paren = 'shiftwidth()',
nested_paren = 'shiftwidth()',