Slide 1

Slide 1 text

Vinicius Stock Improving the development experience with language servers

Slide 2

Slide 2 text

Vinicius Stock Senior dev @ Ruby DX team Shopify Twitter: @vinistock GitHub: @vinistock https://vinistock.com

Slide 3

Slide 3 text

Let’s look back

Slide 4

Slide 4 text

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

Slide 5

Slide 5 text

No standard set of language speci fi c features

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

Language Server Protocol Set of standard features Source: https://microsoft.github.io/language-server-protocol/speci fi cation Background server

Slide 8

Slide 8 text

Language server STDIN Editor (Client) Request (JSON) Response (JSON) STDOUT STDERR

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

Ruby LSP https://github.com/Shopify/vscode-ruby-lsp https://github.com/Shopify/ruby-lsp

Slide 14

Slide 14 text

What does it do?

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

Let’s see how to server works

Slide 19

Slide 19 text

Loop STDIN Read JSON request Run request STDOUT Write JSON response

Slide 20

Slide 20 text

Ruby LSP Text synchronization Parsing Hover Document highlight Folding range Document symbol

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

How can we implement it?

Slide 23

Slide 23 text

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

Slide 24

Slide 24 text

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

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

AST Ruby code Analysis Parse Traverse

Slide 27

Slide 27 text

What’s parsing?

Slide 28

Slide 28 text

AST simpli fi ed from the syntax_tree gem CLASS BODY CONST DEF IDENT BODY STRING

Slide 29

Slide 29 text

We need a way of going through each node

Slide 30

Slide 30 text

No content

Slide 31

Slide 31 text

BODY CONST DEF IDENT BODY STRING CLASS

Slide 32

Slide 32 text

We’re ready to implement folding range

Slide 33

Slide 33 text

No content

Slide 34

Slide 34 text

No content

Slide 35

Slide 35 text

No content

Slide 36

Slide 36 text

No content

Slide 37

Slide 37 text

No content

Slide 38

Slide 38 text

Synchronize text edits Parse Folding range Document symbol Document link Semantic highlighting Inlay hint Selection range AST

Slide 39

Slide 39 text

Ruby LSP https://github.com/Shopify/vscode-ruby-lsp https://github.com/Shopify/ruby-lsp

Slide 40

Slide 40 text

Folding range Document symbol Document link Semantic highlighting Inlay hint Selection range Hover Format on type Document highlight Format on save Diagnostics Code actions

Slide 41

Slide 41 text

The future of Ruby tooling

Slide 42

Slide 42 text

Rich features Cross editor Gradual typing Interactive debugging Any editor can be a fully featured IDE

Slide 43

Slide 43 text

Thank you!

Slide 44

Slide 44 text

• 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