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 .python-version
.DS_Store .DS_Store
plugin/ plugin/
venv

View file

@ -5,19 +5,21 @@ Personal configuration and plugins for Vim
```bash ```bash
curl -LO https://github.com/neovim/neovim/releases/latest/download/nvim.appimage curl -LO https://github.com/neovim/neovim/releases/latest/download/nvim.appimage
chmod u+x nvim.appimage chmod u+x nvim.appimage
mv nvim.appimage "$HOME/bin/." mv nvim.appimage "$HOME/bin/nvim"
ln -s "$HOME/bin/nvim.appimage" "$HOME/bin/nvim" # Optional to avoid extension in commands
# ./nvim.appimage
``` ```
## Installing configuration ## Installing configuration
```bash ```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 # or using symlink
git clone git@github.com:elitherl/vim-config.git /path/to/directory 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 ### Installing `Packer` plugin manager
```bash ```bash
git clone --depth 1 https://github.com/wbthomason/packer.nvim\ 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 Plugin definitions are in `plugins.lua`, inside `vim` run `:PackerSync` to install plugins
## Enabling python support ## Enabling python support
Set up neovim specific virtual environment to install `pynvim` package:
```bash ```bash
pyenv virtualenv neovim3 # Assumes working pyenv python3 -m venv "${XDG_CONFIG_HOME:-$HOME/.config}/nvim/venv"
pyenv activate neovim3 source "${XDG_CONFIG_HOME:-$HOME/.config}/nvim/venv/bin/activate"
pip install -U pip setuptools wheel pip install -U pip setuptools wheel && pip install -U pynvim
pip install -U pynvim pyright fortl # If pyright not available, fallback to: "python-lsp-server[all]" pylsp-mypy source deactivate
pyenv 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 ## Add LUA language server
Follow instructions from [sumneko/lua-language-server GitHub](https://github.com/sumneko/lua-language-server/wiki/Getting-Started#command-line). 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 if [ ! -d $PACKER_DIR ]; then
git clone --depth 1 https://github.com/wbthomason/packer.nvim $PACKER_DIR git clone --depth 1 https://github.com/wbthomason/packer.nvim $PACKER_DIR
fi 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. -- Setup lspconfig.
local capabilities = require('cmp_nvim_lsp').default_capabilities(vim.lsp.protocol.make_client_capabilities()) local capabilities = require('cmp_nvim_lsp').default_capabilities(vim.lsp.protocol.make_client_capabilities())
local function file_exists(name) require('lspconfig')['pyright'].setup {
local f = io.open(name, "r") on_attach = on_attach,
if f ~= nil then io.close(f) return true else return false end flags = lsp_flags,
end capabilities = capabilities,
}
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')['efm'].setup { require('lspconfig')['efm'].setup {
init_options = { documentFormatting = true }, init_options = { documentFormatting = true },
@ -171,7 +145,6 @@ require('lspconfig')['efm'].setup {
} }
require('lspconfig')['fortls'].setup { require('lspconfig')['fortls'].setup {
cmd = { os.getenv("HOME") .. "/.pyenv/versions/neovim3/bin/fortls" },
on_attach = on_attach, on_attach = on_attach,
flags = lsp_flags, flags = lsp_flags,
capabilities = capabilities 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 = { vim.g.python_indent = {
open_paren = 'shiftwidth()', open_paren = 'shiftwidth()',
nested_paren = 'shiftwidth()', nested_paren = 'shiftwidth()',