-
Notifications
You must be signed in to change notification settings - Fork 273
Python
There are two options for setting up a language server with Python:
- Microsoft Python Language Server (MPLS)- maintained by Microsoft
- pyls - maintained by Palantir
Install MPLS from the repo: https://github.com/Microsoft/python-language-server
If you are using Arch, there are two AUR packages that can be found here:
Add the following line to your .vimrc
:
let g:LanguageClient_serverCommands = {
\ 'python' : ['dotnet', 'exec', '<path-to-mpls-installation>/Microsoft.Python.LanguageServer.dll'],
\ }
MPLS needs some additional settings to work with LanguageClient so you need to modify your settings.json
. By default, LanguageClient looks in your working directory for the .vim/settings.json
so that configuration can be done on a per-project basis. Users can choose to override this and have a global settings file by setting the g:LanguageClient_settingsPath
variable in your .vimrc
. You can set the variable to be a list of paths so that settings from all paths are combined, with preference given to paths later in the list (see h: g:LanguageClient_settingsPath
).
Add the following to your settings.json
, either in the global location or the local location for each project. If you decide to use the global location, you need to make some tweaks to be able to use MPLS inside virtual environments. See below section for virtual env setup.
{
"enabled": true,
"initializationOptions": {
"displayOptions": {
"preferredFormat": "plaintext",
"trimDocumentationLines": true,
"maxDocumentationLineLength": 0,
"trimDocumentationText": true,
"maxDocumentationTextLength": 0
},
"interpreter": {
"properties": {
"InterpreterPath": "<path-to-python-executable>",
"UseDefaultDatabase": true,
"Version": "<python-version>"
}
}
}
}
Put the above contents into your global settings file. Set the InterpreterPath
value to your global python interpreter (eg /usr/bin/python
).
Now, in the project directory that you want to use virtual environment in, create a local settings file and copy the above contents in once again. Set the InterpreterPath
value to your virtual env python interpreter (<path-to-virtual-env>/bin/python
).
Then, set the g:LanguageClient_settingsPath
variable in your .vimrc
as follows, , assuming the global file is located at ~/.vim/LanguageClient_settings.json
, and the local file is located at <project-root>/.vim/LanguageClient_settings.json
:
let g:LanguageClient_settingsPath = ['~/.vim/LanguageClient_settings.json', '.vim/LanguageClient_settings.json']
This will effectively default to your global file if there is no local file in your working directory.
NB The majority of the instructions here are obtained from this issue: https://github.com/autozimu/LanguageClient-neovim/issues/633
Install pyls from the repo: https://github.com/palantir/python-language-server.
pyls works by combining the functionality of several other python libraries. You will need to install those as well to use it fully. See the README in the repo to find out which python libraries you need.
You can also install directly via pip:
pip install pyls
If you are using Arch, there is a fork available as a Community package which can be installed with pacman:
sudo pacman -S python-lsp-server
Add the following line to your .vimrc
:
let g:LanguageClient_serverCommands = {
\ 'python' : ['pyls']
\ }