Slide 1

Slide 1 text

©2020 VMware, Inc. Language Server Protocol A new architecture for developer tools Martin Lippert Spring Tools Lead, VMware November 2020

Slide 2

Slide 2 text

©2020 VMware, Inc. A Smalltalk IDE -> written in Smalltalk (e.g. Visual Age for Smalltalk) A Java IDE -> written in Java (e.g. Eclipse) A TypeScript IDE -> written in Typescript (e.g. Visual Studio Code) 2 In the old days

Slide 3

Slide 3 text

©2020 VMware, Inc. 3 The IDE perspective And today? Developers use a variety of languages on a daily base They need an IDE that supports all kinds of languages

Slide 4

Slide 4 text

©2020 VMware, Inc. 4 The language perspective And today? To adopt a new language, developers request good IDE support (language smartness) It is usually not enough to support one IDE, you need to support all the popular IDEs

Slide 5

Slide 5 text

©2020 VMware, Inc. 5 Everything is possible, right? Extensible IDEs IDEs provide an extension API So you can implement language support for each and every IDE

Slide 6

Slide 6 text

©2020 VMware, Inc. 6 Supporting a language in different IDEs What does that mean? Implement different extensions for different IDEs Adopt totally different extension APIs, individually for each IDE Write each IDE extension in a specific language (e.g. in Java for Eclipse, in Typescript for Visual Studio Code, etc.)

Slide 7

Slide 7 text

©2020 VMware, Inc. 7 You can do the math, eh? Huge Complexity This just isn’t the right approach nowadays

Slide 8

Slide 8 text

©2020 VMware, Inc. Language Server Protocol Overview 8

Slide 9

Slide 9 text

©2020 VMware, Inc. Microsoft introduced the language server protocol as part of Visual Studio Code to: • Separate language support from core code editor • Let people implement language support in whatever language they prefer • Allow language support to be written once, not over and over again for every IDE You can read everything about it here: https://microsoft.github.io/language-server-protocol/ 9 Introduction

Slide 10

Slide 10 text

©2020 VMware, Inc. 10 The overall picture Client (editor, IDE) Language Server JSON-RPC

Slide 11

Slide 11 text

©2020 VMware, Inc. 11 The overall picture Client (editor, IDE) Language Server JSON-RPC knows almost nothing about a language focuses on editing experience knows everything about a specific language knows nothing about the concrete environment (UI)

Slide 12

Slide 12 text

©2020 VMware, Inc. 12 The overall picture Client (editor, IDE) Language Server JSON-RPC both sides speak the Language Server Protocol

Slide 13

Slide 13 text

©2020 VMware, Inc. process 2 process 1 13 Separate processes Client (editor, IDE) Language Server JSON-RPC

Slide 14

Slide 14 text

©2020 VMware, Inc. the same physical machine process 2 process 1 14 Separate processes on the same machine Client (editor, IDE) Language Server JSON-RPC

Slide 15

Slide 15 text

©2020 VMware, Inc. process 2 process 1 15 Allows different platforms Client (editor, IDE) Language Server (e.g. for Java) JSON-RPC TypeScript on V8 Java on JVM

Slide 16

Slide 16 text

©2020 VMware, Inc. process 2 process 1 16 Multiple language servers in parallel Client (editor, IDE) Language Server (Java) JSON-RPC TypeScript on V8 Java on JVM process 3 Language Server (C++) Native App

Slide 17

Slide 17 text

