Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Microservices for building an IDE
The innards of JetBrains Rider
Maarten Balliauw
@maartenballiauw
JetBrains Rider
demo
Rider
Cross-platform, full-stack .NET IDE
C#, VB.NET, F#, JavaScript, TypeScript, HTML, Xamarin, Unity, WinForms, WPF, …
....
History
JetBrains
Founded 2000 in Prague (Czech Republic)
2000 IntelliJ Renamer
2001 IntelliJ
2004 ReSharper
2019 20+ IDE’s and ot...
ReSharper IDE
Project halted (but not gone to waste)
Several concepts and architecture remained
Keep functionality separat...
“When will JetBrains come
with its own .NET IDE?”
Why build a .NET IDE?
Many reasons!
“When will JetBrains come with its own .NET IDE?”
ReSharper constrained by Visual Stud...
Cross-platform...
A cross-platform UI toolkit is needed!
ReSharper UI elements in WinForms and WPF
Existing ReSharper UI w...
IntelliJ Platform
Foundation of all of our IDE’s
Provides base infrastructure
Project view, code completion, UI toolkit
+ ...
IntelliJ Platform + R# ?
IntelliJ Platform
Great foundation to build on
Windows, Linux, Mac
JVM
ReSharper (R#)
All of thos...
Options!
Rewrite R# in Java?
14 years of implementation and knowledge
Would bring 2 R# implementations... Automatic conver...
IntelliJ Platform + R# !
Headless R# as a language server
Cross-platform (.NET / Mono)
No constraints
It is ReSharper! 2 p...
Both sides are an IDE...
Is IntelliJ really a thin UI?
Three cases...
Features where IJ handles everything
Features where ...
1 + 1 = 3
demo
How to make them talk?
Inter-process communication
Example: Context actions (Alt+Enter)
1. IntelliJ provides text editor, caret(s) and lets us Alt+Enter
2. Ask current docum...
1. IntelliJ provides text editor and plumbing to display squiggles
2. IntelliJ notifies R# that a document was opened (or ...
1. Bi-directional
User can be typing
A refactoring or completion may be injecting code at the same time
2. Can be implemen...
Types of data
Context actions
A tree of names and icons
Inspections
A set of name, icon, severity, tooltip, text range
Wri...
Which protocol do we use?
Re-use Language Server Protocol (LSP)?
Great in itself – IDE concepts like window, editor, langu...
Request-action-response
LSP and custom protocol are request/response mostly
Conflict resolution...
What if both human and ...
Model-View-ViewModel (MVVM)
IntelliJ is our view, ReSharper provides the model
Protocol is the ViewModel, sharing lightwei...
Conflict resolution...
Changes to data in shared model can come from IJ and R#
Can still cause conflicts due to features o...
Conflict conventions!
View + Model (or client: IntelliJ + server: ReSharper)
Each value stored in the view model has a ver...
Rider protocol
Obligatory diagram
Ideally, our developers do not have
to know the details of this.
Just create view models.
Rider protocol
“Reactive Distributed communication framework for .NET, Kotlin, JS, C++”
Open source - https://github.com/j...
Rider protocol
Only need to know about a few primitives
Conflict resolution, wire protocol, timeouts, ... handled by proto...
Signal (event)
Producers/subscribers
Observable/observer
Using lifetime to manage subscription
// Produce event
interface ...
Property
Signal implementation
Using lifetime to manage subscription
To changes to propery in general
To changes to specif...
Primitives
Primitive Description
Signal Event that is fired when something happens
Property Observable value
List/set/map ...
Hierarchical + lifetimes
Cleanup and resource management
Objects attach to lifetime
Lifetime destroys attached objects
Par...
Hierarchical + lifetimes
Solution
NuGet host
Project
Document
Inspections
PSI (Program Structure Interface)
Class
Field
Me...
Rider protocol
demo
Rider protocol
Very extensible through Kotlin-based DSL
Easy to work with for our developers
Update view model, generate c...
Microservices
Two processes!
Isolation!
Each has their own 64 bit memory space
Also their own, separate GC
Multi-core machines
Start/sto...
Debugging? Four processes.
Rider (IntelliJ + ReSharper)
Debugger worker process
Your application
Multiple processes...
What if certain features were
running in their own process?
No need to run all the time
Own memory c...
Shared view model
Pass around a shared view model
to interested parties
Example: Roslyn analyzers/inspections
Pass around ...
Shared view model
Multiple machines
Socket-based wire protocol
Sockets can be on multiple machines
Example:
Docker debugging
Remote debugging
Unity game engine
www.unity3d.com
Extension to view model
Rider plugin
Unity editor plugin
https://github.com/JetBrains/re...
https://twitter.com/kskrygan/status/1064950644094705664
Future
Model the view as well
public CSharpInteractiveOptionsPage(Lifetime lifetime, ...)
: base(lifetime, ...) {
AddHeader("Tool...
Multiple machines
WPF on macOS/Linux
Rendering on Windows
Front-end on one machine,
back-end on another
...
Every IDE as both a client and server
Front-end and back-end: separate process & memory
Whatever happens in the backend, t...
Summary
Conclusion
Rider is an IDE built on
two IDE’s
two technology stacks
Rich and easy programming model was needed to bridge t...
Thank you!
https://blog.maartenballiauw.be
@maartenballiauw
NDC Sydney 2019 - Microservices for building an IDE – The innards of JetBrains Rider
You’ve finished this document.
Download and read it offline.
Upcoming SlideShare
What to Upload to SlideShare
Next
Upcoming SlideShare
What to Upload to SlideShare
Next
Download to read offline and view in fullscreen.

Share

NDC Sydney 2019 - Microservices for building an IDE – The innards of JetBrains Rider

Download to read offline

Ever wondered how IDE’s are built? In this talk, we’ll skip the marketing bit and dive into the architecture and implementation of JetBrains Rider.

We’ll look at how and why we have built (and open sourced) a reactive protocol, and how the IDE uses a “microservices” architecture to communicate with the debugger, Roslyn, a WPF renderer and even other tools like Unity3D. We’ll explore how things are wired together, both in-process and across those microservices. Let’s geek out!

Related Books

Free with a 30 day trial from Scribd

See all

Related Audiobooks

Free with a 30 day trial from Scribd

See all
  • Be the first to like this

NDC Sydney 2019 - Microservices for building an IDE – The innards of JetBrains Rider

  1. 1. Microservices for building an IDE The innards of JetBrains Rider Maarten Balliauw @maartenballiauw
  2. 2. JetBrains Rider demo
  3. 3. Rider Cross-platform, full-stack .NET IDE C#, VB.NET, F#, JavaScript, TypeScript, HTML, Xamarin, Unity, WinForms, WPF, … .NET full framework, .NET Core, Mono Lightweight, fast & yet a complete IDE! Helps you be more productive Editor, code assistance, navigation, refactoring ReSharper built-in NuGet, unit testing, DB tools, source control, REST client, … Tons of plugins! Free trial! www.jetbrains.com/rider
  4. 4. History
  5. 5. JetBrains Founded 2000 in Prague (Czech Republic) 2000 IntelliJ Renamer 2001 IntelliJ 2004 ReSharper 2019 20+ IDE’s and other developer tools
  6. 6. ReSharper IDE Project halted (but not gone to waste) Several concepts and architecture remained Keep functionality separate from the actual IDE Same core, IDE interoperability layer on top Visual Studio 2010, 2013, 2015, 2017 and 2019 ReSharper command line tools (CLI)
  7. 7. “When will JetBrains come with its own .NET IDE?”
  8. 8. Why build a .NET IDE? Many reasons! “When will JetBrains come with its own .NET IDE?” ReSharper constrained by Visual Studio environment 32 bit process resource constraints Changes in VS impact ReSharper .NET Core No good cross-platform IDE existed at the time
  9. 9. Cross-platform... A cross-platform UI toolkit is needed! ReSharper UI elements in WinForms and WPF Existing ReSharper UI would need converting, new UI to be built WinForms? (Mono sort of has it) GTKSharp? Qt?
  10. 10. IntelliJ Platform Foundation of all of our IDE’s Provides base infrastructure Project view, code completion, UI toolkit + Platform plugins such as version control, terminal, ... + JetBrains <product name> IDE plugins Open source (build your own IDE – e.g. Android Studio, Comma IDE & others) https://github.com/JetBrains/intellij-community Windows, Linux, Mac – already cross-platform thanks to JVM
  11. 11. IntelliJ Platform + R# ? IntelliJ Platform Great foundation to build on Windows, Linux, Mac JVM ReSharper (R#) All of those .NET inspections, refactorings, code generation, project model, ... .NET
  12. 12. Options! Rewrite R# in Java? 14 years of implementation and knowledge Would bring 2 R# implementations... Automatic conversion? Run R# as a command-line process Already possible (thanks, 2004!) “Just need our own UI on top”
  13. 13. IntelliJ Platform + R# ! Headless R# as a language server Cross-platform (.NET / Mono) No constraints It is ReSharper! 2 products, 1 code base IntelliJ as a thin UI Control the R# process
  14. 14. Both sides are an IDE... Is IntelliJ really a thin UI? Three cases... Features where IJ handles everything Features where R# handles almost everything Features where both IDE’s make a more awesome IDE
  15. 15. 1 + 1 = 3 demo
  16. 16. How to make them talk? Inter-process communication
  17. 17. Example: Context actions (Alt+Enter) 1. IntelliJ provides text editor, caret(s) and lets us Alt+Enter 2. Ask current document’s language for items to display in Alt+Enter menu For C#, this language is a facade to the R# process 3. IntelliJ renders list of items, may add its own entries Data: a tree of names and icons
  18. 18. 1. IntelliJ provides text editor and plumbing to display squiggles 2. IntelliJ notifies R# that a document was opened (or modified) 3. R# does its thing (analyze, inspect, summarize that data) 4. R# publishes this to IntelliJ 5. IntelliJ displays this info Data: a set of name, icon, severity, tooltip, text range Can’t do RPC! Analysis can take any amount of time, so IJ should not wait for it. ~~~~~~ Example: Inspections and highlighting
  19. 19. 1. Bi-directional User can be typing A refactoring or completion may be injecting code at the same time 2. Can be implemented with delta’s IntelliJ pushes delta to R# R# pushes delta to IntelliJ Concurrency? Data: a delta (from line + column, to line + column, text to insert) Example: Writing code
  20. 20. Types of data Context actions A tree of names and icons Inspections A set of name, icon, severity, tooltip, text range Writing code Delta with from line + column, to line + column, text to insert Fairly simple messages! Can we make this generic enough? Make one inspection work  make them all work
  21. 21. Which protocol do we use? Re-use Language Server Protocol (LSP)? Great in itself – IDE concepts like window, editor, language, diagnostics, ... We would need customizations for R# feature set Or build a custom REST-like protocol? Experimented with JSON, ProtoBuf, request/response style
  22. 22. Request-action-response LSP and custom protocol are request/response mostly Conflict resolution... What if both human and a refactoring make a change to code? How to keep things synchronized and in a healthy state? Realization: Why a “request-action-response” flow? Why RPC? Both IDE’s share a similar model and architecture Messages are simple, but for RPC they would need context (which solution, which file, state info, ...) – overhead!
  23. 23. Model-View-ViewModel (MVVM) IntelliJ is our view, ReSharper provides the model Protocol is the ViewModel, sharing lightweight data Project.Files.Add("Foo.cs") Project.Files["Foo.cs"].Inspections.Add( "Possible null reference", "Warning", 20, 30, 20, 42); Both processes can react to such change (observable + observer)
  24. 24. Conflict resolution... Changes to data in shared model can come from IJ and R# Can still cause conflicts due to features or timing/GC issues IntelliJ: “I just deleted file foo.cs” R#: “I just refactored foo.cs” Solutions! Locking? (freezes, how to handle deadlocks?) Conventions!
  25. 25. Conflict conventions! View + Model (or client: IntelliJ + server: ReSharper) Each value stored in the view model has a version Updates by the view/client increment the version Updates by the model/server do not Only accept changes if version is the same or newer If not, the change is discarded
  26. 26. Rider protocol
  27. 27. Obligatory diagram Ideally, our developers do not have to know the details of this. Just create view models.
  28. 28. Rider protocol “Reactive Distributed communication framework for .NET, Kotlin, JS, C++” Open source - https://github.com/jetbrains/rd 1. Include protocol libraries and build tools on all sides 2. Write view model in special DSL 3. Generate code 4. Work with generated model .NET/Kotlin/JS/... code generator Model definition DSL Primitives Conflict resolution, serialization, ... Sockets, batching, binary wire protocol
  29. 29. Rider protocol Only need to know about a few primitives Conflict resolution, wire protocol, timeouts, ... handled by protocol Code generated based on the defined view model Bonus points: no reflection/introspection needed on every run Hierarchical + lifetimes
  30. 30. Signal (event) Producers/subscribers Observable/observer Using lifetime to manage subscription // Produce event interface ISource<T> { void Fire(T value); } // Subscribe to event interface ISink<T> { void Advise(Lifetime l, Action<T> handler); } // Event interface ISignal<T> : ISource<T>, ISink<T> { }
  31. 31. Property Signal implementation Using lifetime to manage subscription To changes to propery in general To changes to specific value // Observable property interface IProperty<T> : ISink<T> { T Value { get; set; } void Advise(Lifetime l, Action<T> handler); void View(Lifetime l, Action<Lifetime, T> handler); }
  32. 32. Primitives Primitive Description Signal Event that is fired when something happens Property Observable value List/set/map Observable collections Field Immutable value Call/callback RPC-style call, needed from time to time byte, short, int, long, float, double, char, boolean, string, securestring, void, enum, ... Primitives and special types Aggregatedef/classdef/structdef A node in the viewmodel
  33. 33. Hierarchical + lifetimes Cleanup and resource management Objects attach to lifetime Lifetime destroys attached objects Parent lifetime destroys children NuGet: JetBrains.Lifetimes public class Lifetime : IDisposable { private Stack<Action> resources = new Stack<Action>(); public void Attach(Action resource) { resources.Push(resource); } public void Attach(IDisposable disposable) { resources.Push(disposable.Dispose); } public void Dispose() { while (resources.Count > 0) { var resource = resources.Pop(); resource(); } } }
  34. 34. Hierarchical + lifetimes Solution NuGet host Project Document Inspections PSI (Program Structure Interface) Class Field Method Document Inspections ... Project Local history NuGet tool window Project Editor tab Inspections Language Editor tab Inspections Language viewmodel(Riderprotocol)
  35. 35. Rider protocol demo
  36. 36. Rider protocol Very extensible through Kotlin-based DSL Easy to work with for our developers Update view model, generate code, work with generated code Find Usages, Navigation, ... work while crafting model No need to think about multiple processes, state, conflict resolution, ... Cross-language, cross-platform Plugin model for Rider is more complex (IJ and R# parts may be needed) https://github.com/JetBrains/fsharp-support https://github.com/JetBrains/resharper-unity
  37. 37. Microservices
  38. 38. Two processes! Isolation! Each has their own 64 bit memory space Also their own, separate GC Multi-core machines Start/stop independently
  39. 39. Debugging? Four processes. Rider (IntelliJ + ReSharper) Debugger worker process Your application
  40. 40. Multiple processes... What if certain features were running in their own process? No need to run all the time Own memory constraints Start/stop/crash independently
  41. 41. Shared view model Pass around a shared view model to interested parties Example: Roslyn analyzers/inspections Pass around “reference” of [ { name, icon, severity, tooltip, text range } ]
  42. 42. Shared view model
  43. 43. Multiple machines Socket-based wire protocol Sockets can be on multiple machines Example: Docker debugging Remote debugging
  44. 44. Unity game engine www.unity3d.com Extension to view model Rider plugin Unity editor plugin https://github.com/JetBrains/resharper-unity https://twitter.com/kskrygan/status/1064950644094705664
  45. 45. https://twitter.com/kskrygan/status/1064950644094705664
  46. 46. Future
  47. 47. Model the view as well public CSharpInteractiveOptionsPage(Lifetime lifetime, ...) : base(lifetime, ...) { AddHeader("Tool settings"); AddToolPathFileChooserOption(lifetime, commonFileDialogs); AddEmptyLine(); AddStringOption((CSIOptions s) => s.ToolArguments, "Tool arguments:", "Additional tool arguments"); AddHeader("Tool window behavior"); AddBoolOption((CSIOptions s) => s.FocusOnOpenToolWindow, "Focus tool window on open"); AddBoolOption((CSIOptions s) => s.FocusOnSendLineText, "Focus tool window on Send Line"); AddBoolOption((CSIOptions s) => s.MoveCaretOnSendLineText, "Move caret down on Send Line"); // ... FinishPage(); }
  48. 48. Multiple machines WPF on macOS/Linux Rendering on Windows Front-end on one machine, back-end on another ...
  49. 49. Every IDE as both a client and server Front-end and back-end: separate process & memory Whatever happens in the backend, the frontend can process the user's typing Bring this technology to other IDE’s? Reuse WebStorm's HTML/CSS/JS functionality in ReSharper (e.g. Visual Studio + R# using WebStorm in back-end mode)
  50. 50. Summary
  51. 51. Conclusion Rider is an IDE built on two IDE’s two technology stacks Rich and easy programming model was needed to bridge the two Protocol gave rise to more than two processes more than one machine micro UI Free trial! www.jetbrains.com/rider
  52. 52. Thank you! https://blog.maartenballiauw.be @maartenballiauw

Ever wondered how IDE’s are built? In this talk, we’ll skip the marketing bit and dive into the architecture and implementation of JetBrains Rider. We’ll look at how and why we have built (and open sourced) a reactive protocol, and how the IDE uses a “microservices” architecture to communicate with the debugger, Roslyn, a WPF renderer and even other tools like Unity3D. We’ll explore how things are wired together, both in-process and across those microservices. Let’s geek out!

Views

Total views

231

On Slideshare

0

From embeds

0

Number of embeds

6

Actions

Downloads

2

Shares

0

Comments

0

Likes

0

×