A Python Language Server powered by the latest version of Jedi.
Some frameworks, like coc-jedi and vscode-python, will install and manage jedi-language-server
for you. If you're setting up manually, you can run the following from your command line (bash / zsh):
pip install -U jedi-language-server
Alternatively (and preferably), use pipx to keep jedi-language-server
and its dependencies isolated from your other Python dependencies. Don't worry, jedi is smart enough to figure out which Virtual environment you're currently using!
The following instructions show how to use jedi-language-server
with your development tooling. The instructions assume you have already installed jedi-language-server
.
Users may choose 1 of the following options:
Note: this list is non-exhaustive. If you know of a great choice not included in this list, please submit a PR!
Users may choose one of the following options:
Note: this list is non-exhaustive. If you know of a great choice not included in this list, please submit a PR!
Starting from the October 2021 release, set the python.languageServer
setting to Jedi
to use jedi-language-server
.
See: https://github.com/pappasam/jedi-language-server/issues/50#issuecomment-781101169
jedi-language-server
supports the following initializationOptions:
{
"initializationOptions": {
"codeAction": {
"nameExtractVariable": "jls_extract_var",
"nameExtractFunction": "jls_extract_def"
},
"completion": {
"disableSnippets": false,
"resolveEagerly": false,
"ignorePatterns": []
},
"diagnostics": {
"enable": false,
"didOpen": true,
"didChange": true,
"didSave": true
},
"hover": {
"enable": true,
"disable": {
"class": { "all": false, "names": [], "fullNames": [] },
"function": { "all": false, "names": [], "fullNames": [] },
"instance": { "all": false, "names": [], "fullNames": [] },
"keyword": { "all": false, "names": [], "fullNames": [] },
"module": { "all": false, "names": [], "fullNames": [] },
"param": { "all": false, "names": [], "fullNames": [] },
"path": { "all": false, "names": [], "fullNames": [] },
"property": { "all": false, "names": [], "fullNames": [] },
"statement": { "all": false, "names": [], "fullNames": [] }
}
},
"jediSettings": {
"autoImportModules": [],
"caseInsensitiveCompletion": true,
"debug": false
},
"markupKindPreferred": "markdown",
"workspace": {
"extraPaths": [],
"environmentPath": "/path/to/venv/bin/python",
"symbols": {
"ignoreFolders": [".nox", ".tox", ".venv", "__pycache__", "venv"],
"maxSymbols": 20
}
}
}
}
The different sections of the InitializationOptions are explained below, in detail. Section headers use a .
to separate nested JSON-object keys.
The preferred MarkupKind for all jedi-language-server
messages that take MarkupContent.
string
"markdown"
, "plaintext"
If omitted, jedi-language-server
defaults to the client-preferred configuration. If there is no client-preferred configuration, jedi language server users "plaintext"
.
Modules that jedi will directly import without analyzing. Improves autocompletion but loses goto definition.
string[]
[]
If you're noticing that modules like numpy
and pandas
are taking a super long time to load, and you value completions / signatures over goto definition, I recommend using this option like this:
{
"jediSettings": {
"autoImportModules": ["numpy", "pandas"]
}
}
Completions are by default case-insensitive. Set to false
to make completions case-sensitive.
boolean
true
{
"jediSettings": {
"caseInsensitiveCompletion": false
}
}
Print jedi debugging messages to stderr.
boolean
false
{
"jediSettings": {
"debug": false
}
}
Function name generated by the 'extract_function' codeAction.
string
"jls_extract_def"
Variable name generated by the 'extract_variable' codeAction.
string
"jls_extract_var"
If your language client supports CompletionItem
snippets but you don't like them, disable them by setting this option to true
.
boolean
false
Return all completion results in initial completion request. Set to true
if your language client does not support completionItem/resolve
.
boolean
false
A list of regular expressions. If any regular expression in ignorePatterns matches a completion's name, that completion item is not returned to the client.
string[]
[]
In general, you should prefer the default value for this option. Jedi is very good at filtering values for end users. That said, there are situations where IDE developers, or some programmers in some code bases, may want to filter some completions by name. This flexible interface is provided to accommodate these advanced use cases. If you have one of these advanced use cases, see below for some example patterns (and their corresponding regular expression).
Matches | Non-Matches |
---|---|
_hello , __world |
__dunder__ |
Regular Expression:
^_{1,3}$|^_[^_].*$|^__.*(?<!__)$
Matches | Non-Matches |
---|---|
__world |
_hello , __dunder__ |
Regular Expression:
^_{2,3}$|^__.*(?<!__)$
Matches | Non-Matches |
---|---|
__dunder__ |
_hello , __world |
Regular Expression:
^__.*?__$
Matches | Non-Matches |
---|---|
_hello , __world , __dunder__ |
regular |
Regular Expression:
^_.*$
Enables (or disables) diagnostics provided by Jedi.
boolean
true
When diagnostics are enabled, run on document open
boolean
true
When diagnostics are enabled, run on in-memory document change (eg, while you're editing, without needing to save to disk)
boolean
true
When diagnostics are enabled, run on document save (to disk)
boolean
true
Enable (or disable) all hover text. If set to false
, will cause the hover method not to be registered to the language server.
boolean
true
The following options are available under this prefix:
Disable all hover text of jedi-type specified.
bool
false
Disable hover text identified by name in list of jedi-type specified.
string[]
[]
Disable hover text identified by the fully qualified name in list of jedi-type specified. If no fully qualified name can be found, jedi-language-server
will default to the name to prevent any unexpected behavior for users (relevant for jedi types like keywords that don't have full names).
string[]
[]
Add additional paths for Jedi's analysis. Useful with vendor directories, packages in a non-standard location, etc. You probably won't need to use this, but you'll be happy it's here when you need it!
string[]
[]
Non-absolute paths are relative to your project root. For example, let's say your Python project is structured like this:
├── funky
│ └── haha.py
├── poetry.lock
├── pyproject.toml
├── test.py
Assume that funky/haha.py
contains 1 line, x = 12
, and your build system does some wizardry that makes haha
importable just like os
or pathlib
. In this example, if you want to have this same non-standard behavior with jedi-language-server
, put the following in your coc-settings.json
:
{
"workspace": {
"extraPaths": ["funky"]
}
}
When editing test.py
, you'll get completions, goto definition, and all other lsp features for the line from haha import ...
.
Again, you probably don't need this.
The Python executable path, typically the path of a virtual environment.
string
If omitted, defaults to the active Python environment.
Maximum number of symbols returned by a call to workspace/symbols
.
number
{
"workspace": {
"symbols": {
"maxSymbols": 20
}
}
}
A value less than or equal to zero removes the maximum and allows jedi-language-server
to return all workplace symbols found by jedi.
Performance optimization that sets names of folders that are ignored for workspace/symbols
.
string[]
[".nox", ".tox", ".venv", "__pycache__", "venv"]
{
"workspace": {
"symbols": {
"ignoreFolders": ["hello", "world"]
}
}
}
If you manually set this option, it overrides the default. Setting it to an empty array will result in no ignored folders.
Diagnostics are provided by Python's built-in compile
function.
If you would like additional diagnostics, we recommend using other tools (like diagnostic-language-server) to complement jedi-language-server
.
Again, we recommend that you use diagnostic-language-server. It also supports code formatting.
jedi-language-server
can be run directly from the command line.
$ jedi-language-server --help
usage: jedi-language-server [-h] [--version] [--tcp] [--ws] [--host HOST] [--port PORT] [--log-file LOG_FILE] [-v]
If testing sending requests over stdio manually from the command line, you must include Windows-style line endings: \r\n
. For an example, from within this project, run the following:
$ jedi-language-server -v < ./example-initialization-request.txt
INFO:pygls.server:Starting IO server
...
If testing interactively, be sure to manually insert carriage returns. Although this may differ between shell environments, within most bash terminals, you can explicitly insert the required line endings by typing <C-v><C-m>
, which will insert a ^M
. See:
$ jedi-language-server 2>logs
Content-Length: 1062^M
^M
...
jedi-language-server aims to support Jedi's capabilities and expose them through the Language Server Protocol. It supports the following Language Server capabilities:
To build and run this project from source:
Install the following tools manually:
Fork this repository and clone the fork to your development machine:
git clone https://github.com/<YOUR-USERNAME>/jedi-language-server
cd jedi-language-server
make setup
make fix
make lint
make typecheck
make tests
Palantir's python-language-server inspired this project. In fact, for consistency's sake, many of python-language-server's CLI options are used as-is in jedi-language-server
.
Unlike python-language-server, jedi-language-server
: