Skip to content

emacs lsp-mode client for Microsoft's python language server

License

Notifications You must be signed in to change notification settings

andrew-christianson/lsp-python-ms

 
 

Repository files navigation

lsp-mode client leveraging Microsoft’s python-language-server.

Installation

Include lsp-python-ms in the configuration file:

(require 'lsp-python-ms)
(setq lsp-python-ms-auto-install-server t)
(add-hook 'python-mode-hook #'lsp) ; or lsp-deferred

A minimal use-package initialization might be:

(use-package lsp-python-ms
  :ensure t
  :init (setq lsp-python-ms-auto-install-server t)
  :hook (python-mode . (lambda ()
                          (require 'lsp-python-ms)
                          (lsp))))  ; or lsp-deferred

Installing the executable

NixOS

Building the executable manually is difficult on NixOS, but it can be easily installed via the package manager. At the time of writing (May 2020), it is not available on the 20.03 release, but can be acquired on the unstable branch.

nix-channel --add https://nixos.org/channels/nixos-unstable nixos
nix-channel --update nixos

You can then install the executable by running nix-env -iA nixpkgs.python-language-server or by adding nixpkgs.python-language-server to your configuration.nix and creating a new generation. Note that python37Packages.python-language-server refers to Palintir’s language server, not Microsoft’s.

Finally, ensure that Emacs knows where to find the executable by setting lsp-python-ms-executable.

(use-package lsp-python-ms
  :ensure t
  :hook (python-mode . (lambda ()
                         (require 'lsp-python-ms)
                         (lsp)))
  :init
  (setq lsp-python-ms-executable (executable-find "python-language-server")))

Most other distros

Normally the python-language-server will be downloaded automatically if it doesn’t exist while opening the python scripts.

If you have troubles to download the package, you can also build the server yourselves.

  1. Install dotnet-sdk
  2. Clone and build python-language-server:
    git clone https://github.com/Microsoft/python-language-server.git
    cd python-language-server/src/LanguageServer/Impl
    dotnet publish -c Release -r osx-x64   # mac
        

    Change the -r flag according to your architecture and operating system. See Microsoft’s Runtime ID Catalog for the right value for your system.

    Then make the binary executable.

    chmod a+x $(git rev-parse --show-toplevel)/output/bin/Release/osx-x64/publish/Microsoft.Python.LanguageServer
        

    NOTE: on some systems (for example, Fedora), the executable comes out as Microsoft.Python.LanguageServer.LanguageServer.

  3. Set executable to lsp-python-ms-executable.
    ;; for executable of language server, if it's not symlinked on your PATH
    (setq lsp-python-ms-executable
          "~/python-language-server/output/bin/Release/osx-x64/publish/Microsoft.Python.LanguageServer")
        

For development, you might find it useful to run cask install.

FAQ

  1. Unresolved import warnings

    Set workspace root of `lsp-mode` properly, and add the extra directories to lsp-python-ms-extra-paths or PYTHONPATH. Refer to Troubleshooting - Unresolved import warnings and #96.

  2. Autocompletion doesn’t work

    The folder may have huge folders and files, and the server takes a long time to index them. So please DO NOT put huge files in the project/workspace folder.

Credit

All credit to cpbotha on vxlabs! This just tidies and packages his work there.

About

emacs lsp-mode client for Microsoft's python language server

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Emacs Lisp 100.0%