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

Language Server Protocol - A New Architecture f...

Language Server Protocol - A New Architecture for Developer Tools

Martin Lippert

November 03, 2020
Tweet

More Decks by Martin Lippert

Other Decks in Programming

Transcript

  1. ©2020 VMware, Inc. Language Server Protocol A new architecture for

    developer tools Martin Lippert Spring Tools Lead, VMware November 2020
  2. ©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
  3. ©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
  4. ©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
  5. ©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
  6. ©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.)
  7. ©2020 VMware, Inc. 7 You can do the math, eh?

    Huge Complexity This just isn’t the right approach nowadays
  8. ©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
  9. ©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)
  10. ©2020 VMware, Inc. 12 The overall picture Client (editor, IDE)

    Language Server JSON-RPC both sides speak the Language Server Protocol
  11. ©2020 VMware, Inc. process 2 process 1 13 Separate processes

    Client (editor, IDE) Language Server JSON-RPC
  12. ©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
  13. ©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
  14. ©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
  15. ©2020 VMware, Inc. 17 One language server implementation to rule

    them all Visual Studio Code Language Server (e.g. C#) Eclipse Theia Che . . .
  16. ©2020 VMware, Inc. One IDE or editor, multiple languages Visual

    Studio Code C# LS Java LS Kotlin LS R LS JavaScript LS . . .
  17. ©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
  18. ©2020 VMware, Inc. 22 The overall picture Client (editor, IDE)

    Language Server JSON-RPC Resources (e.g. files)
  19. ©2020 VMware, Inc. 23 Document notifications Client (editor, IDE) Language

    Server didOpen (…) didClose (…) didChange (…) didSave (…) * (the mentioned messages are examples, not a full reference)
  20. ©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
  21. ©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)
  22. ©2020 VMware, Inc. 26 Language smartness - errors, warnings, validations

    Client (editor, IDE) Language Server publishDiagnostics(..) Usually happens as a reaction to content changes
  23. ©2020 VMware, Inc. 27 Language smartness - actions Client (editor,

    IDE) Language Server This is used for quick fixes, for example codeAction (…) Command[] or CodeAction[]
  24. ©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 } } }
  25. ©2020 VMware, Inc. 29 Language smartness - response Client (editor,

    IDE) Language Server completion (…) CompletionItems[] { "jsonrpc": "2.0", "id": "10", "result": { "isIncomplete": false, "items": [...] } }
  26. ©2020 VMware, Inc. We use the Language Server Protocol for

    a framework as well (Spring in this case) 32 More than just languages?
  27. ©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
  28. ©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)
  29. ©2020 VMware, Inc. The protocol allows to define custom messages

    / extensions But you need to implement this again across all clients 37 Custom Extensions
  30. ©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
  31. ©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