Scala development with Vim in 2020

Chris Kipp

2020 ScalaUA

About Me

Grew up in the USA on a farm

Studied International Relations

Now based in the Netherlands

Software Engineer at Lunatech Labs

Enjoy working on tooling

& minimal tech

Switched careers to tech

Goals

  • Convince everyone here to switch to Vim and Metals
  • Show that Vim is not only a viable editor for Scala,  but is well supported and feature rich
  • Show how fast it is to get up and running with Metals + Vim
  • Show a bit how Metals accounts for difference clients

Questions

Feel free to shoot them in the chat.

I'll either see them and address them as they come, or if I have time at the end.

Vim isn't going anywhere

2019

2018

2017

Stack Overflow Developer Surveys

2018 Scala Developer Survey

2019 Scala Developer Survey

Metals isn't going anywhere

Metals isn't going anywhere

Ólafur Páll Geirsson

@olafurpg

Tomasz Godzik

@tgodzik

Gabriele Petronella

@gabro

LSP

  • ycm-core/YouCompleteMe (20.9K★ Python)

  • neoclide / coc.nvim (9.5K ★ - Node)

  • dense-analysis / ale (9.2K ★ - Vimscript)

  • autozimu / LanguageClient-neovim (2.8K ★ - Rust)
  • prabirshrestha / vim-lsp (1.5K ★ - Vimscript)

  • neovim / nvim-lsp (603 ★ - Lua)

  • natebosch / vim-lsc (418 ★ - Vimscript)

My recommendations depending on your situation

 

  • neoclide / coc.nvim (9.5K ★ - Node)
  • Coc is an intellisense engine for Vim/Neovim.

  • Same language server protocol support as VSCode

  • Allows you to re-use VSCode extensions (mostly)

  • Extremely responsive team

scalameta / coc-metals

scalameta / coc-metals

  1. Plug 'neoclide/coc.nvim', {'branch': 'release'}
  2. Paste recommended mappings into your .vimrc

    1. nmap <leader>rn <Plug>(coc-rename)
  3. Either

    1. :CocInstall coc-metals
    2. Plug 'scalameta/coc-metals', {'do': 'yarn install --frozen-lockfile'}

With the assumption you have Node and Java Installed

coc-metals / importing builds

coc-metals / code actions

coc-metals / tree view protocol

coc-metals / worksheets

coc-metals / configuration

coc-metals / commands

coc-metals / doctor

coc-metals / run - debug

Via puremourning / vimspector

 

  • natebosch / vim-lsc (418 ★ - vimscript)
  • Covers the basics very well

  • Has some niceties like striking out deprecated methods

  • Easy setup
  • Pure vimscript

 

  • nvim / nvim-lsp (603 ★ - lua)
  • Built-in to nvim
  • Automated installation of servers

  • Extensible

Keep in mind that the support right now is pretty much experimental

Accounting for Clients

coursier bootstrap \
  --java-opt -Xss4m \
  --java-opt -Xms100m \
  --java-opt -Dmetals.client=vim-lsc \
  org.scalameta:metals_2.12:0.8.3 \
  -r bintray:scalacenter/releases \
  -r sonatype:snapshots \
  -o /usr/local/bin/metals-vim -f

https://scalameta.org/metals/docs/editors/new-editor.html#metals-server-properties

Server Properties

Accounting for Clients

interface ClientCapabilities {
  ...
  
  /**
    * User provided initialization options.
    * */
  initializationOptions?: any;
 }

https://microsoft.github.io/language-server-protocol/specifications/specification-current/#initialize

Initialization Options

Accounting for Clients

interface ClientCapabilities {
  ...
  
  /**
    * Experimental client capabilities.
    */
  experimental?: any;
 }

https://microsoft.github.io/language-server-protocol/specifications/specification-current/#initialize

Client Experimental Capabilities

The future

  • Continued (attempted) parity with VS Code + Metals
  • Built in LSP Client for Neovim
  • Onivim2 release
  • Updated Scala syntax highlighting for Vim

Final tips for coc-metals users

  • Make sure you have

    • "metals.statusBarEnabled": true
    • "codeLens.enable": true
  • Customize the recommended mappings
  • Give nvim a try if you're a vim user

  • Use the built-in commands
    • metals.new-scala-file
    • metals.revealInTreeView
    • etc...

Thank you

@ckipp01

https://www.lunatech.com/