Editing Dlang sources in KDE March 14, 2018, 3:37 p.m.
Tags: { , , , , } Category: Programming

So you decided to jump into the adventurous Dlang world and now in search for a proper text editor? If so you can try Kate, the famous text editor from KDE Apps. First thing you probably have to consider is sources highlighting, which Kate already has for *.d files, so you’re good here. Second thing you’ll probably need is autocompletion and now starts the tricky part. But we’ll get what we want in the end.

We’ll start with setting Kate up. Go to Settings and enable Lumen plugin:

enabling Lumen plugin in Kate

Then check if autocompletion is enabled:

Kate autocompletion settings

Now you have to get and compile the dcd completion engine. The easiest way to do so is by using dub tool:

$ dub fetch dcd
$ dub build --config=client dcd
$ dub build --config=server dcd

Don’t forget to copy or symlink resulting binaries into one of the $PATH dirs:

$ sudo ln -s $HOME/.dub/packages/dcd-*/dcd/bin/dcd-server /usr/local/bin/
$ sudo ln -s $HOME/.dub/packages/dcd-*/dcd/bin/dcd-client /usr/local/bin/

By that step everything should be ready: you can run Kate end enjoy the completion working. But it wasn’t so in my case. I got spammed with unable to complete: client didn't finish in time messages in the console output and completion was not working. This was happening because dcd-client commands weren’t finishing in time, exactly as it says. Maybe because dcd got a bit heavier since the time when Lumen plugin was created. So I had to edit the Kate sources and recompile them. I opened addons/lumen/dcd.cpp, found a line:

static const int TIMEOUT_COMPLETE = 200;

and then replaced 200 with 2000. By the way, default timeout for QProcess::waitForFinished() is 30000 and there’s not much sense to make it smaller here. After recompilation everything was working.

Kate Dlang completion with Lumen plugin

Update: Strangely enough Kate 17.2.3 built against Qt 5.9.4 doesn’t need this patch anymore. Maybe QProcess got some speed-up, not really sure.