Skip to content
Python support for lsp-mode using Microsoft Python Language Server
Branch: master
Clone or download
Latest commit d95ac8f Apr 13, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
screenshots fix server issue Dec 9, 2018
LICENSE
README.org supported diagnostics Apr 13, 2019
ms-python.el supported diagnostics Apr 13, 2019

README.org

ms-python

Python support for lsp-mode using Microsoft Python Language Server

Screenshot

./screenshots/company.png

Installation

ms-python

manual

  1. First, you must install newest lsp-mode,lsp-ui
  2. Download ms-python.el to /path/to/elisp
  3. Add /path/to/elisp into load-path and require it.
    (add-to-list 'load-path (expand-file-name "/path/to/elisp"))
    (require 'ms-python)
    (add-hook 'python-mode-hook #'lsp)
        

Melpa

M-x package-install [RET] ms-python [RET]

Server

First, you must install git and add it to your system path.

ms-python will automatically detect when server is missing and it will build Microsoft Python Language Server before first startup. The server installation will be in ms-python-server-install-dir. If you have installed server, set ms-python-server-install-dir to your server installation directory, which should contain Microsoft.Python.LanguageServer.dll file.

(setq ms-python-server-install-dir "/path/to/server")

Building server requires dotnet sdk, which will detect dotnet executable file in ms-python-dotnet-install-dir or system path. If your have installed dotnet but dotnet dir is not in the system path, set ms-python-dotnet-install-dir to your dotnet dir.

(setq ms-python-dotnet-install-dir "/path/to/dotnet")

Using ms-python-update-server to update server.

Flycheck

Microsoft Python Language Server implements diagnostics (or linting). You can find a list of supported diagnostics on linting-options-diagnostics. Set ms-python-python-lint-enabled to nil to disable diagnostics.

If you want more diagnostics, you can change flycheck-checker to pyton-pylint or python-flake8 after lsp started up.

(add-hook 'lsp-ui-mode-hook #'(lambda() (setq-local flycheck-checker 'python-pylint)))

Pyvenv

Because the server needs Python environment information before the server initialization, you must activate the virtual environment before call lsp.

(defun +my-python/enable-lsp()
  (unless pyvenv-virtual-env-name
    (pyvenv-activate "/path/to/venv/"))
  (lsp)
  ;; You also can put the code for change checker here.
  (setq-local flycheck-checker 'python-pylint))

(add-hook 'python-mode-hook #'+my-python/enable-lsp)

Debug

dap-mode

Quick start

Minimal configuration. Download ms-python.el to ~/.emacs.d/lisp

(condition-case nil
    (require 'use-package)
  (file-error
   (require 'package)
   (add-to-list 'package-archives '("melpa" . "http://melpa.org/packages/"))
   (package-initialize)
   (package-refresh-contents)
   (package-install 'use-package)
   (require 'use-package)))

(use-package projectile
  :ensure t)
(use-package lsp-mode
  :ensure t)
(use-package lsp-ui
  :ensure t
  :config
  (setq lsp-ui-doc-max-height 20
	    lsp-ui-doc-max-width 50
	    lsp-ui-sideline-ignore-duplicate t
	    lsp-ui-peek-always-show t))

(use-package company
  :ensure t
  :config
  (setq company-minimum-prefix-length 1
	    company-idle-delay 0
	    company-tooltip-limit 10
	    company-transformers nil
	    company-show-numbers t
	    )
  (global-company-mode +1))

(use-package company-lsp
  :ensure t
  :commands (company-lsp)
  )

(use-package company-box
  :ensure t
  :hook (company-mode . company-box-mode))

(use-package ms-python
  :config
  (add-hook 'python-mode-hook #'lsp))

Credit

All creadit to vxlabs .

You can’t perform that action at this time.