Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Improving the development experience with language servers

Improving the development experience with language servers

Providing a state of the art development experience greatly contributes to Ruby’s goal of making developers happy. A complete set of editor features can make a big difference in helping navigate and understand our Ruby code. Let’s explore a modern way of enhancing editor functionality: the language server protocol (LSP). What it is, how to implement it and how an LSP server like the Ruby LSP can make writing Ruby even better.

Vinicius Stock

December 07, 2022
Tweet

More Decks by Vinicius Stock

Other Decks in Technology

Transcript

  1. Vinicius Stock Improving the development experience with language servers

  2. Vinicius Stock Senior dev @ Ruby DX team Shopify Twitter:

    @vinistock GitHub: @vinistock https://vinistock.com
  3. Let’s look back

  4. Vim Ruby Source: https://code.visualstudio.com/api/language-extensions/language-server-extension-guide Editors Plugins JavaScript Rust Go Sublime

    VS Code Neovim
  5. No standard set of language speci fi c features

  6. Vim Ruby Source: https://code.visualstudio.com/api/language-extensions/language-server-extension-guide Editors Plugins JavaScript Rust Go Sublime

    VS Code Neovim Syntax highlighting Go to de fi nition Linting
  7. Language Server Protocol Set of standard features Source: https://microsoft.github.io/language-server-protocol/speci fi

    cation Background server
  8. Language server STDIN Editor (Client) Request (JSON) Response (JSON) STDOUT

    STDERR
  9. Vim Ruby Source: https://code.visualstudio.com/api/language-extensions/language-server-extension-guide Editors Language server JavaScript Rust Go

    Sublime VS Code Neovim Client Client Client Client Plugin or built-in
  10. Source: https://microsoft.github.io/language-server-protocol/speci fi cation

  11. Source: https://microsoft.github.io/language-server-protocol/speci fi cation

  12. initialize textDocument/ didOpen textDocument/ foldingRange Language server Editor (Client) capabilities

    Activate language server Open fi le foo.rb Ranges Edit foo.rb textDocument/ didChange Ranges textDocument/ foldingRange
  13. Ruby LSP https://github.com/Shopify/vscode-ruby-lsp https://github.com/Shopify/ruby-lsp

  14. What does it do?

  15. None
  16. None
  17. None
  18. Let’s see how to server works

  19. Loop STDIN Read JSON request Run request STDOUT Write JSON

    response
  20. Ruby LSP Text synchronization Parsing Hover Document highlight Folding range

    Document symbol
  21. None
  22. How can we implement it?

  23. Source: https://microsoft.github.io/language-server-protocol/speci fi cation

  24. Source: https://microsoft.github.io/language-server-protocol/speci fi cation

  25. None
  26. AST Ruby code Analysis Parse Traverse

  27. What’s parsing?

  28. AST simpli fi ed from the syntax_tree gem CLASS BODY

    CONST DEF IDENT BODY STRING
  29. We need a way of going through each node

  30. None
  31. BODY CONST DEF IDENT BODY STRING CLASS

  32. We’re ready to implement folding range

  33. None
  34. None
  35. None
  36. None
  37. None
  38. Synchronize text edits Parse Folding range Document symbol Document link

    Semantic highlighting Inlay hint Selection range AST
  39. Ruby LSP https://github.com/Shopify/vscode-ruby-lsp https://github.com/Shopify/ruby-lsp

  40. Folding range Document symbol Document link Semantic highlighting Inlay hint

    Selection range Hover Format on type Document highlight Format on save Diagnostics Code actions
  41. The future of Ruby tooling

  42. Rich features Cross editor Gradual typing Interactive debugging Any editor

    can be a fully featured IDE
  43. Thank you!

  44. • https://github.com/Shopify/vscode-ruby-lsp • https://github.com/Shopify/ruby-lsp • https://code.visualstudio.com • https://github.com/ruby-syntax-tree/syntax_tree • https://microsoft.github.io/language-server-protocol/speci

    fi cation • All screenshots made with: https://code.visualstudio.com References