 Okay, thanks for joining my session. It's called embracing language service for blockchain development I try to put as many buzzwords as possible in into the title Let us look what it's about just one word to me and cast and I'm working for a company in Germany called item is and We are specialized on tool development and that's it's actually what what it's about today and Yeah, of course, we want to talk a little bit about blockchains and one block chain platform is Ethereum did you hear about the Ethereum already? Okay, and Yeah Short words about that If you're a miss a foundation Who runs? Yeah, a platform which allows you to to execute smart contracts on a blockchain so What is the smart contract? Actually a smart contract is a piece of code that you can deploy and execute On the blockchain so somehow you have to develop these contracts so in these contracts you can say okay under which conditions you do you transfer money from A to B or something like this and Yeah, you compile that code and deploy to the blockchain and just distributed over the blockchain and so it gets available for everyone and it's It's not yeah, infringible that's one of the benefits of blockchains and To execute smart contracts you actually need to have some kind of money. It's called gas and That's actually value. So you can buy gas and you have to use gas to execute transactions and You know what can you do with that? For example, this depends on Yeah, on how many transactions are running at the moment on the blockchain that's this this Determines the price of the gas so when many people are running transactions at the same time try to To get one transaction to one block that the gas prices increases and Let's this lead for me to some strange effect on one of the most popular application of blockchain on the field blockchain is selling and buying kittens and When many people do this these kittens get horribly expensive and I don't Who does this but this was one of the use cases that increase the ethereum gas price But the big question is how do we actually program something from the blockchain? It's Yeah, what we need to talk a little bit about and there are many programming languages out there But the most popular for for ethereum are called solidity and viper And I will call and I will talk now about the solidity language So what is solidity? It's a complete program language and with that program language you can write contracts It's similar to class to a class concept. So you have values your functions that you can call and this program language Yeah, provides you literally everything that you know from the modern program language like multiple inheritance and and Extension methods and multiple term values and so I'm literally I think everything is in this language So you have a nice language to define contracts and And this contract can be compiled to buy it code for the ethereum Virtual machine and then you can deploy it to the virtual machine and I'm a tool developer. I'm interested in providing good support for for that for that language that's actually An IDE provided by ethereum, which is called remix and It is a web-based IDE. Let's see if you have an internet connection and I can show you a live limit so Yeah, here it is So this is actually on Solidity code can add this online and Yeah, you can write simple programs And compile that code Actually, this code is not compilable because there's some syntax error in it And this is marked here Yeah But this is not really a good IDE For example, yeah, this is really annoying here And when I first for example content assist I literally see every keyword Every word that that is in the program and not what makes sense here I do not see Documentation other documentation like Java docs we are used to or I cannot cross reference to elements that are defined somewhere else This is all these things that we are used from modern IDE is not available so Coming back. We have a complex language, but the tooling is really crappy and The problem is if you make Errors here in contracts Then you can really lose money. There was one bug in 2017 where someone by accident called a suicide method on On the contract which Yeah, let's let to the fact that Yeah, millions of dollars were locked in the in the blockchain and just lost So it's really important that you know what you're throwing there And so you shouldn't see if there are errors in there if something make doesn't make sense. Maybe Yeah, do some Decent analysis and so and what you actually know from normal programming languages So what we can do about that? and This is what I'm what actually to talk about is a tool that we created the yakini Solidity tools and in this tool we implemented the Solidity language and providing a language server what this means I'm Telling you know about that. So coming back to it to a small demo showing this live so we see here again Solidity code and Oops, and I Okay, and you see for example here at the very beginning This is one thing that is Solidity is the first statement a pragma which compiler version should be used and maybe it's not the latest one and And here we get Immediately a proposal. Okay, you should maybe upgrade to that can use the quick fix here and immediately change that you can have Content assist For example if I press here Then I only get proposed what makes sense here to enter or here which functions can I call? So we have we have static information about types and all what All what you need, but what are you used from one of the languages? We take this now a step further This is working progress We are also building a tool which is called the your kind of stage our tools and actually you can't think about a contract like a state machine so you can Model this now visually and from that state machines We just cross-compile to to Solidity code and then deploy that to the blockchain So and this can also be simulated so you can simulate What effect does it have if you transfer some money or what whatever? Yeah, but this is Eclipse space you saw and Some people do not like eclipse. I actually love eclipse. I use it every day But I totally understand that there are other editors outside there and You may want to use the language not only in eclipse, but Maybe for different platforms and actually we provide the Solidity language already on four editors Besides the clips we also support eclipse here. I will show you that in a minute It's a web-based editor Visual Studio code and item and more to come. How do we achieve this and? Here we come to the language service What is a language server? We have typically a problem when we develop languages that There are several ideas out there and for each language and each IDE you have to implement tooling and and Yeah, if you would implement this natively for each IDE Then the language provider has plenty to do actually the language provider does not want to Get bothered how it is integrated into a certain IDE on The other side the IDE or editor developers don't want to care about languages they're coming languages every day and they can't support everything and Yeah, the ideas get blow up with with all the two links that that support the languages here and when and Here comes something in which is called the language server protocol When my course of start developing visual studio code they had exactly the same problem they developed a new IDE based on a type script and They needed a language support for typescript and C sharp and Others and then they thought okay. Do we re-implement the wheel again? No, they said, okay We can define a protocol which is to agnostic and Which decouples the editor from the language? So the editor is just Dumb and says okay. I'm opening that file and editing here something. I want to press content assist what can you offer me and a language server is Doing the hard stuff then for the language So the language server knows now, okay You're currently adding this file and at that offset you want to show on content assist I can you show these offers and this Was a good idea and There are stepped some other idea develop us up and implemented also this standard and So all the IDE developers are now they are driving the standard together with Microsoft and so You can now provide languages independently from the ideas The language server protocol is based on jason rpc. So basically it's sending jason messages from from tool to to the server and back and Yeah Works roughly like that You have the tool a user clicks on document and It says okay. I want to to open a document and tell the server here this file is open Then you start editing on the tools Sends text changes to the server knows. Ah, you are editing this document. I'm any entering a word and You put on the server on the other side can also send messages back to the tool say, okay What you entered is not really valid We have a syntax error here and this is my message There's a broad number of clients nowadays available that support the language server protocol And on the other side also brought variety of languages and This is ongoing work, but I can't expect that Editors and IDEs will support that protocol Actually, it does only cover Yeah, the typical 80% of what you actually need For the tooling and each tool has its own tweaks and which cannot be covered by a common protocol but Yeah, the normal things that you that you do is is done in the protocol already and you can also extend the protocol But then the extension must be known both by the client and the server Quick fixes such an example, which is only provided by by the eclipse ID and We provide implementation for quick fixes and yeah, you can see that Then eclipse the protocol is language independent, but there exists a binding for Java So when you're programming any language which are based on or implemented in Java Then it's good to start with this project. It's P4j. It's a framework. It's a library that implements all the messages That protocol defines And of course if you are programming language serving a different language, then you have to use different library We implemented that with Java and especially with a framework called x-text That's actually my work what I'm daily doing. I'm working on that project and x-text is a Framework to develop languages. So when you want to implement programming languages or domain specific languages Then this is a way to go With x-text you can Yeah, I'll describe very simple on a language defined by a grammar Creates all the implementation you get all the editor integration out of the box and also you can build language service with that so I Will now dig a little bit into the code to give you impression What's behind that to build a language service facility? And this is our Development environment see it's quite a bunch of projects that we have here, but there's one project that is most important which contains the language definition and if you're known a little bit to language design, then you know that You need some kind of grammar to describe the language It's Yeah, closely to a BNF form, but we mix concrete and abstract syntax So we also see Keywords that the language supports in the grammar what we do from this is generate a grammar for So behind our parser technology is on there But we this this grammar is much simpler than on the grammar And so here's on the complete definition of of Solidity language It's not that huge Just font lines of codes are you to need that you need for all the rules and Yeah, when you when you have to define that you typically run the code generator and This is what when xx come into play and generate the infrastructure for for the tooling so what you get is The parser you get Syntax highlighting you get cross-linking so scoping is implemented. We have a nice outline view here, so it can Where is it? I think it's Ah, it's here. Okay, so you can directly Navigate to elements. This is what you what you get for free when you use xx for any language that you develop and Solidity is just one example that we develop with that Now let's have a look at the language server. Um, so we saw already that that it's working in eclipse and Now let's look at here So this is now a browser ID you could you could deploy this on the web and Yeah, you have the same things that you that you're Used to from from the eclipse editor So it it proposes you what you can do here It repots when you're writing something wrong so whatever you need and Yeah, the server behind that is the same in eclipse in fear in atom in our visual studio You develop the language once create an application. It's actually in the runnable Java application just and Then you need to provide tool-specific Yan integration For eclipse you would need to write a small eclipse plug-in which use lsp4e for example Invisual studio code you would write in VS code extension, which is an NPM package same for fear and Yeah, it depends on on the tool how it integrates the language server basically what it does and does You describe this is my file extension and whenever you open a file extension start the language server and communicate with that So this is the integration work, but the language server is just wrote written once Okay So let's wrap up We have Ethereum which is a platform to execute smart contracts to execute them you need money and gas and To write such contracts you need programming language and one of those is Solidity with the language server protocol it um, we are We are able now to develop one language and provide to different ID is almost all of ID is support that at the moment and Yeah, we just implemented a Solidity language was an existing language With means of power of x-text and so we get on language server for Solidity. Yeah, and so we have Provide good tooling now for this program language. Okay. I'm already done I'm open now for questions Yes There may be some some very important thing to Talk about maybe the question. What what about privacy send does it send file? One important thing about language services. The word server is Misleading it's not that you run the language servers somewhere on the server and the client is on a different machine It's usually bound to the same machine. It's just separation of concerns you have one process which is the client the tool and the server on the same machine also on the same file system and It's even bound to the user. So it interacts with the user Yes Question is is it hard to add a speed support to x-text? answers no it's actually quite easy and It's already integrated. So you don't have to care about that. So the frame that x-text integrates language server support Through lsp4j and you just don't have to care about that So the only thing is that you have to build your language. I'm using maven or gradle and You can get this out of the box that you You get built scripts that produce you the language server for that question behind Question is do we have experience with integrating language seven and intelligent J? Yes, but not good ones It's actually at the moment that IntelliJ is lacking behind They have there's some some plug-in develop externally that provides language service support But yeah, it works Okay No, the best Lsp support you actually get at the moment is Visual Studio and Eclipse Question was how is Ethereum involved here? Was it our initiative to develop this language? Yes, it was our initiative because we we started to to work with Ethereum and then we saw okay to sucks You can't really work with that and we are an expert in in language development. So then we said, okay we start with that but The fear on foundation is foundation that collects money from its members and also spreads money to to users and we We got a grant to to work on solidity tools on so they partially funded the development now Okay, then no more questions Thank you very much for your attention