6 August 2020
LSP Mode Demo
by Chris Cave-Ayland
Context
RSEs often need to work with multiple programming languages. The Language Server Protocol (originally from Visual Studio Code) was designed to allow multiple language backends to provide a consistent interface to code completion, refactoring, jumping to symbol definitions, syntax highlighting, error messages etc. The lsp-mode package bring the power of LSP to the emacs world.
Meetup Notes
  - Talk website: https://cc-a.github.io/lsp-mode-demo
- Defines an open standard for communication between an IDE/editor and an external service implementing programming assistance
    
      - Multiple languages can have a relatively consistent interface (e.g. keybindings)
- Developed by MS as part of VSCode but an open standard and widely adopted
- Reduces implementation effort from n×m to n+m (n language servers, m editors)
- It’s been very successful, supports a large number of languages, and in some cases multiple server implementations for the same language. Tables: languages, editors
 
- Aside: if you use spacemacs, add the lsplayer plus whichever language layers you need (spacemacsdevelopbranch only). LikewiseDoomemacs has anlsplayer, and a+lapoption for thedebuggerlayer.
Demonstration
Config file
Start the demo emacs config by using the config file provided here.
  - The config file shows some use-package commands in comments to install dependencies
- use-package has been configured with hooks for python-mode and f90-mode
- Config file configures
    
      - Company
- flycheck
- lsp-mode and lsp-ui (for pop-ups, hovers, minibuffer)
 
Python demonsration
  - Open demo.py from the repository
- Errors and warnings are shown inline the extreme right hand side of the buffer, in what is know as the sideline
- If you have installed an lsp server for the language, you’ll see a message about the server starting when you open a buffer
- lsp-modeis used for completion (try typing- datetime.followed by- TAB)
- Completions are documented in a hover
- Opening the brackets creates a minibuffer with the function documentation
- you can format the code using lsp-formatter
- you can jump to definition ctrl.(right?)
- Chris demonstrated a more advance, opinionated config shown at the bottom of the config file. This some options for:
    
      - Smaller documentation popups
- Hover text in sideline
- Disabling auto-display of documentation
 
Fortran demonsration
  - Open demo.f90 from the repository
- Similar features to Python are available
- Fortran features are a subset of what is available with Python
- Fortran has a language server written in Python
Other questions / discussion
  - lsp runs locally, it doesn’t need of the internet! It typically uses the introspection in each language.
- lsp needs of an external server installed for each language. You can install the ones you like.
- there are ways to have it for different environments, but normally you need the python language server in that env. Some possibilities are:
    
  
- eglotis a lightweight alternative to- lsp-mode
- The debugger server looks cool (dap-mode)!
Resources
Ideas for future sessions
  - use-package
- Emacs “distributions” e.g. Spacemacs, Doom Emacs
- TRAMP
tags: