Support for the D Programming Language within IntelliJ IDEA (planned Clion support is experimental. See CLion issues)
Branch | Status |
---|---|
Master | |
Develop |
The primary focus for the project is to support Intellij IDEA (both IC and IU). Some work has been done to try and support CLion but it's not currently usable. It may work on other IDEs such as AppCode, Android Studio, PyCharm, etc but this is not tested by the dev team.
We generally try to support the last years worth of IDE releases. The current build targets Intellij 2023.3 - 2024.2.
For a list of older releases and their supported IDE versions see our Compatibility Matrix.
Assuming you have IntelliJ IDEA, CLion (or another Intellij based IDE installed), you can simply install the plugin via the IDE:
Go to Settings (Preferences on Mac) > Plugins > Browse Repositories and search For "D Language" (you may see 2 plugins, Choose the DLanguage one) then click install and restart IntelliJ
You can also download the plugin jar to your local disk directly from the Jetbrains plugin repository and then in IntelliJ go to Preferences > Plugins > Install plugin from disk and choose the jar you downloaded
After the plugin has been installed you will need to set dmd up as project SDK and configure dub
This plugin is maintained by a very small team of volunteers in their spare time. There are issues that need to be resolved both to add new features and simply keep the plugin compatible with new versions of Intellij. As the project relies on the good will of its contributors, progress can sometimes take a while. Please consider this when creating new issues. You can help by using the plugin and raising issues for feature requests and bugs. Even better get involved and submit pull requests.
If you have an existing dub project you can import it via File > Import Project
When you select this to create a new project with dub, if dub is on your path, it will attempt to use dub init to create a new dub project for you. If dub is not on your path it will create a source directory and you will have to create your sdl/json dub file manually or rename/delete the source folder and then use dub init to recreate it. Alternatively you can open an existing dub project by doing: File -> Open
Once a dub project is loaded, there is right click menu option to run with dub, or you can use the run config – run with Dub.
Before running go and configure the DTools in Settings -> Languages & Frameworks -> D Tools.
There is very basic dub dependency support via Tools > Process D Libraries
It reads the dub dependencies and loads the libraries into the External Libraries
If you add the d-unit dependency to your dub.json d-unit and then run Process D Libraries you will be able to run d-unit tests
The best option is to do and get the following tools and build them according to their GitHub page instructions:
If you put these tools on your path you can go to (Settings -> Languages & Frameworks -> D Tools) and just click autofind on each of the tools and it will find them. Otherwise you will need to select the correct path to the tool for each one.
There is a nice blog post about setting up the tools at: www.samael.me.uk
To configure DCD in the dcd-server add a comma separated list of paths that point to your libraries that you want to include in autocompletion.
For example:
/Library/D/dmd/src/phobos,/Library/D/dmd/src/druntime/import,/Users/hendriki/.dub/packages/rainbow-master/src
This will add the phobos and druntime/import as well as my rainbow dub project. You can add other dub packages by adding the path to them. I should be able to autoconfigure this stuff in a future release.
UPDATE: all project files are now automatically added to DCD and if on MacOS/OSX/macOS the D sources are also added automatically. The position on Linux and Windows is not currently clear since this work was done on OSX.
I noticed that after a while the auto completion seemed to cause the editor to hang. As a first step I have added a menu action in Tools as the last option to Restart the DCD Server. This action will just kill the running process and restart it again which seems to fix the hanging issue. I will investigate further to find a way to prevent the hanging in the first place but this is a helpful restart action.
To reformat D code use the shortcut or the menu item - Code -> Reformat Code with D Format (ctrl+alt+K) or on mac (cmd+alt+K)
Go to Preferences -> Editor -> Colors and Fonts -> D File
You can customize the syntax highlighting colours here. Save as a new theme - and then untick the inherit from checkbox and this will allow you to choose a colour for each item. Only the native items will show as changing in the code example. From function definition downwards the options are related to annotated highlighting which is based on the grammar and not the lexer. So these don't show as changing the code example but they do work.
Here are some screenshots of progress to date:
Dtools configuration
Autocompletion using DCD
Compile checking
Dscanner Code Linting
Goto Class
Configure Syntax Highlighting
Improved Syntax Highlighting with Annotator:
Syntax Highlighting and PSI Structure:
Create a new D project:
Module Settings - add D compiler:
Module Settings - set D compiler in project:
Add new D file (from right click menu)
D file editor:
Run Configuration menus:
Run Configuration create box:
Run Configuration edit:
Run Configuration running:
PSI Tree and Highlighting:
Contributions are accepted via fork and pull request but please co-ordinate via issues so we don't duplicate effort.
read this document: developing custom language plugins for IntelliJ
also see this document for getting the environment setup: plugin development
this one is also helpful: make a plugin in less than 30 mins
The project uses Gradle with the gradle-intellij-plugin. Simply use the Gradle wrapper in the root of the project to build the plugin using the following:
./gradlew buildPlugin
You can also use the plugin to boot up a stand alone instance of IntelliJ with the plugin installed using:
./gradlew runIde
or to run against a specific Intellij version use:
./gradlew runIde -PideaVersion=2018.3.5
This plugin uses portions of code from another project. There original copyright statement is below:
Copyright (c) 2017 Patrick Scheibe
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.