Using Nuclide as an IDE for Swift Compiler Development
I've started using Nuclide when working on the Swift compiler source code. Why?
- Nuclide provides type-aware autocompletion. That means that, as can be seen in the GIF above, the only autocompletion candidates for
StaticSpellingKind::
are members of thatenum
. - Nuclide also displays the documentation for its autocompletion candidates inline.
- Hovering over a symbol in Nuclide displays its documentation.
- Nuclide can jump to any symbol's declaration. And on OS X, this is even mapped to Cmd-Click, just like Xcode.
- Nuclide integrates with lldb. I can set breakpoints on a particular line, and I can print debugger values from within Nuclide.
- Nuclide works in both of my development environments: OS X and Linux.
- Nuclide supports syntax highlighting and diagnostics for Python, and I can download plugins for CMake and Swift support, too.
- Nuclide displays C++ and Python errors inline. It compiles the code in the background to warn me of errors right away, saving me from spending time compiling at the command line.
- It has other features I'd expect in any editor: split panes, fuzzy file search, symbol search, and more.
- I can implement any feature Nuclide is lacking by creating my own plugin. Next time I have a free weekend, I'm planning on writing a plugin to run a Swift test:
In short, Nuclide provides the rich IDE-like features I enjoy from Xcode, but maintains the plugin-based customizability and cross-platform support I'd expect from Sublime Text or Vim.
Setting Up Nuclide (on OS X)
Installing Nuclide takes a few seconds; just follow the instructions on the website.
To work its magic, Nuclide needs a list of the commands use to compile each file in the Swift codebase. You can generate that list by running the following commands from your Swift checkout root:
$ # 1. Generate the list.
$ utils/build-script --make --export-compile-commands
$ # 2. Symlink it to the root of your project.
$ ln -s ../build/Unix_Makefiles-DebugAssert/swift-macosx-x86_64/compile_commands.json compile_commands.json
That's it! Open apple/swift in Nuclide and enjoy. :)
Setting Up Nuclide (on Linux)
Note: The libclang integration preferences described in this section are still being developed by the Nuclide team, and haven't been released yet. Expect an update next week.
Just like OS X, install Nuclide and run the following two lines from your Swift checkout root:
$ # 1. Generate the list of compile commands.
$ utils/build-script --make --export-compile-commands
$ # 2. Symlink it to the root of your project.
$ ln -s ../build/Unix_Makefiles-DebugAssert/swift-linux-x86_64/compile_commands.json compile_commands.json
On Linux you'll need to install libclang, and tell Nuclide where it's installed. Assuming you're using Clang 3.6 to compile Swift, install libclang 3.6:
$ sudo apt-get install -y libclang-3.6-dev
Open your Nuclide preferences and set the libclang path. On Ubuntu 15.10, it's /usr/lib/llvm-3.6/lib/libclang.so
.
And that's it!
What alternatives are there to Nuclide?
I had been using SublimeText before. It supports CMake and Python, but doesn't have type-aware autocompletion.
I also tried Vim. Using YouCompleteMe I was able to get type-aware autocompletion, but it was much harder to set up than Nuclide.
On OS X, I also tried Xcode. You can use the following command to generate an Xcode project for the Swift codebase:
$ utils/build-script --xcode
I normally love Xcode, but it doesn't suit me for Swift compiler development. It doesn't work on Linux, and it doesn't support CMake or Python. The Swift.xcodeproj
file contains a weird directory structure that looks nothing like what's on the filesystem. Autocompletion is okay, but not as good as Nuclide's.
If you use an editor not mentioned here, and you think I should try it out, tweet me!
Tweet