A simple Python language server to provide MRO (Method Resolution Order) inference.
MRO is the order in which Python looks for a method in a hierarchy of classes. Python uses C3 Linearisation (wiki page) as the underlying algorithm.
This project conforms to Microsoft's Language Server Protocol but only support Hover and CodeLens requests. Python 3.6+ are supported.
The Python MRO language server can be easily installed by:
pip install python-mro-language-server
The language server uses jedi
for static syntax analysis and python-jsonrpc-server
for the JsonRPC communications. These two packages and their dependencies, ujson
and parso
, will be installed by the about command as well.
The Python MRO language server can be launched by the following command:
python -m mrols.server [port]
Where port
is 3000 by default if not specified.
The main purpose of this language server is to infer and return the MRO of a target in request via static syntax analysis of the provided source codes.
By static syntax analysis, there is a minimum level of security risk since the source codes will not be run. This is at the expense that the inference may be incomplete in some situations, like when using a dynamically declared type or having no information about the external library. However, the user can expect that the inference should work in a large part of the common cases.
The necessary static syntax analysis is achieved by using both the jedi
analysis library and the Python built-in library ast
(stands for Abstract Syntax Trees). The jedi
library is in primary use and the ast
library provides additional supports.
The Python MRO Language Server implements the Hover Request of the Language Server Protocol. The user can fetch the MRO list of a class or its instance by hovering over the class name (implemented) or instance name (to implement very soon).
The Python MRO Language Server implements the Code Lens Request and the Code Lens Resolve Request as well. A code lens will appear at the first line of every class declaration. The user can get the MRO list of the declared class by clicking the code lens.
This language server is the backend server used in the Python MRO extension for VS Code.
It is very welcomed that this language server can be used in any other extensions to any editor that supports the Language Server Protocol.
The following list includes the features to add into the Python MRO Language Server in the next releases.
- New Features:
- Hover:
- add support to show MRO list when hovering over a class instance
- add support to show the which class in the MRO list will provide the actual implementation when hovering over a method of a class instance (lower priority, scheduled after finishing the other features)
- CodeLens:
- change the way to show MRO list when clicking a code lens from showing in a pop-up message window to showing in a side panel like what GitLens does.
- Hover:
- Project Reliability
- increase the readability of the documentations
- add coverage check and show the result as a badge in README
- add pylint check and show the score as a badge in README
- add logging to the whole scope of the project and save the last logs in file
Any contribution is welcomed!