Skip to content

A simple Python language server to provide MRO (Method Resolution Order) inference via Hover and CodeLens.

License

Notifications You must be signed in to change notification settings

mosckital/python-mro-language-server

Repository files navigation

Python MRO Language Server

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.

Continuous Integration Status GitHub license

Installation

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.

Usage

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.

Language Server Features

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.

Hover functionality

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).

CodeLens functionality

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.

Relation to the Python MRO extension for VS Code

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.

Incoming Features

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.
  • 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

Contribution

Any contribution is welcomed!

About

A simple Python language server to provide MRO (Method Resolution Order) inference via Hover and CodeLens.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages