LSP Mode

What’s LSP

LSP is abbreviation of language server protocol, an idea proposed by Microsoft. According to its website, the idea behind the LSP is to standardize the protocol for how such servers and development tools communicate. In short words, LSP expect to standardize common features (i.e. auto-completion, go-to-definition, show-documentation, etc.) among different editors/IDEs. I knew this last night when I was finding some FORTRAN support on emacs; and was surprised by this great idea before I tried it (it was around 1 AM).

Emacs implementation

There’re two packages doint this, LSP-mode and eglot-mode. I tried the former firstly, surpring by its great functions and many integration, but soon found some bugs which I can’t solve (e.g. the deprecated function lsp-define-stdio-client error). Naturally I found eglot which is smaller and more suitable for me. I’ll show python and fortran suppport as following.

Python and fortran support

1
2
3
4
5
6
7
(use-package eglot
  :config
  (add-to-list 'eglot-server-programs '((c++-mode c-mode) "clangd")) 
  (add-to-list 'eglot-server-programs '(f90-mode . ("fortls")))
  (add-hook 'python-mode-hook 'eglot-ensure)
  (add-hook 'c-mode-hook 'eglot-ensure)
)

The server for python (pyls) and fortran (fortls) respectively need to be pre-installed. Both can be downloaded through pip. Clangd which is used for C and Cpp need to be compiled and installed instead.

0%