{"id":715,"date":"2017-03-31T13:35:58","date_gmt":"2017-03-31T13:35:58","guid":{"rendered":"http:\/\/dlang.org\/blog\/?p=715"},"modified":"2021-10-08T11:11:01","modified_gmt":"2021-10-08T11:11:01","slug":"project-highlight-workspace-d","status":"publish","type":"post","link":"https:\/\/dlang.org\/blog\/2017\/03\/31\/project-highlight-workspace-d\/","title":{"rendered":"Project Highlight: workspace-d"},"content":{"rendered":"<p>Not so long ago, Jan Jurzitza sat down at his keyboard intent on writing a D plugin for <a href=\"https:\/\/atom.io\/\">Atom<\/a>, his text editor of choice at the time. Then came disappointment.<\/p>\n<p>\u201cI was pretty unhappy with their API,\u201d he says.<\/p>\n<p>Visual Studio Code was released a short time after. He decided to give it a go and \u201cinstantly fell in love with it\u201d. His Atom plugin was pushed aside and he started work on a new plugin for VS Code called <a href=\"https:\/\/github.com\/Pure-D\/code-d\">code-d<\/a>.<\/p>\n<blockquote><p>However, I did not want to maintain the same functionality in two plugins for two different text editors, so I thought that making a program which contains most of the plugin logic, like starting and calling dcd, dscanner, dfmt, etc., would be beneficial and would also help with including D support in more editors and IDEs in the future.<\/p><\/blockquote>\n<p>For the uninitiated, <a href=\"https:\/\/github.com\/Hackerpilot\/DCD\">DCD (the D Completion Daemon)<\/a>, <a href=\"https:\/\/github.com\/Hackerpilot\/Dscanner\">DScanner<\/a>, and <a href=\"https:\/\/github.com\/Hackerpilot\/dfmt\">Dfmt<\/a> are D-oriented tools for plugin developers, all maintained by Brian Schott. They are, respectively, a client-server based auto-completion program, a source code analyzer, and a code formatter. A number of <a href=\"http:\/\/wiki.dlang.org\/IDEs\">IDE<\/a> and <a href=\"http:\/\/wiki.dlang.org\/Editors\">text editor<\/a> plugins employ them directly.<\/p>\n<p>So Jan started work on his new tool and named it <a href=\"https:\/\/github.com\/Pure-D\/workspace-d\">workspace-d<\/a>.<\/p>\n<blockquote><p>With workspace-d I want to make it simple for plugin developers to integrate D functionality into their editor of choice. workspace-d is designed to work both as a standalone program through stdio and as a D library. Once I ported most of the code from my Atom extension to workspace-d, I could simply spawn it as a subprocess in code-d, which I got working with it quite quickly.<\/p><\/blockquote>\n<p>In addition to porting his <a href=\"https:\/\/github.com\/Pure-D\/atomize-d\">Atom plugin<\/a> to use workspace-d, he also created <a href=\"https:\/\/github.com\/Pure-D\/sublime-d\">one for Sublime Text<\/a>. Currently, he\u2019s not devoting any time to either and is looking for someone else to take over maintenance of one or both. Anyone interested might start by submitting pull requests. Aside from workspace-d itself, Jan\u2019s focus is on code-d.<\/p>\n<p>He\u2019s recently been working on version 2.0 of workspace-d, with a focus on streamlining the way it handles requests.<\/p>\n<blockquote><p>Using <a href=\"http:\/\/dlang.org\/spec\/traits.html\">traits<\/a>, <a href=\"http:\/\/dlang.org\/spec\/template.html\">templates<\/a>, and <a href=\"http:\/\/dlang.org\/spec\/function.html#interpretation\">CTFE<\/a>\u00a0(Compile-Time Function Execution), basically all D compile time magic, I was able to make an automatic wrapper for the functions for version 2.0. Basically, when a request like <code>{\"cmd\":\"hello\"}<\/code> comes in, it runs the D function <code>hello<\/code> with its default arguments. If the arguments don\u2019t match, it responds with an error. This system automatically binds function arguments to JSON values and generates a response from the return value.<\/p><\/blockquote>\n<p>To deserialize the JSON requests, he\u2019s using <a href=\"https:\/\/github.com\/BlackEdder\/painlessjson\">painlessjson<\/a>, a third-party library available in <a href=\"https:\/\/code.dlang.org\/\">the DUB package registry<\/a>.<\/p>\n<blockquote><p>It works really great and I can really recommend it for some simple and easy conversions between D types and JSON. This change really cleaned up all the code and made it possible to use workspace-d as a library.<\/p><\/blockquote>\n<p>He&#8217;s also working on a new project,\u00a0<a href=\"https:\/\/github.com\/Pure-D\/serve-d\">serve-d<\/a>, that works with Microsoft\u2019s <a href=\"https:\/\/github.com\/Microsoft\/language-server-protocol\">Language Server Protocol<\/a>.<\/p>\n<blockquote><p>serve-d is an alternative for the workspace-d command line I\/O for those who prefer JSON RPC over my custom binary\/JSON mix. It\u2019s fiber based and uses workspace-d as a library, which results in really clean code. There\u2019s an alpha version of the implementation on github already, both the server and a new branch on code-d. With the Language Server Protocol, I\u2019m hoping for easier integration in other editors. The concept is basically the same as workspace-d\u2019s command line interface, but, because Microsoft is such a big company, I\u2019m hoping that more editors by big developers are going to implement this protocol.<\/p><\/blockquote>\n<p>Building and installing workspace-d should go pretty smoothly on Linux or OS X, but it\u2019s currently a little bumpy on Windows. Because of an issue Jan has yet to resolve, it can only be built on Windows with <a href=\"https:\/\/github.com\/ldc-developers\/ldc\/releases\">LDC<\/a>.<\/p>\n<blockquote><p>The auto completion didn\u2019t work for some people on Windows because it got stuck in the <code>std.process.execute<\/code> function when creating a pipe to write to. I couldn\u2019t find any way to reproduce it in a standalone program so I couldn\u2019t file a bug either. So what we did to avoid this issue in the short term was to simply disallow compilation on Windows using DMD. It works just fine when compiled with LDC.<\/p><\/blockquote>\n<p>Jan\u2019s primarily a Linux user (he doesn\u2019t own a Mac and only runs Windows in a VM). He credits GitHub user <a href=\"https:\/\/github.com\/Andrepuel\">@Andrepuel<\/a> for getting it operational on OS X, and <a href=\"https:\/\/github.com\/aka-demik\">@aka-demik<\/a> for finding the issue on Windows and verifying that it compiles with LDC. He\u2019ll be grateful to anyone who can help fully resolve the Windows\/DMD issue once and for all.<\/p>\n<p>If you&#8217;re looking to develop a D plugin for your favorite editor, consider taking advantage of the work Jan as already done with workspace-d to save yourself some effort. And VS Code users can put it to use via code-d\u00a0to get code completion and more. Visit its <a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=webfreak.code-d\">VS Code marketplace page<\/a> to read reviews and installation instructions.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Not so long ago, Jan Jurzitza sat down at his keyboard intent on writing a D plugin for Atom, his text editor of choice at the time. Then came disappointment. \u201cI was pretty unhappy with their API,\u201d he says. Visual Studio Code was released a short time after. He decided to give it a go [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[12,17,13],"tags":[],"_links":{"self":[{"href":"https:\/\/dlang.org\/blog\/wp-json\/wp\/v2\/posts\/715"}],"collection":[{"href":"https:\/\/dlang.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dlang.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dlang.org\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dlang.org\/blog\/wp-json\/wp\/v2\/comments?post=715"}],"version-history":[{"count":4,"href":"https:\/\/dlang.org\/blog\/wp-json\/wp\/v2\/posts\/715\/revisions"}],"predecessor-version":[{"id":719,"href":"https:\/\/dlang.org\/blog\/wp-json\/wp\/v2\/posts\/715\/revisions\/719"}],"wp:attachment":[{"href":"https:\/\/dlang.org\/blog\/wp-json\/wp\/v2\/media?parent=715"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dlang.org\/blog\/wp-json\/wp\/v2\/categories?post=715"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dlang.org\/blog\/wp-json\/wp\/v2\/tags?post=715"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}