©2020 VMware, Inc. 17 One language server implementation to rule them all Visual Studio Code Language Server (e.g. C#) Eclipse Theia Che . . .

Slide 18

Slide 18 text

©2020 VMware, Inc. One IDE or editor, multiple languages Visual Studio Code C# LS Java LS Kotlin LS R LS JavaScript LS . . .

Slide 19

Slide 19 text

©2020 VMware, Inc. Language Server Protocol In more detail 19

Slide 20

Slide 20 text

©2020 VMware, Inc. Microsoft introduced this as part of Visual Studio Code You can read everything about it here: https://microsoft.github.io/language-server-protocol/ 20 Language Server Protocol - Introduction

Slide 21

Slide 21 text

©2020 VMware, Inc. https://microsoft.github.io/language-server-protocol/specifications/specification-current/ 21 Specification

Slide 22

Slide 22 text

©2020 VMware, Inc. 22 The overall picture Client (editor, IDE) Language Server JSON-RPC Resources (e.g. files)

Slide 23

Slide 23 text

©2020 VMware, Inc. 23 Document notifications Client (editor, IDE) Language Server didOpen (…) didClose (…) didChange (…) didSave (…) * (the mentioned messages are examples, not a full reference)

Slide 24

Slide 24 text

©2020 VMware, Inc. Based on the provided information, the language server need to make some sense out of the files inside of the workspace • Identify projects • Resolve the classpath and dependencies • Parse and understand the files 24 The work inside the language server

Slide 25

Slide 25 text

©2020 VMware, Inc. 25 Language smartness - examples Client (editor, IDE) Language Server completion (…) Location[] CompletionItems[] references (…) * (the mentioned messages are examples, not a full reference)

Slide 26

Slide 26 text

©2020 VMware, Inc. 26 Language smartness - errors, warnings, validations Client (editor, IDE) Language Server publishDiagnostics(..) Usually happens as a reaction to content changes

Slide 27

Slide 27 text

©2020 VMware, Inc. 27 Language smartness - actions Client (editor, IDE) Language Server This is used for quick fixes, for example codeAction (…) Command[] or CodeAction[]

Slide 28

Slide 28 text

©2020 VMware, Inc. 28 Language smartness - request Client (editor, IDE) Language Server completion (…) { "jsonrpc": "2.0", "id": "10", "method": "textDocument/completion", "params": { "textDocument": { "uri": "file:///demo/OwnerController.java" }, "uri": „file:///demo/OwnerController.java", "position": { "line": 97, "character": 14 } } }

Slide 29

Slide 29 text

©2020 VMware, Inc. 29 Language smartness - response Client (editor, IDE) Language Server completion (…) CompletionItems[] { "jsonrpc": "2.0", "id": "10", "result": { "isIncomplete": false, "items": [...] } }

Slide 30

Slide 30 text

©2020 VMware, Inc. 30 Libraries https://microsoft.github.io/language-server-protocol/implementors/sdks/

Slide 31

Slide 31 text

©2020 VMware, Inc. Language Server Protocol Only for Languages? 31

Slide 32

Slide 32 text

©2020 VMware, Inc. We use the Language Server Protocol for a framework as well (Spring in this case) 32 More than just languages?

Slide 33

Slide 33 text

©2020 VMware, Inc. The protocol is designed for languages and language smartness features Does this work for something like a framework at all, for example, Spring? 33 Adopt the concepts

Slide 34

Slide 34 text

©2020 VMware, Inc. 34 Spring Tools 4 - Language Server Live Demo

Slide 35

Slide 35 text

©2020 VMware, Inc. Language Server Protocol Limitations 35

Slide 36

Slide 36 text

©2020 VMware, Inc. 36 No shared language knowledge Client (editor, IDE) Java Language Server JSON-RPC Spring Boot Language Server Knows all about Java projects, how to resolve the classpath, how to find types, etc. Need to know about Java as well (e.g. to provide content-assist in Spring XML config files)

Slide 37

Slide 37 text

©2020 VMware, Inc. The protocol allows to define custom messages / extensions But you need to implement this again across all clients 37 Custom Extensions

Slide 38

Slide 38 text

©2020 VMware, Inc. Language Server Protocol And beyond 38

Slide 39

Slide 39 text

©2020 VMware, Inc. • Debug Server Protocol (to run and debug applications) • Visual Studio Code Remote Extensions (to connect to containers) 39 Beyond the Language Server Protocol

Slide 40

Slide 40 text

©2020 VMware, Inc. Language Server Protocol: https://microsoft.github.io/language-server-protocol/ Invented by the awesome team behind Visual Studio Code Now the de-facto standard for building language support 40 Conclusions

Slide 41

Slide 41 text

©2020 VMware, Inc. Thank You Martin Lippert @martinlippert lippertm@vmware.com